Repository navigation
fix(inkless:switch): keep consolidated records past a lowered seal [KC-837] - #884
giuseppelillo wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The repaired epoch boundary can be lost during future-log promotion or log-directory moves, allowing a later leader-epoch change to truncate or recreate the consolidated log.
2 open issues
What changed in this PR
This PR fixes lowered-seal recovery by starting the diskless leader epoch at the committed seal, even when the first consolidated batch starts later. This helps replicas retain valid consolidated records across leader-epoch changes.
Changes:
- Assign the diskless epoch at the seal before appending a batch that starts past it.
- Add regression tests for epoch assignment and record retention on leaders and followers.
- Document the lowered-seal behavior.
| File | Description |
|---|---|
docs/inkless/DISKLESS_CONSOLIDATION.md |
Explain epoch-cache repair when the first batch starts past the seal. |
docs/inkless/CLASSIC_TO_DISKLESS_SWITCH.md |
Document consolidated-record retention after lowering the seal. |
core/src/test/scala/unit/kafka/server/ReplicaManagerInklessTest.scala |
Test record retention across leader and follower transitions. |
core/src/test/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThreadTest.scala |
Test lowered-seal epoch assignment and the no-gap case. |
core/src/main/scala/io/aiven/inkless/consolidation/ConsolidationFetcherThread.scala |
Assign the diskless epoch at the seal before appending across a gap. |
Review effort: Balanced
…C-837] `lower-seal` moves the committed seal from `S` to `S' < S`, but the diskless log still starts at `S`. Consolidation fetches at `S'` and appends the first diskless batch at `S`, so every replica's leader epoch cache maps `[S', S)` to the last classic epoch. `hasConsolidatedDisklessSuffixFromSeal` read the epoch at the seal, got that classic epoch, and reported the consolidated records as a classic tail. `maybeTruncateSwitchedFollower` and `maybeReconcileSwitchedLeader` then truncated them to `S'`, and `divergenceFromCommittedHistory` recreated the replica on a new leader epoch. This hit every replica in phase 2. The leader that the seal was lowered to has the diskless leader epoch at `S'` from `makeLeader`, but the restart that the recovery needs bumps its leader epoch. The consolidated batch then replaces that entry with the diskless leader epoch at `S`. `hasConsolidatedDisklessSuffixFromSeal` now starts its proof at the first local batch that holds an offset at or past the seal. A batch that spans the seal still starts the proof at the seal. A classic record past the seal still fails the check. The check reads the log, not a cache entry that only consolidation writes, so it gives the same answer after a log directory move or a rebuild from remote storage. Testing - `ReplicaManagerInklessTest.testSwitchedReplicaKeepsConsolidatedRecordsAfterLoweredSeal` applies a phase 2 delta with a new leader epoch to a replica with classic records `[0, 7)`, a lowered seal `7`, and consolidated records `[10, 13)` in the diskless leader epoch. Its cache maps `7` to epoch `0`. The replica keeps its log as a leader, as a leader whose cache had a later epoch at `7` before the append, and as a follower. - `testSwitchedFollowerTruncatesOnlyClassicTailPastLoweredSeal` applies a phase 1 follower delta. The follower keeps `[10, 13)` when its classic records end at the seal, and truncates to the seal when it holds a classic tail `[7, 9)`. - With the previous check, the four cases that keep the log fail, and the classic-tail case passes. - No cluster test takes a lowered seal through phase 2. Assisted-by: Claude Opus 5.5
9d715fe to
26ea6bb
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unhandled storage failures and retention races during phase-two validation can abort metadata updates after fetchers are stopped, leaving healthy replicas unable to resume fetching.
2 open issues
2 resolved since last review
Review effort: Balanced
| val localSuffixStart = math.max(seal, log.localLogStartOffset()) | ||
| val suffixStart = math.max(localSuffixStart, firstBatchBaseOffset(log, localSuffixStart)) |
| // Returns the base offset of the first local batch that holds an offset at or past startOffset, or startOffset | ||
| // if the log holds none. | ||
| private def firstBatchBaseOffset(log: UnifiedLog, startOffset: Long): Long = { | ||
| val batches = log.read(startOffset, 1, FetchIsolation.LOG_END, true).records.batches().iterator() |
|
Closing: KC-837 only follows a phase 1 last-known-leader election that lost records, and a manual procedure (forcing local retention past the old seal) heals it, so it will be documented instead of fixed in code. A new PR will cover it. 🤖 Generated with Claude Code |


lower-sealmoves the committed seal fromStoS' < S, but the diskless log still starts atS. Consolidation fetches atS'and appends the first diskless batch atS, so every replica's leader epoch cache maps[S', S)to the last classic epoch.hasConsolidatedDisklessSuffixFromSealread the epoch at the seal, got that classic epoch, and reported the consolidated records as a classic tail.maybeTruncateSwitchedFollowerandmaybeReconcileSwitchedLeaderthen truncated them toS', anddivergenceFromCommittedHistoryrecreated the replica on a new leader epoch.This hit every replica in phase 2. The leader that the seal was lowered to has the diskless leader epoch at
S'frommakeLeader, but the restart that the recovery needs bumps its leader epoch. The consolidated batch then replaces that entry with the diskless leader epoch atS.hasConsolidatedDisklessSuffixFromSealnow starts its proof at the first local batch that holds an offset at or past the seal. A batch that spans the seal still starts the proof at the seal. A classic record past the seal still fails the check. The check reads the log, not a cache entry that only consolidation writes, so it gives the same answer after a log directory move or a rebuild from remote storage.Test plan
ReplicaManagerInklessTest.testSwitchedReplicaKeepsConsolidatedRecordsAfterLoweredSealapplies a phase 2 delta with a new leader epoch to a replica with classic records[0, 7), a lowered seal7, and consolidated records[10, 13)in the diskless leader epoch. Its cache maps7to epoch0. The replica keeps its log as a leader, as a leader whose cache had a later epoch at7before the append, and as a follower.testSwitchedFollowerTruncatesOnlyClassicTailPastLoweredSealapplies a phase 1 follower delta. The follower keeps[10, 13)when its classic records end at the seal, and truncates to the seal when it holds a classic tail[7, 9).ReplicaManagerInklessTestandConsolidationFetcherThreadTestpass.🤖 Generated with Claude Code