diff options
author | Jon Bratseth <bratseth@vespa.ai> | 2023-07-12 22:58:01 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@vespa.ai> | 2023-07-12 22:58:01 +0200 |
commit | 4ebadcb380aa4842327e7f5187efbcb13bedd925 (patch) | |
tree | 12aeb4a680953f8437fb3d7a8b7df9f34eeba687 /node-repository | |
parent | 6995d695bb0f9007604b34413abcb5a5078f00ef (diff) |
node -> candidate
Diffstat (limited to 'node-repository')
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/GroupAssigner.java | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/GroupAssigner.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/GroupAssigner.java index 4d7114520b3..542f2c00f95 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/GroupAssigner.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/GroupAssigner.java @@ -34,14 +34,14 @@ class GroupAssigner { this.clock = clock; } - Collection<NodeCandidate> assignTo(Collection<NodeCandidate> nodes) { - int[] countInGroup = countInEachGroup(nodes); - nodes = byUnretiringPriority(nodes).stream().map(node -> unretireNodeInExpandedGroup(node, countInGroup)).toList(); - nodes = nodes.stream().map(node -> assignGroupToNewNode(node, countInGroup)).toList(); - nodes = byUnretiringPriority(nodes).stream().map(node -> moveNodeInSurplusGroup(node, countInGroup)).toList(); - nodes = byRetiringPriority(nodes).stream().map(node -> retireSurplusNodeInGroup(node, countInGroup)).toList(); - nodes = nodes.stream().filter(node -> ! shouldRemove(node)).toList(); - return nodes; + Collection<NodeCandidate> assignTo(Collection<NodeCandidate> candidates) { + int[] countInGroup = countInEachGroup(candidates); + candidates = byUnretiringPriority(candidates).stream().map(node -> unretireNodeInExpandedGroup(node, countInGroup)).toList(); + candidates = candidates.stream().map(node -> assignGroupToNewNode(node, countInGroup)).toList(); + candidates = byUnretiringPriority(candidates).stream().map(node -> moveNodeInSurplusGroup(node, countInGroup)).toList(); + candidates = byRetiringPriority(candidates).stream().map(node -> retireSurplusNodeInGroup(node, countInGroup)).toList(); + candidates = candidates.stream().filter(node -> ! shouldRemove(node)).toList(); + return candidates; } /** Prefer to retire nodes we want the least */ @@ -57,11 +57,11 @@ class GroupAssigner { .toList(); } - private int[] countInEachGroup(Collection<NodeCandidate> nodes) { + private int[] countInEachGroup(Collection<NodeCandidate> candidates) { int[] countInGroup = new int[requested.groups()]; - for (var node : nodes) { - if (node.allocation().get().membership().retired()) continue; - var currentGroup = node.allocation().get().membership().cluster().group(); + for (var candidate : candidates) { + if (candidate.allocation().get().membership().retired()) continue; + var currentGroup = candidate.allocation().get().membership().cluster().group(); if (currentGroup.isEmpty()) continue; if (currentGroup.get().index() >= requested.groups()) continue; countInGroup[currentGroup.get().index()]++; @@ -70,81 +70,81 @@ class GroupAssigner { } /** Assign a group to new or to be reactivated nodes. */ - private NodeCandidate assignGroupToNewNode(NodeCandidate node, int[] countInGroup) { - if (node.state() == Node.State.active && node.allocation().get().membership().retired()) return node; - if (node.state() == Node.State.active && node.allocation().get().membership().cluster().group().isPresent()) return node; - return inFirstGroupWithDeficiency(node, countInGroup); + private NodeCandidate assignGroupToNewNode(NodeCandidate candidate, int[] countInGroup) { + if (candidate.state() == Node.State.active && candidate.allocation().get().membership().retired()) return candidate; + if (candidate.state() == Node.State.active && candidate.allocation().get().membership().cluster().group().isPresent()) return candidate; + return inFirstGroupWithDeficiency(candidate, countInGroup); } - private NodeCandidate moveNodeInSurplusGroup(NodeCandidate node, int[] countInGroup) { - var currentGroup = node.allocation().get().membership().cluster().group(); - if (currentGroup.isEmpty()) return node; - if (currentGroup.get().index() < requested.groups()) return node; - return inFirstGroupWithDeficiency(node, countInGroup); + private NodeCandidate moveNodeInSurplusGroup(NodeCandidate candidate, int[] countInGroup) { + var currentGroup = candidate.allocation().get().membership().cluster().group(); + if (currentGroup.isEmpty()) return candidate; + if (currentGroup.get().index() < requested.groups()) return candidate; + return inFirstGroupWithDeficiency(candidate, countInGroup); } - private NodeCandidate retireSurplusNodeInGroup(NodeCandidate node, int[] countInGroup) { - if (node.allocation().get().membership().retired()) return node; - var currentGroup = node.allocation().get().membership().cluster().group(); - if (currentGroup.isEmpty()) return node; - if (currentGroup.get().index() >= requested.groups()) return node; - if (requested.count().isEmpty()) return node; // Can't retire - if (countInGroup[currentGroup.get().index()] <= requested.groupSize()) return node; + private NodeCandidate retireSurplusNodeInGroup(NodeCandidate candidate, int[] countInGroup) { + if (candidate.allocation().get().membership().retired()) return candidate; + var currentGroup = candidate.allocation().get().membership().cluster().group(); + if (currentGroup.isEmpty()) return candidate; + if (currentGroup.get().index() >= requested.groups()) return candidate; + if (requested.count().isEmpty()) return candidate; // Can't retire + if (countInGroup[currentGroup.get().index()] <= requested.groupSize()) return candidate; countInGroup[currentGroup.get().index()]--; - return node.withNode(node.toNode().retire(Agent.application, clock.instant())); + return candidate.withNode(candidate.toNode().retire(Agent.application, clock.instant())); } /** Unretire nodes that are already in the correct group when the group is deficient. */ - private NodeCandidate unretireNodeInExpandedGroup(NodeCandidate node, int[] countInGroup) { - if ( ! node.allocation().get().membership().retired()) return node; - var currentGroup = node.allocation().get().membership().cluster().group(); - if (currentGroup.isEmpty()) return node; - if (currentGroup.get().index() >= requested.groups()) return node; - if (node.preferToRetire() || node.wantToRetire()) return node; - if (requested.count().isPresent() && countInGroup[currentGroup.get().index()] >= requested.groupSize()) return node; - node = unretire(node); - if (node.allocation().get().membership().retired()) return node; + private NodeCandidate unretireNodeInExpandedGroup(NodeCandidate candidate, int[] countInGroup) { + if ( ! candidate.allocation().get().membership().retired()) return candidate; + var currentGroup = candidate.allocation().get().membership().cluster().group(); + if (currentGroup.isEmpty()) return candidate; + if (currentGroup.get().index() >= requested.groups()) return candidate; + if (candidate.preferToRetire() || candidate.wantToRetire()) return candidate; + if (requested.count().isPresent() && countInGroup[currentGroup.get().index()] >= requested.groupSize()) return candidate; + candidate = unretire(candidate); + if (candidate.allocation().get().membership().retired()) return candidate; countInGroup[currentGroup.get().index()]++; - return node; + return candidate; } - private NodeCandidate inFirstGroupWithDeficiency(NodeCandidate node, int[] countInGroup) { + private NodeCandidate inFirstGroupWithDeficiency(NodeCandidate candidate, int[] countInGroup) { for (int group = 0; group < requested.groups(); group++) { if (requested.count().isEmpty() || countInGroup[group] < requested.groupSize()) { - return inGroup(group, node, countInGroup); + return inGroup(group, candidate, countInGroup); } } - return node; + return candidate; } - private boolean shouldRemove(NodeCandidate node) { - var currentGroup = node.allocation().get().membership().cluster().group(); + private boolean shouldRemove(NodeCandidate candidate) { + var currentGroup = candidate.allocation().get().membership().cluster().group(); if (currentGroup.isEmpty()) return true; // new and not assigned an index: Not needed return currentGroup.get().index() >= requested.groups(); } - private NodeCandidate inGroup(int group, NodeCandidate node, int[] countInGroup) { - node = unretire(node); - if (node.allocation().get().membership().retired()) return node; - var membership = node.allocation().get().membership(); + private NodeCandidate inGroup(int group, NodeCandidate candidate, int[] countInGroup) { + candidate = unretire(candidate); + if (candidate.allocation().get().membership().retired()) return candidate; + var membership = candidate.allocation().get().membership(); var currentGroup = membership.cluster().group(); countInGroup[group]++; if ( ! currentGroup.isEmpty() && currentGroup.get().index() < requested.groups()) countInGroup[membership.cluster().group().get().index()]--; - return node.withNode(node.toNode().with(node.allocation().get().with(membership.with(membership.cluster().with(Optional.of(ClusterSpec.Group.from(group))))))); + return candidate.withNode(candidate.toNode().with(candidate.allocation().get().with(membership.with(membership.cluster().with(Optional.of(ClusterSpec.Group.from(group))))))); } /** Attempt to unretire the given node if it is retired. */ - private NodeCandidate unretire(NodeCandidate node) { - if (node.retiredNow()) return node; - if ( ! node.allocation().get().membership().retired()) return node; - if ( ! hasCompatibleResources(node) ) return node; - var parent = node.parentHostname().flatMap(hostname -> allNodes.node(hostname)); - if (parent.isPresent() && (parent.get().status().wantToRetire() || parent.get().status().preferToRetire())) return node; - node = node.withNode(); - if ( ! requested.isCompatible(node.resources())) - node = node.withNode(resize(node.toNode())); - return node.withNode(node.toNode().unretire()); + private NodeCandidate unretire(NodeCandidate candidate) { + if (candidate.retiredNow()) return candidate; + if ( ! candidate.allocation().get().membership().retired()) return candidate; + if ( ! hasCompatibleResources(candidate) ) return candidate; + var parent = candidate.parentHostname().flatMap(hostname -> allNodes.node(hostname)); + if (parent.isPresent() && (parent.get().status().wantToRetire() || parent.get().status().preferToRetire())) return candidate; + candidate = candidate.withNode(); + if ( ! requested.isCompatible(candidate.resources())) + candidate = candidate.withNode(resize(candidate.toNode())); + return candidate.withNode(candidate.toNode().unretire()); } private Node resize(Node node) { |