fix(inkless:switch): recreate phase 2 replicas that don't hold the committed classic prefix [KC-702] #857
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 #857"
general
weight: 0.35
jeqo
In phase 2 of the classic-to-diskless switch, the controller adds every live replica to the ISR without checking its local copy of the classic prefix, and any replica can lead. A replica can hold records below the seal that the partition doesn't hold. It led an older leader epoch and wrote records that the next leader didn't have, or an unclean leader election before the switch discarded records below its high watermark. Forced deletion keeps the leader epoch cache of that replica, and the remote log manager uses it to compute the highest offset in remote storage and to pick remote segments. On that replica, a tiered read below the seal fails with
OFFSET_OUT_OF_RANGE, and the consumer resets its offset. On an idle topic, the highest offset in remote storage also stays below the seal, so forced deletion never completes.Example
Broker B leads epoch 1 and appends
[80, 100), but no follower fetches those records before B goes offline. The controller elects A in epoch 2, and A appends its own[80, 100). A seals the partition at 100 and uploads the classic prefix while B stays offline.A requests the phase 2 flag with
lastClassicLeaderEpoch = 2, the epoch of its record at 99. In phase 2, B returns, joins the ISR, and can lead. Its log ends at the seal, so it looks complete. Without this change, B serves its epoch 1 records at[80, 100), which no other replica holds. The cache of B also maps that range to epoch 1, and no remote segment has that epoch.With this change, B checks its log in
applyDeltabefore it leads. Its epoch at 99 is 1, so the broker deletes the log and lets the leadership change create an empty one, which the existing recovery rebuilds from remote storage:Recreate instead of truncate
The broker never truncates a log that it keeps in place. A truncation leaves state that later steps trust, and each piece needs its own guard. A recreated log starts without any of it. In this example, broker B led epoch 3, uploaded
[50, 119], and still holds[100, 120)when an unclean leader election makes A the leader in epoch 4. A seals at 100 and recordslastClassicLeaderEpoch = 2.A truncation of B to the seal leaves this state behind:
| State | After a truncation in place | After a recreate |
| --- | --- | --- |
| Highest offset in remote storage | Stays 119, because it only grows. The WAL pruner then deletes diskless batches
[100, 120)before consolidation uploads them. |-1until the remote log manager computes it from the rebuilt log. || Future log of a log directory move | Keeps
[100, 120)in epoch 3 and replaces the current log once both end at 120. | Deleted with the current log. || Remote log tasks | Can compute 119 in epoch 3 before the truncation and apply it after consolidation grows the log back past it. The copy task keeps a copied offset that skips
[100, 120). | Canceled. A task that still runs updates only the deleted log. || Promotion of the future log | Can run between the check and the truncation. | Stopping the move fetcher waits for a running promotion. |
The epoch of B at 99 is 2, but the check still rejects B because it holds classic records past the seal. If B applied the seal while it was online, it already truncated its log to 100. The check then rejects B because its remote progress 119 isn't below its log end offset 100. A remote log task that computed 119 before that truncation can't install it after the check, because the log drops an offset that a task computed before a truncation.
Remote segment that crosses the seal
Leader X appends
[100, 120)in epoch 3 and uploads a segment[50, 119]with epochs 2 and 3. An unclean leader election then makes Y the leader in epoch 4. Y's log ends at 100. The partition loses[100, 120). Y seals at 100 before any new produce and recordslastClassicLeaderEpoch = 2.The segment at 99 in epoch 2 is the right one to rebuild from, but it ends at 119. Without this change,
TierStateMachinestarts the local log at 120. The consolidating leader then never materializes the diskless records[100, 120), and the WAL prune deletes them. With this change, a phase 2 rebuild starts the local log at the seal with only the epoch 2 entry, and the leader consolidates the diskless records from 100 on.Source with local classic records below the seal
In phase 2, a classic leader can still hold local classic segments below the seal, and so can the current log of a log directory move. Upstream
TierStateMachinerebuilds from the segment that contains the record before the local log start of the source. Broker X leads epoch 1 and uploads a segment[0, 119]with its records[80, 120). An unclean leader election then makes A the leader in epoch 2. A appends its own records from 80 and seals at 100. It recordslastClassicLeaderEpoch = 2. The local log of A starts at 50.A follower that rebuilds from A looks up the record at 49 in epoch 0. The segment of X holds that record in the same epoch, so remote storage can return that segment:
[80, 100)and starts its local log at 120, past the diskless records[100, 120).Changes
seal - 1inSetClassicPrefixInRemoteStorage. The controller stores it with the flag as tag104(lastClassicLeaderEpoch) and drops it when the switch is undone. The value is-1if the leader's log doesn't contain a record below the seal. The controller rejects a value below-1or higher than the current leader epoch, which no replica can match.DescribeTopicPartitionsreturns the epoch with the other switch fields, andkafka-topic-switch.sh stateprints it.applyDeltachecks each consolidating phase 2 replica that is new to the broker or gets a higher leader epoch, before the leader and follower transitions. The flag record bumps the leader epoch, which makes live replicas run the check when phase 2 starts. The broker first stops the replica, move, and consolidation fetchers of the partition. It keeps the log only if all of these are true:- The epoch at
min(seal, LEO) - 1is the recorded epoch, or the log has no record below that offset. Each epoch has one leader, so a matching epoch proves that the records below the seal are the committed ones, at any high watermark.- Records past the seal are consolidated diskless records (
hasConsolidatedDisklessSuffixFromSeal).-
highestOffsetInRemoteStorageis below the log end offset.- The future log, if any, ends at or below the current log end offset, in the same epoch as the current log at that offset. A future log that ends at or below the log start offset of the current log also passes: the current log holds none of its records, and the move fetcher drops them on its next fetch.
stopPartitionsanddeleteLocalLog = true, as for a deleted partition. That removes the partition, deletes the current and future logs, and cancels the remote log tasks. A newkeepRemoteLogMetadataflag keeps the remote log metadata subscription and the topic ID of the partition, because the partition stays on the broker. The leader or follower transition in the same delta then creates an empty log, and the existing recovery rebuilds the log, the leader epoch cache, and the producer state from remote storage.UnifiedLogand the remote log manager need no change for this path.stopPartitionscancels the remote log tasks even if a deletion fails, because a copy task that keeps running also keeps the copy progress of the deleted log.UnifiedLognow counts truncations. A truncation counts itself and changes the log under the log lock. The follower and copy tasks read the count under that lock before they read the leader epoch cache or the segments. A task never pairs the new count with the state from before the truncation.updateHighestOffsetInRemoteStorage(offset, truncationCount)installs the offset under the log lock only if the count didn't change. After a truncation, the copy task also finds its copied offset again instead of resuming after the discarded tail.TierStateMachinelooks up the remote segment that holdsseal - 1in the recorded epoch, whatever the local log start of the source is, and starts the local log at the seal. Each epoch has one leader, so the records of that segment below the seal are the committed prefix, even if the segment also covers discarded records past the seal. The rebuild keeps the epochs that start below the seal and skips the epoch lookup on the source. It restores the producer snapshot only if the segment ends atseal - 1. Sealing aborts undecided transactions, so the empty producer state is correct at the seal. Partitions without a recorded epoch, including partitions in phase 1, keep the upstream rebuild.TierStateMachine.javais a newINTERLEAVEDentry inINKLESS_OWNERSHIP.fetchEarliestLocalOffsetapplies the same bound. The control plane keeps the WAL start at the classic log start until the first prune moves it to the seal. Without the bound, a leader that lost its local log before that prune reads the first diskless batch at offset 0, and its local log hides the remote prefix.DeleteRecordsmoved the cross-tier earliest offset to the diskless start or past it, the endpoint returnsOFFSET_OUT_OF_RANGEbefore it asks remote storage. The reset then starts the local log at that offset.DeleteRecordsat the seal runs only the local leg, so before the first prune the WAL start stays below the seal. Without this check, the fetcher waits for coverage ofseal - 1that never returns, or rebuilds a deleted prefix from a segment that remote storage still lists.CLASSIC_TO_DISKLESS_SWITCH.mddescribes the recorded epoch, the replica check, the recreate, and the phase 2 rebuild.DISKLESS_CONSOLIDATION.mddescribes the first-prune bound, the deleted-prefix reset, the retention guard, and why a replica with stale remote progress is recreated.A leader uploads only segments below its last stable offset, so the partition had committed every record in remote storage when its leader uploaded it. Phase 1 blocks unclean leader election. An unclean leader election before the switch, through the cluster default or an
ElectLeadersrequest, can still discard uploaded records, and the phase 2 rebuild handles that case.inkless-release-0.50has theSetClassicPrefixInRemoteStorageRPC and tag103, but its brokers don't send the flag request. So no released partition is in phase 2 without the recorded epoch.Limitations
TierStateMachinerebuild, like a leader that lost its local log. A gap in that rebuild affects both cases.RemoteLogManager.Assisted-by: Claude Opus 5.5
[KC-727]: https://aiven.atlassian.net/browse/KC-727?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ