Skip to content

perf: optimize coordinator HistoricalManagement duty runtime#19532

Open
jtuglu1 wants to merge 2 commits into
apache:masterfrom
jtuglu1:coordinator-duty-perf
Open

perf: optimize coordinator HistoricalManagement duty runtime#19532
jtuglu1 wants to merge 2 commits into
apache:masterfrom
jtuglu1:coordinator-duty-perf

Conversation

@jtuglu1

@jtuglu1 jtuglu1 commented May 30, 2026

Copy link
Copy Markdown
Contributor

Description

High-level changes

  • BalanceSegments - computes cluster shape (historicals, segments) once per run and reuses it for both the segment-move budget and the summary log, instead of calling getNumHistoricalsAndSegments() twice.
  • MarkOvershadowedSegmentsAsUnused - builds the set of datasources that actually have overshadowed segments first, then skips timeline construction entirely for every other datasource, both when scanning servers and when checking zero-replica segments.
  • MarkEternityTombstonesAsUnused - groups overshadowed segments by datasource up front, then checks each candidate tombstone only against its own datasource's group, instead of scanning the full overshadowed-segment list per candidate. Also swaps the timeline-based findNonOvershadowedObjectsInInterval scan for a direct per-segment isOvershadowed check.
  • RunRules - caches ruleHandler.getRulesWithDefault(datasource) per datasource in a map built during the segment loop, and reuses that same map for the later broadcast-datasource check. Previously rules were looked up once per segment and then a second time per datasource during the broadcast scan.
  • PrepareBalancerAndLoadQueues - collectUsedSegmentStats now iterates ImmutableDruidDataSource objects directly, using getTotalSizeOfSegments() and getSegments().size(), instead of streaming and summing over every segment in each datasource's timeline.
  • SegmentReplicationStatus - the constructor no longer makes two full ImmutableMap.copyOf defensive copies. It holds the caller's map directly (safe because it's rebuilt fresh each cycle and not mutated after this point) and computes the total-replica-count map in one pass instead of a separate forEach. Also adds computeSegmentStats(), which does unavailable, under-replicated, and deep-storage-only counting in one pass over used segments instead of three.
  • StrategicSegmentAssigner - allTiersInCluster is now computed once in the constructor and stored as a field, instead of being rebuilt with Sets.newHashSet(cluster.getTierNames()) on every replicateSegment/replicateSegmentPartially call.

I've kept the logging changes in in-case we deem some of them are debug-level worthy. Otherwise, please ignore those diffs during the review as they will be removed before merge. Initial results have shown a decrease in total HistoricalManagement duty runtime of about 35% on a cluster with 4M segments.

Release note

Speed-up coordinator HistoricalManagementDuties duty group


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.

@jtuglu1 jtuglu1 added this to the 38.0.0 milestone Jun 16, 2026
@jtuglu1 jtuglu1 force-pushed the coordinator-duty-perf branch from 924dcf0 to 520c157 Compare June 25, 2026 07:55
@jtuglu1 jtuglu1 force-pushed the coordinator-duty-perf branch 2 times, most recently from b0cea24 to a2df321 Compare June 25, 2026 08:24
Comment on lines +118 to +128
return new DataSegment(
DATASOURCE,
interval,
"v1",
Collections.emptyMap(),
Collections.emptyList(),
Collections.emptyList(),
null,
0,
1
);

private static DataSegment segment(String datasource, Interval interval, String version)
{
return DataSegment.builder()
@jtuglu1 jtuglu1 force-pushed the coordinator-duty-perf branch from a2df321 to fc83ff7 Compare June 27, 2026 00:01
@jtuglu1 jtuglu1 force-pushed the coordinator-duty-perf branch from fc83ff7 to 205af94 Compare July 1, 2026 19:30
@jtuglu1 jtuglu1 marked this pull request as ready for review July 1, 2026 20:34
@jtuglu1 jtuglu1 marked this pull request as draft July 1, 2026 20:34
@jtuglu1 jtuglu1 force-pushed the coordinator-duty-perf branch from 205af94 to 21ce8e3 Compare July 2, 2026 20:22
@jtuglu1 jtuglu1 force-pushed the coordinator-duty-perf branch from 21ce8e3 to 4ee48f9 Compare July 2, 2026 20:27
@jtuglu1 jtuglu1 marked this pull request as ready for review July 2, 2026 20:39
@jtuglu1 jtuglu1 changed the title perf: optimize coordinator duty runtime perf: optimize coordinator HistoricalManagement duty runtime Jul 2, 2026

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have reviewed the code for correctness, edge cases, concurrency, and integration risks; no issues found.

Reviewed 15 of 15 changed files.


This is an automated review by Codex GPT-5.5

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.

3 participants