apache/hadoop · error · IOException
Har: truncate not allowed
Error message
Har: truncate not allowed
What it means
IOException thrown by HarFileSystem.truncate() because the HAR (Hadoop Archive) filesystem is read-only and does not support truncating files. Hadoop Archives (.har) are immutable collections of files created via 'hadoop archive'; operations that modify file contents (truncate, append, rename, setReplication, delete) are intentionally unimplemented. Fix: do not call truncate on paths inside a .har archive; instead unpack the archive (hadoop fs -cp har:///... localfs), truncate the extracted file on a writable filesystem, and re-create the archive if needed. This is an expected failure for programs that generically invoke FileSystem.truncate without checking whether the target filesystem supports modification.
Solutions
- Truncate the source file on the underlying HDFS and re-create the archive
- If the whole archive is disposable, delete the .har directory via the underlying filesystem
- Skip truncate calls for read-only filesystems by checking the scheme first
Example fix
// before
fs.truncate(new Path("har://hdfs-nn:8020/a/data.har/blob.bin"), 1024);
// after
hdfs.truncate(new Path("hdfs://nn:8020/a/data/blob.bin"), 1024);
// then rebuild the archive from the truncated tree Defensive patterns
Strategy: validation
Validate before calling
if ("har".equals(p.toUri().getScheme())) {
throw new UnsupportedOperationException("truncate is not supported on har; rebuild the archive instead");
} Prevention
- Replace truncate-based space reclamation on archives with full-archive rebuilds
- Skip truncate in generic file-management loops when the scheme is har
When it happens
Trigger: fs.truncate(harPath, newLength) on any har:// path — tools that shrink files or reclaim space, or generic file-management code that truncates instead of delete+recreate.
Common situations: Space-reclamation jobs sweeping all filesystems; ported code that relied on truncate semantics (e.g., HBase-style truncation) and now points at archived data.
Related errors
- Har: append not allowed.
- Har: completeLocalOutput not allowed
- Har: copyfromlocalfile not allowed
- Har: create not allowed.
- Har: delete not allowed
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/8fa0345593471e22.
Report an issue: GitHub.
Appendix: source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/HarFileSystem.java:769
throw new IOException("Har: setReplication not allowed");
}
@Override
public boolean rename(Path src, Path dst) throws IOException {
throw new IOException("Har: rename not allowed");
}
@Override
public FSDataOutputStream append(Path f) throws IOException {
throw new IOException("Har: append not allowed");
}
/**
* Not implemented.
*/
@Override
public boolean truncate(Path f, long newLength) throws IOException {
throw new IOException("Har: truncate not allowed");
}
/**
* Not implemented.
*/
@Override
public boolean delete(Path f, boolean recursive) throws IOException {
throw new IOException("Har: delete not allowed");
}
/**
* liststatus returns the children of a directory
* after looking up the index files.
*/
@Override
public FileStatus[] listStatus(Path f) throws IOException {
//need to see if the file is an index in file
//get the filestatus of the archive directoryView on GitHub (pinned to 2add963021)