← Back to Pull requests

fix(inkless:switch): validate the classic epoch history of replicas admitted in phase 2 [KC-702] #851

Closed
unknown closed this pull request without merging on Nov 05, 2026 12:21 UTC
View on GitHub
unknown unknown commented on Nov 04, 2026 10:56 UTC
Author

In phase 2 of the classic-to-diskless switch, the controller adds every live replica to the ISR without checking its local copy of the classic prefix, and any replica can lead. A replica can hold records below the seal that the partition doesn't hold. It led an older leader epoch and wrote records that the next leader didn't have, or an unclean leader election before the switch discarded records below its high watermark. Forced deletion keeps the leader epoch cache of that replica, and the remote log manager uses it to compute the highest offset in remote storage and to pick remote segments. On that replica, a tiered read below the seal fails with OFFSET_OUT_OF_RANGE, and the consumer resets its offset. On an idle topic, the highest offset in remote storage also stays below the seal, so forced deletion never completes.

Changes

  • Recorded epoch: the leader that requests the phase 2 flag sends the leader epoch of its record at seal - 1 in SetClassicPrefixInRemoteStorage. The controller stores it with the flag as tag 104 (lastClassicLeaderEpoch) and drops it when the switch is undone. The value is -1 if the leader's log doesn't contain a record below the seal.

  • Replica check: a consolidating replica checks its leader epoch cache when it becomes the leader, and when it becomes a follower of a new leader epoch. A follower runs the check after its fetchers stop. If the cache doesn't map seal - 1 to the recorded epoch, the replica truncates its log fully at the log start offset. Each epoch has one leader, so a matching epoch proves that the records below the seal are the committed ones, at any high watermark. After the truncation, the log ends below the seal, like the log of a replica that lost its local data. The existing recovery rebuilds the log, the leader epoch cache, and the producer state from remote storage. A follower that keeps its leader epoch when phase 2 starts was an ISR member or ran the classic fetcher in phase 1, so the leader's divergence check covers it.

  • Rebuild: for the epoch before the diskless epoch, DisklessLeaderEndPoint returns the recorded epoch instead of the queried one. That epoch has no records, and TierStateMachine looks up the remote segment at seal - 1 by the returned epoch. Remote storage can also hold a segment at seal - 1 from a discarded epoch, so the endpoint doesn't take the epoch from remote storage.

  • First prune: for a switched topic, the endpoint uses the seal as the lowest WAL start, and fetchEarliestLocalOffset applies the same bound. The control plane keeps the WAL start at the classic log start until the first prune moves it to the seal. Without the bound, a leader that lost its local log before that prune reads the first diskless batch at offset 0, and its local log hides the remote prefix.

  • Retention: while a consolidating leader rebuilds, its leader epoch cache lacks the older epochs. The remote log manager runs its expiration task as soon as the broker becomes the leader. That task deletes every remote segment whose epochs are all older than the earliest cached epoch, without an offset check. For a consolidating partition, that cleanup now deletes only the segments that end below the cross-tier log start. Without this guard, the task deletes the classic prefix that the rebuild reads. A leader that lost its local log had the same exposure.

  • Docs: CLASSIC_TO_DISKLESS_SWITCH.md describes the recorded epoch and the replica check. DISKLESS_CONSOLIDATION.md describes the epoch that the endpoint returns, the first-prune bound, and the retention guard.
  • A leader uploads only segments below its last stable offset. Unclean leader election is off before the switch and blocked in phase 1, so the classic prefix in remote storage contains only committed records.

    inkless-release-0.50 has the SetClassicPrefixInRemoteStorage RPC and tag 103, but its brokers don't send the flag request. So no released partition is in phase 2 without the recorded epoch.

    Limitations

  • If lastClassicLeaderEpoch is -1, brokers skip the check. Besides an empty prefix, that covers a flag that a controller or leader without this change set, for example during a rolling upgrade.

  • Only consolidating partitions run the check. A switched leader below the seal of a partition that doesn't consolidate goes offline, because nothing rebuilds its prefix from remote storage.

  • A replica whose log ends below the seal compares the latest epoch in its cache, so it can truncate even when its records match. That costs only the rebuild.

  • The leader relies on the TierStateMachine rebuild, like a leader that lost its local log. A gap in that rebuild affects both cases.

  • For a consolidating partition, a remote segment from an epoch older than the leader's cache that doesn't end below the cross-tier log start stays until retention moves that start past it. That includes a divergent segment from before the switch. Upstream treats a divergent segment inside the cached epochs the same way.
  • Testing

  • testSwitchedLeaderInPhaseTwoChecksLastClassicLeaderEpoch elects a leader that wrote [7, 10) in epoch 1, with its high watermark at 7 and at the seal. If the recorded epoch is 0, the leader truncates fully, stays online, and starts consolidation at 0. If it's 1, the leader keeps its log and starts consolidation at the seal.

  • testSwitchedConsolidatingFollowerInPhaseTwoChecksLastClassicLeaderEpoch runs a follower at the seal with its high watermark at the seal. With a matching epoch, it consolidates from the seal. With a divergent epoch, it truncates fully and fetches from 0 on the classic fetcher.

  • testTierStateMachineLooksUpLastClassicSegmentByRecordedEpoch runs TierStateMachine against DisklessLeaderEndPoint while a segment from a discarded epoch also covers seal - 1. The lookup uses the recorded epoch and never the discarded one.

  • testFetchEpochEndOffsetsBelowDisklessEpochReturnsLastClassicLeaderEpoch checks the epoch that the endpoint returns for a query above, at, and below the recorded epoch, and without one.

  • PartitionRegistrationTest, PartitionChangeBuilderTest, ReplicationControlManagerInklessTest, and InitDisklessLogManagerTest cover the field from the leader's request through the controller record, replay, merge, and switch undo.

  • testFetchAtSealBeforeFirstPruneReadsTheWal, testFetchSignalsOffsetMovedBelowSealBeforeFirstPrune, testFetchRetriesBelowSealBeforeFirstPruneWithoutRemoteCoverage, and testFetchEarliestLocalOffsetBeforeFirstPruneUsesSealAndDisklessEpoch cover the first-prune bound.

  • testEpochCacheCleanupKeepsConsolidatingSegmentsFromCrossTierStart and testFullTruncationBeforePromotionKeepsRemotePrefixUntilRebuild cover the retention guard. The second test runs on a real log, before and after the rebuild.

  • ReplicaManagerInklessTest, ReplicaManagerTest, ReplicaFetcherThreadTest, DisklessSwitchInvariantsTest, DisklessSwitchFlowTest, InitDisklessLogManagerTest, InklessMetadataViewTest, DisklessLeaderEndPointTest, ConsolidationFetcherThreadTest, RemoteLogManagerTest, QuorumControllerTest, RequestResponseTest, and MessageTest pass, along with the metadata tests in the preceding item.

  • checkstyleMain, checkstyleTest, spotbugsMain, and spotlessCheck pass on clients, metadata, and core. The full ./gradlew check -x test -x generateJooqClasses didn't run locally.

  • The system tests under tests/kafkatest/tests/inkless/ didn't run on this change.

  • make vale doesn't report any alerts.
  • Assisted-by: Claude Opus 5.5

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