MINOR: Skip further reads from log for share fetches if max records reached by apoorvmittal10 · Pull Request #23892 · apache/kafka · GitHub
Skip to content

MINOR: Skip further reads from log for share fetches if max records reached - #23892

Open
apoorvmittal10 wants to merge 2 commits into
apache:trunkfrom
apoorvmittal10:minor_max_records
Open

apoorvmittal10 wants to merge 2 commits into
apache:trunkfrom
apoorvmittal10:minor_max_records

Conversation

@apoorvmittal10

@apoorvmittal10 apoorvmittal10 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

On the slow path, DelayedShareFetch.combineLogReadResponse reuses the
data read in tryComplete and issues a second readFromLog for
partitions that became acquirable only at completion. The second read
was issued even when the already fetched data covered maxFetchRecords,
in which case SharePartition.acquire receives a zero budget and
returns empty, so the read was wasted.

The remaining record budget is now computed from the already fetched
data and the second read is skipped when nothing remains. Skipped
partitions are absent from the response, as share sessions already do
for partitions without data, and their locks are released on the same
path as before.

Reviewers: Abhinav Dixit adixit@confluent.io, Andrew Schofield
aschofield@confluent.io

@github-actions github-actions Bot added triage PRs from the community core Kafka Broker KIP-932 Queues for Kafka labels Oct 20, 2026
@apoorvmittal10 apoorvmittal10 added ci-approved and removed triage PRs from the community labels Oct 20, 2026

@adixitconfluent adixitconfluent 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.

Thanks for the PR. Mostly looks good to me. One question

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.

what is the case when startOffset is not found in fetchOffsets?

@AndrewJSchofield AndrewJSchofield left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR. An AI-assisted review suggests this PR is a regression in behaviour.

The skip drops the partitions that currently have first claim on the budget (DelayedShareFetch.java:849). The new comment says "the already fetched records are handed out first". They are not. The merge at the end of combineLogReadResponse does missingTopicPartitionsLogReadResponse.putAll(existingFetchedData), so the missing partitions sit first in the combined map, and processFetchResponse acquires in map order with maxFetchRecords - acquiredRecordsCount. So before this change the missing partitions were acquired first and the already-fetched ones got the remainder. After it, the already-fetched span is used to decide the missing ones get nothing. Concrete scenario, one consumer, tp0 and tp1 both with deep backlogs:

  • tp0 is served, so its next fetch offset moves and its cached fetch-offset metadata goes stale. It is read in tryComplete and lands in the already-fetched set every time.
  • tp1 is not served, so its offset and cached metadata stay valid. It is never read in tryComplete and is always a "missing" partition.
  • Before the change, tp1 was acquired first on each fetch and the two alternated naturally. After it, tp0's span is at least maxFetchRecords, so tp1 is skipped on every fetch for as long as tp0 has a backlog. That is indefinite starvation of tp1.

Comment on lines +845 to +848

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.

The code actually does opposite of the comment. It puts missing first and then the existing ones

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is what the AI highlighted too.

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

Labels

ci-approved core Kafka Broker KIP-932 Queues for Kafka

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants