diff options
-rw-r--r-- | clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/NodeStateChangeChecker.java | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/NodeStateChangeChecker.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/NodeStateChangeChecker.java index 50cdf260105..a36bd187a47 100644 --- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/NodeStateChangeChecker.java +++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/NodeStateChangeChecker.java @@ -16,6 +16,7 @@ import com.yahoo.vespa.clustercontroller.utils.staterestapi.requests.SetUnitStat import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -391,26 +392,30 @@ public class NodeStateChangeChecker { } private Result checkRedundancy(DistributorNodeInfo distributorNodeInfo, Node node) { - List<StorageNode> storageNodes = distributorNodeInfo.getHostInfo().getDistributor().getStorageNodes(); - for (StorageNode storageNode : storageNodes) { - if (storageNode.getIndex() == node.getIndex()) { - Integer minReplication = storageNode.getMinCurrentReplicationFactorOrNull(); - // Why test on != null? Missing min-replication is OK (indicate empty/few buckets on system). - if (minReplication != null && minReplication < requiredRedundancy) { - return disallow("Distributor " + distributorNodeInfo.getNodeIndex() - + " says storage node " + node.getIndex() - + " has buckets with redundancy as low as " - + storageNode.getMinCurrentReplicationFactorOrNull() - + ", but we require at least " + requiredRedundancy); - } else { - return allow(); - } - } + Integer minReplication = minReplication(distributorNodeInfo).get(node.getIndex()); + // Why test on != null? Missing min-replication is OK (indicate empty/few buckets on system). + if (minReplication != null && minReplication < requiredRedundancy) { + return disallow("Distributor " + distributorNodeInfo.getNodeIndex() + + " says storage node " + node.getIndex() + + " has buckets with redundancy as low as " + + minReplication + ", but we require at least " + requiredRedundancy); } return allow(); } + private Map<Integer, Integer> minReplication(DistributorNodeInfo distributorNodeInfo) { + Map<Integer, Integer> replicationPerNodeIndex = new HashMap<>(); + for (StorageNode storageNode : distributorNodeInfo.getHostInfo().getDistributor().getStorageNodes()) { + var currentValue = replicationPerNodeIndex.get(storageNode.getIndex()); + Integer minReplicationFactor = storageNode.getMinCurrentReplicationFactorOrNull(); + if (currentValue == null || (minReplicationFactor != null && minReplicationFactor < currentValue)) + replicationPerNodeIndex.put(storageNode.getIndex(), minReplicationFactor); + } + + return replicationPerNodeIndex; + } + /** * We want to check with the distributors to verify that it is safe to take down the storage node. * @param node the node to be checked |