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/09/05 02:24:17 UTC

[PR] feat: partial load rules assignment prefer in-place reload over fresh load (druid)

clintropolis opened a new pull request, #20267:
URL: https://github.com/apache/druid/pull/20267

   ### Description
   Updates `PartialSegmentStatusInTier` and `StrategicSegmentAssigner` to prefer in-place reloads of partial segments rather than load-then-drop to an empty server. The reason it was like this is because partial load rules were introduced before historicals could actually honor them, and my design at the time meant that they would only do an additive load on rule change; however the functionality that got actually merged ended up having the rules using internal holds on the weak references that make up a partially loaded segment in cache, so a rule change is not just additive (we load any missing bundles, and release the holds on any bundles no longer pinned by rules, allowing them to be evicted). This means that there is no downside to doing an in-place reload since it only has to download the difference rather than the whole set, so this PR flips the priority to do fresh load as the fallback behavior.


-- 
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: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3983632865


##########
server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java:
##########
@@ -161,12 +161,24 @@ public void addSegment(
         currentDropLatch.cancelOrAwait();
       }
 
+      // A load request for a segment this server already serves is a reload, not a new load. The failure cleanup
+      // below exists to discard the half-materialized state a failed *new* load leaves behind, and running it for a
+      // reload would instead unannounce and drop a replica that is still serving.
+      final boolean isReload = segmentManager.isSegmentLoaded(segment);

Review Comment:
   consolidated so the decision is in one place now so I think this is good 



##########
server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java:
##########
@@ -161,12 +161,24 @@ public void addSegment(
         currentDropLatch.cancelOrAwait();
       }
 
+      // A load request for a segment this server already serves is a reload, not a new load. The failure cleanup
+      // below exists to discard the half-materialized state a failed *new* load leaves behind, and running it for a
+      // reload would instead unannounce and drop a replica that is still serving.
+      final boolean isReload = segmentManager.isSegmentLoaded(segment);

Review Comment:
   consolidated so the decision is in one place now so I think this should be fixed



-- 
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: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "capistrant (via GitHub)" <gi...@apache.org>.
capistrant commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3959699477


##########
server/src/main/java/org/apache/druid/server/coordinator/loading/StrategicSegmentAssigner.java:
##########
@@ -516,25 +520,68 @@ private int loadPartialReplicas(
       return 0;
     }
 
-    // The classifier's list is already the complete candidate set when nothing was canceled.
+    // The classifier's lists are already the complete candidate sets when nothing was canceled.
+    final List<ServerHolder> inPlaceDestinations;
     final List<ServerHolder> freshCandidates;
     if (canceledStaleServers.isEmpty()) {
+      inPlaceDestinations = status.getEligibleForInPlaceReload();
       freshCandidates = status.getEligibleForFreshLoad();
     } else {
+      inPlaceDestinations = new ArrayList<>(status.getEligibleForInPlaceReload());
       freshCandidates = new ArrayList<>(status.getEligibleForFreshLoad());
-      freshCandidates.addAll(canceledStaleServers);
+      for (ServerHolder server : canceledStaleServers) {
+        if (server.isServingSegment(segment) && PartialSegmentStatusInTier.canReloadInPlace(server)) {
+          inPlaceDestinations.add(server);
+        } else {
+          freshCandidates.add(server);
+        }
+      }
     }
 
-    final Iterator<ServerHolder> destinations = Iterators.concat(
-        serversToLoadSegment(segment, tier, freshCandidates),
-        status.getEligibleForAdditiveReload().iterator()
+    int numLoadsQueued = queuePartialLoads(

Review Comment:
   also, does the coded behavior actually help avoid a loop of requests to in place reload that fail each time?
   
   request in place, fail. unannounce stale load. fresh load on next cycle.
   
   instead of
   
   request in place. fail. request in place. fail. repeat.



-- 
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: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "capistrant (via GitHub)" <gi...@apache.org>.
capistrant commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3991247219


##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -1116,8 +1117,13 @@ private DataSegment loadPartial(DataSegment dataSegment) throws SegmentLoadingEx
           final Set<String> selected = Set.copyOf(
               wrapper.getSelectedBundleNames(dataSegment, mapper.getSegmentFileMetadata())
           );
+          // Snapshot the rule this call is about to replace, then pin the UNION of it and the new selection for the
+          // duration of the attempt.
           final String priorFingerprint = metadata.getRuleFingerprint();
-          metadata.applyRule(wrapper.getFingerprint(), selected);
+          final Set<String> priorSelection = metadata.getRuleSelectedBundleNames();
+          final Set<String> attemptSelection = new HashSet<>(priorSelection);
+          attemptSelection.addAll(selected);
+          metadata.applyRule(wrapper.getFingerprint(), attemptSelection);

Review Comment:
   seems reasonable to consider adding an info file re-write to the restore prior flow 



-- 
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: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis merged PR #20267:
URL: https://github.com/apache/druid/pull/20267


-- 
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: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "capistrant (via GitHub)" <gi...@apache.org>.
capistrant commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3959662681


##########
server/src/main/java/org/apache/druid/server/coordinator/loading/StrategicSegmentAssigner.java:
##########
@@ -516,25 +520,68 @@ private int loadPartialReplicas(
       return 0;
     }
 
-    // The classifier's list is already the complete candidate set when nothing was canceled.
+    // The classifier's lists are already the complete candidate sets when nothing was canceled.
+    final List<ServerHolder> inPlaceDestinations;
     final List<ServerHolder> freshCandidates;
     if (canceledStaleServers.isEmpty()) {
+      inPlaceDestinations = status.getEligibleForInPlaceReload();
       freshCandidates = status.getEligibleForFreshLoad();
     } else {
+      inPlaceDestinations = new ArrayList<>(status.getEligibleForInPlaceReload());
       freshCandidates = new ArrayList<>(status.getEligibleForFreshLoad());
-      freshCandidates.addAll(canceledStaleServers);
+      for (ServerHolder server : canceledStaleServers) {
+        if (server.isServingSegment(segment) && PartialSegmentStatusInTier.canReloadInPlace(server)) {
+          inPlaceDestinations.add(server);
+        } else {
+          freshCandidates.add(server);
+        }
+      }
     }
 
-    final Iterator<ServerHolder> destinations = Iterators.concat(
-        serversToLoadSegment(segment, tier, freshCandidates),
-        status.getEligibleForAdditiveReload().iterator()
+    int numLoadsQueued = queuePartialLoads(

Review Comment:
   This sounds like a legitimate observation. But I wonder if it should be accepted behavior since it self recovers on the next coordinator cycle?



-- 
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: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3989505479


##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -1116,8 +1117,13 @@ private DataSegment loadPartial(DataSegment dataSegment) throws SegmentLoadingEx
           final Set<String> selected = Set.copyOf(
               wrapper.getSelectedBundleNames(dataSegment, mapper.getSegmentFileMetadata())
           );
+          // Snapshot the rule this call is about to replace, then pin the UNION of it and the new selection for the
+          // duration of the attempt.
           final String priorFingerprint = metadata.getRuleFingerprint();
-          metadata.applyRule(wrapper.getFingerprint(), selected);
+          final Set<String> priorSelection = metadata.getRuleSelectedBundleNames();
+          final Set<String> attemptSelection = new HashSet<>(priorSelection);
+          attemptSelection.addAll(selected);
+          metadata.applyRule(wrapper.getFingerprint(), attemptSelection);

Review Comment:
   [P1] Restore the info file when a rule swap fails
   
   `loadPartial` rewrites the segment info file before this in-memory rule swap and `realizeRuleOrRestorePrior` have completed. On an existing serving replica, an eager bundle failure now restores the prior rule in memory and throws, so the handler keeps the old announcement, but the info file still contains the new fingerprint/delegate/selection. If the historical restarts before a retry succeeds, bootstrap trusts that file and re-applies the failed rule; another capacity or deep-storage failure then makes `loadSegmentOnBootstrap` call `cacheManager.drop`, deleting the last good replica, while a successful bootstrap silently changes the durable rule ahead of coordinator state. Write the new info file only after realization commits, or atomically restore the prior info file on every failed reload path (including mount/selection failures), and add a restart-after-failed-reload 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] feat: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3962119887


##########
server/src/main/java/org/apache/druid/server/coordinator/loading/StrategicSegmentAssigner.java:
##########
@@ -516,25 +520,68 @@ private int loadPartialReplicas(
       return 0;
     }
 
-    // The classifier's list is already the complete candidate set when nothing was canceled.
+    // The classifier's lists are already the complete candidate sets when nothing was canceled.
+    final List<ServerHolder> inPlaceDestinations;
     final List<ServerHolder> freshCandidates;
     if (canceledStaleServers.isEmpty()) {
+      inPlaceDestinations = status.getEligibleForInPlaceReload();
       freshCandidates = status.getEligibleForFreshLoad();
     } else {
+      inPlaceDestinations = new ArrayList<>(status.getEligibleForInPlaceReload());
       freshCandidates = new ArrayList<>(status.getEligibleForFreshLoad());
-      freshCandidates.addAll(canceledStaleServers);
+      for (ServerHolder server : canceledStaleServers) {
+        if (server.isServingSegment(segment) && PartialSegmentStatusInTier.canReloadInPlace(server)) {
+          inPlaceDestinations.add(server);
+        } else {
+          freshCandidates.add(server);
+        }
+      }
     }
 
-    final Iterator<ServerHolder> destinations = Iterators.concat(
-        serversToLoadSegment(segment, tier, freshCandidates),
-        status.getEligibleForAdditiveReload().iterator()
+    int numLoadsQueued = queuePartialLoads(

Review Comment:
   i think not dropping and retrying the in-place reload is the best way to handle this, so i've made that change.
   
   i think the only 'expected' way for the reload to fail is if there is insufficient space; where leaving the stale replica there and retrying on the next run seems fine. If there is sufficient room on other servers, I would expect balancing to move some segments from the server with the stales, in which case the retry works after balancing, or else the other nodes are also full, in which case everything is going to be 'stuck' and so also not a problem if we keep retrying in-place here. Any other cause (transient problem, etc) should work on the retry, or if not, is something that would also be a problem on fresh load (like missing from deep storage or whatever).



##########
server/src/main/java/org/apache/druid/server/coordinator/loading/StrategicSegmentAssigner.java:
##########
@@ -516,25 +520,68 @@ private int loadPartialReplicas(
       return 0;
     }
 
-    // The classifier's list is already the complete candidate set when nothing was canceled.
+    // The classifier's lists are already the complete candidate sets when nothing was canceled.
+    final List<ServerHolder> inPlaceDestinations;
     final List<ServerHolder> freshCandidates;
     if (canceledStaleServers.isEmpty()) {
+      inPlaceDestinations = status.getEligibleForInPlaceReload();
       freshCandidates = status.getEligibleForFreshLoad();
     } else {
+      inPlaceDestinations = new ArrayList<>(status.getEligibleForInPlaceReload());
       freshCandidates = new ArrayList<>(status.getEligibleForFreshLoad());
-      freshCandidates.addAll(canceledStaleServers);
+      for (ServerHolder server : canceledStaleServers) {
+        if (server.isServingSegment(segment) && PartialSegmentStatusInTier.canReloadInPlace(server)) {
+          inPlaceDestinations.add(server);
+        } else {
+          freshCandidates.add(server);
+        }
+      }
     }
 
-    final Iterator<ServerHolder> destinations = Iterators.concat(
-        serversToLoadSegment(segment, tier, freshCandidates),
-        status.getEligibleForAdditiveReload().iterator()
+    int numLoadsQueued = queuePartialLoads(

Review Comment:
   i think not dropping and retrying the in-place reload is the best way to handle this, so i've made that change.
   
   i think the only 'expected' way for the reload to fail is if there is insufficient space; where leaving the stale replica there and retrying on the next run seems fine. If there is sufficient room on other servers, I would expect balancing to move some segments from the server with the stales, in which case the retry works after balancing, or else the other nodes are also full, in which case everything is going to be 'stuck' and so also not a problem if we keep retrying in-place here.
   
   Any other cause (transient problem, etc) should work on the retry, or if not, is something that would also be a problem on fresh load (like missing from deep storage or whatever).



-- 
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: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3968515839


##########
server/src/main/java/org/apache/druid/server/coordinator/loading/StrategicSegmentAssigner.java:
##########
@@ -516,25 +520,68 @@ private int loadPartialReplicas(
       return 0;
     }
 
-    // The classifier's list is already the complete candidate set when nothing was canceled.
+    // The classifier's lists are already the complete candidate sets when nothing was canceled.
+    final List<ServerHolder> inPlaceDestinations;
     final List<ServerHolder> freshCandidates;
     if (canceledStaleServers.isEmpty()) {
+      inPlaceDestinations = status.getEligibleForInPlaceReload();
       freshCandidates = status.getEligibleForFreshLoad();
     } else {
+      inPlaceDestinations = new ArrayList<>(status.getEligibleForInPlaceReload());
       freshCandidates = new ArrayList<>(status.getEligibleForFreshLoad());
-      freshCandidates.addAll(canceledStaleServers);
+      for (ServerHolder server : canceledStaleServers) {
+        if (server.isServingSegment(segment) && PartialSegmentStatusInTier.canReloadInPlace(server)) {
+          inPlaceDestinations.add(server);
+        } else {
+          freshCandidates.add(server);
+        }
+      }
     }
 
-    final Iterator<ServerHolder> destinations = Iterators.concat(
-        serversToLoadSegment(segment, tier, freshCandidates),
-        status.getEligibleForAdditiveReload().iterator()
+    int numLoadsQueued = queuePartialLoads(

Review Comment:
   Thanks for the change, but the current head still has the original P1 in the real partial-cache path. `SegmentLocalCacheManager.loadPartial` can evict a stale `CompleteSegmentCacheEntry` before reserving the partial entry, or swap the existing rule/holds and then call `clearRule()` after an eager bundle failure; neither restores the previous cache state. With `SegmentLoadDropHandler.java:173` skipping `removeSegment` (and `SegmentManager.java:355` skipping `cacheManager.drop`), the old timeline/announcement can remain while the only cached replica has been deleted or made evictable. Please make that transition rollback-safe (or clean up when old state is gone) and add a failure-after-eviction/eager-download test; retrying the same in-place request is not safe if it no longer serves the old data.
   
   <!-- mergelens:review -->



##########
server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java:
##########
@@ -161,12 +161,24 @@ public void addSegment(
         currentDropLatch.cancelOrAwait();
       }
 
+      // A load request for a segment this server already serves is a reload, not a new load. The failure cleanup
+      // below exists to discard the half-materialized state a failed *new* load leaves behind, and running it for a
+      // reload would instead unannounce and drop a replica that is still serving.
+      final boolean isReload = segmentManager.isSegmentLoaded(segment);
       final DataSegment loaded;
       try {
         loaded = segmentManager.loadSegment(segment);
       }
       catch (Exception e) {
-        removeSegment(segment, DataSegmentChangeCallback.NOOP, false);
+        if (isReload) {

Review Comment:
   [P1] Preserve cache state on failed in-place reload
   
   This treats any load exception for a segment already in SegmentManager's timeline as safe to leave announced, but that is not true for the partial-load path. SegmentLocalCacheManager.loadPartial can evict an existing CompleteSegmentCacheEntry before reserving the partial entry, or replace an existing partial rule and then clear the new rule when an eager bundle download fails; neither path restores the previous cache state. Since this branch skips removeSegment (and SegmentManager.loadSegment likewise skips cacheManager.drop), the timeline and old announcement can remain while the only cached replica has been deleted or made eviction-eligible, so queries can see a non-serving replica and the coordinator keeps retrying in place. Make the cache/rule transition rollback-safe or only retain the announcement after verifying the old state is intact, and add a failure-after-eviction/eager-download 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] feat: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3983480354


##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -1076,6 +1072,11 @@ private DataSegment loadPartial(DataSegment dataSegment) throws SegmentLoadingEx
           return dataSegment;
         }
 
+        // Committed to attempting the rule now. If a stale non-partial cache entry sits at this segment id (a
+        // complete created by a prior acquireSegment while virtualStoragePartialDownloadsEnabled=false, for example),
+        // evict it before any partial-entry lookup or reservation.
+        evictStaleNonPartialWeakEntry(dataSegment.getId());

Review Comment:
   I think i'm going to solve this in a follow-up to make it impossible for this to happen by migrating non-partial v10 files into partial format during bootstrap, which would make a config switch convert the files on disk. There are a few similar operations already happening (migrating legacy deeply nested structure to flat structure, removing complete entries in partial mode if the info file indicates it should be partial, etc), so i think an up front cost to eliminate weird things that wouldn't happen in fresh flows is worth the complexity it eliminates of trying to handle it everywhere.



-- 
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: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3983489963


##########
server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java:
##########
@@ -161,12 +161,24 @@ public void addSegment(
         currentDropLatch.cancelOrAwait();
       }
 
+      // A load request for a segment this server already serves is a reload, not a new load. The failure cleanup
+      // below exists to discard the half-materialized state a failed *new* load leaves behind, and running it for a
+      // reload would instead unannounce and drop a replica that is still serving.
+      final boolean isReload = segmentManager.isSegmentLoaded(segment);

Review Comment:
   this works nicer now i think, switched to reserve and acquire the new bundles first before releasing stale holds so that a failure only has to release the difference, making rollback easy (at the cost of needing to reserve a slight bit of extra space bounded by total segment size before it can drop the old stuff)



-- 
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: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3989502815


##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -1076,6 +1072,11 @@ private DataSegment loadPartial(DataSegment dataSegment) throws SegmentLoadingEx
           return dataSegment;
         }
 
+        // Committed to attempting the rule now. If a stale non-partial cache entry sits at this segment id (a
+        // complete created by a prior acquireSegment while virtualStoragePartialDownloadsEnabled=false, for example),
+        // evict it before any partial-entry lookup or reservation.
+        evictStaleNonPartialWeakEntry(dataSegment.getId());

Review Comment:
   ## Follow-up assessment
   
   I rechecked 13 of 13 changed files at head `7a6d039a7d0ce63210b702b6d93bf8797ae61b5e`. The proposed bootstrap migration is not present in this PR, and `evictStaleNonPartialWeakEntry` still removes an unheld `CompleteSegmentCacheEntry` before the partial reservation/eager realization begins. If that reload fails, the historical keeps its timeline and announcement but cannot restore the discarded complete cache entry. This P1 therefore remains open for the current head; please retain the complete entry until the partial state commits, or remove the timeline/announcement when conversion fails.
   
   <!-- mergelens:review -->



##########
server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java:
##########
@@ -161,12 +161,24 @@ public void addSegment(
         currentDropLatch.cancelOrAwait();
       }
 
+      // A load request for a segment this server already serves is a reload, not a new load. The failure cleanup
+      // below exists to discard the half-materialized state a failed *new* load leaves behind, and running it for a
+      // reload would instead unannounce and drop a replica that is still serving.
+      final boolean isReload = segmentManager.isSegmentLoaded(segment);
       final DataSegment loaded;
       try {
         loaded = segmentManager.loadSegment(segment);
       }
       catch (Exception e) {
-        removeSegment(segment, DataSegmentChangeCallback.NOOP, false);
+        if (isReload) {

Review Comment:
   ## Follow-up assessment
   
   I rechecked 13 of 13 changed files at head `7a6d039a7d0ce63210b702b6d93bf8797ae61b5e`. The union pinning now fixes the in-memory hold rollback for an eager-download failure, but `loadPartial` has already rewritten the info file with the new rule before this restoration path runs. A restart can therefore retry the failed new rule from disk and, on another bootstrap failure, drop the last good replica; the current test only checks the in-memory fingerprint and holds. Please make the info-file update part of the same commit point as realization, or restore the prior file on failure. I’m tracking this as a P1 for the current head.
   
   <!-- 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: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3979252284


##########
server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java:
##########
@@ -1076,6 +1072,11 @@ private DataSegment loadPartial(DataSegment dataSegment) throws SegmentLoadingEx
           return dataSegment;
         }
 
+        // Committed to attempting the rule now. If a stale non-partial cache entry sits at this segment id (a
+        // complete created by a prior acquireSegment while virtualStoragePartialDownloadsEnabled=false, for example),
+        // evict it before any partial-entry lookup or reservation.
+        evictStaleNonPartialWeakEntry(dataSegment.getId());

Review Comment:
   [P1] Preserve a complete cache entry until the partial reload succeeds
   
   `evictStaleNonPartialWeakEntry` removes the existing unheld `CompleteSegmentCacheEntry` before the new partial entry is reserved or its eager downloads succeed. If a historical was bootstrapped with a full cache entry (for example after partial-download configuration changed) and this reload then fails because the loading pool rejects the work or deep storage cannot provide a selected bundle, `realizeRuleOrRestorePrior` can only restore a prior partial rule; it cannot restore the evicted complete entry. The new code then clears the attempted rule while `SegmentManager`/`SegmentLoadDropHandler` retain the existing timeline and announcement as a reload, so a previously queryable local full replica has been discarded and the server continues to advertise it. Keep the old complete entry through the attempt or make failure remove the announcement/timeline instead of treating the replica as safely retained.



##########
server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java:
##########
@@ -161,12 +161,24 @@ public void addSegment(
         currentDropLatch.cancelOrAwait();
       }
 
+      // A load request for a segment this server already serves is a reload, not a new load. The failure cleanup
+      // below exists to discard the half-materialized state a failed *new* load leaves behind, and running it for a
+      // reload would instead unannounce and drop a replica that is still serving.
+      final boolean isReload = segmentManager.isSegmentLoaded(segment);

Review Comment:
   [P1] Make reload cleanup use one consistent decision
   
   The handler snapshots `isReload` here, but `SegmentManager.loadSegment` independently snapshots it again at its own call site, with no segment-level synchronization covering either check and the load. Loads are submitted independently by `processRequest`, so a concurrent initial load can add the segment to the timeline between these checks. If the cache load then fails, `SegmentManager` sees a reload and preserves the cache, while this stale `false` makes the handler call `removeSegment`, unannouncing and dropping the live replica. The reverse ordering can also make cleanup inconsistent. Compute the cleanup decision once under the same lifecycle lock, or return the decision from `SegmentManager`, so a failed concurrent load cannot recreate the availability loss this change is meant to avoid.



-- 
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: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3983629227


##########
server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java:
##########
@@ -161,12 +161,24 @@ public void addSegment(
         currentDropLatch.cancelOrAwait();
       }
 
+      // A load request for a segment this server already serves is a reload, not a new load. The failure cleanup
+      // below exists to discard the half-materialized state a failed *new* load leaves behind, and running it for a
+      // reload would instead unannounce and drop a replica that is still serving.
+      final boolean isReload = segmentManager.isSegmentLoaded(segment);
       final DataSegment loaded;
       try {
         loaded = segmentManager.loadSegment(segment);
       }
       catch (Exception e) {
-        removeSegment(segment, DataSegmentChangeCallback.NOOP, false);
+        if (isReload) {

Review Comment:
   this works nicer now i think, switched to reserve and acquire the new bundles first before releasing stale holds so that a failure only has to release the difference, making rollback easy (at the cost of needing to reserve a slight bit of extra space bounded by total segment size before it can drop the old stuff)



-- 
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: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "FrankChen021 (via GitHub)" <gi...@apache.org>.
FrankChen021 commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3940653841


##########
server/src/main/java/org/apache/druid/server/coordinator/loading/StrategicSegmentAssigner.java:
##########
@@ -516,25 +520,68 @@ private int loadPartialReplicas(
       return 0;
     }
 
-    // The classifier's list is already the complete candidate set when nothing was canceled.
+    // The classifier's lists are already the complete candidate sets when nothing was canceled.
+    final List<ServerHolder> inPlaceDestinations;
     final List<ServerHolder> freshCandidates;
     if (canceledStaleServers.isEmpty()) {
+      inPlaceDestinations = status.getEligibleForInPlaceReload();
       freshCandidates = status.getEligibleForFreshLoad();
     } else {
+      inPlaceDestinations = new ArrayList<>(status.getEligibleForInPlaceReload());
       freshCandidates = new ArrayList<>(status.getEligibleForFreshLoad());
-      freshCandidates.addAll(canceledStaleServers);
+      for (ServerHolder server : canceledStaleServers) {
+        if (server.isServingSegment(segment) && PartialSegmentStatusInTier.canReloadInPlace(server)) {
+          inPlaceDestinations.add(server);
+        } else {
+          freshCandidates.add(server);
+        }
+      }
     }
 
-    final Iterator<ServerHolder> destinations = Iterators.concat(
-        serversToLoadSegment(segment, tier, freshCandidates),
-        status.getEligibleForAdditiveReload().iterator()
+    int numLoadsQueued = queuePartialLoads(

Review Comment:
   [P1] Preserve the serving replica when an in-place reload fails
   
   This now queues an in-place reload before trying any empty server, but a failed `loadPartial` is handled by `SegmentLoadDropHandler.addSegment` as a failed segment load: it unannounces and drops the existing segment. Failures are possible here (for example, the old cache entry is held or the new partial bundles cannot be reserved), and `canReloadInPlace` intentionally does not check disk capacity. With one stale replica and a viable empty server, this can remove the only serving copy even though the previous fresh-first path would have kept it serving while the replacement loaded. Preserve or roll back the old replica, or fall back to a fresh destination when the in-place load cannot proceed, and add a failure-with-fresh-candidate 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] feat: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3939217515


##########
server/src/main/java/org/apache/druid/server/coordinator/loading/PartialSegmentStatusInTier.java:
##########
@@ -119,19 +122,19 @@
   }
 
   /**
-   * Stale-loaded servers that can take an additive reload request; kept as a subset of {@link #getStaleLoaded()}
-   * filtered for decommissioning / load-queue-full, so the algorithm can target them as a fallback destination when
-   * no fresh-load slots are available. See {@code StrategicSegmentAssigner.updateReplicasInTierPartial}.
+   * Stale-loaded servers that can take an in-place reload request; a subset of {@link #getStaleLoaded()} filtered by
+   * {@link #canReloadInPlace}. The preferred destination for a matching deficit, ahead of
+   * {@link #getEligibleForFreshLoad()}. See {@link StrategicSegmentAssigner#updateReplicasInTierPartial}.
    */
-  public List<ServerHolder> getEligibleForAdditiveReload()
+  public List<ServerHolder> getEligibleForInPlaceReload()

Review Comment:
   ## CodeQL / Exposing internal representation
   
   getEligibleForInPlaceReload exposes the internal representation stored in field eligibleForInPlaceReload. The value may be modified [after this call to getEligibleForInPlaceReload](1).
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/11935)



-- 
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: partial load rules assignment prefer in-place reload over fresh load (druid)

Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #20267:
URL: https://github.com/apache/druid/pull/20267#discussion_r3983489963


##########
server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java:
##########
@@ -161,12 +161,24 @@ public void addSegment(
         currentDropLatch.cancelOrAwait();
       }
 
+      // A load request for a segment this server already serves is a reload, not a new load. The failure cleanup
+      // below exists to discard the half-materialized state a failed *new* load leaves behind, and running it for a
+      // reload would instead unannounce and drop a replica that is still serving.
+      final boolean isReload = segmentManager.isSegmentLoaded(segment);

Review Comment:
   this works nicer now i think, switched to reserve and acquire the new bundles first before releasing stale holds so that a failure only has to release the difference, making rollback easy (at the cost of needing to reserve a slight bit of extra space bounded by total segment size before it can drop the old stuff)



-- 
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