Avoid unnecessary node list sorting in SimpleNodeSelector
@@ -128,17 +128,22 @@ public class SimpleNodeSelector
Set<InternalNode> blockedExactNodes = new HashSet<>();
boolean splitWaitingForAnyNode = false;
- // todo identify if sorting will cause bottleneck
- List<HostAddress> sortedCandidates = sortedNodes(nodeMap);
+ List<HostAddress> sortedCandidates = null;
OptionalInt preferredNodeCount = OptionalInt.empty();
for (Split split : splits) {
List<InternalNode> candidateNodes;
switch (split.getNodeSelectionStrategy()) {
case HARD_AFFINITY:
+ if (sortedCandidates == null) {
+ sortedCandidates = sortedNodes(nodeMap);
+ }
candidateNodes = selectExactNodes(nodeMap, split.getPreferredNodes(sortedCandidates), includeCoordinator);
preferredNodeCount = OptionalInt.of(candidateNodes.size());
break;
case SOFT_AFFINITY:
+ if (sortedCandidates == null) {
+ sortedCandidates = sortedNodes(nodeMap);
+ }
candidateNodes = selectExactNodes(nodeMap, split.getPreferredNodes(sortedCandidates), includeCoordinator);
preferredNodeCount = OptionalInt.of(candidateNodes.size());
candidateNodes = ImmutableList.<InternalNode>builder().addAll(candidateNodes).addAll(randomNodeSelection.pickNodes(split)).build();
