← Back to Pull requests

fix(inkless:switch): seal and register a pending partition in the first delta after a restart [KC-752] #877

Closed
unknown closed this pull request without merging on Nov 19, 2026 11:20 UTC
View on GitHub
unknown unknown commented on Nov 17, 2026 11:19 UTC
Author

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 DuplicateBrokerRegistrationException until 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.applyLocalLeadersDelta takes the switch branch only for a partition that already has a Partition object. In the first delta after a restart, no Partition exists. #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. consolidationActiveFor is true while the switch is pending, so the consolidating branch runs makeLeader and queues the partition for consolidation fetching. It doesn't seal, abort, or register.

No broker sends InitDisklessLog for that partition, and produce gets REPLICA_NOT_AVAILABLE. The switch resumes only after the controller fences the old session and bumps the leader epoch, so it's delayed by up to broker.session.timeout.ms.

Fix

  • A pending leader always takes the switch branch, for a consolidating topic too.

  • If the partition doesn't exist, the switch branch creates it, runs makeLeader, and then seals it. The log exists only after makeLeader. Produce can't append to the classic log in between, because appendRecords answers REPLICA_NOT_AVAILABLE for a pending partition before it reaches the log.

  • If the partition doesn't exist and the broker has no local log, the switch branch logs a warning and skips the partition, as applyLocalFollowersDelta does 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. Otherwise makeLeader creates an empty log, registerPartition proposes its high watermark of 0 as the seal, the controller commits it, and the followers truncate the classic prefix they hold.

  • In both cases where the leader has a log, it then aborts open transactions with abortOngoingTransactionsAsSealedLeader() and registers the partition with InitDisklessLogManager.

  • The post-restart branch now handles only committed seals, so the pending-switch handling that #874 added there moves into the switch branch.
  • maybeReconcileSwitchedLeader, maybeRollSwitchedLeaderForUpload, and maybeDropLocalClassicPrefix return early for a negative seal, so they don't act on the pending partition. CLASSIC_TO_DISKLESS_SWITCH.md describes 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 expects registerPartition counts of 2 and 3 after the later deltas.

    Test plan

  • testFirstDeltaAsPendingLeaderOfConsolidatingTopicSealsAndRegisters and testFirstDeltaAsPendingLeaderOfNonConsolidatingTopicSealsAndRegisters apply a first delta from TopicsImage.EMPTY with -2 and 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.

  • testConsolidatingSwitchSealsRegistersThenStartsConsolidationOnClassicPrefixFlagCommit now expects registration after its first delta and a second registration after the leader epoch bump.

  • testApplyDeltaFencesConsolidatingLeaderBelowSealInPhaseOne now expects the pending delta to seal and roll the active segment, and the seal commit to fence the leader without another roll.

  • testFirstDeltaAsPendingLeaderOfConsolidatingTopicWithoutLocalLogSkipsThePartition and testFirstDeltaAsPendingLeaderOfNonConsolidatingTopicWithoutLocalLogSkipsThePartition apply the same first delta with no local log. They check that the broker creates no log and no Partition, never calls registerPartition, and, for the consolidating topic, starts no consolidation fetcher. Without the missing-log check, both tests fail.

  • With ReplicaManager.scala reset to main, the consolidating test and the two updated tests fail. The non-consolidating test and testApplyDeltaRegistersPendingSwitchLeaderWithoutExistingPartition from #874 pass, because #874 already handles that case.

  • ReplicaManagerInklessTest (297 tests), DisklessSwitchInvariantsTest (15 tests), InitDisklessLogManagerTest (65 tests), and PartitionTest (105 tests) pass, along with :core:checkstyleMain and :core:checkstyleTest. Vale reports no alerts on the added lines.

  • No cluster test covers this case. It needs a broker that crashes without a controlled shutdown, and a controlled shutdown moves leadership before the broker restarts.
  • KC-752

    🤖 Generated with Claude Code

    [KC-752]: https://aiven.atlassian.net/browse/KC-752?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

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