apache/hadoop · error · IOException
Har: truncate not allowed
Error message
Har: truncate not allowed
What it means
truncate would change the length of a byte range inside a har part file, which is immutable, so the override throws 'Har: truncate not allowed'. Only read APIs are implemented on HarFileSystem.
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)
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: create not allowed.
- Har: append not allowed.
- Har: setReplication not allowed
- Har: rename 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.