fix(inkless:switch): seal and register a pending partition in the first delta after a restart [KC-752] #877
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 #877"
general
weight: 0.35
viktorsomogyi
A broker that crashes and restarts while a classic-to-diskless switch is pending can apply a first metadata image that still shows it as the leader in the same leader epoch. The controller rejects the new registration with
DuplicateBrokerRegistrationExceptionuntil the old session expires, and the broker publishes its first image once it catches up to the metadata high watermark, without waiting for the registration.Problem
ReplicaManager.applyLocalLeadersDeltatakes the switch branch only for a partition that already has aPartitionobject. In the first delta after a restart, noPartitionexists. #874 covers a topic that doesn't consolidate: the post-restart branch seals, aborts open transactions, and registers the partition. A consolidating topic still misses it.consolidationActiveForis true while the switch is pending, so the consolidating branch runsmakeLeaderand queues the partition for consolidation fetching. It doesn't seal, abort, or register.No broker sends
InitDisklessLogfor that partition, and produce getsREPLICA_NOT_AVAILABLE. The switch resumes only after the controller fences the old session and bumps the leader epoch, so it's delayed by up tobroker.session.timeout.ms.Fix
makeLeader, and then seals it. The log exists only aftermakeLeader. Produce can't append to the classic log in between, becauseappendRecordsanswersREPLICA_NOT_AVAILABLEfor a pending partition before it reaches the log.applyLocalFollowersDeltadoes for a pending switch. This case happens after a disk replacement, or when the partition directory is missing and an ELR election picks the broker. OtherwisemakeLeadercreates an empty log,registerPartitionproposes its high watermark of 0 as the seal, the controller commits it, and the followers truncate the classic prefix they hold.abortOngoingTransactionsAsSealedLeader()and registers the partition withInitDisklessLogManager.maybeReconcileSwitchedLeader,maybeRollSwitchedLeaderForUpload, andmaybeDropLocalClassicPrefixreturn early for a negative seal, so they don't act on the pending partition.CLASSIC_TO_DISKLESS_SWITCH.mddescribes the restarted leader in the leadership-change paragraph.Interaction with #872
#872 adds
testRearmAfterLoweringMinIsrLetsAStuckPendingSwitchReachTheSeal, which starts from an empty image with this broker as the pending leader of a consolidating topic. With this change, that first delta seals and registers the partition, so the test now checks a registration after its first delta and expectsregisterPartitioncounts of 2 and 3 after the later deltas.Test plan
testFirstDeltaAsPendingLeaderOfConsolidatingTopicSealsAndRegistersandtestFirstDeltaAsPendingLeaderOfNonConsolidatingTopicSealsAndRegistersapply a first delta fromTopicsImage.EMPTYwith-2and this broker as the leader, on a local log with an open transaction. They check that the partition is online, leads, is sealed, and is registered once, that the transaction is aborted with a control batch in the restart leader epoch, and, for the consolidating topic, that no consolidation fetcher starts.testConsolidatingSwitchSealsRegistersThenStartsConsolidationOnClassicPrefixFlagCommitnow expects registration after its first delta and a second registration after the leader epoch bump.testApplyDeltaFencesConsolidatingLeaderBelowSealInPhaseOnenow expects the pending delta to seal and roll the active segment, and the seal commit to fence the leader without another roll.testFirstDeltaAsPendingLeaderOfConsolidatingTopicWithoutLocalLogSkipsThePartitionandtestFirstDeltaAsPendingLeaderOfNonConsolidatingTopicWithoutLocalLogSkipsThePartitionapply the same first delta with no local log. They check that the broker creates no log and noPartition, never callsregisterPartition, and, for the consolidating topic, starts no consolidation fetcher. Without the missing-log check, both tests fail.ReplicaManager.scalareset tomain, the consolidating test and the two updated tests fail. The non-consolidating test andtestApplyDeltaRegistersPendingSwitchLeaderWithoutExistingPartitionfrom #874 pass, because #874 already handles that case.ReplicaManagerInklessTest(297 tests),DisklessSwitchInvariantsTest(15 tests),InitDisklessLogManagerTest(65 tests), andPartitionTest(105 tests) pass, along with:core:checkstyleMainand:core:checkstyleTest. Vale reports no alerts on the added lines.KC-752
🤖 Generated with Claude Code
[KC-752]: https://aiven.atlassian.net/browse/KC-752?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ