← Back to Pull requests

refactor(inkless:switch): replace the seal and repair commands with rearm and lower-seal #872

Closed
unknown closed this pull request without merging on Nov 17, 2026 18:56 UTC
View on GitHub
unknown unknown commented on Nov 13, 2026 15:30 UTC
Author

This PR reduces kafka-topic-switch.sh to a read-only state command and two narrow write commands, rearm and lower-seal. It removes every other operator command that writes a seal offset or changes the control plane.

Removed:

  • The seal command, with all its options: --offset with N ≥ 0, -1, and -2, plus --clear-producer-states and --dry-run.

  • The repair command.

  • Every AlterDisklessSwitch input except two: -2 on a pending switch, and a seal lower than the committed seal in phase 1. The ClearProducerStates field is gone, and AlterDisklessSwitchOptions no longer has clearProducerStates.

  • The RepairDisklessLog broker RPC, along with Admin.repairDisklessLog, its broker handler, its control plane code in both implementations, and its metrics.

  • The repair_diskless_log_v1 Postgres function and its types, which migration V32__Remove_repair_diskless_log.sql drops.
  • New:

  • The rearm --topic T --partition P command. It sends AlterDisklessSwitch with -2, which the controller accepts only while the switch is pending. The controller bumps the leader epoch, so the leader seals again.

  • The lower-seal --topic T --partition P --offset N command. It sends AlterDisklessSwitch with N, which the controller accepts only for a committed seal in phase 1 and a seal that is at least 0 and lower than the committed one. The command rejects a negative offset before it sends the request, because the controller reads -2 as a re-arm. It keeps the recovery in the "Last-known-leader election" section of CLASSIC_TO_DISKLESS_SWITCH.md working: after a last-known-leader election picks a leader whose log ends below the seal, lowering the seal to that leader's log end offset brings the partition back.
  • Unchanged:

  • The state command.

  • The leader-driven switch flow.
  • [!NOTE]

    After lower-seal, the seal in KRaft and the diskless log in the control plane disagree, and the records between them are lost.

    > lower-seal writes the new seal to KRaft only. Every replica truncates its classic log to the new seal. The control plane already has a row for the partition, and the diskless records past the old seal already have their offsets. When the leader sends InitDisklessLog again, the control plane answers already_initialized and changes nothing. So the diskless log still starts at the old seal, and the offsets between the two seals exist in neither log.

    > For example, ClassicToDisklessSwitchLastKnownLeaderClusterTest commits a seal at offset 20 and then writes diskless records at offsets 20 to 24. A last-known-leader election picks a leader whose log ends at offset 15, so the partition goes offline. After lower-seal --offset 15 and a leader restart:

    > - The seal in KRaft is 15.

    - Every replica's classic log ends at offset 15, so it holds offsets 0 to 14.

    - The control plane's diskless log still starts at offset 20.

    - A consumer that reads from offset 0 gets offsets 0 to 14, then 20 to 24. Offsets 15 to 19 are gone, and the broker returns no error for them.

    > No tool reconciles the two, and nothing needs one: the partition serves every remaining record and finishes the switch. The removed repair command didn't change this either, because it only wrote the control plane's diskless_start_offset column, which nothing reads at runtime.

    Before and after

    Each row of the following table describes a problem an operator can face, how the tooling handled it before this PR, and how it's handled after. The last column describes what to do in the cases this PR makes impossible.

    | Problem | Before this PR | After this PR | How to deal with it |
    | --- | --- | --- | --- |
    | A pending switch doesn't progress because the leader isn't driving it, for example after the leader restarted while the switch was pending. | seal --offset -2 re-arms the switch. The controller bumps the leader epoch, so the leader seals again and registers the partition for InitDisklessLog. | rearm --topic T --partition P does the same thing. It sends AlterDisklessSwitch with -2. | Not needed |
    | A pending switch is stuck because the ISR dropped below min.insync.replicas, so the high watermark can't reach the sealed log end offset. | seal, with or without --offset N, commits a seal without the leader. The seal carries no producer states, so an idempotent producer that was active before the seal fails with OUT_OF_ORDER_SEQUENCE_NUMBER on its next batch. If the seal is above the high watermark, it includes records that aren't fully replicated. | Restart the brokers of the out-of-sync followers. They keep fetching up to the sealed log end offset while the switch is pending, and once they rejoin the ISR, the leader proposes the seal. If they can't come back, lower the topic's min.insync.replicas and run rearm: the leader recomputes its high watermark and proposes the seal with producer states. Adding new replicas doesn't help, because a new replica doesn't fetch until the seal commits. | Not needed |
    | A phase 1 partition is offline because a last-known-leader election picked a leader whose log ends below the seal. No other replica can lead, and phase 2 can't start. | seal --offset N lowers the seal to the leader's log end offset. The same command also accepts a pending switch, -1, and -2. The documented procedure then runs repair, which writes a control plane column that nothing reads. | lower-seal --offset N sends AlterDisklessSwitch with N. The controller accepts it only for a committed seal in phase 1 and a seal lower than the committed one. The procedure has no repair step. In both cases, every replica truncates its classic log to N, the control plane keeps the diskless log starting at the old seal, and the partition loses the records between N and the old seal. A consumer that reads across them gets the diskless records from the old seal on, without an error. | Not needed |
    | The committed producer states should be cleared. | seal --clear-producer-states never works. The controller builds a record with tags out of order, which can't be serialized. Each attempt makes the active controller resign, and the client gets UNKNOWN_SERVER_ERROR. | Not possible. | Not needed. The option only applied to a forced seal (--offset N with N ≥ 0), whose seal could disagree with the producer states already committed. The leader commits the seal and the producer states together, from the same log end offset, so they always match. |
    | A pending switch should be canceled, and the partition should go back to classic. | seal --offset -1 doesn't revert the partition. The topic keeps diskless.enable=true, so produce takes the diskless path and fails with UNKNOWN_TOPIC_OR_PARTITION, the classic log stays sealed, and the controller guards for a local-only classic prefix stop applying. Nothing can undo it: the controller rejects any later AlterDisklessSwitch for the partition, setting diskless.enable=true again starts no switch, and diskless.enable can't be disabled. | Not possible. A switch can only be finished, with rearm or a leader election. | The switch must be completed. |
    | The control plane disagrees with the seal in KRaft after an operator lowered the seal. | repair sets the control plane's diskless_start_offset to the new seal. Nothing at runtime reads that column, so it changes nothing for produce, fetch, or ListOffsets. | No command reconciles them, and nothing needs it. The control plane keeps the diskless log starting at the old seal. A consumer reads the classic records up to the new seal, then the diskless records from the old seal on. See the preceding note. | Not needed |

    Test plan

  • ./gradlew check -x test -x generateJooqClasses and make docs pass, with no uncommitted changes.

  • make vale reports no alerts.

  • These test classes pass: TopicSwitchCommandTest, ReplicationControlManagerInklessTest, RequestResponseTest, ApiKeysTest, MessageTest, RequestQuotaTest, ControllerApisTest, ReplicaManagerInklessTest, AbstractControlPlaneTest subclasses, and AvailabilityGatedControlPlaneTest.

  • InklessTopicTypeSwitcherClusterTest passes. The new testAlterDisklessSwitchRejectsReArmAndNonLowerSealOnCommittedSwitch switches a topic, waits for the seal to commit, and checks that the controller rejects -2, -1, the committed seal, and a higher seal, and keeps the seal.

  • ClassicToDisklessSwitchLastKnownLeaderClusterTest passes in both cases. With loseTail=true, it lowers the seal with alterDisklessSwitch, restarts the leader without running repair, finishes the switch, and reads the expected records from offset 0.

  • The new ReplicationControlManagerInklessTest cases check that alterDisklessSwitch lowers a committed seal in phase 1, keeps the leader epoch and the producer states, and writes a record that survives serialization. They also check that it rejects a seal on a pending switch, a lower seal in phase 2, on a classic topic, or on an unknown partition, a seal that isn't lower than the committed one, and every negative seal offset other than -2.

  • TopicSwitchCommandTest checks that lower-seal rejects -2 and -1 without sending a request.

  • The new testRearmAfterLoweringMinIsrLetsAStuckPendingSwitchReachTheSeal puts a leader in a pending switch with its ISR below min.insync.replicas. Lowering the config leaves the high watermark in place, and the rearm record advances it to the log end offset and registers the partition again.

  • testConsolidatingSwitchSealsRegistersThenStartsConsolidationOnClassicPrefixFlagCommit covers the restarted leader: a first delta from an empty image doesn't register the partition, and the record that rearm writes does.

  • testFetchConsolidatingDisklessSwitchPendingReadsFromUnifiedLogWhenConsolidationEnabled covers consumer reads from a pending partition.
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: giuseppelillo Review duration: 5965m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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 #872"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository