fix(inkless:switch): answer epoch 0 from the diskless log in OffsetsForLeaderEpoch [KC-852] #888
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 #888"
general
weight: 0.35
giuseppelillo
A consumer that reads past the seal of a switched partition resets to the seal the next time it validates its position. It then re-reads every record from the seal to that position.
Problem
Diskless produce stamps every batch with leader epoch 0 (
UnifiedLog.LEADER_EPOCH), andFetchHandlerreturns the batches with that epoch. A consumer that tails a switched partition therefore holds a position past the seal withoffsetEpoch=0.The consumer validates a position with
OffsetsForLeaderEpochin two cases: when it resumes from a committed offset that carries a leader epoch, and when a metadata update shows a different leader or leader epoch for the partition. The request carries the epoch of the position and no offset.For a switched partition,
ReplicaManager.lastOffsetForLeaderEpochasks the local classic log first. If the classic end offset is at or belowclassicToDisklessStartOffset, the broker returns it. In the classic log, epoch 0 is a real epoch that ends at or below the seal, so the broker answers the diskless placeholder with a classic end offset. The consumer treats an end offset below its position as a truncation.Example on
mainThe setup matches
testLastOffsetForLeaderEpochKeepsPlaceholderEpochPositionPastSeal:| Item | Value |
| ---- | ----- |
| Classic prefix | Offsets 0 to 9, leader epoch 0 |
| Seal (
classicToDisklessStartOffset) | 10 || Diskless leader epoch | 5 |
| Local log of the answering broker | Offsets 0 to 12, epoch cache
[(epoch 0, start 0), (epoch 5, start 10)]|| Diskless end offset | 200 |
| Consumer position | Offset 200,
offsetEpoch=0|The validation runs in this order:
1. The consumer sends
OffsetsForLeaderEpochwithleaderEpoch=0.2. The broker asks the local classic log.
LeaderEpochFileCache.endOffsetFor(0)returns the start offset of the next cached epoch, which is 10.3. The classic answer, 10, is at or below the seal, so the broker returns
endOffset=10.4. The consumer compares the end offset with its position. 10 is less than 200, so the consumer logs
Truncation detectedand seeks to offset 10.5. The consumer reads offsets 10 to 199 a second time.
Fix
For a switched partition, the broker answers a request for epoch 0 with the diskless end offset. The classic log still answers every other epoch that ends at or below the seal.
The diskless answer for a switched partition is at least the committed seal. A control-plane placeholder row reports end offset 0, and without the floor a consumer in the classic prefix would truncate to 0.
DisklessLeaderEndPoint.atLeastCommittedSealapplies the same floor for consolidating followers.The local lookup still runs first, so its errors, such as
NOT_LEADER_OR_FOLLOWER, reach the client as before.The rule keys on the requested epoch, not on the classic answer. If the classic log had leader changes before the switch, classic epoch 0 ends at the start of classic epoch 1, which is below the seal. A check that compares the classic answer with the seal doesn't catch that case.
The same example with the fix
1. The consumer sends
OffsetsForLeaderEpochwithleaderEpoch=0.2. The requested epoch is 0, so the broker doesn't use the classic answer. It asks the control plane for the end offset, which is 200.
3. 200 is above the seal, 10, so the floor doesn't apply. The broker returns
endOffset=200.4. The consumer compares the end offset with its position. 200 isn't less than 200, so the validation completes and the consumer keeps position 200.
Trade-offs
FetchHandlerreturns still carry epoch 0.Test plan
testLastOffsetForLeaderEpochKeepsPlaceholderEpochPositionPastSealbuilds the example and expects end offset 200 for epoch 0. Onmainit fails withexpected: <200> but was: <10>.testLastOffsetForLeaderEpochHybridFloorsDisklessEndOffsetAtSealhas the control plane report end offset 0 for a partition sealed at 101 and expects end offset 101.testLastOffsetForLeaderEpochHybridAtSwitchBoundaryUsesLocalLogandtestLastOffsetForLeaderEpochHybridAtSwitchBoundaryUsesFollowerLocalLogasserted that the classic log answers epoch 0. They now build the classic prefix with epoch 1 and request epoch 1, so they still cover the classic answer at the seal.ReplicaManagerInklessTest(309 tests) andInklessDisklessListOffsetsTest(5 tests) pass.InklessTopicTypeSwitcherClusterTestsetup, a consumer tails a switched partition sealed at offset 20 and commits offset 50 withleaderEpoch=0. A second consumer in the same group starts at offset 20 onmainand at offset 50 with this change. That test isn't part of this PR, because its precondition depends on timing: a consumer that starts after consolidation catches up reads the local log, commitsleaderEpoch=2, and resumes at its committed offset onmain.make valereports no inkless-owned prose to lint in this change.test_switch_succeeds_with_degraded_network, where the failure first showed, passes in 3 local runs on this change. In 2 of the runs, the consumer validates a position with epoch 0 about 3 seconds after phase 2 starts, on 3 partitions in total. Each answer is above the partition's seal: 1836 for seal 1674, 1908 for seal 1742, and 1757 for seal 1625. In the third run, the consumer validates only at the seal. The test wasn't run onmainlocally.🤖 Generated with Claude Code