← Back to Pull requests

feat(inkless:switch): gate consolidation on the switch phase #840

Closed
unknown closed this pull request without merging on Nov 03, 2026 14:44 UTC
View on GitHub
unknown unknown commented on Oct 28, 2026 11:11 UTC
Author

A committed seal doesn't mean the classic prefix is safe to drop from local disks. Until the controller commits classicPrefixInRemoteStorage, the local logs of the ISR members store the only complete copy. In phase 1, a replica that starts consolidating advances the cross-tier log start offset over a prefix that remote storage doesn't hold yet. A client routed to a replica outside the ISR can read a truncated prefix.

In phase 2 the opposite holds. In the record that sets the flag, the controller adds every live replica to the ISR without checking its local copy. From then on, brokers trust only the remote copy.

Phase 1: treat the partition as not consolidating

  • consolidationActiveFor(tp) gates consolidation per partition and is off in phase 1. isReadyForConsolidation and ConsolidationReconciler wait for the flag.

  • The classic fetcher applies the ISR rule of a topic that doesn't consolidate. A follower at the seal leaves the classic fetcher once it's in the ISR, and it starts consolidating when the flag commits. That commit always bumps the leader epoch. The follower path then runs again.

  • The broker fences a leader whose local log ends below the seal, as on a topic that doesn't consolidate. Nothing rebuilds the prefix in phase 1, so only phase 2 keeps that leader online for consolidation to rebuild the prefix from remote storage.

  • The metadata transformer advertises only alive ISR members for a pending switch and in phase 1.

  • InklessMetadataView exposes the flag, isSwitchedPhaseOne, and isSwitchedWithLocalClassicPrefix.
  • Phase 2: delete the local classic prefix

  • When a replica applies the flag, it deletes every local segment below the seal through UnifiedLog.forceDeleteLocalSegmentsBelow. If the active segment contains the end of the prefix, the replica rolls it first. The deletion skips the retention checks. It advances the local log start offset and keeps the log start offset and the leader epoch cache. Reads below the seal take the tiered path, and the leader can still validate follower fetches.

  • A follower's remote log metadata can trail the leader's, and a tiered read of a segment that the metadata doesn't list resets the consumer. So forced deletion removes only the segments that this broker's highest offset in remote storage covers, and ReplicaManager retries the rest once per second.

  • The classic fetcher runs the same idempotent step when it evicts a partition at the seal. That covers a follower that fetched part of the prefix after it applied the flag. Because the metadata delta and the eviction both run the deletion, the reconciler has no deletion step or failure path.

  • readFromLog never serves local records below the seal. If this broker's highest offset in remote storage covers the offset, a consumer read takes the tiered path. Otherwise, and for followers, the broker answers NOT_LEADER_OR_FOLLOWER, and the client retries. The check runs on the records that the read returned, so one rule covers both fetch branches, a fetch that waited in purgatory since phase 1, a read that races the deletion, and a log directory move that swaps the log. A read that hits the local prefix also queues the deletion again.

  • The tiered path matters most after an upgrade. On earlier releases, a follower at the seal started consolidating in phase 1 and appended the first diskless records to the segment that ends the prefix. Forced deletion can't remove that segment, so without the tiered path, consumers routed to that follower would get errors until local retention deletes it.

  • A consumer read below the seal never takes a diskless supplement. That read returns nothing when the request's byte budget is already spent, and a supplement from the local log end offset would skip the rest of the prefix.

  • A log directory move copies the prefix into the future log. The alter-log-dirs thread rolls the future log before it copies the first record at the seal. Without the roll, one segment would contain both the end of the prefix and the start of the diskless records, and forced deletion couldn't remove that segment. Before it promotes, shouldDelayFutureReplicaPromotion runs forced deletion on the caught-up future log and delays promotion while that log still holds prefix records.

  • If the deletion fails with a storage error, the broker reports the log directory to the log directory failure handler instead of marking the partition offline. The classic fetcher thread runs the deletion, and applyDelta waits for idle fetcher threads to stop while it holds replicaStateChangeLock, so taking that lock from the fetcher thread could deadlock.

  • UnifiedLog.java and ReplicaAlterLogDirsThread.scala become interleaved paths in INKLESS_OWNERSHIP.
  • Known limitations

  • If a replica with a segment that spans the seal leads the partition, a follower below the seal can't fetch that part of the prefix until local retention removes the segment. A log directory move on such a replica waits for the same deletion. Fixing both needs the leader to report the seal as its earliest local offset in phase 2. The follower rebuild uses that ListOffsets response. KC-714 tracks the fix.

  • If remote storage is off or remote.log.copy.disable is true, the broker keeps the prefix and logs a warning. Consumer reads succeed only for offsets that this broker already sees in remote storage.

  • This change leaves DisklessFetchOffsetRouter and the pending-state handling as they are. ISR shrink (KC-633), DeleteRecords, and RetentionEnforcer are out of scope.
  • Testing

  • ReplicaManagerInklessTest covers per-partition gating, the fence of a phase 1 leader below the seal, the phase 1 to phase 2 hand-off for leaders and followers, deletion on the flag commit and its retry, the read check in both phases with and without purgatory, the tiered path for a consumer read of a local prefix that remote storage covers, a phase 2 read below the seal that returns nothing, a storage error during the deletion, the promotion decision, and a log directory move that spans the flag commit.

  • ReplicaFetcherThreadTest checks that a consolidating follower at the seal waits for the ISR in phase 1, and that eviction deletes the prefix before consolidation starts.

  • ConsolidationReconcilerTest covers the phase 1 retry.

  • UnifiedLogTest checks that forced deletion keeps the log start offset and the epoch cache. Other cases cover the active-segment roll, the remote-copy precondition, and segments that remote storage doesn't cover.

  • ReplicaAlterLogDirsThreadTest checks that a delayed promotion keeps the partition on the thread, and that the thread rolls the future log at the seal before it appends.

  • InklessMetadataViewTest and InklessTopicMetadataTransformerTest cover the phase predicates and ISR-only routing.

  • InklessTopicTypeSwitcherClusterTest runs on the tiered storage stack and waits until every broker deletes its local prefix before it consumes. The consumer then reads the switched prefix from remote storage. With the no-op remote storage manager, the switch test fails.

  • ReplicaManagerTest, DelayedFetchTest, DisklessSwitchFlowTest, InitDisklessLogManagerTest, and DisklessFetchOffsetRouterTest pass unchanged.

  • make vale doesn't report any alerts.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: giuseppelillo Review duration: 8852m
    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 #840"
    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