docs(inkless:switch): describe the last-known-leader election in phase 1 [KC-759] #871
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 576 lines diff across 7 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.380
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #871"
general
weight: 0.35
giuseppelillo
With eligible leader replicas (ELR) enabled, a partition in phase 1 of the classic-to-diskless switch can still elect a leader from outside its ISR.
CLASSIC_TO_DISKLESS_SWITCH.mdsays that a partition that loses every ISR member has no leader until one of them returns. The last-known-leader election of KIP-966 contradicts that, and the docs don't describe it.Problem
The phase 1 guards in
ReplicationControlManagerblock unclean leader election by not callingsetElection(Election.UNCLEAN).PartitionChangeBuilder.electAnyLeaderandelectPreferredLeadercallcanElectLastKnownLeader()before they check the election type. So the last-known-leader election runs for every election type, andunclean.leader.election.enabledoesn't control it.The following example uses replicas
[2, 0, 1],min.insync.replicas=2, and a seal at 20:| Step | Event | ISR | ELR |
lastKnownElr| Leader || --- | --- | --- | --- | --- | --- |
| 1 | Phase 1 starts |
[2, 0, 1]|[]|[]| 2 || 2 | Brokers 0 and 1 stop |
[2]|[0]|[]| 2 || 3 | Broker 2 stops after its log loses offsets 15 to 19 |
[]|[0, 2]|[2]| none || 4 | Brokers 0 and 1 return after an unclean shutdown |
[]|[2]|[2]| none || 5 | Broker 2 returns after an unclean shutdown |
[2]|[]|[]| 2,RECOVERING|The partition loses offsets 15 to 19, even though the high watermark covered them. KIP-966 accepts the same loss for a classic topic. In phase 1, the loss shows up differently:
Change
The switch doc gains a "Last-known-leader election" subsection. It describes when the controller runs the election, what happens to a partition in phase 1, and how to recover one that's offline:
1. Lower the seal to the leader's log end offset with
kafka-topic-switch.sh seal.2. Restart the leader. The broker doesn't apply metadata changes to a partition that it marked offline.
3. Run
kafka-topic-switch.sh repair.The recovery loses the records between the leader's log end offset and the old seal. The "Unclean leader election" section and the phase table now point to the new subsection.
This change doesn't modify controller behavior. Blocking the election in phase 1 would leave the partition without a leader in both outcomes: the one where the last known leader holds the whole prefix, and the one where it doesn't.
Testing
ClassicToDisklessSwitchLastKnownLeaderClusterTestruns the sequence in the example on a 3-broker cluster with ELR enabled. A gated remote storage manager fails segment copies until the test releases it. Without the gate, the leader rolls its active segment at the seal and the partition leaves phase 1 within one task interval. The test deletes the clean-shutdown markers, so the controller sees unclean shutdowns.The test is parametrized on
loseTail, so it covers both outcomes in the doc.With
loseTail=true, the test truncates the leader's log to 15 before the leader stops. It then checks the following:RECOVERINGstate, and the leader marks the partition offline.kafka-topic-switch.sh sealvalidates against. After the seal is lowered, the partition stays offline until the leader restarts.auto.offset.reset=nonereads offsets 0 to 14 and the diskless records at 20 to 24.With
loseTail=false, the test checks the following:The test doesn't run the recovery without the repair step, or the election while the switch is pending. The doc describes the pending case from the code.
KC-759
🤖 Generated with Claude Code
Assisted-by: Claude Opus 5.5
[KC-759]: https://aiven.atlassian.net/browse/KC-759?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ