[CORE-14223] kafka/client: full fetch when broker withholds an unknown partition - #31300
Open
mnajda-redpanda wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a direct-consumer fetch-session edge case where a recreated subscription can end up with “unknown” source offsets (e.g., source_high_watermark = -1) indefinitely when the broker withholds an unchanged partition in incremental fetch responses (KIP-227). The change ensures the client forces a one-time full fetch when it detects a partition has never been reported by the broker.
Changes:
- Track whether each partition has ever been reported by the broker (
source_reported) and request a fetch-session reset to force a full fetch when needed. - Plumb a
needs_full_fetchsignal through fetch processing and reset the session after processing the triggering response. - Add a regression test covering subscription teardown/recreate while the source partition is idle.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/v/kafka/client/direct_consumer/tests/direct_consumer_fixture_test.cc | Adds a regression test for learning source offsets after an idle reassign/restart scenario. |
| src/v/kafka/client/direct_consumer/fetcher.h | Extends per-partition fetch state with a source_reported flag and adds needs_full_fetch to fetch results. |
| src/v/kafka/client/direct_consumer/fetcher.cc | Implements detection of withheld “never reported” partitions and forces a full fetch by resetting the fetch session. |
mnajda-redpanda
force-pushed
the
mnajda/full-fetch-unknown-source-offsets
branch
from
July 27, 2026 15:34
530153c to
7c4922f
Compare
A recreated subscription starts with default source offsets. The partition is included in exactly one fetch request; if the source is already drained, the broker's incremental fetch filter omits it, so the offsets are never learned and stay at the -1 sentinel for the lifetime of the subscription. Per KIP-227 an unchanged partition is omitted from incremental fetch responses, so re-including it incrementally does not help. Track whether the broker has ever reported a partition and reset the fetch session when it has not. A full fetch is returned unpruned, so every requested partition is reported and the offsets converge in one cycle. Replication is unaffected: an omitted partition is still subscribed. Only the reported source offsets were wrong, which the shadow link status API and the shadow lag metric consume.
mnajda-redpanda
force-pushed
the
mnajda/full-fetch-unknown-source-offsets
branch
from
July 27, 2026 15:49
7c4922f to
d60d91f
Compare
mnajda-redpanda
marked this pull request as ready for review
July 27, 2026 15:52
mnajda-redpanda
requested review from
a team,
bartoszpiekny-redpanda,
dotnwat,
nguyen-andrew and
pgellert
and removed request for
a team
July 27, 2026 15:52
Collaborator
CI test resultstest results on build#87775
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A replicator restart (leadership change or partition move) recreates the
direct_consumer subscription with default-initialized source offsets. The partition
goes into one fetch request, and if the source partition is already drained the
broker's incremental fetch filter omits it - so
update_and_filter_offsets()neverruns and the source offsets stay at
-1indefinitely. Per KIP-227 the broker omitsunchanged partitions from incremental fetch responses; a full fetch is returned
unfiltered.
Replication itself is not affected - a partition omitted under KIP-227 is still
subscribed. What breaks is reporting:
GetShadowTopicreturnssource_high_watermark = -1,redpanda_shadow_link_shadow_lagis wrong, andrpk shadow statusprints anegative lag. This is also the cause of the
ShadowLinkingReplicationTestsflake,which compares
source_high_watermarkagainst the source topic's high watermark.The fix tracks whether the broker has ever reported each partition, and resets the
fetch session to force a full fetch when it has not. Full fetches are returned
unpruned, so this converges in one extra fetch cycle. The reset is fetcher-wide, so
one unknown partition re-sends every partition on that broker - bounded to a single
cycle, and only on subscription recreation.
Backports Required
Release Notes