Hold lock while committing transaction
@@ -509,18 +509,21 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
// This call will remove application in zookeeper. Watches in TenantApplications will remove the application
// and allocated hosts in model and handlers in RPC server
transaction.add(tenantApplications.createDeleteTransaction(applicationId));
+ transaction.onCommitted(() -> log.log(Level.INFO, "Deleted " + applicationId));
- hostProvisioner.ifPresent(provisioner -> {
+ if (hostProvisioner.isPresent()) {
if (acquireProvisionLock.value()) {
- try (var provisionLock = provisioner.lock(applicationId)) {
- provisioner.remove(transaction, provisionLock);
+ try (var provisionLock = hostProvisioner.get().lock(applicationId)) {
+ hostProvisioner.get().remove(transaction, provisionLock);
+ transaction.commit();
}
- } else {
- provisioner.remove(transaction, applicationId);
+ } else { // TODO(mpolden): Remove when feature flag is removed
+ hostProvisioner.get().remove(transaction, applicationId);
+ transaction.commit();
}
- });
- transaction.onCommitted(() -> log.log(Level.INFO, "Deleted " + applicationId));
+ } else {
transaction.commit();
+ }
return true;
}
}
@@ -736,16 +739,19 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
CompletionWaiter waiter = session.getSessionZooKeeperClient().createActiveWaiter();
NestedTransaction transaction = new NestedTransaction();
transaction.add(deactivateCurrentActivateNew(previousActiveSession, session, force));
- hostProvisioner.ifPresent(provisioner -> {
+ if (hostProvisioner.isPresent()) {
if (acquireProvisionLock.value()) {
- try (var lock = provisioner.lock(applicationId)) {
- provisioner.activate(transaction, session.getAllocatedHosts().getHosts(), lock);
+ try (var lock = hostProvisioner.get().lock(applicationId)) {
+ hostProvisioner.get().activate(transaction, session.getAllocatedHosts().getHosts(), lock);
+ transaction.commit();
}
- } else {
- provisioner.activate(transaction, applicationId, session.getAllocatedHosts().getHosts());
+ } else { // TODO(mpolden): Remove when feature flag is removed
+ hostProvisioner.get().activate(transaction, applicationId, session.getAllocatedHosts().getHosts());
+ transaction.commit();
}
- });
+ } else {
transaction.commit();
+ }
return waiter;
}
