{"record":{"id":"a92298d6a104b4d6","repo":"apache/hadoop","slug":"rename-destination-parent-not-found","errorCode":null,"errorMessage":"rename destination parent {} not found.","messagePattern":"rename destination parent (.+?) not found\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java","lineNumber":424,"sourceCode":"          error);\n      throw new IOException(error);\n    }\n\n    BlockStoragePolicySuite bsps = fsd.getBlockStoragePolicySuite();\n    fsd.ezManager.checkMoveValidity(srcIIP, dstIIP);\n    final INode dstInode = dstIIP.getLastINode();\n    List<INodeDirectory> dstSnapshottableDirs = new ArrayList<>();\n    if (dstInode != null) { // Destination exists\n      validateOverwrite(src, dst, overwrite, srcInode, dstInode);\n      FSDirSnapshotOp.checkSnapshot(fsd, dstIIP, dstSnapshottableDirs);\n    }\n\n    INode dstParent = dstIIP.getINode(-2);\n    if (dstParent == null) {\n      error = \"rename destination parent \" + dst + \" not found.\";\n      NameNode.stateChangeLog.warn(\"DIR* FSDirectory.unprotectedRenameTo: \" +\n          error);\n      throw new FileNotFoundException(error);\n    }\n    if (!dstParent.isDirectory()) {\n      error = \"rename destination parent \" + dst + \" is a file.\";\n      NameNode.stateChangeLog.warn(\"DIR* FSDirectory.unprotectedRenameTo: \" +\n          error);\n      throw new ParentNotDirectoryException(error);\n    }\n\n    validateNestSnapshot(fsd, src,\n            dstParent.asDirectory(), srcSnapshottableDirs);\n    checkUnderSameSnapshottableRoot(fsd, srcIIP, dstIIP);\n\n    // Ensure dst has quota to accommodate rename\n    verifyFsLimitsForRename(fsd, srcIIP, dstIIP);\n    Pair<Optional<QuotaCounts>, Optional<QuotaCounts>> quotaPair =\n        verifyQuotaForRename(fsd, srcIIP, dstIIP);\n\n    RenameOperation tx = new RenameOperation(fsd, srcIIP, dstIIP, quotaPair);","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java#L406-L442","documentation":"FileNotFoundException when the destination's parent directory does not exist - HDFS rename never creates missing parents, so the new name must live inside an existing directory. It fires when dstIIP's second-to-last inode is null, after src/dst validation succeeded.","triggerScenarios":"`hdfs dfs -mv /src /newdir/dst` where /newdir does not exist; renaming into a date-partitioned directory the job forgot to create; dst parent deleted concurrently between resolution and validation.","commonSituations":"Pipeline steps that mkdir output partitions only on success paths; ordering bugs where the move runs before the mkdir; destination paths built with a date string that skips a level.","solutions":["Create the parent first: `hdfs dfs -mkdir -p <dstParent>` then retry the rename.","Fix step ordering in the job so directory creation precedes the move.","In code, pre-check fs.exists(dst.getParent()) and mkdirs it when absent."],"exampleFix":"// before\nfs.rename(new Path(\"/staging/part\"), new Path(\"/out/2026/08/22/part\")); // parent /out/2026 missing\n\n// after\nPath dst = new Path(\"/out/2026/08/22/part\");\nif (!fs.exists(dst.getParent())) fs.mkdirs(dst.getParent());\nfs.rename(new Path(\"/staging/part\"), dst);","handlingStrategy":"validation","validationCode":"Path parent = dst.getParent();\nif (!fs.exists(parent) && !fs.mkdirs(parent)) {\n  throw new IOException(\"Could not create destination parent \" + parent);\n}\nfs.rename(src, dst);","typeGuard":null,"tryCatchPattern":"try {\n  fs.rename(src, dst);\n} catch (FileNotFoundException e) {\n  if (!fs.exists(dst.getParent())) {\n    fs.mkdirs(dst.getParent());\n    fs.rename(src, dst);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Ensure output-partition directories are created before the move step in pipelines.","Add fs.exists(dst.getParent()) guards at every rename site that builds paths dynamically."],"tags":["hdfs","rename","file-not-found","destination"],"backgroundTag":"destination-parent-missing","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}