Lock node throughput as well
@@ -113,8 +113,7 @@ public class Rebalancer extends Maintainer {
return bestMove;
}
- private boolean markWantToRetire(Node node, boolean wantToRetire) {
- try (Mutex lock = nodeRepository().lock(node)) {
+ private boolean markWantToRetire(Node node, boolean wantToRetire, Mutex lock) {
Optional<Node> nodeToMove = nodeRepository().getNode(node.hostname());
if (nodeToMove.isEmpty()) return false;
if (nodeToMove.get().state() != Node.State.active) return false;
@@ -123,7 +122,6 @@ public class Rebalancer extends Maintainer {
nodeRepository().write(nodeToMove.get().withWantToRetire(wantToRetire, Agent.system, clock.instant()), lock);
return true;
}
- }
/**
* Try a redeployment to effect the chosen move.
@@ -135,10 +133,9 @@ public class Rebalancer extends Maintainer {
ApplicationId application = move.node.allocation().get().owner();
try (MaintenanceDeployment deployment = new MaintenanceDeployment(application, deployer, nodeRepository())) {
if ( ! deployment.isValid()) return false;
-
- boolean couldMarkRetired = markWantToRetire(move.node, true);
+ try (Mutex lock = nodeRepository().lock(move.node)) {
+ boolean couldMarkRetired = markWantToRetire(move.node, true, lock);
if ( ! couldMarkRetired) return false;
-
try {
if ( ! deployment.prepare()) return false;
if (nodeRepository().getNodes(application, Node.State.reserved).stream().noneMatch(node -> node.hasParent(move.toHost.hostname())))
@@ -149,7 +146,8 @@ public class Rebalancer extends Maintainer {
return true;
}
finally {
- markWantToRetire(move.node, false); // Necessary if this failed
+ markWantToRetire(move.node, false, lock); // In case this failed, noop otherwise
+ }
}
}
}
