apache/cassandra · error · IOException

Trailing data encountered in segment index

Error message

Trailing data encountered in segment index 

What it means

When opening an on-disk segment index, OnDiskIndex.validate reads the declared entry count and verifies the CRC. If bytes remain after the expected content and CRC, the index file is structurally corrupt and an IOException is thrown. This detects truncated-then-appended or wrongly-sized index files.

Source

Thrown at src/java/org/apache/cassandra/journal/OnDiskIndex.java:149

        }
    }

    void validate() throws IOException
    {
        CRC32 crc = Crc.crc32();

        try (DataInputBuffer in = new DataInputBuffer(buffer, true))
        {
            int entryCount = in.readInt();
            updateChecksumInt(crc, entryCount);
            validateCRC(crc, in.readInt());

            Crc.updateCrc32(crc, buffer, FILE_PREFIX_SIZE, FILE_PREFIX_SIZE + entryCount * ENTRY_SIZE);
            in.skipBytesFully(entryCount * ENTRY_SIZE);
            validateCRC(crc, in.readInt());

            if (in.available() != 0)
                throw new IOException("Trailing data encountered in segment index " + descriptor.fileFor(Component.INDEX));
        }
    }

    static <K> void write(
        NavigableMap<K, long[]> entries, KeySupport<K> keySupport, DataOutputPlus out, int userVersion) throws IOException
    {
        CRC32 crc = Crc.crc32();

        int size = entries.values()
                          .stream()
                          .mapToInt(offsets -> offsets.length)
                          .sum();
        out.writeInt(size);
        updateChecksumInt(crc, size);
        out.writeInt((int) crc.getValue());

        for (Map.Entry<K, long[]> entry : entries.entrySet())
        {

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Delete the corrupted segment index and run journal recovery/reserialization so the index is rebuilt
  2. Restore the segment files from a verified backup
  3. Check disk health (filesystem errors, bad sectors)
  4. Verify segments were copied atomically (no partial files) when moving data between nodes
Defensive patterns

Strategy: try-catch

Validate before calling

// check expected index size = FILE_PREFIX_SIZE + entryCount*ENTRY_SIZE + 4 before opening
long expected = readEntryCount(file)*ENTRY_SIZE + FILE_PREFIX_SIZE + 4; if (Files.size(indexFile) != expected) quarantine(file);

Try / catch

try { OnDiskIndex.open(desc, ...); } catch (IOException e) { if (e.getMessage().contains("Trailing data")) rebuildIndex(desc); else throw e; }

Prevention

When it happens

Trigger: Opening a segment whose INDEX component contains extra bytes beyond entryCount*ENTRY_SIZE plus prefix and CRC — e.g. corrupted file, wrong file paired with a descriptor, or a partially overwritten index.

Common situations: Crash during index write leaving inconsistent size; copying segments incorrectly; disk corruption; manually rebuilding/moving journal files.

Understand the failure class

Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/2ce6d8fdd510d0b6. Report an issue: GitHub.