|
@@ -1966,6 +1966,21 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
throw new UnsupportedOperationException(
|
|
throw new UnsupportedOperationException(
|
|
"Cannot truncate lazy persist file " + src);
|
|
"Cannot truncate lazy persist file " + src);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Check if the file is already being truncated with the same length
|
|
|
|
+ final BlockInfoContiguous last = file.getLastBlock();
|
|
|
|
+ if (last != null && last.getBlockUCState() == BlockUCState.UNDER_RECOVERY) {
|
|
|
|
+ final Block truncateBlock
|
|
|
|
+ = ((BlockInfoContiguousUnderConstruction)last).getTruncateBlock();
|
|
|
|
+ if (truncateBlock != null) {
|
|
|
|
+ final long truncateLength = file.computeFileSize(false, false)
|
|
|
|
+ + truncateBlock.getNumBytes();
|
|
|
|
+ if (newLength == truncateLength) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// Opening an existing file for truncate. May need lease recovery.
|
|
// Opening an existing file for truncate. May need lease recovery.
|
|
recoverLeaseInternal(RecoverLeaseOp.TRUNCATE_FILE,
|
|
recoverLeaseInternal(RecoverLeaseOp.TRUNCATE_FILE,
|
|
iip, src, clientName, clientMachine, false);
|
|
iip, src, clientName, clientMachine, false);
|