summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2024-05-13 15:10:54 +0200
committerjonmv <venstad@gmail.com>2024-05-13 15:10:54 +0200
commit02b3dc2db1d9edbea9b0dfd7890756485365c920 (patch)
treea3100cee0f6e914419093de0537ca55f67d16333
parentfbb61835446abe18b15dd5e36e9df6b01181a73c (diff)
Restore map order, and verify count when deconstructing
-rw-r--r--clustercontroller-apps/src/main/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterController.java15
1 files changed, 10 insertions, 5 deletions
diff --git a/clustercontroller-apps/src/main/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterController.java b/clustercontroller-apps/src/main/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterController.java
index bd9b538b91b..114b88f03a8 100644
--- a/clustercontroller-apps/src/main/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterController.java
+++ b/clustercontroller-apps/src/main/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterController.java
@@ -30,7 +30,7 @@ public class ClusterController extends AbstractComponent
private final JDiscMetricWrapper metricWrapper;
private final Object monitor = new Object();
private final Map<String, FleetController> controllers = new TreeMap<>();
- private final Map<String, StatusHandler.ContainerStatusPageServer> status = new HashMap<>();
+ private final Map<String, StatusHandler.ContainerStatusPageServer> status = new TreeMap<>();
private final Map<String, Integer> referents = new HashMap<>();
private final AtomicBoolean shutdown = new AtomicBoolean();
@@ -72,10 +72,15 @@ public class ClusterController extends AbstractComponent
*/
void countdown(String clusterName) {
synchronized (monitor) {
- if (0 == referents.merge(clusterName, -1, Integer::sum)) {
- shutDownController(controllers.remove(clusterName));
- status.remove(clusterName);
- }
+ referents.compute(clusterName, (__, count) -> {
+ if (count == null) throw new IllegalStateException("trying to remove unknown cluster: " + clusterName);
+ if (count == 1) {
+ shutDownController(controllers.remove(clusterName));
+ status.remove(clusterName);
+ return null;
+ }
+ return count - 1;
+ });
}
}