← Back to Pull requests

feat(inkless:controller): gate ISR, reassignment, and leader election on switch phase #833

Closed
unknown closed this pull request without merging on Oct 23, 2026 13:53 UTC
View on GitHub
unknown unknown commented on Oct 21, 2026 12:26 UTC
Author

In the two-phase classic-to-diskless switch, phase 1 lasts while a partition has a seal (classicToDisklessStartOffset != -1) and classicPrefixInRemoteStorage is false. During phase 1, the classic prefix below the seal exists only on the replicas' local disks, so the controller must enforce classic ISR, reassignment, and leader election rules. Once classicPrefixInRemoteStorage is true (phase 2), the prefix lives in remote storage and no replica relies on its local copy, so the controller applies born-diskless rules.

This PR adds isSwitchedWithLocalClassicPrefix(PartitionRegistration) on ReplicationControlManager and gates the controller's switch-sensitive paths on it. Broker-side ISR shrink for lag in phase 1 moves to a follow-up PR, as it requires consolidation stop in phase 1 which is not implemented yet.

Changes

  • Add ReplicationControlManager.isSwitchedWithLocalClassicPrefix: returns true when classicToDisklessStartOffset != NO_CLASSIC_TO_DISKLESS_START_OFFSET and classicPrefixInRemoteStorage is false.

  • ReplicationControlManager.alterDisklessSwitch: reject any seal modification once classicPrefixInRemoteStorage is true, including lowering the seal. In phase 2, brokers delete their local prefix below the committed seal and start consolidating from it, so the seal can't move afterward.

  • ReplicationControlManager.leaderAcceptorFor (both overloads): use LeaderAcceptor (which requires an online replica directory) when isSwitchedWithLocalClassicPrefix(partition) is true, and keep isActive-only for born-diskless and phase-2 partitions.

  • ReplicationControlManager.changePartitionReassignment: take the staged addingReplicas/removingReplicas path when isSwitchedWithLocalClassicPrefix(part) is true, and take the one-step path for born-diskless and phase-2 partitions. This supersedes #757. When an administrator retargets a diskless partition that already has a reassignment in progress, the staged path reconciles the inherited adding and removing replicas against the new target, and the one-step path clears them even when the new target equals the current replicas.

  • ReplicationControlManager.expandIsrForDisklessManagedPartitions: skip unfence ISR expansion only while isSwitchedWithLocalClassicPrefix(partition) is true, so phase-2 partitions re-add unfenced replicas and complete in-flight reassignments like born-diskless partitions. Pass r -> r == brokerId || clusterControl.isActive(r) to leaderAcceptorFor so an in-flight reassignment that removes the current leader can elect the unfencing broker before its BrokerRegistrationChangeRecord is replayed.
  • Test plan

  • ReplicationControlManagerInklessTest.testAlterDisklessSwitchRejectedAfterClassicPrefixInRemoteStorage: verifies that lowering (0, 50), matching (100), raising (150), and negative (-1, -2) seal offsets all fail with InvalidRequestException once the flag is set.

  • ReplicationControlManagerInklessTest$DisklessManagedReplicasTests.testLeaderElectionRequiresOnlineDirectoryUntilClassicPrefixIsInRemoteStorage: verifies that a replica with DirectoryId.LOST can't win leader election in phase 1 or while the switch is pending (via both handleBrokerFenced and electLeader), and can win in phase 2.

  • ReplicationControlManagerInklessTest$DisklessManagedReplicasTests: covers staged reassignment completion and cancellation in phase 1 (testReassignSwitchedPartitionStagesTargetInsteadOfGrantingIsr, testCancelReassignmentOfSwitchedPartitionRevertsStagedState, testReassignConsolidatingSwitchedPartitionAlsoStages) and one-step reassignment in phase 2 (testReassignSwitchedPartitionWithClassicPrefixInRemoteStorageCompletesInOneStep).

  • ReplicationControlManagerInklessTest$DisklessManagedReplicasTests.testUnfenceExpandsIsrOfBornDisklessButNotSwitchedPartitions: verifies that unfencing expands ISR for born-diskless and phase-2 partitions and skips phase-1 and pending-switch partitions.

  • ReplicationControlManagerInklessTest$SetClassicPrefixInRemoteStorageTests.testSetClassicPrefixInRemoteStorageInFlightReassignmentCompletesOnLaterPhase2Unfence: verifies that a staged reassignment still in flight when the flag commits completes when the adding replica unfences in phase 2.
  • Known limitation

    A consolidating follower can leave the classic fetcher at the seal without reporting itself in sync. Until a follow-up PR stops consolidation in phase 1, a phase-1 reassignment that adds such a follower can wait for the flag commit to finish it. The controller side in this PR handles that case: the flag commit completes the reassignment and elects the leader with phase-2 rules.

  • ReplicationControlManagerInklessTest$DisklessManagedReplicasTests.testRetargetAfterFlagKeepsRequestedReplicasWhenTargetKeepsRemovingReplica and testRetargetAfterFlagClearsStaleAddingReplica: verify that retargeting a partition whose phase-1 reassignment survived the flag commit uses exactly the requested replicas.

  • ReplicationControlManagerInklessTest$SetClassicPrefixInRemoteStorageTests.testSetClassicPrefixInRemoteStorageElectsLeaderWithLostDirectoryWhenCompletingReassignment: verifies that the flag commit elects a leader among the target replicas when they all have lost directories.

  • ReplicationControlManagerInklessTest$DisklessManagedReplicasTests.testRetargetAfterFlagToExactCurrentReplicasClearsUnfinishedReassignment: verifies that requesting exactly the current replicas clears an unfinished phase-1 move after the flag commits.

  • ReplicationControlManagerInklessTest$DisklessManagedReplicasTests.testRetargetStagedReassignmentDropsAddingReplicaThatIsNoLongerRequested and testRetargetStagedReassignmentKeepsCatchUpForAddingReplicaStillRequested: verify that retargeting a staged phase-1 reassignment drops adding replicas that are no longer requested and keeps catch-up for the ones that still are.
  • Assisted-by: Gemini 4 Argon

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: giuseppelillo Review duration: 2967m
    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 #833"
    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