fix(inkless:consolidation): keep diskless leader epoch across leader changes [KC-727] #864
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #864"
general
weight: 0.35
giuseppelillo
Summary
When a partition's leader changes,
Partition.makeLeaderassigns a cache entry for the new leader epoch. Consolidation then appends batches in the lower diskless leader epoch.LeaderEpochFileCache.assigndrops every entry whose epoch is equal or higher on a non-monotonic append. The consolidated records lose their epoch, and tiered storage can no longer match their segments to the lineage.The skip covers a switched partition in phase 2 and a born-diskless partition once the cache contains an entry for the consolidation epoch. Phase 1 and a pending switch still assign the entry, because consolidation doesn't append there. A broker restart takes the same path: a fresh
Partitionstarts at leader epoch -1, somakeLeadertreats the unchanged leader epoch as new.A promoted follower whose log is still at the seal has no diskless leader epoch entry.
makeLeaderassigns the new epoch at the seal, so a lookup for an epoch between the last classic epoch and the diskless leader epoch returns the seal. The next consolidated append replaces that entry with the diskless leader epoch at the seal.Brokers that ran without the skip already carry damaged caches. On a born-diskless partition, the damaged cache is
(0, X), whereXis the log end offset at the leader change or restart. Offsets belowXhave no epoch, so remote copies of those segments fail and remote reads returnOFFSET_NOT_AVAILABLE. The consolidation fetcher repairs the cache before every consolidated append:Every consolidated batch of a born-diskless partition has epoch 0, so the correct cache is
(0, log start offset). The assignment changes nothing on a correct cache. It replaces a damaged(0, X)entry, and it drops a stale higher entry that a checkpoint kept from before the upgrade. The fetcher runs on leaders and followers, so the next append also repairs a cache that a tier-state rebuild restored from a damaged remote checkpoint. The guard checks the seal, not the diskless leader epoch. Partitions switched before the diskless leader epoch existed have a seal but no diskless leader epoch, and assigning epoch 0 there would drop their classic entries.The become-leader log mentions the skip when it applies, and a comment next to the skip records the upstream
endOffsetForassumption that the skip breaks.Partitionreads the consolidation epoch through a hook, the same way it readsreplicationStopOffset. The glossary gains entries for Diskless Leader Epoch and Seal.Evidence
PartitionTest.testMakeLeaderKeepsDisklessLeaderEpochAfterLeaderChangefails. The cache entry for the diskless leader epoch moves from the seal to the log end:(4, 2)becomes(4, 4). The born-diskless case fails the same way:(0, 0)becomes(0, 2), and so does the restart case,PartitionTest.testMakeLeaderKeepsBornDisklessEpochAfterRestart. An unconditional skip also failsPartitionTest.testMakeLeaderAtSealAssignsEpochWhenDisklessEpochIsMissing: a follower promoted at the seal keeps only(2, 0), andendOffsetFor(3)returns undefined instead of the seal.After: the cached diskless leader epoch stays
(4, 2), and the born-diskless cache stays(0, 0)across a leader change and a restart. The promotion at the seal writes(5, 2),endOffsetFor(3)returns2, and the following consolidated append leaves(2, 0), (4, 2). ThosePartitionTestcases pass.ConsolidationFetcherThreadTestleaves a damaged cache at(0, 10)and a stale cache at(0, 5), (4, 10). An empty cache doesn't get an entry. A realUnifiedLogrebuilt from a damaged checkpoint stays at(0, 10)after a consolidated append.After: with log start offset 5, each of those caches becomes
(0, 5). A correct cache, a pending switch, and switched partitions keep their entries. ThoseConsolidationFetcherThreadTestcases pass.Test plan
PartitionTestcovers a switched partition and a born-diskless partition across a leader change, a born-diskless partition across a restart into the same leader epoch, and a promotion at the seal before the cache has an entry for the diskless leader epoch.ReplicaManagerInklessTestcoversconsolidationLeaderEpochin each switch phase, an end-to-endapplyDeltapromotion, and anOffsetsForLeaderEpochquery of the new leader epoch that the local cache can't answer.ConsolidationFetcherThreadTestcovers the repair of a damaged cache, a stale higher entry, and an empty cache. It also checks that correct caches, a pending switch, and switched partitions with and without a diskless leader epoch keep their entries, and it rebuilds a realUnifiedLogfrom a damaged checkpoint before a consolidated append.Merge Danger
Door: two-way
Reverting the change restores the old assignment on the next leader change. A cache that the repair already rewrote keeps its
(0, log start offset)entry, which the old code also reads correctly. A promotion at the seal writes a temporary entry for the new epoch, and the next consolidated append replaces it.Blast Radius: consolidation
When the consolidation epoch is already cached, the latest cached epoch sits below the current leader epoch, so
endOffsetForreturns undefined for the current epoch. Every caller handles that result today. Turning the broker consolidation flag on or off can still give a born-diskless partition the old behavior, because the check follows that flag.A damaged born-diskless partition recovers on each replica at its next consolidated append. These limits remain:
{0: X}and indexes the segment atX. After the repair, reads between the segment's base offset andXreturnOFFSET_OUT_OF_RANGEinstead ofOFFSET_NOT_AVAILABLE, and a consumer that resets to the earliest offset can reach the same gap again. Every other offset belowXbecomes readable. The gap lasts until retention deletes that segment.Xkeep failing.AlterDisklessSwitchcancels a pending switch, the partition goes back to having no seal. The repair then treats it as born-diskless. The existing epoch-0 append already drops its classic entries, so the repair doesn't make that state worse.