diff options
author | Martin Polden <mpolden@mpolden.no> | 2021-03-03 10:31:44 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2021-03-03 10:35:42 +0100 |
commit | 0071c6fe030f01b8ad6d3b83f20d276cd20be2bd (patch) | |
tree | cd687edb8e3a84cd51c428e5c25ad3eaa411b44b | |
parent | 71fa6921afabcb113fe53446d2e56050e735e9c2 (diff) |
Add workaround for discontinuous cluster indices
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java index d96ce354337..f6e0ede4e7d 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeAllocation.java @@ -306,21 +306,23 @@ class NodeAllocation { /** Returns the indices to use when provisioning hosts for this */ List<Integer> provisionIndices(int count) { - if (count == 0) return List.of(); + if (count < 1) throw new IllegalArgumentException("Count must be positive"); NodeType hostType = requestedNodes.type().hostType(); // Tenant hosts have a continuously increasing index if (hostType == NodeType.host) return nodeRepository.database().readProvisionIndices(count); - // Infrastructure hosts have fixed indices: Their cluster index + 1 - int offset = 1; + // Infrastructure hosts have fixed indices, starting at 1 Set<Integer> currentIndices = allNodes.nodeType(hostType) .stream() - .map(node -> node.allocation().get().membership().index()) - .map(index -> index + offset) + .map(Node::hostname) + // TODO(mpolden): Use cluster index instead of parsing hostname, once all + // config servers have been replaced once and have switched + // to compact indices + .map(NodeAllocation::parseIndex) .collect(Collectors.toSet()); List<Integer> indices = new ArrayList<>(count); - for (int i = offset; indices.size() < count; i++) { + for (int i = 1; indices.size() < count; i++) { if (!currentIndices.contains(i)) { indices.add(i); } @@ -433,6 +435,15 @@ class NodeAllocation { return ": Not enough nodes available due to " + String.join(", ", reasons); } + private static Integer parseIndex(String hostname) { + // Node index is the first number appearing in the hostname, before the first dot + try { + return Integer.parseInt(hostname.replaceFirst("^\\D+(\\d+)\\..*", "$1")); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Could not parse index from hostname '" + hostname + "'", e); + } + } + static class FlavorCount { private final NodeResources flavor; |