praveenc7 commented on code in PR #13952:
URL: https://github.com/apache/pinot/pull/13952#discussion_r1750889890


##########
pinot-broker/src/main/java/org/apache/pinot/broker/routing/instanceselector/ReplicaGroupInstanceSelector.java:
##########
@@ -152,21 +155,28 @@ private Pair<Map<String, String>, Map<String, String>> 
selectServersUsingAdaptiv
       SegmentInstanceCandidate selectedInstance = candidates.get(instanceIdx);
       // Adaptive Server Selection
       // TODO: Support numReplicaGroupsToQuery with Adaptive Server Selection.
-      if (!serverRankList.isEmpty()) {
-        int minIdx = Integer.MAX_VALUE;
+      if (!serverRankMap.isEmpty()) {
+        int bestRank = Integer.MAX_VALUE;
         for (SegmentInstanceCandidate candidate : candidates) {
-          int idx = serverRankList.indexOf(candidate.getInstance());
-          if (idx == -1) {
+          Integer rank = serverRankMap.get(candidate.getInstance());
+          if (rank == null) {
             // Let's use the round-robin approach until stats for all servers 
are populated.
             selectedInstance = candidates.get(instanceIdx);
             break;
           }
-          if (idx < minIdx) {
-            minIdx = idx;
+          // Update the candidate if the current one has a better rank
+          if (rank < bestRank) {
+            bestRank = rank;
             selectedInstance = candidate;
           }
         }
       }
+
+      if (selectedServers.contains(selectedInstance.getInstance())) {

Review Comment:
   As discussed moved the set inside the second loop and use it to exit early



-- 
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-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to