{"record":{"id":"eb897bb62e05fe11","repo":"apache/hadoop","slug":"failed-to-delete-the-mapped-file-filepath","errorCode":null,"errorMessage":"Failed to delete the mapped file: {filePath}","messagePattern":"Failed to delete the mapped file: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"warning","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetUtil.java","lineNumber":232,"sourceCode":"      }\n\n      @Override\n      public InputStream getDataInputStream(long seekOffset)\n          throws IOException {\n        return Files.newInputStream(blockFile.toPath());\n      }\n    };\n\n    FsDatasetImpl.computeChecksum(wrapper, dstMeta, smallBufferSize, conf);\n  }\n\n  public static void deleteMappedFile(String filePath) throws IOException {\n    if (filePath == null) {\n      throw new IOException(\"The filePath should not be null!\");\n    }\n    boolean result = Files.deleteIfExists(Paths.get(filePath));\n    if (!result) {\n      throw new IOException(\n          \"Failed to delete the mapped file: \" + filePath);\n    }\n  }\n}\n","sourceCodeStart":214,"sourceCodeEnd":237,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetUtil.java#L214-L237","documentation":"deleteMappedFile calls Files.deleteIfExists and throws when it returns false - the mapped file was already gone (another cleanup won the race or the temp dir was purged) or cannot be unlinked (still mapped/open on some platforms, permissions). Only intermediate checksum temp data is affected, never block data.","triggerScenarios":"Concurrent cleanup racing (double invocation of the cleanup path); file already removed by temp-dir eviction; the mapped file still open where unlink requires closure; missing parent directory.","commonSituations":"Mostly benign, appearing when two shutdown paths clean the same mapped file; recurring hits suggest double-cleanup bugs in a patched build.","solutions":["If occasional during shutdown, treat as noise - the desired end state (file absent) already holds.","Check the stack for duplicate cleanup calls (two finally blocks deleting the same path) and remove the double delete.","Where unlink-while-mapped semantics apply, close/unmap the buffer before deleting.","Verify the temp location under dfs.datanode.data.dir is not swept by external tooling mid-run."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (filePath != null && Files.exists(Paths.get(filePath))) {\n  FsDatasetUtil.deleteMappedFile(filePath);\n}","typeGuard":null,"tryCatchPattern":"try {\n  FsDatasetUtil.deleteMappedFile(path);\n} catch (IOException e) {\n  if (Files.notExists(Paths.get(path))) {\n    // already gone: goal state reached, ignore\n  } else {\n    throw e;\n  }\n}","preventionTips":["Use a single cleanup path per mapped file; avoid double finally deletes.","Unmap/close the buffer before deleting on platforms that forbid unlink-while-open.","Keep external temp-dir sweepers away from DN storage directories."],"tags":["hdfs","datanode","file-delete","race-condition","checksum"],"backgroundTag":"file-delete-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}