From 19422075fa5e9c6328ee4ba1cc0f274234ec9447 Mon Sep 17 00:00:00 2001 From: gbrodman Date: Fri, 31 Jan 2025 11:47:44 -0500 Subject: [PATCH] Remove nested transactions from domain (un)locking (#2658) --- .../registry/tools/DomainLockUtils.java | 4 +-- .../tools/LockOrUnlockDomainCommand.java | 34 ++++++------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/google/registry/tools/DomainLockUtils.java b/core/src/main/java/google/registry/tools/DomainLockUtils.java index 7b0af21ea..2f2d9e8e7 100644 --- a/core/src/main/java/google/registry/tools/DomainLockUtils.java +++ b/core/src/main/java/google/registry/tools/DomainLockUtils.java @@ -138,7 +138,7 @@ public final class DomainLockUtils { createLockBuilder(domainName, registrarId, registrarPocId, isAdmin) .setLockCompletionTime(now) .build()); - tm().transact(() -> applyLockStatuses(newLock, now, isAdmin)); + applyLockStatuses(newLock, now, isAdmin); setAsRelock(newLock); return newLock; }); @@ -160,7 +160,7 @@ public final class DomainLockUtils { createUnlockBuilder(domainName, registrarId, isAdmin, relockDuration) .setUnlockCompletionTime(now) .build()); - tm().transact(() -> removeLockStatuses(result, isAdmin, now)); + removeLockStatuses(result, isAdmin, now); return result; }); // Submit relock outside the transaction to make sure that it fully succeeded diff --git a/core/src/main/java/google/registry/tools/LockOrUnlockDomainCommand.java b/core/src/main/java/google/registry/tools/LockOrUnlockDomainCommand.java index 9e17d59af..67c6ebf23 100644 --- a/core/src/main/java/google/registry/tools/LockOrUnlockDomainCommand.java +++ b/core/src/main/java/google/registry/tools/LockOrUnlockDomainCommand.java @@ -16,11 +16,9 @@ package google.registry.tools; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.ImmutableSet.toImmutableSet; -import static com.google.common.collect.Iterables.partition; import static google.registry.model.eppcommon.StatusValue.SERVER_DELETE_PROHIBITED; import static google.registry.model.eppcommon.StatusValue.SERVER_TRANSFER_PROHIBITED; import static google.registry.model.eppcommon.StatusValue.SERVER_UPDATE_PROHIBITED; -import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.util.CollectionUtils.findDuplicates; import com.beust.jcommander.Parameter; @@ -38,8 +36,6 @@ public abstract class LockOrUnlockDomainCommand extends ConfirmingCommand { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - private static final int BATCH_SIZE = 10; - public static final ImmutableSet REGISTRY_LOCK_STATUSES = ImmutableSet.of( SERVER_DELETE_PROHIBITED, SERVER_TRANSFER_PROHIBITED, SERVER_UPDATE_PROHIBITED); @@ -79,26 +75,16 @@ public abstract class LockOrUnlockDomainCommand extends ConfirmingCommand { protected String execute() { ImmutableSet.Builder successfulDomainsBuilder = new ImmutableSet.Builder<>(); ImmutableMap.Builder failedDomainsToReasons = new ImmutableMap.Builder<>(); - partition(getDomains(), BATCH_SIZE) - .forEach( - batch -> - // we require that the jpaTm is the outer transaction in DomainLockUtils - tm().transact( - () -> - tm().transact( - () -> { - for (String domain : batch) { - try { - createAndApplyRequest(domain); - } catch (Throwable t) { - logger.atSevere().withCause(t).log( - "Error when (un)locking domain %s.", domain); - failedDomainsToReasons.put(domain, t.getMessage()); - continue; - } - successfulDomainsBuilder.add(domain); - } - }))); + for (String domain : getDomains()) { + try { + createAndApplyRequest(domain); + } catch (Throwable t) { + logger.atSevere().withCause(t).log("Error when (un)locking domain %s.", domain); + failedDomainsToReasons.put(domain, t.getMessage()); + continue; + } + successfulDomainsBuilder.add(domain); + } ImmutableSet successfulDomains = successfulDomainsBuilder.build(); ImmutableSet failedDomains = failedDomainsToReasons.build().entrySet().stream()