apache/hadoop · error · IOException
Cannot truncate block to from oldlen (=${oldlen}) to newlen
Error message
Cannot truncate block to from oldlen (=${oldlen}) to newlen (=${newlen}) What it means
Error "Cannot truncate block to from oldlen (=${oldlen}) to newlen (=${newlen})" thrown in apache/hadoop.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/LocalReplica.java:488
FsPermission permission = new FsPermission(oldPermission.getUserAction(),
oldPermission.getGroupAction(), oldPermission.getOtherAction(), true);
localFS.setPermission(path, permission);
}
public static void truncateBlock(
FsVolumeSpi volume, File blockFile, File metaFile,
long oldlen, long newlen, FileIoProvider fileIoProvider)
throws IOException {
LOG.info("truncateBlock: blockFile=" + blockFile
+ ", metaFile=" + metaFile
+ ", oldlen=" + oldlen
+ ", newlen=" + newlen);
if (newlen == oldlen) {
return;
}
if (newlen > oldlen) {
throw new IOException("Cannot truncate block to from oldlen (=" + oldlen
+ ") to newlen (=" + newlen + ")");
}
// fis is closed by BlockMetadataHeader.readHeader.
final FileInputStream fis = fileIoProvider.getFileInputStream(
volume, metaFile);
DataChecksum dcs = BlockMetadataHeader.readHeader(fis).getChecksum();
int checksumsize = dcs.getChecksumSize();
int bpc = dcs.getBytesPerChecksum();
long n = (newlen - 1)/bpc + 1;
long newmetalen = BlockMetadataHeader.getHeaderSize() + n*checksumsize;
long lastchunkoffset = (n - 1)*bpc;
int lastchunksize = (int)(newlen - lastchunkoffset);
byte[] b = new byte[Math.max(lastchunksize, checksumsize)];
try (RandomAccessFile blockRAF = fileIoProvider.getRandomAccessFile(
volume, blockFile, "rw")) {
//truncate blockFileView on GitHub (pinned to 2add963021)
Solutions
- Verify the truncate length is not larger than the current block length and the replica is in a state that allows truncation.
- Retry the operation; if it repeats, check the block's recovery state and DataNode logs for conflicting writers.
When it happens
Trigger: A truncate request asks to change a block from oldlen to newlen in a way the replica does not support (e.g., newlen > oldlen or invalid state).
Common situations: A truncate was requested with a new length inconsistent with the current block length. Ensure the truncate length is smaller than the current length.
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/fbfbce019e1fcaf1.
Report an issue: GitHub.