apache/hadoop · error · IOException
Cannot open filename {}
Error message
Cannot open filename {} What it means
fetchAndCheckLocatedBlocks() treats a null result from dfsClient.getLocatedBlocks(src, 0) as fatal. The NameNode returned no block metadata for the path at all, which in practice means the file vanished (deleted or renamed) between open and the located-blocks RPC, or the RPC landed on a Standby/Router NameNode that yielded null instead of a proper error.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java:292
}
private void waitFor(int waitTime) throws IOException {
try {
Thread.sleep(waitTime);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new InterruptedIOException(
"Interrupted while getting the last block length.");
}
}
private LocatedBlocks fetchAndCheckLocatedBlocks(LocatedBlocks existing)
throws IOException {
LocatedBlocks newInfo = dfsClient.getLocatedBlocks(src, 0);
DFSClient.LOG.debug("newInfo = {}", newInfo);
if (newInfo == null) {
throw new IOException("Cannot open filename " + src);
}
if (existing != null) {
Iterator<LocatedBlock> oldIter =
existing.getLocatedBlocks().iterator();
Iterator<LocatedBlock> newIter = newInfo.getLocatedBlocks().iterator();
while (oldIter.hasNext() && newIter.hasNext()) {
if (!oldIter.next().getBlock().equals(newIter.next().getBlock())) {
throw new IOException("Blocklist for " + src + " has changed!");
}
}
}
return newInfo;
}
private long getLastBlockLength(LocatedBlocks blocks) throws IOException{
long lastBlockBeingWrittenLength = 0;View on GitHub (pinned to 2add963021)
Solutions
- Verify the path still exists (fs.exists / getFileStatus) and re-resolve it before retrying
- Check HA configuration: dfs.nameservices, dfs.ha.namenodes.<ns>, and the failover proxy provider settings
- If using HDFS Router, verify the mount table maps the path to a subcluster that owns it
- Coordinate producers/consumers so files are not deleted while being opened
Example fix
// before
FSDataInputStream in = fs.open(path);
// after: confirm the file exists right before opening
if (!fs.exists(path)) throw new FileNotFoundException(path.toString());
try (FSDataInputStream in = fs.open(path)) { /* read */ } Defensive patterns
Strategy: validation
Validate before calling
if (!fs.exists(path)) {
throw new FileNotFoundException(path.toString());
}
try (FSDataInputStream in = fs.open(path)) { /* read */ } Type guard
static boolean isFileVanished(IOException e) {
return e.getMessage() != null && e.getMessage().startsWith("Cannot open filename");
} Try / catch
try {
in = fs.open(path);
} catch (IOException e) {
if (isFileVanished(e)) { /* re-resolve path or skip */ }
else throw e;
} Prevention
- Stat the file immediately before opening when deletions can race
- Coordinate producers/consumers so files are not removed while being read
- Verify HA nameservice and router mount configuration so RPCs reach an active NN
When it happens
Trigger: openInfo()/openInfo(true) refresh racing a delete or rename of src; HA misconfiguration where every RPC goes to a standby NameNode; HDFS Router federation routing the path to the wrong subcluster.
Common situations: Reading temp/part files that a cleaner process removes concurrently; retrying reads after a file was overwritten by delete+recreate; wrong dfs.ha.namenodes.<id> addresses so the client only ever reaches standby NNs.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- The log file {} seems to contain valid transactions ; journa
- The journal edits cache is not enabled, which is a requireme
- Manual HA control for this NameNode is disallowed, because a
- Request from ZK failover controller at {Server.getRemoteAddr
- Enabling or disabling storage policy satisfier service on {s
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/6a2482391b749f05.
Report an issue: GitHub.