{"record":{"id":"167dd0bfd8332417","repo":"apache/hadoop","slug":"destination-parentfile-directory-cannot-be-cre-167dd0","errorCode":null,"errorMessage":"Destination '{parentFile}' directory cannot be created","messagePattern":"Destination '(.+?)' directory cannot be created","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java","lineNumber":1362,"sourceCode":"    final File srcMeta = new File(srcReplica.getMetadataURI());\n\n    DataChecksum checksum;\n    try (FileInputStream fis =\n             srcReplica.getFileIoProvider().getFileInputStream(\n                 srcReplica.getVolume(), srcMeta)) {\n      checksum = BlockMetadataHeader.readDataChecksum(\n          fis, DFSUtilClient.getIoFileBufferSize(conf), srcMeta);\n    }\n\n    final byte[] data = new byte[1 << 16];\n    final byte[] crcs = new byte[checksum.getChecksumSize(data.length)];\n\n    DataOutputStream metaOut = null;\n    try {\n      File parentFile = dstMeta.getParentFile();\n      if (parentFile != null) {\n        if (!parentFile.mkdirs() && !parentFile.isDirectory()) {\n          throw new IOException(\"Destination '\" + parentFile\n              + \"' directory cannot be created\");\n        }\n      }\n      metaOut = new DataOutputStream(new BufferedOutputStream(\n          Files.newOutputStream(dstMeta.toPath()), smallBufferSize));\n      BlockMetadataHeader.writeHeader(metaOut, checksum);\n\n      int offset = 0;\n      try (InputStream dataIn = srcReplica.getDataInputStream(0)) {\n\n        for (int n; (n = dataIn.read(data, offset, data.length - offset)) != -1; ) {\n          if (n > 0) {\n            n += offset;\n            offset = n % checksum.getBytesPerChecksum();\n            final int length = n - offset;\n\n            if (length > 0) {\n              checksum.calculateChunkedSums(data, 0, length, crcs, 0);","sourceCodeStart":1344,"sourceCodeEnd":1380,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java#L1344-L1380","documentation":"Thrown as IOException from FsDatasetImpl.computeChecksum (reached via copyBlockFiles with calculateChecksum=true) when the destination meta file's parent directory cannot be created: parentFile.mkdirs() returns false AND parentFile.isDirectory() is false — i.e. creation failed and it is not already a directory. The message contains the offending parent path.","triggerScenarios":"Recomputing a replica's checksum into dstMeta on a volume where the parent subdir (e.g. .../current/finalized subdir or a lazy-persist destination) cannot be created: permissions deny mkdir, a non-directory file exists at the parent path, the filesystem is read-only or out of inodes.","commonSituations":"Destination volume mounted read-only after an array failure; a stray file occupies the dir path (partial restore/copy of data dirs); DataNode user lost group ownership on the volume; inode exhaustion on small filesystems.","solutions":["ls -ld the parent path from the message; if a regular file blocks the path, remove/rename it (usually debris from a failed restore).","chown -R hdfs:hadoop (or your DN user) the volume root and chmod u+w the parent chain.","mount/df the destination filesystem — read-only remounts and inode exhaustion (df -i) both fail mkdirs silently.","Retry the copy/move operation; with the parent creatable, checksum recompute proceeds."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure dst meta parent exists and is a writable dir before checksum copy.\nFile parent = dstMeta.getParentFile();\nif (parent != null) {\n  Files.createDirectories(parent.toPath()); // throws a descriptive reason\n  if (!parent.isDirectory() || !parent.canWrite()) {\n    throw new IOException(\"Cannot use destination dir: \" + parent);\n  }\n}","typeGuard":null,"tryCatchPattern":"// Surface the failing parent path to operators; retry after repair.\ntry {\n  fsDataset.copyBlockFiles(src, dstMeta, dstFile, true, bufSize, conf);\n} catch (IOException e) {\n  if (String.valueOf(e.getMessage()).contains(\"cannot be created\")) {\n    LOG.error(\"Destination dir unusable (see {}), fix mount/permissions\",\n        dstMeta.getParent());\n  }\n  throw e;\n}","preventionTips":["Pre-create destination dir trees with Files.createDirectories (which reports the real cause) instead of relying on mkdirs().","After any volume restore/clone, verify no regular file occupies a directory path in the data-dir tree.","Mount data volumes read-write and alert on read-only remounts (a common precursor to silent mkdirs failure)."],"tags":["hadoop","hdfs","datanode","fsdataset","checksum","mkdir","permissions"],"backgroundTag":"directory-creation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}