{"record":{"id":"f1c56533e07b6912","repo":"apache/hadoop","slug":"unable-to-delete","errorCode":null,"errorMessage":"Unable to delete {}","messagePattern":"Unable to delete (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImagePreTransactionalStorageInspector.java","lineNumber":222,"sourceCode":"      NNStorage.getStorageFile(latestNameSD, NameNodeFile.IMAGE);\n    File ckptFile =\n      NNStorage.getStorageFile(latestNameSD, NameNodeFile.IMAGE_NEW);\n    \n    //\n    // If we were in the midst of a checkpoint\n    //\n    if (ckptFile.exists()) {\n      needToSave = true;\n      if (NNStorage.getStorageFile(latestEditsSD, NameNodeFile.EDITS_NEW)\n          .exists()) {\n        //\n        // checkpointing migth have uploaded a new\n        // merged image, but we discard it here because we are\n        // not sure whether the entire merged image was uploaded\n        // before the namenode crashed.\n        //\n        if (!ckptFile.delete()) {\n          throw new IOException(\"Unable to delete \" + ckptFile);\n        }\n      } else {\n        //\n        // checkpointing was in progress when the namenode\n        // shutdown. The fsimage.ckpt was created and the edits.new\n        // file was moved to edits. We complete that checkpoint by\n        // moving fsimage.new to fsimage. There is no need to \n        // update the fstime file here. renameTo fails on Windows\n        // if the destination file already exists.\n        //\n        if (!ckptFile.renameTo(curFile)) {\n          if (!curFile.delete())\n            LOG.warn(\"Unable to delete dir \" + curFile + \" before rename\");\n          if (!ckptFile.renameTo(curFile)) {\n            throw new IOException(\"Unable to rename \" + ckptFile +\n                                  \" to \" + curFile);\n          }\n        }","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImagePreTransactionalStorageInspector.java#L204-L240","documentation":"During recovery of a crashed pre-transactional checkpoint: if both fsimage.ckpt and edits.new exist, the inspector cannot know whether the SecondaryNameNode finished uploading the merged image, so it discards the checkpoint file. File.delete() returning false is turned into this IOException — an environment-level failure: missing permission, a file held open/locked, or a read-only filesystem.","triggerScenarios":"NameNode restart while fsimage.ckpt and edits.new both exist in current/, and java.io.File.delete() fails on ckptFile (permission denied, read-only mount, Windows file lock, stale NFS handle).","commonSituations":"name directory owned by root while the NN runs as hdfs; storage on a read-only or broken NFS export; antivirus or a lingering process holding the file open on Windows.","solutions":["Fix ownership/permissions so the NN user can write the name dir: chown -R hdfs:hdfs /dfs/name","Check for a stale in_use.lock or a second NameNode running against the same directories","Remount read-only filesystems read-write, or move storage off the broken NFS volume","Once you confirm no checkpoint is in flight, delete the stale fsimage.ckpt and edits.new manually and restart the NameNode"],"exampleFix":"# before: NN user cannot delete the checkpoint file\nls -l /dfs/name/current/fsimage.ckpt   # owned by root\n# after\nchown -R hdfs:hdfs /dfs/name && su - hdfs -c 'hdfs --daemon start namenode'","handlingStrategy":"validation","validationCode":"for (URI u : FSNamesystem.getNamespaceDirs(conf)) {\n  File cur = new File(u.getPath(), \"current\");\n  if (!cur.isDirectory() || !Files.isWritable(cur.toPath())) {\n    throw new IOException(\"name dir not writable by NameNode user: \" + cur);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the NN under a dedicated user that owns the name dirs (chown -R hdfs:hdfs)","Pre-start check: writable current/ dir, no foreign-owned files, no second NN (in_use.lock)","Avoid NFS-backed name storage with quirky delete/rename semantics"],"tags":["hadoop","hdfs","namenode","checkpoint-recovery","file-permissions","legacy-format"],"backgroundTag":"file-permission-denied","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}