apache/flink · error · IllegalArgumentException
The given offset is not contained in the any block.
Error message
The given offset is not contained in the any block.
What it means
Thrown internally by FileInputFormat.getBlockIndexForPosition when a computed split start offset does not fall inside any HDFS/filesystem block range returned by getFileBlockLocations. It indicates the split layout no longer matches the physical block layout of the file, so the split-to-block locality mapping is inconsistent.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/io/FileInputFormat.java:777
*/
private int getBlockIndexForPosition(
BlockLocation[] blocks, long offset, long halfSplitSize, int startIndex) {
// go over all indexes after the startIndex
for (int i = startIndex; i < blocks.length; i++) {
long blockStart = blocks[i].getOffset();
long blockEnd = blockStart + blocks[i].getLength();
if (offset >= blockStart && offset < blockEnd) {
// got the block where the split starts
// check if the next block contains more than this one does
if (i < blocks.length - 1 && blockEnd - offset < halfSplitSize) {
return i + 1;
} else {
return i;
}
}
}
throw new IllegalArgumentException("The given offset is not contained in the any block.");
}
// --------------------------------------------------------------------------------------------
/**
* Opens an input stream to the file defined in the input format. The stream is positioned at
* the beginning of the given split.
*
* <p>The stream is actually opened in an asynchronous thread to make sure any interruptions to
* the thread working on the input format do not reach the file system.
*/
@Override
public void open(FileInputSplit fileSplit) throws IOException {
this.currentSplit = fileSplit;
this.splitStart = fileSplit.getStart();
final Path path = fileSplit.getPath();
this.splitLength =View on GitHub (pinned to 2f3c205e92)
Solutions
- Ensure input files are stable (not being written/truncated) for the full job run; stage data into an immutable location before submitting the job.
- Verify the FileSystem implementation reports correct BlockLocation offsets/lengths; for object stores use the supported S3/Hadoop FS plugin.
- Recompute splits by re-running the job once the file is settled; avoid pointing at live/log directories being appended.
- If the file is small/unsplittable, set the input format unsplittable so a single split covers the whole file and no block lookup mismatch occurs.
Example fix
// before: pointing at a directory a live process is writing to
env.readTextFile("hdfs:///logs/today-live/");
// after: stage an immutable snapshot first
env.readTextFile("hdfs:///snapshots/today-frozen/"); Defensive patterns
Strategy: validation
Validate before calling
// Ensure input files are immutable/stable before submit
Path input = new Path("hdfs:///snapshots/frozen/");
FileSystem fs = input.getFileSystem();
for (FileStatus f : fs.listStatus(input)) {
long len = f.getLen();
BlockLocation[] blks = fs.getFileBlockLocations(f, 0, len);
long covered = Arrays.stream(blks).mapToLong(BlockLocation::getLength).sum();
if (covered < len) {
throw new IllegalStateException("Block locations do not cover " + f.getPath());
}
} Try / catch
// Catch in the source open path and fail fast with context
try {
format.open(split);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("not contained in the any block")) {
LOG.error("Stale block metadata for {} — file may have changed", split.getPath());
}
throw e;
} Prevention
- Stage inputs into an immutable directory before job submission.
- Avoid reading from directories a live process is appending to.
- For object stores, use the supported FS plugin which reports consistent block locations.
- If files are small/unsplittable, mark the format unsplittable to bypass block lookup.
When it happens
Trigger: The file changed size or was rewritten between createInputSplits (which captures block locations) and split assignment/open; a filesystem returns block offsets that do not cover the full file length; splits computed against stale file metadata; a custom FileSystem reports inconsistent BlockLocation offsets/lengths.
Common situations: The input file is appended to or overwritten while the job is starting; HDFS under-replication or namemode metadata lag returns partial BlockLocations; reading from an object store (S3) whose 'block locations' are synthetic and inconsistent; a file was truncated between split computation and reading.
Related errors
- Input opening request timed out. Opener was {} alive. Stack
- Cannot find the partition value from path for partition: %s
- Number of input splits has to be at least 1.
- Error opening the Input Split {} [{},{}]: {}
- Output path could not be initialized.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/1bf92fa83802f8e9.
Report an issue: GitHub.