yuanlihan commented on a change in pull request #11257:
URL: https://github.com/apache/druid/pull/11257#discussion_r663621289



##########
File path: 
server/src/main/java/org/apache/druid/server/coordinator/ReservoirSegmentSampler.java
##########
@@ -31,6 +32,42 @@
 
   private static final EmittingLogger log = new 
EmittingLogger(ReservoirSegmentSampler.class);
 
+  static List<BalancerSegmentHolder> getRandomBalancerSegmentHolders(
+      final List<ServerHolder> serverHolders,
+      Set<String> broadcastDatasources,
+      int k
+  )
+  {
+    List<BalancerSegmentHolder> holders = new ArrayList<>(k);
+    int numSoFar = 0;
+
+    for (ServerHolder server : serverHolders) {
+      if (!server.getServer().getType().isSegmentReplicationTarget()) {
+        // if the server only handles broadcast segments (which don't need to 
be rebalanced), we have nothing to do
+        continue;
+      }
+
+      for (DataSegment segment : server.getServer().iterateAllSegments()) {
+        if (broadcastDatasources.contains(segment.getDataSource())) {
+          // we don't need to rebalance segments that were assigned via 
broadcast rules
+          continue;
+        }
+
+        if (numSoFar < k) {
+          holders.add(new BalancerSegmentHolder(server.getServer(), segment));
+          numSoFar++;
+          continue;
+        }
+        int randNum = ThreadLocalRandom.current().nextInt(numSoFar + 1);
+        if (randNum < k) {
+          holders.set(randNum, new BalancerSegmentHolder(server.getServer(), 
segment));
+        }

Review comment:
       It makes sense to me to retain the `percentOfSegmentsToConsider` and add 
an another dynamic parameter `useBatchedSegmentSampler` to enable the new 
improvement. In this way, the changing will be less aggressive.

##########
File path: 
server/src/main/java/org/apache/druid/server/coordinator/BalancerStrategy.java
##########
@@ -71,13 +71,60 @@
    * @return {@link BalancerSegmentHolder} containing segment to move and 
server it currently resides on, or null if
    *         there are no segments to pick from (i. e. all provided 
serverHolders are empty).
    */
+  @Deprecated

Review comment:
       updated




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

Reply via email to