You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2019/03/01 16:19:12 UTC

[GitHub] drcrallen commented on a change in pull request #7174: Change reservoir sampling of segments to spliterator approach

drcrallen commented on a change in pull request #7174: Change reservoir sampling of segments to spliterator approach
URL: https://github.com/apache/incubator-druid/pull/7174#discussion_r261665877
 
 

 ##########
 File path: server/src/main/java/org/apache/druid/server/coordinator/ReservoirSegmentSampler.java
 ##########
 @@ -21,36 +21,57 @@
 
 import org.apache.druid.timeline.DataSegment;
 
+import java.util.Collection;
 import java.util.List;
+import java.util.Spliterator;
 import java.util.concurrent.ThreadLocalRandom;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
 
 final class ReservoirSegmentSampler
 {
+  final static int SPLITERATOR_SIZE_THRESHOLD = 10;
 
   static BalancerSegmentHolder getRandomBalancerSegmentHolder(final List<ServerHolder> serverHolders)
   {
-    ServerHolder fromServerHolder = null;
+    ServerHolder fromServerHolder = getRandomElementFromList(serverHolders);
+    Collection<DataSegment> segments = fromServerHolder.getServer().getSegments();
+    Spliterator<DataSegment> chosenSpliterator = segments.spliterator();
     DataSegment proposalSegment = null;
-    int numSoFar = 0;
-
-    for (ServerHolder server : serverHolders) {
-      for (DataSegment segment : server.getServer().getSegments()) {
-        int randNum = ThreadLocalRandom.current().nextInt(numSoFar + 1);
-        // w.p. 1 / (numSoFar+1), swap out the server and segment
-        if (randNum == numSoFar) {
-          fromServerHolder = server;
-          proposalSegment = segment;
-        }
-        numSoFar++;
+
+    for (int i = 0; i < Math.log(segments.size()); i++) {
+      if (chosenSpliterator.estimateSize() < SPLITERATOR_SIZE_THRESHOLD) {
+        List<DataSegment> finalList = StreamSupport
 
 Review comment:
   can it just be checked if the spliterator is `SIZED` and pick a specific element if so?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org