Repository navigation
fix(inkless:consolidation): don't supplement an empty local read of a consolidating partition [KC-848] - #907
Conversation
… consolidating partition [KC-848] A consumer fetch of a consolidating partition can come back from the local log with no records and no error, although the log holds data at the fetch offset. This happens when an earlier partition uses up the request byte budget, or when the next batch doesn't fit the remaining budget. buildConsolidationSupplementFetchInfos anchored the supplement for such a read at the local log end offset, so the exhaustion guard passed and the response started at the log end offset. The consumer then skipped [fetchOffset, logEndOffset) without an error. The helper now anchors an empty read at the fetch offset, so the guard drops the supplement and the consumer fetches again from its own offset. The helper also skips a partition whose local read returns a preferred read replica or a remote storage redirect. This covers DelayedFetch.onComplete, which has none of the inline path's guards. fetchParamsWithNewMaxBytes still gives every leg the full byte budget. That behavior is out of scope here. ## Test plan - Rewrite the test that pinned the old behavior to expect no supplement for an empty read below the log end offset. - Add DelayedFetch tests for a mixed request with an empty local read, a preferred read replica, and a remote storage redirect. They fail without the fix. - Run DelayedFetchTest, ReplicaManagerInklessTest, and ReplicaManagerTest. Assisted-by: Claude Sonnet 5.5 Assisted-by: Claude Opus 5.5
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the fetch-supplement changes.
No open issues 🎉
What changed in this PR
This PR prevents lagging consumers from skipping committed records after an empty local read of a consolidating partition. It updates the shared supplement builder used by both immediate and delayed broker fetches.
Changes:
- Anchor empty reads at the requested fetch offset, suppressing supplements when the read hasn't reached the local log end.
- Skip supplements when local reads return a preferred replica or remote storage redirect.
- Add regression coverage and document supplement eligibility and delayed-fetch behavior.
| File | Description |
|---|---|
docs/inkless/DISKLESS_CONSOLIDATION.md |
Clarifies supplement exclusions and delayed completion's minBytes behavior. |
core/src/test/scala/unit/kafka/server/ReplicaManagerInklessTest.scala |
Tests empty-read boundaries, missing results, and redirect exclusions. |
core/src/test/scala/integration/kafka/server/DelayedFetchTest.scala |
Adds delayed-fetch regressions for mixed requests and redirected reads. |
core/src/main/scala/kafka/server/ReplicaManager.scala |
Corrects the empty-read supplement offset and rejects redirected local reads. |
Review effort: Balanced
| .filter(_.isPresent) | ||
| .map(_.get().nextOffset()) | ||
| .getOrElse(logEndOffset) | ||
| .getOrElse(pd.fetchOffset) |
There was a problem hiding this comment.
Nit, non-blocking: fetchMessages adds a partition to consolidatingLocalFetchSupplements only when fetchPartitionData.fetchOffset < logEndOffset (line 2906), and DelayedFetch reuses that map. So whenever this fallback runs, pd.fetchOffset is below logEndOffset, and the exhaustion guard always drops the partition. An empty local read never takes a supplement, no matter which offset this line picks. The behavior is correct, but you have to trace back to the routing code to see it, because this line reads as if an empty read gets a supplement starting at the fetch offset.
As a result, testBuildConsolidationSupplementFetchInfosStartsAtFetchOffsetForEmptyLocalReadAtLogEndOffset tests a state the routing doesn't produce: a supplement entry whose fetch offset equals its log end offset. The new Javadoc and the DISKLESS_CONSOLIDATION.md paragraph also describe the empty case in terms of the anchor offset, so neither says that an empty read always ends without a supplement.
A couple of ways to make this clearer, if you think it's worth it:
- Treat an empty local read as one more reason to skip, next to the error, preferred-replica, and remote-redirect checks in
localReadUnusable, and remove or rewrite the test that covers the unreachable case. - Keep the code as it is and add a sentence to the comment or Javadoc saying that routing only adds partitions below the log end offset, so an empty read always fails the guard.
There was a problem hiding this comment.
Agreed. I took the first option with a small change in shape. The builder now computes a start offset only from the last complete batch of the local read, and a read without one gets no supplement. That removes the fetchOffset fallback, so the empty case no longer depends on the routing gate.
testBuildConsolidationSupplementFetchInfosStartsAtFetchOffsetForEmptyLocalReadAtLogEndOffset is now testBuildConsolidationSupplementFetchInfosSkipsEmptyLocalReadAtLogEndOffset and expects no supplement. It checks that the builder doesn't rely on routing to drop an empty read. The Scaladoc and the DISKLESS_CONSOLIDATION.md paragraph now say that an empty local read never takes a supplement.
Fixed in ba51ae4.
…out a complete batch The previous commit anchored an empty local read at the fetch offset. Routing adds a partition only when its fetch offset is below the log end offset, so the exhaustion guard always dropped that read. The outcome was correct, but the code read as if an empty read gets a supplement starting at the fetch offset. buildConsolidationSupplementFetchInfos now computes a start offset only from the last complete batch of the local read. A read without one gets no supplement, whatever offset routing admits. ## Test plan - Rename the test for an empty read at the log end offset to testBuildConsolidationSupplementFetchInfosSkipsEmptyLocalReadAtLogEndOffset. It now expects no supplement. - Run DelayedFetchTest, ReplicaManagerInklessTest, and ReplicaManagerTest: 467 tests pass. Assisted-by: Claude Opus 5.5
Summary
A lagging consumer of a consolidating partition can skip committed records without an error. The broker may answer a fetch inside the local log with records that start at the local log end offset instead of the fetch offset. This happens when the local read comes back empty with no error. An earlier partition in the request can use up the byte budget and cause that read.
buildConsolidationSupplementFetchInfosanchored the diskless supplement for that read at the log end offset, so the exhaustion guard passed. The consumer then moved past[fetchOffset, logEndOffset).buildConsolidationSupplementFetchInfosnow anchors an empty read at the fetch offset. The guard then drops the supplement, and the consumer fetches again from its own offset. It also skips a partition whose local read returns a preferred read replica or a remote storage redirect. Both fetch paths call the helper. The change also coversDelayedFetch.onComplete, which has none of the inline path's guards.Follow-ups, not in this change:
DelayedFetch.onCompleteissues the supplement without checkingminBytesagain.DISKLESS_CONSOLIDATION.mdnow states this behavior.fetchParamsWithNewMaxBytesgives every leg of a mixed fetch the full byte budget.Evidence
DelayedFetch.onCompleterequests a supplement for both consolidating partitions. The second partition's local read is empty, and its response starts at the log end offset.After: only the first partition gets a supplement. The second partition's response is empty, and the consumer fetches again from its offset.
ReplicaManager, the three newDelayedFetchTesttests and four newbuildConsolidationSupplementFetchInfostests fail.testBuildConsolidationSupplementFetchInfosSkipsEmptyLocalReadBelowLogEndOffsetreplaces the test that pinned the old behavior. It asserts that the helper doesn't emit a supplement.testCompletionWithConsolidationSupplementuses a local read that reaches the log end offset, so it still covers the merge.DelayedFetchTestandReplicaManagerInklessTestpass with 338 tests.ReplicaManagerTestpasses with 129 tests.:core:checkstyleTestpasses, andmake valedoesn't report alerts on the added lines.Merge danger
Door: two-way
The change touches only the broker fetch path. It doesn't write state or change a protocol or config. A revert restores the previous behavior.
Blast radius: consolidating partitions
Only consumer fetches of consolidating partitions that start inside the local log change. After an empty local read, the response for that partition used to contain a supplement. It's now empty. The consumer fetches again, so a lagging consumer can take more round trips to catch up. Classic partitions, pure diskless partitions, and follower fetches don't change.
🤖 Generated with Claude Code
Assisted-by: Claude Sonnet 5.5
Assisted-by: Claude Opus 5.5