adutra commented on code in PR #1896:
URL: 
https://github.com/apache/cassandra-java-driver/pull/1896#discussion_r1468438125


##########
core/src/main/java/com/datastax/oss/driver/internal/core/loadbalancing/BasicLoadBalancingPolicy.java:
##########
@@ -322,20 +336,41 @@ protected Queue<Node> maybeAddDcFailover(@Nullable 
Request request, @NonNull Que
     }
     QueryPlan remote =
         new LazyQueryPlan() {
-
           @Override
           protected Object[] computeNodes() {
             Object[] remoteNodes =
                 liveNodes.dcs().stream()
                     .filter(Predicates.not(Predicates.equalTo(localDc)))
-                    .flatMap(dc -> 
liveNodes.dc(dc).stream().limit(maxNodesPerRemoteDc))
+                    .sorted(
+                        Comparator.comparingInt(
+                            dc -> {
+                              int i = preferredRemoteDcs.indexOf(dc);
+                              return i < 0 ? Integer.MAX_VALUE : i;
+                            }))
+                    .flatMap(
+                        dc -> {
+                          if (preferredRemoteDcs.isEmpty()) {

Review Comment:
   ```suggestion
                             if (maxNodesPerRemoteDc == 1 || 
preferredRemoteDcs.isEmpty()) {
   ```



##########
core/src/main/java/com/datastax/oss/driver/internal/core/loadbalancing/BasicLoadBalancingPolicy.java:
##########
@@ -322,20 +336,41 @@ protected Queue<Node> maybeAddDcFailover(@Nullable 
Request request, @NonNull Que
     }
     QueryPlan remote =
         new LazyQueryPlan() {
-
           @Override
           protected Object[] computeNodes() {
             Object[] remoteNodes =
                 liveNodes.dcs().stream()
                     .filter(Predicates.not(Predicates.equalTo(localDc)))
-                    .flatMap(dc -> 
liveNodes.dc(dc).stream().limit(maxNodesPerRemoteDc))
+                    .sorted(
+                        Comparator.comparingInt(
+                            dc -> {
+                              int i = preferredRemoteDcs.indexOf(dc);
+                              return i < 0 ? Integer.MAX_VALUE : i;
+                            }))
+                    .flatMap(
+                        dc -> {
+                          if (preferredRemoteDcs.isEmpty()) {
+                            return 
liveNodes.dc(dc).stream().limit(maxNodesPerRemoteDc);
+                          } else {
+                            final Object[] nodesPerRemoteDc =
+                                
liveNodes.dc(dc).stream().limit(maxNodesPerRemoteDc).toArray();
+                            if (nodesPerRemoteDc.length > 0) {

Review Comment:
   ```suggestion
                               if (nodesPerRemoteDc.length > 1) {
   ```



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

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


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

Reply via email to