← Back to Pull requests

fix(inkless:switch): answer OffsetsForLeaderEpoch on in-sync followers while the switch is pending [KC-870] #904

Closed
unknown closed this pull request without merging on Nov 26, 2026 13:36 UTC
View on GitHub
unknown unknown commented on Nov 25, 2026 16:00 UTC
Author

While the switch of a partition is pending, an in-sync follower rejects OffsetsForLeaderEpoch, and a consumer that the metadata routing sends to that follower reads nothing until the controller commits the seal. With this change the in-sync follower answers from its local classic log.

Problem

While classicToDisklessStartOffset is -2, InklessTopicMetadataTransformer advertises an alive ISR member as the leader, a replica in the client's zone first. For many clients that replica is a follower.

The controller bumps the leader epoch when it marks the switch pending. A consumer whose position has a leader epoch then validates the position with OffsetsForLeaderEpoch before it fetches again, and it sends the request to the advertised replica. In ReplicaManager.lastOffsetForLeaderEpoch, the pending case answers only on the leader, so a follower returns NOT_LEADER_OR_FOLLOWER. The consumer refreshes its metadata, gets the same follower, and retries until the seal commits.

ListOffsets already lets an in-sync follower answer a client request in this state, and a consumer fetch works on the follower. Only the validation fails.

Example before this change

On a 3-broker cluster in three zones, one follower stops without a controlled shutdown and stays in the ISR. The leader then holds one record above its high watermark, and the switch stays pending for 31 seconds. During that time, three consumers poll for 6 seconds from offset 5:

| Consumer | Records read |
| --- | --- |
| Routed to the in-sync follower, position with a leader epoch | 0 |
| Routed to the in-sync follower, position without a leader epoch | 15 |
| Routed to the leader, position with a leader epoch | 15 |

After the seal commits, the first consumer reads its records. On a healthy cluster the switch stays pending for 533 to 566 ms, measured over three switches.

Fix

While the switch is pending, a follower that is in the ISR answers OffsetsForLeaderEpoch from its local classic log. Its log holds every record below the leader's high watermark, and a consumer validates a position at or below that offset. The end offset that the follower returns is at or past that position.

A follower caches only the leader epochs of the batches it appends. It has no end offset for a leader epoch higher than the last one in its log, such as the leader epoch of the switch. A consumer reads an undefined end offset as a truncation and resets its position. The follower returns NOT_LEADER_OR_FOLLOWER for such an epoch, as before this change.

A replica outside the ISR still returns NOT_LEADER_OR_FOLLOWER. The leader's answer doesn't change.

Test plan

  • ReplicaManagerInklessTest has three new tests for a follower of a pending partition: an in-sync follower answers, a follower outside the ISR returns NOT_LEADER_OR_FOLLOWER, and an in-sync follower returns NOT_LEADER_OR_FOLLOWER for an epoch higher than the last one in its log. The first test fails without the change to ReplicaManager. The class passes with 317 tests, and ReplicaManagerTest passes with 129 tests.

  • InklessTopicTypeSwitcherClusterTest has a new test, testConsumerRoutedToInSyncFollowerReadsWhileSwitchIsPending. It holds the switch pending as in the example, and a consumer in the follower's zone reads from its position while the switch is still pending. Without the change to ReplicaManager it fails with The consumer read no record from the in-sync follower. The class passes with 10 tests.

  • The new cluster test uses a no-controlled-shutdown tag. For a tagged test, the setup sets controlled.shutdown.enable=false and broker.session.timeout.ms=30000. The other tests keep the default values.

  • This branch merges without conflicts with #900, #901, and #903. With all three merged, the new tests and the cluster tests of #900 and #903 pass.

  • :core:checkstyleMain, :core:checkstyleTest, :core:spotlessCheck, and :core:spotbugsMain pass. make vale reports no alerts on the added lines.
  • 🤖 Generated with Claude Code

    Assisted-by: Claude Fable 5.2

    Diff: 513 lines (+384 / -129) across 6 files Reviewer: giuseppelillo Review duration: 1296m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 513 lines diff across 6 files
    0.48
    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.373
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #904"
    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: 47.7% (MEDIUM) · Higher = larger blast radius
    47.7%
    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: 18.8% · Safe to merge
    18.8%
    Repository