{"record":{"id":"36f58eb9d080d5fa","repo":"apache/hadoop","slug":"mkdirs-failed-to-create-baddir","errorCode":null,"errorMessage":"Mkdirs failed to create ${badDir}","messagePattern":"Mkdirs failed to create (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalFileSystem.java","lineNumber":132,"sourceCode":"      String device = new DF(f, getConf()).getMount();\n      File parent = f.getParentFile();\n      File dir = null;\n      while (parent != null && FileUtil.canWrite(parent) &&\n          parent.toString().startsWith(device)) {\n        dir = parent;\n        parent = parent.getParentFile();\n      }\n\n      if (dir==null) {\n        throw new IOException(\n                              \"not able to find the highest writable parent dir\");\n      }\n        \n      // move the file there\n      File badDir = new File(dir, \"bad_files\");\n      if (!badDir.mkdirs()) {\n        if (!badDir.isDirectory()) {\n          throw new IOException(\"Mkdirs failed to create \" + badDir.toString());\n        }\n      }\n      String suffix = \".\" + rand.nextInt();\n      File badFile = new File(badDir, f.getName()+suffix);\n      LOG.warn(\"Moving bad file \" + f + \" to \" + badFile);\n      in.close();                               // close it first\n      boolean b = f.renameTo(badFile);                      // rename it\n      if (!b) {\n        LOG.warn(\"Ignoring failure of renameTo\");\n      }\n      // move checksum file too\n      File checkFile = ((RawLocalFileSystem)fs).pathToFile(getChecksumFile(p));\n      // close the stream before rename to release the file handle\n      sums.close();\n      b = checkFile.renameTo(new File(badDir, checkFile.getName()+suffix));\n      if (!b) {\n          LOG.warn(\"Ignoring failure of renameTo\");\n        }","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalFileSystem.java#L114-L150","documentation":"In the same bad-file quarantine flow, LocalFileSystem.reportChecksumFailure() creates <highest-writable-parent>/bad_files via mkdirs(); if mkdirs() returns false and the path is not already a directory, this IOException aborts moving the corrupt file (and its checksum) aside.","triggerScenarios":"reportChecksumFailure() quarantine when bad_files cannot be created: parent permissions changed between the canWrite scan and mkdirs, disk full, volume remounted read-only, or a non-directory file already occupies the bad_files name.","commonSituations":"Full disks, security hardening stripping write bits at runtime, leftover file named bad_files from earlier failed runs.","solutions":["Free space or repair the disk that holds the bad_files parent","chmod/chown the parent so the process user can create bad_files","Remove any non-directory entry named bad_files and rerun"],"exampleFix":"// before: bad_files cannot be created under the writable parent\n// after\n$ sudo -u <procuser> mkdir -p <writable-parent>/bad_files\n$ sudo chown <procuser> <writable-parent>/bad_files","handlingStrategy":"try-catch","validationCode":"File bad = new File(writableParent, \"bad_files\");\nif (!bad.isDirectory() && !bad.mkdirs()) {\n  throw new IOException(\"cannot create quarantine dir \" + bad);\n}","typeGuard":null,"tryCatchPattern":"try {\n  in = localFs.open(p);\n} catch (IOException e) {\n  // 'Mkdirs failed to create ...bad_files': free disk space / fix ownership, then re-read\n}","preventionTips":["Watch disk space on volumes holding local scratch data","Keep bad_files owned by the process user","Do not remount scratch volumes read-only at runtime"],"tags":["checksum","mkdirs","local-filesystem","disk-full","quarantine"],"backgroundTag":"mkdir-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}