{"record":{"id":"39d163d55d096d96","repo":"apache/hadoop","slug":"cannot-find-target-file-trg","errorCode":null,"errorMessage":"Cannot find target file - {trg}","messagePattern":"Cannot find target file - (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/async/RouterAsyncClientProtocol.java","lineNumber":320,"sourceCode":"              + \" allowed. The number of remote locations for both source and\"\n              + \" target should be same.\");\n        }\n        rpcClient.invokeConcurrent(locs, method);\n      } else {\n        rpcClient.invokeSequential(locs, method, null, null);\n      }\n    });\n  }\n\n  @Override\n  public void concat(String trg, String[] src) throws IOException {\n    rpcServer.checkOperation(NameNode.OperationCategory.WRITE);\n\n    // Concat only effects when all files in the same namespace.\n    getFileRemoteLocation(trg);\n    asyncApply((AsyncApplyFunction<RemoteLocation, Object>) targetDestination -> {\n      if (targetDestination == null) {\n        throw new IOException(\"Cannot find target file - \" + trg);\n      }\n      String targetNameService = targetDestination.getNameserviceId();\n      String[] sourceDestinations = new String[src.length];\n      int[] index = new int[1];\n      asyncForEach(Arrays.stream(src).iterator(), (forEachRun, sourceFile) -> {\n        getFileRemoteLocation(sourceFile);\n        asyncApply((ApplyFunction<RemoteLocation, Object>) srcLocation -> {\n          if (srcLocation == null) {\n            throw new IOException(\"Cannot find source file - \" + sourceFile);\n          }\n          sourceDestinations[index[0]++] = srcLocation.getDest();\n          if (!targetNameService.equals(srcLocation.getNameserviceId())) {\n            throw new IOException(\"Cannot concatenate source file \" + sourceFile\n                + \" because it is located in a different namespace\" + \" with nameservice \"\n                + srcLocation.getNameserviceId() + \" from the target file with nameservice \"\n                + targetNameService);\n          }\n          return null;","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/async/RouterAsyncClientProtocol.java#L302-L338","documentation":"In RouterAsyncClientProtocol.concat, the Router first resolves the target file's actual remote location (getFileRemoteLocation(trg)). A null targetDestination means no subcluster returned a file status for the target path, so concat cannot proceed and IOException('Cannot find target file - <trg>') is thrown. concat requires the target to exist because its nameservice determines where the concatenated blocks must live.","triggerScenarios":"WebHDFS/RPC concat where the target file does not exist in any namespace; target was deleted concurrently; mount table maps the target path to a different namespace than where it actually resides.","commonSituations":"Stale paths after file migration between subclusters; races between a listing and concat in job commit logic; mount table edits that re-route the target path.","solutions":["Verify the target exists via the Router (hdfs dfs -ls) and re-issue concat with the correct path","If the file exists in a subcluster but not through the Router, fix the mount entry for that path (hdfs dfsrouteradmin -ls / -add) and refresh","Guard against races by re-checking existence immediately before concat in job logic"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify target exists via the Router before concat:\nif (dfs.getClient().getNamenode().getFileInfo(trg) == null) {\n  // fail fast with a clear error instead of calling concat\n}","typeGuard":null,"tryCatchPattern":"catch (IOException e) {\n  if (e.getMessage().startsWith(\"Cannot find target file - \")) {\n    // refresh path or fix mount entry; do not retry blindly\n  }\n}","preventionTips":["Check target existence (and its namespace) immediately before concat in job commit code","Build concat target paths from a fresh listing rather than stored job state","Verify mount entries route the target where its data actually lives"],"tags":["hadoop","hdfs","rbf","concat","file-not-found","async-rpc"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}