You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "clintropolis (via GitHub)" <gi...@apache.org> on 2026/08/04 23:54:57 UTC
[PR] fix: partial rule to regular rule transitions (druid)
clintropolis opened a new pull request, #19884:
URL: https://github.com/apache/druid/pull/19884
### Description
Fixes transition from partial load rule back to regular load rule, and adds embedded-test for this scenario. Prior to this PR this transition would be stuck because the non-partial assignment path was not partial aware, so it would see a segment and count it as available, even though it was stale since it was pinned with a partial load rule.
--
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] fix: partial rule to regular rule transitions (druid)
Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis merged PR #19884:
URL: https://github.com/apache/druid/pull/19884
--
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] fix: partial rule to regular rule transitions (druid)
Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #19884:
URL: https://github.com/apache/druid/pull/19884#discussion_r3720541485
##########
server/src/main/java/org/apache/druid/server/coordinator/loading/StrategicSegmentAssigner.java:
##########
@@ -615,8 +615,16 @@ private int updateReplicasInTier(
final int movingReplicas = replicaCountOnTier.moving();
final boolean shouldCancelMoves = requiredReplicas == 0 && movingReplicas > 0;
+ // A replica serving under a partial-load profile is pinned by a partial-load rule, but we got here through the
+ // regular full-load path, so that rule no longer applies: the datasource's partial-load rule was replaced or
+ // shadowed by a higher-priority load rule, or its matcher stopped resolving and fell through to FULL_LOAD. That
+ // replica needs an in-place reload carrying the plain unwrapped load spec so the historical releases its rule
+ // holds. When the tier wants no replicas at all we skip it, the drops below are already on their way and dropping
+ // clears the rule on the historical.
+ final int replicasToRevert = requiredReplicas > 0 ? replicaCountOnTier.loadedWithPartialProfile() : 0;
Review Comment:
[P2] Revert profiles during partial-to-broadcast transitions
This reconciliation is only reached through `replicateSegment`, while `BroadcastDistributionRule` calls `broadcastSegment`; its `loadBroadcastSegment` immediately returns for an already-serving historical. Replacing a partial rule with a broadcast rule therefore never sends the unwrapped reload, leaving the old partial profile and rule holds indefinitely. Apply equivalent reversion in the broadcast path and cover this transition.
##########
server/src/main/java/org/apache/druid/server/coordinator/loading/StrategicSegmentAssigner.java:
##########
@@ -645,20 +653,54 @@ private int updateReplicasInTier(
}
// Cancel loads and queue drops if the projected count exceeds the requirement
+ int dropsQueuedOnTier = 0;
if (projectedReplicas > requiredReplicas) {
int replicaSurplus = projectedReplicas - requiredReplicas;
int canceledLoads =
cancelOperations(SegmentAction.LOAD, replicaSurplus, segment, segmentStatus);
int numReplicasToDrop = Math.min(replicaSurplus - canceledLoads, maxReplicasToDrop);
if (numReplicasToDrop > 0) {
- int dropsQueuedOnTier = dropReplicas(numReplicasToDrop, segment, tier, segmentStatus);
+ dropsQueuedOnTier = dropReplicas(numReplicasToDrop, segment, tier, segmentStatus);
incrementStat(Stats.Segments.DROPPED, segment, tier, dropsQueuedOnTier);
- return dropsQueuedOnTier;
}
}
- return 0;
+ // Release partial-load rules that no longer apply. Done last so the load/drop decisions above claim their
+ // servers first: a replica that just picked up an action is no longer `isServingSegment`, so it is skipped here
+ // and reverted on a later run if it is still around.
+ if (replicasToRevert > 0) {
+ final int reverted = revertPartialProfileReplicas(segment, tier);
+ if (reverted > 0) {
+ incrementStat(Stats.Segments.PARTIAL_RULE_REVERTED, segment, tier, reverted);
+ }
+ }
+
+ return dropsQueuedOnTier;
+ }
+
+ /**
+ * Queues an in-place reload on every server in {@code tier} that serves {@code segment} under a
+ * {@link PartialLoadProfile}. The request carries the plain unwrapped {@code segment}, which is what tells the
+ * historical to release its rule holds rather than apply or swap one.
+ * <p>
+ * The replica count is deliberately left alone: these servers <em>are</em> serving, so they still satisfy the
+ * rule's replication requirement and must not be double-counted as a deficit. This only refreshes what they hold.
+ * <p>
+ * Servers with any queued action are skipped via {@link ServerHolder#isServingSegment}, which covers both the
+ * load/drop decisions made earlier in this run and operations left over from a previous one.
+ */
+ private int revertPartialProfileReplicas(DataSegment segment, String tier)
+ {
+ int numReverted = 0;
+ for (ServerHolder server : cluster.getManagedHistoricalsByTier(tier)) {
+ if (server.isServingSegment(segment)
+ && server.getServer().getPartialLoadProfile(segment.getId()) != null
+ && loadQueueManager.loadSegment(segment, server, SegmentAction.LOAD, null)) {
Review Comment:
[P1] Honor the per-server load queue limit
`ServerHolder.startOperation` does not reject operations after `maxSegmentsInNodeLoadingQueue` is reached; normal load paths first check `canLoadSegment` or `isLoadQueueFull`. This loop directly queues every profiled segment, so changing a large datasource to a full-load rule can enqueue all reverts on each historical in one coordinator run, bypassing the configured cap and flooding the peon/historical. Check the queue budget before enqueueing and add a capped-queue test.
--
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] fix: partial rule to regular rule transitions (druid)
Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on PR #19884:
URL: https://github.com/apache/druid/pull/19884#issuecomment-5209995608
oops, I think I committed a broken test `SegmentLoadingTest` is failing in master, i didn't notice CI hadn't run yet on the last commit when I merged this.
--
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] fix: partial rule to regular rule transitions (druid)
Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on PR #19884:
URL: https://github.com/apache/druid/pull/19884#issuecomment-5210082646
>oops, I think I committed a regression, test SegmentLoadingTest is failing in master, i didn't notice CI hadn't run yet on the last commit when I merged this.
i think #19912 should fix it
--
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] fix: partial rule to regular rule transitions (druid)
Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #19884:
URL: https://github.com/apache/druid/pull/19884#discussion_r3728798222
##########
server/src/main/java/org/apache/druid/server/coordinator/loading/StrategicSegmentAssigner.java:
##########
@@ -645,20 +653,74 @@ private int updateReplicasInTier(
}
// Cancel loads and queue drops if the projected count exceeds the requirement
+ int dropsQueuedOnTier = 0;
if (projectedReplicas > requiredReplicas) {
int replicaSurplus = projectedReplicas - requiredReplicas;
int canceledLoads =
cancelOperations(SegmentAction.LOAD, replicaSurplus, segment, segmentStatus);
int numReplicasToDrop = Math.min(replicaSurplus - canceledLoads, maxReplicasToDrop);
if (numReplicasToDrop > 0) {
- int dropsQueuedOnTier = dropReplicas(numReplicasToDrop, segment, tier, segmentStatus);
+ dropsQueuedOnTier = dropReplicas(numReplicasToDrop, segment, tier, segmentStatus);
incrementStat(Stats.Segments.DROPPED, segment, tier, dropsQueuedOnTier);
- return dropsQueuedOnTier;
}
}
- return 0;
+ // Release partial-load rules that no longer apply. Done last so the load/drop decisions above claim their
+ // servers first: a replica that just picked up an action is no longer `isServingSegment`, so it is skipped here
+ // and reverted on a later run if it is still around.
+ if (replicasToRevert > 0) {
+ final int reverted = revertPartialProfileReplicas(segment, tier);
+ if (reverted > 0) {
+ incrementStat(Stats.Segments.PARTIAL_RULE_REVERTED, segment, tier, reverted);
+ }
+ }
+
+ return dropsQueuedOnTier;
+ }
+
+ /**
+ * Queues an in-place reload on every server in {@code tier} that serves {@code segment} under a
+ * {@link PartialLoadProfile}. The request carries the plain unwrapped {@code segment}, which is what tells the
+ * historical to release its rule holds rather than apply or swap one.
+ * <p>
+ * The replica count is deliberately left alone: these servers <em>are</em> serving, so they still satisfy the
+ * rule's replication requirement and must not be double-counted as a deficit. This only refreshes what they hold.
+ * <p>
+ * Servers are skipped when:
+ * <ul>
+ * <li>they have any queued action, via {@link ServerHolder#isServingSegment}, which covers both the load/drop
+ * decisions made earlier in this run and operations left over from a previous one;</li>
+ * <li>their load queue is already at the configured {@code maxSegmentsInNodeLoadingQueue} budget for this run.</li>
+ * <li>they are decommissioning, since their replicas are on the way out and reloading them is wasted work.</li>
+ * </ul>
+ * These are the same two eligibility conditions {@code PartialSegmentStatusInTier.canReloadAdditively} applies to
+ * the partial-load reconciler's in-place reload. {@link ServerHolder#canLoadSegment} is not usable here because it
+ * requires the server to <em>not</em> already have the segment, which is precisely the case being handled.
+ */
+ private int revertPartialProfileReplicas(DataSegment segment, String tier)
+ {
+ int numReverted = 0;
+ for (ServerHolder server : cluster.getManagedHistoricalsByTier(tier)) {
+ if (revertPartialProfileReplica(segment, server)) {
+ ++numReverted;
+ }
+ }
+ return numReverted;
+ }
+
+ /**
+ * Queues the in-place reload described by {@link #revertPartialProfileReplicas} on a single server, if that server
+ * is holding {@code segment} under a partial-load rule and has room in its load queue. Returns whether a reload was
+ * queued.
+ */
+ private boolean revertPartialProfileReplica(DataSegment segment, ServerHolder server)
+ {
+ return server.isServingSegment(segment)
+ && !server.isDecommissioning()
+ && !server.isLoadQueueFull()
+ && server.getServer().getPartialLoadProfile(segment.getId()) != null
+ && loadQueueManager.loadSegment(segment, server, SegmentAction.LOAD, null);
Review Comment:
[P2] Keep in-place reverts out of replica surplus accounting
If this in-place reload remains queued into the next coordinator run, `SegmentReplicaCountMap` counts both the already-announced partial replica and this `LOAD`. For a one-replica full-load rule, `projectedReplicas` therefore becomes 2 and `updateReplicasInTier` treats the reload as surplus, canceling it through `cancelOperations(LOAD)`. `HttpLoadQueuePeon` permits cancellation until dispatch; under queue backlog the coordinator can repeatedly cancel and requeue the revert, or with a finite queue budget cancel it and wait another run, preventing the partial-to-full transition from completing. Represent this as a non-replica refresh or exclude same-server reloads from replica counting and surplus cancellation, and add a two-run test with a pending revert.
--
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] fix: partial rule to regular rule transitions (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #19884:
URL: https://github.com/apache/druid/pull/19884#discussion_r3717079780
##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/query/PartialProjectionLoadRuleQueryTest.java:
##########
@@ -319,6 +307,134 @@
);
}
+ @Test
+ void testRuleTransitionBetweenPartialAndFullLoad()
+ {
+ // Rule churn in both directions against an already-loaded segment.
+ //
+ // Observed through sys.servers.curr_size, which is driven by the loadedBytes the historical announces: the
+ // partial footprint excludes the unmatched projection's bytes, while a full-load announcement carries no profile
+ // at all and falls back to segment.getSize().
+ final long fullSize = queryFullSegmentSize();
+ Assertions.assertTrue(fullSize > 0, "sys.segments.size must be populated for the ingested segment");
+
+ // Precondition from loadDataAndConfigureRule(): the segment is already loaded under the partial rule.
+ MatcherAssert.assertThat(
+ "partial-load rule should already be in effect at the start of this test",
+ queryHistoricalCurrSize(),
+ Matchers.lessThan(fullSize)
+ );
+
+ boolean restored = false;
+ try {
+ final LatchableEmitter coordinatorEmitter = coordinator.latchableEmitter();
+ coordinatorEmitter.flush();
+
+ // Leg 1: partial -> full.
+ applyRule(new ForeverLoadRule(Map.of("_default_tier", 1), null));
+ coordinatorEmitter.waitForEvent(
+ event -> event.hasMetricName("segment/partial/ruleReverted/count")
+ .hasDimension(DruidMetrics.DATASOURCE, dataSource)
+ );
+ Assertions.assertEquals(
+ fullSize,
+ awaitHistoricalCurrSize(
+ size -> size == fullSize,
+ "full segment size after reverting to a regular load rule"
+ ),
+ "a reverted replica must announce with no partial-load profile, so loadedBytes falls back to segment size"
+ );
+
+ // Leg 2: full -> partial. Already covered by the initial load, but asserting it here proves the transition is
+ // symmetric on an already-loaded segment and restores the state the other tests in this class depend on.
+ applyRule(partialProjectionRule());
+ restored = true;
+ MatcherAssert.assertThat(
+ "re-applying the partial rule must shrink the announced footprint again",
+ awaitHistoricalCurrSize(size -> size < fullSize, "partial footprint after re-applying the partial rule"),
+ Matchers.lessThan(fullSize)
+ );
+ }
+ finally {
+ // Best effort only, and deliberately silent: on the success path leg 2 already restored and verified the rule.
+ // This exists so a failure above can't leave the wrong rule behind for the rest of the class, and it must never
+ // mask the original failure.
+ if (!restored) {
+ try {
+ applyRule(partialProjectionRule());
+ }
+ catch (Exception ignored) {
+ // fall through; the failure that got us here is the one worth reporting
+ }
+ }
+ }
+ }
+
+ /**
+ * The partial-load rule this class runs under: selects only {@link #PROJECTION_NAME}, leaving the base-table
+ * cluster-group bundles and {@link #UNMATCHED_PROJECTION_NAME} off the historical's disk.
+ */
+ private static ForeverPartialLoadRule partialProjectionRule()
+ {
+ return new ForeverPartialLoadRule(
+ Map.of("_default_tier", 1),
+ null,
+ new WildcardProjectionPartialLoadMatcher(List.of(PROJECTION_NAME), null),
+ CannotMatchBehavior.FALL_THROUGH
+ );
+ }
+
+ private void applyRule(Rule rule)
+ {
+ cluster.callApi().onLeaderCoordinator(c -> c.updateRulesForDatasource(dataSource, List.of(rule)));
+ }
+
+ /**
+ * The ingested segment's full on-disk size, i.e. what the historical would report if it held everything.
+ */
+ private long queryFullSegmentSize()
+ {
+ return Long.parseLong(
+ cluster.callApi().runSql(
+ "SELECT \"size\" FROM sys.segments WHERE datasource = '" + dataSource + "'"
+ ).trim()
+ );
Review Comment:
## CodeQL / Missing catch of NumberFormatException
Potential uncaught 'java.lang.NumberFormatException'.
[Show more details](https://github.com/apache/druid/security/code-scanning/11606)
##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/query/PartialProjectionLoadRuleQueryTest.java:
##########
@@ -319,6 +307,134 @@
);
}
+ @Test
+ void testRuleTransitionBetweenPartialAndFullLoad()
+ {
+ // Rule churn in both directions against an already-loaded segment.
+ //
+ // Observed through sys.servers.curr_size, which is driven by the loadedBytes the historical announces: the
+ // partial footprint excludes the unmatched projection's bytes, while a full-load announcement carries no profile
+ // at all and falls back to segment.getSize().
+ final long fullSize = queryFullSegmentSize();
+ Assertions.assertTrue(fullSize > 0, "sys.segments.size must be populated for the ingested segment");
+
+ // Precondition from loadDataAndConfigureRule(): the segment is already loaded under the partial rule.
+ MatcherAssert.assertThat(
+ "partial-load rule should already be in effect at the start of this test",
+ queryHistoricalCurrSize(),
+ Matchers.lessThan(fullSize)
+ );
+
+ boolean restored = false;
+ try {
+ final LatchableEmitter coordinatorEmitter = coordinator.latchableEmitter();
+ coordinatorEmitter.flush();
+
+ // Leg 1: partial -> full.
+ applyRule(new ForeverLoadRule(Map.of("_default_tier", 1), null));
+ coordinatorEmitter.waitForEvent(
+ event -> event.hasMetricName("segment/partial/ruleReverted/count")
+ .hasDimension(DruidMetrics.DATASOURCE, dataSource)
+ );
+ Assertions.assertEquals(
+ fullSize,
+ awaitHistoricalCurrSize(
+ size -> size == fullSize,
+ "full segment size after reverting to a regular load rule"
+ ),
+ "a reverted replica must announce with no partial-load profile, so loadedBytes falls back to segment size"
+ );
+
+ // Leg 2: full -> partial. Already covered by the initial load, but asserting it here proves the transition is
+ // symmetric on an already-loaded segment and restores the state the other tests in this class depend on.
+ applyRule(partialProjectionRule());
+ restored = true;
+ MatcherAssert.assertThat(
+ "re-applying the partial rule must shrink the announced footprint again",
+ awaitHistoricalCurrSize(size -> size < fullSize, "partial footprint after re-applying the partial rule"),
+ Matchers.lessThan(fullSize)
+ );
+ }
+ finally {
+ // Best effort only, and deliberately silent: on the success path leg 2 already restored and verified the rule.
+ // This exists so a failure above can't leave the wrong rule behind for the rest of the class, and it must never
+ // mask the original failure.
+ if (!restored) {
+ try {
+ applyRule(partialProjectionRule());
+ }
+ catch (Exception ignored) {
+ // fall through; the failure that got us here is the one worth reporting
+ }
+ }
+ }
+ }
+
+ /**
+ * The partial-load rule this class runs under: selects only {@link #PROJECTION_NAME}, leaving the base-table
+ * cluster-group bundles and {@link #UNMATCHED_PROJECTION_NAME} off the historical's disk.
+ */
+ private static ForeverPartialLoadRule partialProjectionRule()
+ {
+ return new ForeverPartialLoadRule(
+ Map.of("_default_tier", 1),
+ null,
+ new WildcardProjectionPartialLoadMatcher(List.of(PROJECTION_NAME), null),
+ CannotMatchBehavior.FALL_THROUGH
+ );
+ }
+
+ private void applyRule(Rule rule)
+ {
+ cluster.callApi().onLeaderCoordinator(c -> c.updateRulesForDatasource(dataSource, List.of(rule)));
+ }
+
+ /**
+ * The ingested segment's full on-disk size, i.e. what the historical would report if it held everything.
+ */
+ private long queryFullSegmentSize()
+ {
+ return Long.parseLong(
+ cluster.callApi().runSql(
+ "SELECT \"size\" FROM sys.segments WHERE datasource = '" + dataSource + "'"
+ ).trim()
+ );
+ }
+
+ /**
+ * The footprint the coordinator currently attributes to the historical, i.e. the {@code loadedBytes} carried by the
+ * segment's most recent announcement.
+ */
+ private long queryHistoricalCurrSize()
+ {
+ return Long.parseLong(
+ cluster.callApi().runSql(
+ "SELECT curr_size FROM sys.servers WHERE server_type = 'historical'"
+ ).trim()
+ );
Review Comment:
## CodeQL / Missing catch of NumberFormatException
Potential uncaught 'java.lang.NumberFormatException'.
[Show more details](https://github.com/apache/druid/security/code-scanning/11607)
--
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