From a755bedda05e45fefbc5768baaf978b098824bfd Mon Sep 17 00:00:00 2001 From: Ben McIlwain Date: Fri, 8 Oct 2021 16:44:45 -0400 Subject: [PATCH] Revert update auto timestamp non-transactional fallback (#1380) This was added recently in PR #1341 as an attempted fix for our test flakiness, but it turns out that it didn't address the root issue (whereas PR #1361 did). So this removes the fallback, as there's no reason this should ever be called outside of a transactional context. --- .../registry/beam/initsql/Transforms.java | 5 ++--- .../registry/model/UpdateAutoTimestamp.java | 19 ++----------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/google/registry/beam/initsql/Transforms.java b/core/src/main/java/google/registry/beam/initsql/Transforms.java index 53af5f0da..0de9103f8 100644 --- a/core/src/main/java/google/registry/beam/initsql/Transforms.java +++ b/core/src/main/java/google/registry/beam/initsql/Transforms.java @@ -330,9 +330,8 @@ public final class Transforms { // instead of append. See b/185954992. entity.setUnindexedProperty("reason", Reason.RENEW.name()); entity.setUnindexedProperty("flags", ImmutableList.of(Flag.AUTO_RENEW.name())); - } - // Canonicalize old domain/host names from 2016 and earlier before we were enforcing this. - else if (entity.getKind().equals("DomainBase")) { + } else if (entity.getKind().equals("DomainBase")) { + // Canonicalize old domain/host names from 2016 and earlier before we were enforcing this. entity.setIndexedProperty( "fullyQualifiedDomainName", canonicalizeDomainName((String) entity.getProperty("fullyQualifiedDomainName"))); diff --git a/core/src/main/java/google/registry/model/UpdateAutoTimestamp.java b/core/src/main/java/google/registry/model/UpdateAutoTimestamp.java index fcd254d7e..20370af06 100644 --- a/core/src/main/java/google/registry/model/UpdateAutoTimestamp.java +++ b/core/src/main/java/google/registry/model/UpdateAutoTimestamp.java @@ -15,12 +15,8 @@ package google.registry.model; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; -import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm; import static google.registry.util.DateTimeUtils.START_OF_TIME; -import static org.joda.time.DateTimeZone.UTC; -import com.google.common.flogger.FluentLogger; -import com.google.common.flogger.StackSize; import com.googlecode.objectify.annotation.Ignore; import com.googlecode.objectify.annotation.OnLoad; import google.registry.model.translators.UpdateAutoTimestampTranslatorFactory; @@ -44,12 +40,10 @@ import org.joda.time.DateTime; @Embeddable public class UpdateAutoTimestamp extends ImmutableObject { - private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - // When set to true, database converters/translators should do the auto update. When set to // false, auto update should be suspended (this exists to allow us to preserve the original value // during a replay). - private static ThreadLocal autoUpdateEnabled = ThreadLocal.withInitial(() -> true); + private static final ThreadLocal autoUpdateEnabled = ThreadLocal.withInitial(() -> true); @Transient DateTime timestamp; @@ -63,16 +57,7 @@ public class UpdateAutoTimestamp extends ImmutableObject { @PrePersist @PreUpdate void setTimestamp() { - // On the off chance that this is called outside of a transaction, log it instead of failing - // with an exception from attempting to call jpaTm().getTransactionTime(), and then fall back - // to DateTime.now(UTC). - if (!jpaTm().inTransaction()) { - logger.atSevere().withStackTrace(StackSize.MEDIUM).log( - "Failed to update automatic timestamp because this wasn't called in a JPA transaction%s.", - ofyTm().inTransaction() ? " (but there is an open Ofy transaction)" : ""); - timestamp = DateTime.now(UTC); - lastUpdateTime = DateTimeUtils.toZonedDateTime(timestamp); - } else if (autoUpdateEnabled() || lastUpdateTime == null) { + if (autoUpdateEnabled() || lastUpdateTime == null) { timestamp = jpaTm().getTransactionTime(); lastUpdateTime = DateTimeUtils.toZonedDateTime(timestamp); }