Skip to content

fix: Limit number of unused segment rows scanned - #19690

Merged
kfaraz merged 4 commits into
apache:masterfrom
kfaraz:fix_unused_segment_sql
Jul 15, 2026
Merged

fix: Limit number of unused segment rows scanned#19690
kfaraz merged 4 commits into
apache:masterfrom
kfaraz:fix_unused_segment_sql

Conversation

@kfaraz

@kfaraz kfaraz commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Related to #19685

Description

In large clusters with a large number of unused segments for a single datasource, the UnusedSegmentsKiller may error out while fetching the list of unused segment intervals.

Fix

  • Limit the number of unused segment rows scanned in a single cycle of the UnusedSegmentsKiller to 1M

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@kfaraz
kfaraz requested review from capistrant and cryptoe July 15, 2026 13:56
@kfaraz kfaraz added this to the 38.0.0 milestone Jul 15, 2026

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

Changes look good to me.

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

Main code LGTM, I had some comments about the comments and naming.

+ " GROUP BY %2$send%2$s, start"
+ " %3$s",
dbTables.getSegmentsTable(), connector.getQuoteString(), connector.limitClause(limit)
// Text blocks are not supported in the current checkstyle version

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.

I believe this comment is inaccurate. We use text blocks elsewhere. Maybe there's some other reason that checkstyle flags this block. The suppression is for Regexp so it could be one of our custom rules.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is one of the custom rules. I will try to update it in a later PR.
Thanks for calling this out, I will fix the comment.

* list contains the earliest or latest intervals present in the datasource.
* Gets unused segment intervals for the specified datasource.
* <p>
* Note: This method does NOT guarantee that:

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.

I see why we need to weaken the guarantees. However, I think it still does guarantee that if there are unused segments, then we will return at least one interval. This is a useful guarantee that should be mentioned.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, will do.

*
* @return List of unused segment intervals containing upto {@code limit} interval entries.
*/
public List<Interval> retrieveUnusedSegmentIntervals(String dataSource, int limit)

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.

Consider renaming it to retrieveSomeUnusedSegmentIntervals, just to emphasize that not all of them will necessarily be returned.

@kfaraz

kfaraz commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews, @cryptoe , @gianm , @capistrant !

@kfaraz
kfaraz merged commit 1211652 into apache:master Jul 15, 2026
38 checks passed
@kfaraz
kfaraz deleted the fix_unused_segment_sql branch July 15, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants