← Back to Pull requests

fix(inkless:switch): return a diskless leader epoch with a diskless offset in ListOffsets [KC-865] #900

Closed
unknown closed this pull request without merging on Nov 27, 2026 10:38 UTC
View on GitHub
unknown unknown commented on Nov 25, 2026 13:55 UTC
Author

A consumer that takes its position and leader epoch from ListOffsets on a switched partition seeks back to the seal the next time it validates that position. With this change, ListOffsets returns an epoch that keeps the position.

Problem

ListOffsets returns leader epoch 0 with every diskless offset, because FetchOffsetHandler sets a placeholder epoch on each control-plane result. On a switched partition, ReplicaManager.lastOffsetForLeaderEpoch treats an epoch below initialDisklessLeaderEpoch as a classic epoch and answers with an end offset at or below the seal. A client that keeps the epoch of the ListOffsets response then sees a truncation when it validates its position.

A consumer fetch doesn't have this problem: ReplicaManager.stampDisklessLeaderEpoch sets disklessLeaderEpoch on the batches that a switched partition serves from diskless storage. The Java consumer drops the epoch of a reset position (OffsetFetcherUtils.resetPositionIfNeeded), so it isn't affected on a reset. Other clients keep the epoch:

  • librdkafka passes the epoch of the ListOffsets response to the fetch position (rd_kafka_toppar_handle_Offset), and rd_kafka_offset_validate sends it when metadata shows a higher leader epoch.

  • The Java consumer, if the application calls seek(TopicPartition, OffsetAndMetadata) with the epoch from offsetsForTimes or Admin.listOffsets.
  • Example before this change

    On a 3-broker cluster, a partition is sealed at offset 20 and has 30 diskless records:

  • Admin.listOffsets(latest) returns offset 50 with leaderEpoch=0. A Java consumer that seeks to offset 50 with that epoch reads its first record at offset 20.

  • kcat 1.7.0 (librdkafka 2.11.1) starts at the log end while the partition is in phase 1 and receives no record. After the leader epoch bump that starts phase 2, with no record produced, kcat prints offsets 20 to 49.
  • Fix

    DisklessFetchOffsetRouter replaces the placeholder on a switched partition:

  • An offset at or past the seal gets disklessLeaderEpoch, the epoch that a consumer fetch carries for the same offsets. OffsetsForLeaderEpoch answers that epoch with the diskless log end offset, so the client keeps its position.

  • An offset below the seal gets no leader epoch, because the broker doesn't know its classic epoch. The client skips the validation.
  • Born-diskless partitions keep the placeholder, and a result from the local log keeps the epoch of the local record.

    Test plan

  • DisklessFetchOffsetRouterTest covers LATEST, MAX_TIMESTAMP, EARLIEST, and a timestamp lookup on both sides of the seal, in phase 1 and phase 2, and a partition with a seal of 0.

  • ReplicaManagerInklessTest.testFetchOffsetLatestOnSwitchedPartitionReturnsAnEpochThatKeepsThePosition sends ListOffsets and validates the returned epoch with OffsetsForLeaderEpoch.

  • InklessTopicTypeSwitcherClusterTest.testConsumerKeepsAPositionFromListOffsetsOnASwitchedPartition runs on 3 brokers. A consumer seeks to the offset and epoch that ListOffsets returns, in phase 1 and in phase 2, and starts at that offset.

  • Without the change to DisklessFetchOffsetRouter, the new router tests, the ReplicaManagerInklessTest test, and the cluster test fail.

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

    Diff: 436 lines (+327 / -109) across 5 files Reviewer: viktorsomogyi Review duration: 2683m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 436 lines diff across 5 files
    0.45
    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.364
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #900"
    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: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    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: 17.9% · Safe to merge
    17.9%
    Repository