apache/hadoop · error · IOException
Cannot concatenate source file {} because it is located in a
Error message
Cannot concatenate source file {} because it is located in a different namespace with nameservice {} from the target file with nameservice {} What it means
HDFS concat physically appends blocks to the target file, which only works within a single NameNode namespace. The Router therefore checks every source's resolved nameservice against the target's; on mismatch it throws IOException naming the source file, its nameservice, and the target's nameservice. This is a structural limitation of concat under federation, not a transient error.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java:701
// Concat only effects when all files in the same namespace.
RemoteLocation targetDestination = getFileRemoteLocation(trg);
if (targetDestination == null) {
throw new IOException("Cannot find target file - " + trg);
}
String targetNameService = targetDestination.getNameserviceId();
String[] sourceDestinations = new String[src.length];
for (int i = 0; i < src.length; i++) {
String sourceFile = src[i];
RemoteLocation srcLocation = getFileRemoteLocation(sourceFile);
if (srcLocation == null) {
throw new IOException("Cannot find source file - " + sourceFile);
}
sourceDestinations[i] = srcLocation.getDest();
if (!targetNameService.equals(srcLocation.getNameserviceId())) {
throw new IOException("Cannot concatenate source file " + sourceFile
+ " because it is located in a different namespace" + " with nameservice "
+ srcLocation.getNameserviceId() + " from the target file with nameservice "
+ targetNameService);
}
}
// Invoke
RemoteMethod method = new RemoteMethod("concat",
new Class<?>[] {String.class, String[].class},
targetDestination.getDest(), sourceDestinations);
rpcClient.invokeSingle(targetDestination, method, Void.class);
}
@Override
public boolean truncate(String src, long newLength, String clientName)
throws IOException {
rpcServer.checkOperation(NameNode.OperationCategory.WRITE);
final List<RemoteLocation> locations =View on GitHub (pinned to 2add963021)
Solutions
- Ensure target and ALL sources live in the same nameservice (same mount subtree) before concat
- If data must be combined across subclusters, use distcp/copy to move sources into the target's namespace first, then concat
- Re-examine mount layout: put the directory tree that needs concat behind a single mount
Example fix
# before: rejected, /mntB is a different nameservice hdfs dfs -fs hdfs://router -concat /mntA/trg /mntB/part-0 # after: copy source into target's namespace, then concat hadoop distcp hdfs://router/mntB/part-0 hdfs://router/mntA/part-0 hdfs dfs -fs hdfs://router -concat /mntA/trg /mntA/part-0
Defensive patterns
Strategy: validation
Validate before calling
// Enforce single-namespace concat before calling the Router
RemoteLocation t = clientProtocol.getFileRemoteLocation(trg);
for (String s : srcs) {
RemoteLocation l = clientProtocol.getFileRemoteLocation(s);
if (l == null || !l.getNameserviceId().equals(t.getNameserviceId())) {
throw new IOException(s + " is in "
+ (l == null ? "?" : l.getNameserviceId())
+ ", target is in " + t.getNameserviceId());
}
}
clientProtocol.concat(trg, srcs); Try / catch
try {
clientProtocol.concat(trg, srcs);
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().contains("located in a different namespace")) {
// copy the offending source into the target's namespace (distcp), then concat there
} else { throw e; }
} Prevention
- Keep files destined for concat under one mount (one nameservice)
- Teach pipelines that RBF is a router, not a merged namespace: cross-cluster concat is impossible
When it happens
Trigger: hdfs dfs -concat /mntA/trg /mntB/src where /mntA and /mntB are mounts into different subclusters (different nameservice IDs); multi-destination mounts where the target resolves to ns0 but a source resolves to ns1.
Common situations: Users assume Router federation merges namespaces transparently and try to concat across mount points; data pipeline writing parts to two different subclusters then attempting to concat.
Related errors
- Cannot find target file - {}
- Cannot concatenate source file {sourceFile} because it is lo
- Permission denied: {} is not allowed to change quota of {}
- Mount table state store is not available.
- File not found in downstream nameservices: {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/3ba2231ca0d6ea11.
Report an issue: GitHub.