Skip to content

fix(inkless:consolidation): skip the diskless supplement when the local read ends mid-batch [KC-876] - #911

Open
viktorsomogyi wants to merge 2 commits into
mainfrom
svv/kc-876-partial-batch
Open

viktorsomogyi wants to merge 2 commits into
mainfrom
svv/kc-876-partial-batch

Conversation

@viktorsomogyi

Copy link
Copy Markdown
Contributor

Why

A byte-limited local read of a consolidating partition can end inside a batch. The batch iterator drops that partial tail, so the supplement starts at the partial batch's base offset. The merge still keeps the partial bytes, so the response holds a truncated batch in front of the diskless batches. The consumer reads the partial header, runs into the diskless bytes, and fails the CRC check.

The local log isn't frozen at the seal, because the consolidation fetcher keeps appending to it. The log end offset that DelayedFetch captures at routing can therefore be stale, which lets the exhaustion guard pass.

The committed data isn't lost, but the consumer can't make progress until a later fetch avoids the same shape.

What changes

buildConsolidationSupplementFetchInfos skips the supplement when the complete batches don't account for all local bytes. The partial batch then stays the last thing in the response, where it's harmless, and the consumer re-fetches from the last complete batch.

This change doesn't move the log end offset that DelayedFetch.onComplete uses. That idea from the ticket is a separate change.

Test plan

  • Add testBuildConsolidationSupplementFetchInfosSkipsWhenLocalReadEndsMidBatch to ReplicaManagerInklessTest. The test fails without the guard and passes with it.
  • Run ReplicaManagerInklessTest (321 tests) and DelayedFetchTest (5 tests) with no failures.
  • Run make vale with no alerts.

Fixes KC-876.

🤖 Generated with Claude Code

…al read ends mid-batch [KC-876]

A byte-limited local read of a consolidating partition can end inside a
batch. The batch iterator drops that partial tail, so the supplement
starts at the partial batch's base offset. The merge still keeps the
partial bytes, and the response holds a truncated batch in front of the
diskless batches. The consumer reads the partial header, runs into the
diskless bytes, and fails the CRC check.

The local log isn't frozen at the seal, because the consolidation
fetcher keeps appending to it. The log end offset captured at routing
can therefore be stale, which lets the exhaustion guard pass.

Skip the supplement when the complete batches don't account for all
local bytes. The partial batch then stays the last thing in the
response, and the consumer re-fetches from the last complete batch.

Testing

Add a `ReplicaManagerInklessTest` case that ends the local read inside
a batch past the stale log end offset. The test fails without the guard.

Assisted-by: Claude Sonnet 5.5

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The change adds a redundant full-batch scan to each local read, repeating file-channel header reads even when supplementation is ineligible; combine the traversals and skip unnecessary work.

1 open issue
What changed in this PR

This PR prevents consumer CRC failures during consolidation by skipping diskless supplements when a local read ends inside a batch. It leaves the DelayedFetch log-end-offset capture unchanged.

Changes:

  • Check that complete batches account for all local record bytes before supplementing.
  • Add a regression test for a partial trailing batch with a stale routing-time log end offset.
File Description
core/​src/​test/​scala/​unit/​kafka/​server/​ReplicaManagerInklessTest.scala Tests that a local read ending mid-batch produces no supplement.
core/​src/​main/​scala/​kafka/​server/​ReplicaManager.scala Adds a batch-boundary guard before requesting a diskless supplement.

Review effort: Balanced

…e supplement [KC-876]

The batch-boundary check added a second pass over each local read, on top
of the `lastBatch()` walk. For a file-backed read, every pass costs a
channel read per batch, even when no supplement can run.

Find the last batch and total the complete bytes in one pass. Run the pass
only after the cheap checks (usable local read, remaining byte budget)
leave a supplement possible.

Testing

Run `ReplicaManagerInklessTest` and `DelayedFetchTest` with no failures.

Assisted-by: Claude Sonnet 5.5

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the change that suppresses diskless supplements after truncated local reads.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants