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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
