apache/cassandra · error · RuntimeException

Error reading key %s in segment %s at position %d: %s

Error message

Error reading key %s in segment %s at position %d: %s

What it means

StandaloneJournalUtil (offline journal dump/read tool) deserializes each key from a journal segment and prints it. If deserialization of a key throws, the tool wraps the failure in a RuntimeException pinpointing the key, segment, and byte position, with the original throwable as cause — so the corrupt/unreadable entry can be located precisely.

Source

Thrown at src/java/org/apache/cassandra/tools/StandaloneJournalUtil.java:179

                    if (metadataOnly)
                        return;

                    StaticSegment<JournalKey, Object> segment = DumpUtil.open(descriptor, JournalKey.SUPPORT);
                    segment.forEachRecord((segment1, position, key, buffer, userVersion) -> {
                        if (kind != null && key.type != JournalKey.Type.valueOf(kind))
                            return;

                        if (txnId != null && !TxnId.parse(txnId).equals(key.id))
                            return;

                        try (DataInputBuffer in = new DataInputBuffer(buffer, false))
                        {
                            Object v = key.type.serializer.deserialize(key, in, Version.V1);
                            output.out.printf("%s: %s%n", key, v);
                        }
                        catch (Throwable t)
                        {
                            throw new RuntimeException(String.format("Error reading key %s in segment %s at position %d: %s",
                                                                key, segment1, position, t.getMessage()), t);
                        }
                    });
                });
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }

        }
    }

    @Command(name = "dump_journal", description = "Dump journal")
    public static class DumpJournal implements Runnable
    {
        @Option(names = {"-s", "--sstables"}, description = "Path to sstables")
        public String sstables;

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Inspect the cause in the stack trace to see the actual deserialization failure
  2. Restore the corrupted segment from a replica/backup of the same journal
  3. Verify the tool and data files come from compatible Cassandra versions
  4. Isolate the bad segment file and exclude it / re-copy it before running the dump again
Defensive patterns

Strategy: try-catch

Validate before calling

if (!segmentFile.canRead() || segmentFile.length() == 0)
    throw new IllegalStateException("Segment unreadable or empty: " + segmentFile);

Try / catch

try { StandaloneJournalUtil.run(...); }
catch (RuntimeException e) {
    LOG.error("journal read failed at " + e.getMessage(), e.getCause());
}

Prevention

When it happens

Trigger: Reading a journal segment whose bytes at a key position cannot be deserialized with Version.V1 serializers: corrupted segment data, truncated entry, or a payload written by an incompatible version.

Common situations: Disk corruption or torn writes in journal segment files; reading segments copied from a node running a different Cassandra version; interrupted compaction/truncation of the journal.

Related errors


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