apache/hadoop · error · IOException

<fileDiffEntry> contained no <count> entry.

Error message

<fileDiffEntry> contained no <count> entry.

What it means

A <fileDiffEntry> header is missing its <count> child, which declares how many <fileDiff> elements follow and becomes DiffEntry.numOfDiff. Without it the reconstructor cannot loop over the diffs and aborts the entry.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java:1546

      expectTagEnd(SNAPSHOT_DIFF_SECTION_DIR_DIFF_ENTRY);
    }

    private void processFileDiffEntry() throws IOException {
      LOG.debug("Processing fileDiffEntry");
      DiffEntry.Builder headerBld = DiffEntry.newBuilder();
      headerBld.setType(DiffEntry.Type.FILEDIFF);
      Node fileDiffHeader = new Node();
      loadNodeChildren(fileDiffHeader, "fileDiffEntry fields", "fileDiff");
      Long inodeId = fileDiffHeader.removeChildLong(
          SNAPSHOT_DIFF_SECTION_INODE_ID);
      if (inodeId == null) {
        throw new IOException("<fileDiffEntry> contained no <inodeid> entry.");
      }
      headerBld.setInodeId(inodeId);
      Integer expectedDiffs = fileDiffHeader.removeChildInt(
          SNAPSHOT_DIFF_SECTION_COUNT);
      if (expectedDiffs == null) {
        throw new IOException("<fileDiffEntry> contained no <count> entry.");
      }
      headerBld.setNumOfDiff(expectedDiffs);
      fileDiffHeader.verifyNoRemainingKeys("fileDiffEntry");
      headerBld.build().writeDelimitedTo(out);
      for (int actualDiffs = 0; actualDiffs < expectedDiffs; actualDiffs++) {
        try {
          expectTag(SNAPSHOT_DIFF_SECTION_FILE_DIFF, false);
        } catch (IOException e) {
          throw new IOException("Only read " + (actualDiffs + 1) +
              " diffs out of " + expectedDiffs, e);
        }
        Node fileDiff = new Node();
        loadNodeChildren(fileDiff, "fileDiff fields");
        FsImageProto.SnapshotDiffSection.FileDiff.Builder bld =
            FsImageProto.SnapshotDiffSection.FileDiff.newBuilder();
        Integer snapshotId = fileDiff.removeChildInt(
            SNAPSHOT_DIFF_SECTION_SNAPSHOT_ID);
        if (snapshotId != null) {

View on GitHub (pinned to 2add963021)

Solutions

  1. Add <count>N</count> to the entry header, N being the number of <fileDiff> children present
  2. Verify <count> precedes the first <fileDiff>
  3. Pre-validate every <fileDiffEntry> carries both <inodeId> and <count>
  4. Regenerate the XML from the original image

Example fix

<!-- before -->
<fileDiffEntry><inodeId>16390</inodeId>
  <fileDiff>...</fileDiff>
</fileDiffEntry>
<!-- after -->
<fileDiffEntry><inodeId>16390</inodeId><count>1</count>
  <fileDiff>...</fileDiff>
</fileDiffEntry>
Defensive patterns

Strategy: validation

Validate before calling

# python: every fileDiffEntry needs <count> equal to its <fileDiff> children
import xml.etree.ElementTree as ET

def file_counts_ok(path):
    for ev, el in ET.iterparse(path, events=('end',)):
        if el.tag == 'fileDiffEntry':
            c = el.find('count')
            if c is None or int(c.text) != len(el.findall('fileDiff')):
                return False
    return True

Try / catch

// catch '<fileDiffEntry> contained no <count>'; add/recount it,
// delete partial output, re-run oiv

Prevention

When it happens

Trigger: A <fileDiffEntry> with <count> omitted, renamed, or positioned after the first <fileDiff> terminator; header fields damaged by line-based edits.

Common situations: Hand-edited or script-generated entries missing the count; counts dropped as 'redundant'; version-skewed XML writers.

Related errors


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