summaryrefslogtreecommitdiffstats
path: root/node-repository
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2023-01-24 10:52:33 +0100
committerjonmv <venstad@gmail.com>2023-01-24 10:52:33 +0100
commitf05adc74b487f37f5558fb665a3e7c128fafdde4 (patch)
tree51fe2dca26ea4d6ae1edec20545e9f25babd5d96 /node-repository
parent14bf3cb2666a849db1a18ea4f8839cc116d68dfc (diff)
Close node repo lock when given illegal argument
Diffstat (limited to 'node-repository')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Nodes.java19
1 files changed, 10 insertions, 9 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Nodes.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Nodes.java
index 5c2a6601ad8..56a57dbb327 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Nodes.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Nodes.java
@@ -639,18 +639,19 @@ public class Nodes {
private List<Node> decommission(String hostname, HostOperation op, Agent agent, Instant instant) {
Optional<NodeMutex> nodeMutex = lockAndGet(hostname);
if (nodeMutex.isEmpty()) return List.of();
- Node host = nodeMutex.get().node();
- if (!host.type().isHost()) throw new IllegalArgumentException("Cannot " + op + " non-host " + host);
-
+ List<Node> result = new ArrayList<>();
boolean wantToDeprovision = op == HostOperation.deprovision;
boolean wantToRebuild = op == HostOperation.rebuild || op == HostOperation.softRebuild;
boolean wantToRetire = op.needsRetirement();
- List<Node> result = new ArrayList<>();
- try (NodeMutex lock = nodeMutex.get(); Mutex allocationLock = lockUnallocated()) {
- // Modify parent with wantToRetire while holding the allocationLock to prevent
- // any further allocation of nodes on this host
- Node newHost = lock.node().withWantToRetire(wantToRetire, wantToDeprovision, wantToRebuild, agent, instant);
- result.add(write(newHost, lock));
+ Node host = nodeMutex.get().node();
+ try (NodeMutex lock = nodeMutex.get()) {
+ if ( ! host.type().isHost()) throw new IllegalArgumentException("Cannot " + op + " non-host " + host);
+ try (Mutex allocationLock = lockUnallocated()) {
+ // Modify parent with wantToRetire while holding the allocationLock to prevent
+ // any further allocation of nodes on this host
+ Node newHost = lock.node().withWantToRetire(wantToRetire, wantToDeprovision, wantToRebuild, agent, instant);
+ result.add(write(newHost, lock));
+ }
}
if (wantToRetire) { // Apply recursively if we're retiring