Skip to content

Use total stream partition count for realtime partition function divisor#18708

Merged
Jackie-Jiang merged 1 commit into
apache:masterfrom
Jackie-Jiang:fix-realtime-partition-function-divisor
Jun 9, 2026
Merged

Use total stream partition count for realtime partition function divisor#18708
Jackie-Jiang merged 1 commit into
apache:masterfrom
Jackie-Jiang:fix-realtime-partition-function-divisor

Conversation

@Jackie-Jiang

Copy link
Copy Markdown
Contributor

Summary

RealtimeSegmentDataManager.setPartitionParameters derived the partition function divisor (numPartitions) from computePartitionGroupMetadata(clientId, streamConfig, emptyList(), timeoutMs).size(). That call fetches and discards a StreamPartitionMsgOffset for every partition just to take the list size, and — more importantly — returns the wrong count in two cases:

  • Kafka partition-subset feature (stream.kafka.partition.ids): the KafkaStreamMetadataProvider override returns the subset size, not the topic's full partition count. The subset path also preserves the original Kafka partition ids as the partition group ids, so a divisor equal to the subset size cannot even represent those ids (e.g. a subset {5, 17, 42} with divisor 3). The per-segment partition metadata is then computed inconsistently and partition pruning can prune valid segments, returning wrong results.
  • Kinesis: the override excludes expired shards, so .size() reflects active shards rather than the producer's hashing space.

The divisor must match the partition count the upstream producer hashed each key over. fetchPartitionCount returns exactly that with a single call, so switch to it. For Kafka it resolves via partitionsFor(topic), i.e. the full topic partition count, independent of any configured subset.

Kinesis partitioning remains unsupported (shards split/merge and ids are not a contiguous 0..N range); a TODO records this.

Also refreshed the stale surrounding comments (no metric is emitted on mismatch; it is now logged at warn), promoted the fetch-failure log to error, and aligned the failure log message with the actual timeout.

🤖 Generated with Claude Code

`RealtimeSegmentDataManager.setPartitionParameters` derived the partition
function divisor (`numPartitions`) from
`computePartitionGroupMetadata(..., emptyList(), ...).size()`. That call
fetches and discards a `StreamPartitionMsgOffset` for every partition just to
take the list size, and — more importantly — returns the wrong count in two
cases:

- Kafka partition-subset feature (`stream.kafka.partition.ids`): the override
  returns the subset size, not the topic's full partition count. The subset
  also preserves the original Kafka partition ids as the partition group ids,
  so a divisor equal to the subset size cannot even represent those ids. The
  segment partition metadata is computed inconsistently and partition pruning
  can prune valid segments, returning wrong results.
- Kinesis: the override excludes expired shards, so the count reflects active
  shards rather than the producer's hashing space.

The divisor must match the partition count the upstream producer hashed each
key over. `fetchPartitionCount` returns exactly that with a single call, so
switch to it. Kinesis partitioning remains unsupported (shards split/merge and
ids are not a contiguous 0..N range); a TODO records this.

Also refresh the stale surrounding comments (no metric is emitted; the
mismatch is logged) and align the fetch-failure log message with the timeout.
@Jackie-Jiang Jackie-Jiang added bug Something is not working as expected ingestion Related to data ingestion pipeline real-time Related to realtime table ingestion and serving labels Jun 8, 2026
@codecov-commenter

codecov-commenter commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.49%. Comparing base (b26d8c9) to head (b68ea5f).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...a/manager/realtime/RealtimeSegmentDataManager.java 16.66% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #18708      +/-   ##
============================================
+ Coverage     56.92%   64.49%   +7.57%     
- Complexity        7     1291    +1284     
============================================
  Files          2587     3372     +785     
  Lines        150165   208650   +58485     
  Branches      24274    32595    +8321     
============================================
+ Hits          85485   134575   +49090     
- Misses        57460    63282    +5822     
- Partials       7220    10793    +3573     
Flag Coverage Δ
custom-integration1 100.00% <ø> (ø)
integration 100.00% <ø> (ø)
integration1 100.00% <ø> (ø)
integration2 0.00% <ø> (ø)
java-21 64.49% <16.66%> (+7.57%) ⬆️
temurin 64.49% <16.66%> (+7.57%) ⬆️
unittests 64.49% <16.66%> (+7.56%) ⬆️
unittests1 56.89% <0.00%> (-0.03%) ⬇️
unittests2 37.13% <16.66%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Jackie-Jiang Jackie-Jiang merged commit 5ba9df1 into apache:master Jun 9, 2026
11 checks passed
@Jackie-Jiang Jackie-Jiang deleted the fix-realtime-partition-function-divisor branch June 9, 2026 01:05
@xiangfu0

xiangfu0 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Opened the corresponding docs update PR: pinot-contrib/pinot-docs#861

xiangfu0 added a commit to pinot-contrib/pinot-docs that referenced this pull request Jun 9, 2026
## Summary
- clarify that Kafka subset-partition ingestion still uses the full
Kafka topic partition count for realtime segment partition metadata
- document that `segmentPartitionConfig.numPartitions` must match the
full topic partition count, not the consumed subset size, when partition
pruning is enabled

## Source cross-check
-
`pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/RealtimeSegmentDataManager.java`
-
`pinot-plugins/pinot-stream-ingestion/pinot-kafka-3.0/src/test/java/org/apache/pinot/plugin/stream/kafka30/KafkaPartitionLevelConsumerTest.java`
-
`pinot-plugins/pinot-stream-ingestion/pinot-kafka-4.0/src/test/java/org/apache/pinot/plugin/stream/kafka40/KafkaPartitionLevelConsumerTest.java`

## Validation
- `git diff --check`
Akanksha-kedia pushed a commit to Akanksha-kedia/pinot that referenced this pull request Jun 10, 2026
cypherean pushed a commit to cypherean/pinot that referenced this pull request Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something is not working as expected ingestion Related to data ingestion pipeline real-time Related to realtime table ingestion and serving

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants