Batch stream offset fetch in KafkaStreamMetadataProvider - #19116
Open
shounakmk219 wants to merge 2 commits into
Open
Batch stream offset fetch in KafkaStreamMetadataProvider#19116shounakmk219 wants to merge 2 commits into
shounakmk219 wants to merge 2 commits into
Conversation
computePartitionGroupMetadata previously created one Kafka consumer per partition and fetched offsets serially. On tables with many partitions (~1024) this ran hundreds of back-to-back ~1s consumer creations, and because the call happens inside the controller's ideal-state update lock (RealtimeSegmentValidationManager -> ensureAllPartitionsConsuming), it held the per-table lock for minutes and stalled concurrent segment commits (observed "updating ideal state: ~291000ms" vs ~180ms median). Resolve all partitions needing a stream fetch in a single batched call (beginningOffsets/endOffsets/offsetsForTimes accept a collection and resolve in one broker round-trip) via a new fetchOffsetsForPartitions helper; fetchStreamPartitionOffset now delegates to it. Applied to both kafka-3.0 and kafka-4.0; Kinesis/Pulsar are untouched.
shounakmk219
marked this pull request as draft
July 29, 2026 15:32
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19116 +/- ##
============================================
- Coverage 65.54% 65.52% -0.03%
Complexity 1423 1423
============================================
Files 3432 3432
Lines 218107 218127 +20
Branches 34661 34671 +10
============================================
- Hits 142960 142929 -31
- Misses 63598 63633 +35
- Partials 11549 11565 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
shounakmk219
marked this pull request as ready for review
July 30, 2026 04:24
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.
Problem
RealtimeSegmentValidationManager(RVM) runs on the lead controller and callsPinotLLCRealtimeSegmentManager.ensureAllPartitionsConsuming, which fetches stream offsets inside the per-table Helix ideal-state update lock (HelixHelper.updateIdealState→IdealStateGroupCommit).KafkaStreamMetadataProvider.computePartitionGroupMetadatafetched those offsets one partition at a time, creating a freshKafkaConsumerper partition viacreatePartitionMetadataProvider(~1s each). On a table with ~1024 partitions this meant hundreds of serial consumer creations while holding the ideal-state lock, so concurrent segment commits stalled for minutes.Observed on a production controller log:
updating ideal state: ~291000mson stalled commits versus a ~180ms median.Fix
Resolve all partitions that need a stream fetch in a single batched call. Kafka's
beginningOffsets(Collection)/endOffsets(Collection)/offsetsForTimes(Map)each resolve a whole collection of partitions in one broker round-trip and do not require the consumer to be assigned to those partitions (the existingfetchLatestStreamOffset(Set, ...)already relies on this).fetchOffsetsForPartitions(Collection<Integer>, OffsetCriteria, long)performs the batched, criteria-aware fetch (SMALLEST/LARGEST/PERIOD/TIMESTAMP, with the period/timestamp → end-offset fallback preserved).computePartitionGroupMetadatacollects the partitions not already covered by a consumption status and fetches them all at once.fetchStreamPartitionOffset(single partition) now delegates to the same helper.pinot-kafka-3.0andpinot-kafka-4.0. Kinesis and Pulsar have their owncomputePartitionGroupMetadata(shard/partition-group semantics) and are intentionally untouched.This collapses ~1024 serial consumer creations into one round-trip, cutting the RVM lock-hold from minutes to seconds.
Note on duplication
The helper is duplicated across
pinot-kafka-3.0andpinot-kafka-4.0, matching the existing intentional split between the two Kafka client versions (the code reads per-module instance state). Kept in sync between the modules.Follow-up (separate PR)
Move the offset fetch entirely out of the ideal-state lock in
PinotLLCRealtimeSegmentManager.ensureAllPartitionsConsuming(pre-fetch beforeHelixHelper.updateIdealState, pass an immutable snapshot into the updater), so the lock-hold is proportional to the ideal-state mutation and the fetch is not re-run on CAS retries.Testing
KafkaStreamMetadataProviderTestin both modules (10 tests each, all passing): single-batched-call guarantee (ArgumentCaptor asserts all partitions in one call), SMALLEST / LARGEST / PERIOD / TIMESTAMP-with-fallback, dead-partition-omitted, andfetchStreamPartitionOffsethappy + missing-offset paths.