apache/hadoop · error · EOFException

{b}'s on-disk length {onDiskLength} is shorter than minLengt

Error message

{b}'s on-disk length {onDiskLength} is shorter than minLength {minLength}

What it means

EOFException thrown by FsDatasetImpl.checkBlock when the block file exists but getLength(b) (actual on-disk bytes) is smaller than the minLength the caller requires. The replica is present yet truncated relative to the length the operation expects, so reading it would hit end-of-file prematurely.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java:2267

   */
  @Override // FsDatasetSpi
  public void checkBlock(ExtendedBlock b, long minLength, ReplicaState state)
      throws ReplicaNotFoundException, UnexpectedReplicaStateException,
      FileNotFoundException, EOFException, IOException {
    final ReplicaInfo replicaInfo = volumeMap.get(b.getBlockPoolId(), 
        b.getLocalBlock());
    if (replicaInfo == null) {
      throw new ReplicaNotFoundException(b);
    }
    if (replicaInfo.getState() != state) {
      throw new UnexpectedReplicaStateException(b,state);
    }
    if (!replicaInfo.blockDataExists()) {
      throw new FileNotFoundException(replicaInfo.getBlockURI().toString());
    }
    long onDiskLength = getLength(b);
    if (onDiskLength < minLength) {
      throw new EOFException(b + "'s on-disk length " + onDiskLength
          + " is shorter than minLength " + minLength);
    }
  }

  /**
   * Check whether the given block is a valid one.
   * valid means finalized
   */
  @Override // FsDatasetSpi
  public boolean isValidBlock(ExtendedBlock b) {
    // If block passed is null, we should return false.
    if (b == null) {
      return false;
    }
    return isValid(b, ReplicaState.FINALIZED);
  }
  
  /**

View on GitHub (pinned to 2add963021)

Solutions

  1. Run hdfs fsck -blocks to locate truncated replicas; the NameNode will re-replicate from healthy copies.
  2. Investigate why the file is short: check for 'No space left on device' or I/O errors in DataNode logs around the write time.
  3. If this replica is the only copy, consider block-recovery tooling (hdfs debug recoverLease, or manual salvage) before deleting it.
  4. Free disk space / fix hardware and restart the DataNode to re-scan volumes.
Defensive patterns

Strategy: try-catch

Validate before calling

// Read only up to the length actually on disk when tolerating partial data:
long visible = dataset.getReplicaInfo(b) != null ? dataset.getLength(b) : -1;
if (visible >= 0 && visible < minLength) {
  // truncated: choose another replica rather than provoking EOFException
}

Try / catch

try {
  dataset.checkBlock(b, minLength, ReplicaState.FINALIZED);
} catch (EOFException e) {
  // truncated on disk: rotate replica; if last copy, escalate to fsck/block salvage
  return nextReplicaOrEscalate(b);
}

Prevention

When it happens

Trigger: checkBlock(b, minLength, state) where minLength exceeds onDiskLength - e.g., a client requests a length up to the block's reported visible length but the file on disk is shorter after an unclean shutdown mid-write.

Common situations: DataNode crash between data write and meta/fsync leaving a short file; disk full condition truncated a write; VM snapshot rollback restoring an older, shorter block file; short read caused by faulty RAID controller.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/c763e984f137b52a. Report an issue: GitHub.