{"record":{"id":"586911034457085c","repo":"apache/hadoop","slug":"failed-to-delete-dir","errorCode":null,"errorMessage":"Failed to delete {dir}","messagePattern":"Failed to delete (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java","lineNumber":1388,"sourceCode":"          + \"' to '\" + destFile + \"'\");\n    }\n    if (preserveFileDate) {\n      if (destFile.setLastModified(srcFile.lastModified()) == false) {\n        LOG.debug(\"Failed to preserve last modified date from'{}' to '{}'\",\n            srcFile, destFile);\n      }\n    }\n  }\n\n  /**\n   * Recursively delete all the content of the directory first and then \n   * the directory itself from the local filesystem.\n   * @param dir The directory to delete\n   * @throws IOException\n   */\n  public static void deleteDir(File dir) throws IOException {\n    if (!FileUtil.fullyDelete(dir))\n      throw new IOException(\"Failed to delete \" + dir.getCanonicalPath());\n  }\n  \n  /**\n   * Write all data storage files.\n   * @throws IOException\n   */\n  public void writeAll() throws IOException {\n    this.layoutVersion = getServiceLayoutVersion();\n    for (Iterator<StorageDirectory> it = storageDirs.iterator(); it.hasNext();) {\n      writeProperties(it.next());\n    }\n  }\n\n  /**\n   * Unlock all storage directories.\n   * @throws IOException\n   */\n  public void unlockAll() throws IOException {","sourceCodeStart":1370,"sourceCodeEnd":1406,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java#L1370-L1406","documentation":"Storage.deleteDir wraps FileUtil.fullyDelete, which recursively removes a directory's contents and then the directory itself, returning false on any failure. This IOException therefore means the recursive delete did not fully succeed - some entry could not be removed.","triggerScenarios":"A file inside the directory is held open by another process (Windows locking, NFS silly-rename); a subdirectory or file is not writable/executable by the daemon user; the volume is read-only; SELinux denies unlink; path components changed during deletion.","commonSituations":"Cleaning up old checkpoint or storage dirs while a daemon still holds files; cleanup scripts running as the wrong user; NFS-backed temp dirs; containers with leftover handles.","solutions":["Find open handles under the directory (lsof +D <dir>) and close/stop the holders, then retry","Run the cleanup as the directory's owning user, or fix ownership: chown -R hdfs:hdfs <dir>","Confirm the filesystem is mounted read-write and no SELinux denial appears in the audit log","Retry after the concurrent writer/reader has exited"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (dir.exists() && (!dir.canRead() || !dir.canWrite())) {\n  throw new IOException(\"cannot clean \" + dir + \" as current user; fix ownership first\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  Storage.deleteDir(dir);\n} catch (IOException e) {\n  // list remaining entries, lsof them, stop holders, then retry once; otherwise rethrow\n  throw e;\n}","preventionTips":["Stop processes that hold files under the directory before cleanup","Run cleanup as the directory's owning user","Treat persistent fullyDelete failures as a signal of handles or SELinux, not of random corruption"],"tags":["hdfs","storage","delete","directory","permissions"],"backgroundTag":"directory-delete-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}