|
42 | 42 | import com.datastax.oss.driver.internal.core.util.collection.LazyQueryPlan;
|
43 | 43 | import com.datastax.oss.driver.internal.core.util.collection.QueryPlan;
|
44 | 44 | import com.datastax.oss.driver.internal.core.util.collection.SimpleQueryPlan;
|
| 45 | +import com.datastax.oss.driver.shaded.guava.common.base.Predicates; |
45 | 46 | import edu.umd.cs.findbugs.annotations.NonNull;
|
46 | 47 | import edu.umd.cs.findbugs.annotations.Nullable;
|
47 | 48 | import java.nio.ByteBuffer;
|
@@ -322,30 +323,19 @@ protected Queue<Node> maybeAddDcFailover(@Nullable Request request, @NonNull Que
|
322 | 323 |
|
323 | 324 | @Override
|
324 | 325 | protected Object[] computeNodes() {
|
325 |
| - Object[] dcs = liveNodes.dcs().toArray(); |
326 |
| - if (dcs.length <= 1) { |
327 |
| - return EMPTY_NODES; |
328 |
| - } |
329 |
| - Object[] remoteNodes = new Object[(dcs.length - 1) * maxNodesPerRemoteDc]; |
330 |
| - int remoteNodesLength = 0; |
331 |
| - for (Object dc : dcs) { |
332 |
| - if (!dc.equals(localDc)) { |
333 |
| - Object[] remoteNodesInDc = liveNodes.dc((String) dc).toArray(); |
334 |
| - for (int i = 0; i < maxNodesPerRemoteDc && i < remoteNodesInDc.length; i++) { |
335 |
| - remoteNodes[remoteNodesLength++] = remoteNodesInDc[i]; |
336 |
| - } |
337 |
| - } |
338 |
| - } |
| 326 | + Set<String> dcs = liveNodes.dcs(); |
| 327 | + Object[] remoteNodes = |
| 328 | + dcs.stream() |
| 329 | + .filter(Predicates.not(Predicates.equalTo(localDc))) |
| 330 | + .flatMap(dc -> liveNodes.dc(dc).stream().limit(maxNodesPerRemoteDc)) |
| 331 | + .toArray(); |
| 332 | + |
| 333 | + int remoteNodesLength = remoteNodes.length; |
339 | 334 | if (remoteNodesLength == 0) {
|
340 | 335 | return EMPTY_NODES;
|
341 | 336 | }
|
342 | 337 | shuffleHead(remoteNodes, remoteNodesLength);
|
343 |
| - if (remoteNodes.length == remoteNodesLength) { |
344 |
| - return remoteNodes; |
345 |
| - } |
346 |
| - Object[] trimmedRemoteNodes = new Object[remoteNodesLength]; |
347 |
| - System.arraycopy(remoteNodes, 0, trimmedRemoteNodes, 0, remoteNodesLength); |
348 |
| - return trimmedRemoteNodes; |
| 338 | + return remoteNodes; |
349 | 339 | }
|
350 | 340 | };
|
351 | 341 |
|
|
0 commit comments