You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "davidalexander3986 (via GitHub)" <gi...@apache.org> on 2026/08/27 03:25:27 UTC
[PR] feat: warn when hash/range ingest publishes oversized segments (druid)
davidalexander3986 opened a new pull request, #20173:
URL: https://github.com/apache/druid/pull/20173
<!-- Thanks for trying to help us make Apache Druid be the best it can be! Please fill out as much of the following information as is possible (where relevant, and remove it when irrelevant) to help make the intention and scope of this PR clear in order to ease review. -->
<!-- Please read the doc for contribution (https://github.com/apache/druid/blob/master/CONTRIBUTING.md) before making this PR. Also, once you open a PR, please _avoid using force pushes and rebasing_ since these make it difficult for reviewers to see what you've changed in response to their reviews. See [the 'If your pull request shows conflicts with master' section](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#if-your-pull-request-shows-conflicts-with-master) for more details. -->
Fixes #19573.
<!-- Replace XXXX with the id of the issue fixed in this PR. Remove this section if there is no corresponding issue. Don't reference the issue in the title of this pull-request. -->
<!-- If you are a committer, follow the PR action item checklist for committers:
https://github.com/apache/druid/blob/master/dev/committer-instructions.md#pr-and-issue-action-item-checklist-for-committers. -->
### Description
Hash and range native batch ingest can publish segments much larger than `maxRowsPerSegment` / `targetRowsPerSegment` when a partition key is hot. Operators had no signal for that besides noticing huge segments later.
This PR counts published segments whose row count exceeds `maxRowsPerSegment × 2`, then warns, emits a metric, and records the count on the completion report.
<!-- Describe the goal of this PR, what problem are you fixing. If there is a corresponding issue (referenced above), it's not necessary to repeat the description here, however, you may choose to keep one summary sentence. -->
<!-- Describe your patch: what did you change in code? How did you fix the problem? -->
<!-- If there are several relatively logically separate changes in this PR, create a mini-section for each of them. For example: -->
#### Detect oversized segments at supervisor publish
After a successful publish, `ParallelIndexSupervisorTask` runs the check only for **HASH** or **RANGE** when `getMaxRowsPerSegment()` is non-null (so hashed + `numShards` with no max is skipped). Ratio is `2.0`. For range, resolved max is already `target + target/2`, so the warn is effectively **3×** the user’s `targetRowsPerSegment`.
If the count is > 0:
- WARN on the supervisor task
- metric `ingest/segments/oversized`
Live reports omit the field. Completion reports include `oversizedSegments` (`Long`, omitted when null). Sequential `IndexTask` (`maxNumConcurrentSubTasks: 1`) does not run this check.
#### Tests
- `IndexTaskUtils.getOversizedSegments` unit cases (threshold, null `totalRows`, mixed)
- Multi-phase hashed and range skewed ingest expecting `oversizedSegments = 1`; even range expects `0`; hashed + `numShards` omits the field
- Task report serde round-trips a non-null `oversizedSegments`
- Metric listed in `metrics.md`, logging emitter allow-list, Prometheus, and StatsD catalogs
<!--
In each section, please describe design decisions made, including:
- Choice of algorithms
- Behavioral aspects. What configuration values are acceptable? How are corner cases and error conditions handled, such as when there are insufficient resources?
- Class organization and design (how the logic is split between classes, inheritance, composition, design patterns)
- Method organization and design (how the logic is split between methods, parameters and return types)
- Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
-->
<!-- It's good to describe an alternative design (or mention an alternative name) for every design (or naming) decision point and compare the alternatives with the designs that you've implemented (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
### Implementation decision
In the cited issue it was recomended to set this logic in the PartialHashSegmentGenerateTask hooks and to use Appenderator.getRowCount(SegmentIdWithShardSpec) to get the row count. I ended up not doing this because I realized in the partial tasks we don't yet have the final segments. The final segments are only available after the final merge, right after publishing to S3. So, I instead went with wiring this through in the PartialSegmentMergetask instead.
#### Side effect
Those jobs merge and push DataSegments without going through an appenderator, so totalRows was never set. The supervisor still emits ingest/rows/published via IndexTaskUtils.getTotalRowCount(), which skips nulls, so the metric was always 0. After this change the metric should emit correctly for range and hash index_parallel jobs.
<!-- If there was a discussion of the design of the feature implemented in this PR elsewhere (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), link to that discussion from this PR description and explain what have changed in your final design compared to your original proposal or the consensus version in the end of the discussion. If something hasn't changed since the original discussion, you can omit a detailed discussion of those aspects of the design here, perhaps apart from brief mentioning for the sake of readability of this PR description. -->
<!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
#### Release note
You can now have visibility into when your range and hash partitioning settings are resulting in creating overly large segment files (hot partitions) in a time chunk. Native batch hash and range ingest now warns and emits a count of segments `ingest/segments/oversized` for all published segments with more than 2× `maxRowsPerSegment` rows (for range, that is 3× `targetRowsPerSegment`). The count is also on the task completion report as `oversizedSegments`.
<hr>
##### Key changed/added classes in this PR
* `IndexTaskUtils`
* `ParallelIndexSupervisorTask`
* `PartialSegmentMergeTask`
* `IngestionStatsAndErrors`
* `AbstractBatchIndexTask`
<hr>
<!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
This PR has:
- [x] been self-reviewed.
- [x] added documentation for new or modified features or behaviors.
- [x] a release note entry in the PR description.
- [x] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [x] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
- [x] added integration tests.
- [x] been tested in a test Druid cluster.
### Verification
Ran the cluster locally, and submitted an ingestion spec with hashed partitioning for wikipedia, using channel as a partition key:
```
...
"tuningConfig": {
"type": "index_parallel",
"maxRowsInMemory": 25000,
"forceGuaranteedRollup": true,
"maxNumConcurrentSubTasks": 2,
"partitionsSpec": {
"type": "hashed",
"maxRowsPerSegment": 2000,
"partitionDimensions": ["channel"]
}
}
}
...
```
since channel is often wikipedia#en for many rows, this will cause a hot partition for the same time chunk. Confirmed in report that oversizedSegments is set:
<img width="520" height="502" alt="image" src="https://github.com/user-attachments/assets/6e0c63c2-bea9-4c28-b1c7-68b44ef2a08e" />
and the warn log:
<img width="1251" height="58" alt="image" src="https://github.com/user-attachments/assets/f32f41a9-94d8-4148-9bfa-3e66a61994ea" />
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] feat: warn when hash/range ingest publishes oversized segments (druid)
Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 merged PR #20173:
URL: https://github.com/apache/druid/pull/20173
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] feat: warn when hash/range ingest publishes oversized segments (druid)
Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #20173:
URL: https://github.com/apache/druid/pull/20173#discussion_r3889566309
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/batch/parallel/PartialSegmentMergeTask.java:
##########
@@ -295,13 +296,17 @@ private DataSegmentsWithSchemas mergeAndPushSegments(
), "version for interval[%s]", interval),
0
);
+ try (QueryableIndex index = toolbox.getIndexIO().loadIndex(mergedFileAndDimensionNames.lhs)) {
Review Comment:
`BatchAppenderator` provides precedent, but it loads the index because it also needs dimensions and cluster metadata. This new code loads it only for the row count.
<!-- mergelens:review -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] feat: warn when hash/range ingest publishes oversized segments (druid)
Posted by "davidalexander3986 (via GitHub)" <gi...@apache.org>.
davidalexander3986 commented on code in PR #20173:
URL: https://github.com/apache/druid/pull/20173#discussion_r3889501971
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/batch/parallel/PartialSegmentMergeTask.java:
##########
@@ -295,13 +296,17 @@ private DataSegmentsWithSchemas mergeAndPushSegments(
), "version for interval[%s]", interval),
0
);
+ try (QueryableIndex index = toolbox.getIndexIO().loadIndex(mergedFileAndDimensionNames.lhs)) {
Review Comment:
That's a fair point, butI'd rather not add an IndexIO.getNumRows(File) helper with v9/v10 branching in this PR. BatchAppenderator already does the same loadIndex + getNumRows() after merge, so this matches an existing ingest path. The extra open is try-with-resources and short-lived; the merged file is already on disk (and likely still in page cache).
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/batch/parallel/PartialSegmentMergeTask.java:
##########
@@ -295,13 +296,17 @@ private DataSegmentsWithSchemas mergeAndPushSegments(
), "version for interval[%s]", interval),
0
);
+ try (QueryableIndex index = toolbox.getIndexIO().loadIndex(mergedFileAndDimensionNames.lhs)) {
Review Comment:
That's a fair point, but I'd rather not add an IndexIO.getNumRows(File) helper with v9/v10 branching in this PR. BatchAppenderator already does the same loadIndex + getNumRows() after merge, so this matches an existing ingest path. The extra open is try-with-resources and short-lived; the merged file is already on disk (and likely still in page cache).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] feat: warn when hash/range ingest publishes oversized segments (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #20173:
URL: https://github.com/apache/druid/pull/20173#discussion_r3872087325
##########
indexing-service/src/test/java/org/apache/druid/indexing/common/task/IndexTaskUtilsTest.java:
##########
@@ -110,4 +118,40 @@
IndexTaskUtils.setTaskDimensions(metricBuilder, abstractTask);
Assertions.assertNull(metricBuilder.getDimension(DruidMetrics.GROUP_ID));
}
+
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("oversizedSegmentCases")
+ public void testGetOversizedSegments(
+ String name,
Review Comment:
## CodeQL / Useless parameter
The parameter 'name' is never used.
[Show more details](https://github.com/apache/druid/security/code-scanning/11927)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] feat: warn when hash/range ingest publishes oversized segments (druid)
Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #20173:
URL: https://github.com/apache/druid/pull/20173#discussion_r3881085105
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/batch/parallel/PartialSegmentMergeTask.java:
##########
@@ -295,13 +296,17 @@ private DataSegmentsWithSchemas mergeAndPushSegments(
), "version for interval[%s]", interval),
0
);
+ try (QueryableIndex index = toolbox.getIndexIO().loadIndex(mergedFileAndDimensionNames.lhs)) {
Review Comment:
[P2] Avoid loading the full segment to read its row count
IndexIO.loadIndex(File) defaults to lazy=false. For v9 and legacy segments this eagerly builds the column holders, and for v10 it maps all containers and eagerly deserializes every column before getNumRows() is called. This call only needs the row count, so a large merged segment can add substantial heap/native memory pressure (and potentially OOM) during publishing. Read the row count through a format-specific metadata-only path instead: v10 has baseProjection.getNumRows(), while v9/legacy can extract totalSize from the __time column header. Passing lazy=true would reduce eager deserialization but still maps the segment buffers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] feat: warn when hash/range ingest publishes oversized segments (druid)
Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #20173:
URL: https://github.com/apache/druid/pull/20173#discussion_r3881085105
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/batch/parallel/PartialSegmentMergeTask.java:
##########
@@ -295,13 +296,17 @@ private DataSegmentsWithSchemas mergeAndPushSegments(
), "version for interval[%s]", interval),
0
);
+ try (QueryableIndex index = toolbox.getIndexIO().loadIndex(mergedFileAndDimensionNames.lhs)) {
Review Comment:
[P2] Avoid loading the full segment to read its row count
IndexIO.loadIndex(File) defaults to lazy=false. For v9 and legacy segments this eagerly builds the column holders, and for v10 it maps all containers and eagerly deserializes every column before getNumRows() is called. This call only needs the row count, so a large merged segment can add substantial heap/native memory pressure (and potentially OOM) during publishing.
Could we add or use an IndexIO.getNumRows(File) / metadata-only row-count helper that dispatches on the segment version? For v10, read the persisted base projection numRows from druid.segment; for v9 and legacy, read only the __time column header totalSize. Then call that helper here instead of constructing a QueryableIndex. Passing lazy=true is not sufficient because it still maps the segment buffers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org