summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2023-07-14 12:29:53 +0200
committerHarald Musum <musum@yahooinc.com>2023-07-14 12:29:53 +0200
commit9f56b9f995e2297f60b02fc06af5a8f0897612bf (patch)
tree140850125b072cc4ce358e5fab1bc3f6f30e0f2c /clustercontroller-core
parent11f10d3d96b6a80440a826dd044ab2eed09a28f9 (diff)
Split out method for finding min replication per distributor
Diffstat (limited to 'clustercontroller-core')
-rw-r--r--clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/NodeStateChangeChecker.java35
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