← Back to Pull requests

fix(inkless:consolidation): keep diskless leader epoch across leader changes [KC-727] #864

Closed
unknown closed this pull request without merging on Nov 11, 2026 11:29 UTC
View on GitHub
unknown unknown commented on Nov 09, 2026 12:47 UTC
Author

Summary

When a partition's leader changes, Partition.makeLeader assigns a cache entry for the new leader epoch. Consolidation then appends batches in the lower diskless leader epoch. LeaderEpochFileCache.assign drops every entry whose epoch is equal or higher on a non-monotonic append. The consolidated records lose their epoch, and tiered storage can no longer match their segments to the lineage.

 makeLeader
   if the leader epoch is new
-    assignEpochStartOffset(newEpoch, log end offset)
+    if the consolidation epoch is already cached and lower than the new epoch
+      skip the new epoch entry
+    else
+      assignEpochStartOffset(newEpoch, log end offset)

The skip covers a switched partition in phase 2 and a born-diskless partition once the cache contains an entry for the consolidation epoch. Phase 1 and a pending switch still assign the entry, because consolidation doesn't append there. A broker restart takes the same path: a fresh Partition starts at leader epoch -1, so makeLeader treats the unchanged leader epoch as new.

A promoted follower whose log is still at the seal has no diskless leader epoch entry. makeLeader assigns the new epoch at the seal, so a lookup for an epoch between the last classic epoch and the diskless leader epoch returns the seal. The next consolidated append replaces that entry with the diskless leader epoch at the seal.

Brokers that ran without the skip already carry damaged caches. On a born-diskless partition, the damaged cache is (0, X), where X is the log end offset at the leader change or restart. Offsets below X have no epoch, so remote copies of those segments fail and remote reads return OFFSET_NOT_AVAILABLE. The consolidation fetcher repairs the cache before every consolidated append:

 ConsolidationFetcherThread.processPartitionData
+  if the partition has no seal
+    assignEpochStartOffset(0, log start offset)
   stamp the diskless leader epoch
   append

Every consolidated batch of a born-diskless partition has epoch 0, so the correct cache is (0, log start offset). The assignment changes nothing on a correct cache. It replaces a damaged (0, X) entry, and it drops a stale higher entry that a checkpoint kept from before the upgrade. The fetcher runs on leaders and followers, so the next append also repairs a cache that a tier-state rebuild restored from a damaged remote checkpoint. The guard checks the seal, not the diskless leader epoch. Partitions switched before the diskless leader epoch existed have a seal but no diskless leader epoch, and assigning epoch 0 there would drop their classic entries.

The become-leader log mentions the skip when it applies, and a comment next to the skip records the upstream endOffsetFor assumption that the skip breaks. Partition reads the consolidation epoch through a hook, the same way it reads replicationStopOffset. The glossary gains entries for Diskless Leader Epoch and Seal.

Evidence

  • Before: with the skip removed, PartitionTest.testMakeLeaderKeepsDisklessLeaderEpochAfterLeaderChange fails. The cache entry for the diskless leader epoch moves from the seal to the log end: (4, 2) becomes (4, 4). The born-diskless case fails the same way: (0, 0) becomes (0, 2), and so does the restart case, PartitionTest.testMakeLeaderKeepsBornDisklessEpochAfterRestart. An unconditional skip also fails PartitionTest.testMakeLeaderAtSealAssignsEpochWhenDisklessEpochIsMissing: a follower promoted at the seal keeps only (2, 0), and endOffsetFor(3) returns undefined instead of the seal.

  • After: the cached diskless leader epoch stays (4, 2), and the born-diskless cache stays (0, 0) across a leader change and a restart. The promotion at the seal writes (5, 2), endOffsetFor(3) returns 2, and the following consolidated append leaves (2, 0), (4, 2). Those PartitionTest cases pass.
  • Before: with the repair call removed, ConsolidationFetcherThreadTest leaves a damaged cache at (0, 10) and a stale cache at (0, 5), (4, 10). An empty cache doesn't get an entry. A real UnifiedLog rebuilt from a damaged checkpoint stays at (0, 10) after a consolidated append.

  • After: with log start offset 5, each of those caches becomes (0, 5). A correct cache, a pending switch, and switched partitions keep their entries. Those ConsolidationFetcherThreadTest cases pass.

    Test plan

    PartitionTest covers a switched partition and a born-diskless partition across a leader change, a born-diskless partition across a restart into the same leader epoch, and a promotion at the seal before the cache has an entry for the diskless leader epoch. ReplicaManagerInklessTest covers consolidationLeaderEpoch in each switch phase, an end-to-end applyDelta promotion, and an OffsetsForLeaderEpoch query of the new leader epoch that the local cache can't answer. ConsolidationFetcherThreadTest covers the repair of a damaged cache, a stale higher entry, and an empty cache. It also checks that correct caches, a pending switch, and switched partitions with and without a diskless leader epoch keep their entries, and it rebuilds a real UnifiedLog from a damaged checkpoint before a consolidated append.

    Merge Danger

    Door: two-way

    Reverting the change restores the old assignment on the next leader change. A cache that the repair already rewrote keeps its (0, log start offset) entry, which the old code also reads correctly. A promotion at the seal writes a temporary entry for the new epoch, and the next consolidated append replaces it.

    Blast Radius: consolidation

    When the consolidation epoch is already cached, the latest cached epoch sits below the current leader epoch, so endOffsetFor returns undefined for the current epoch. Every caller handles that result today. Turning the broker consolidation flag on or off can still give a born-diskless partition the old behavior, because the check follows that flag.

    A damaged born-diskless partition recovers on each replica at its next consolidated append. These limits remain:

  • Segment uploaded while damaged: its remote metadata keeps {0: X} and indexes the segment at X. After the repair, reads between the segment's base offset and X return OFFSET_OUT_OF_RANGE instead of OFFSET_NOT_AVAILABLE, and a consumer that resets to the earliest offset can reach the same gap again. Every other offset below X becomes readable. The gap lasts until retention deletes that segment.

  • Partitions without new appends: the repair waits for the next consolidated append. Until then, remote copies and reads below X keep failing.

  • Switched partitions: the repair skips them. Their damaged range went to remote storage labeled with the last classic epoch, so a local-only repair would make those segments unreadable. They need a separate fix.

  • Canceled switch: when AlterDisklessSwitch cancels a pending switch, the partition goes back to having no seal. The repair then treats it as born-diskless. The existing epoch-0 append already drops its classic entries, so the repair doesn't make that state worse.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: giuseppelillo Review duration: 2801m
    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 #864"
    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