{"record":{"id":"98a4db3b0d6d547c","repo":"apache/hadoop","slug":"cannot-truncate-lazy-persist-file-src","errorCode":null,"errorMessage":"Cannot truncate lazy persist file <src>","messagePattern":"Cannot truncate lazy persist file <src>","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirTruncateOp.java","lineNumber":101,"sourceCode":"    try {\n      iip = fsd.resolvePath(pc, srcArg, DirOp.WRITE);\n      src = iip.getPath();\n      if (fsd.isPermissionEnabled()) {\n        fsd.checkPathAccess(pc, iip, FsAction.WRITE);\n      }\n      INodeFile file = INodeFile.valueOf(iip.getLastINode(), src);\n\n      // not support truncating file with striped blocks\n      if (file.isStriped()) {\n        throw new UnsupportedOperationException(\n            \"Cannot truncate file with striped block \" + src);\n      }\n\n      final BlockStoragePolicy lpPolicy = fsd.getBlockManager()\n          .getStoragePolicy(\"LAZY_PERSIST\");\n\n      if (lpPolicy != null && lpPolicy.getId() == file.getStoragePolicyID()) {\n        throw new UnsupportedOperationException(\n            \"Cannot truncate lazy persist file \" + src);\n      }\n\n      // Check if the file is already being truncated with the same length\n      final BlockInfo last = file.getLastBlock();\n      if (last != null && last.getBlockUCState()\n          == BlockUCState.UNDER_RECOVERY) {\n        final BlockInfo truncatedBlock = last.getUnderConstructionFeature()\n            .getTruncateBlock();\n        if (truncatedBlock != null) {\n          final long truncateLength = file.computeFileSize(false, false)\n              + truncatedBlock.getNumBytes();\n          if (newLength == truncateLength) {\n            return new TruncateResult(false, fsd.getAuditFileInfo(iip));\n          } else {\n            throw new AlreadyBeingCreatedException(\n                RecoverLeaseOp.TRUNCATE_FILE.getExceptionMessage(src,\n                    clientName, clientMachine, src + \" is being truncated.\"));","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirTruncateOp.java#L83-L119","documentation":"Error \"Cannot truncate lazy persist file <src>\" thrown in apache/hadoop.","triggerScenarios":"Truncating a file that was created with the LAZY_PERSIST flag.","commonSituations":"See trigger scenarios.","solutions":["Do not truncate files with the LAZY_PERSIST storage policy; unset the policy or rewrite the file."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}