From e82cbe60a94db2ac7f6173272e3b7a278bcf2f2e Mon Sep 17 00:00:00 2001 From: Lai Jiang Date: Thu, 7 Dec 2023 19:02:16 -0500 Subject: [PATCH] Do not log nested transactions in production (#2251) This might be the cause of the SQL performance degradation that we are observing during the recent launch. The change went in a month ago but there hasn't been enough increase in mutating traffic to make it problematic until the launch. Note that presubmits should run faster too with this chance, which serves as an evidence that excessive logging is the culprit. --- .../persistence/transaction/JpaTransactionManagerImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/google/registry/persistence/transaction/JpaTransactionManagerImpl.java b/core/src/main/java/google/registry/persistence/transaction/JpaTransactionManagerImpl.java index a2a863012..875859193 100644 --- a/core/src/main/java/google/registry/persistence/transaction/JpaTransactionManagerImpl.java +++ b/core/src/main/java/google/registry/persistence/transaction/JpaTransactionManagerImpl.java @@ -33,6 +33,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; import com.google.common.flogger.FluentLogger; import com.google.common.flogger.StackSize; +import google.registry.config.RegistryEnvironment; import google.registry.model.ImmutableObject; import google.registry.persistence.JpaRetries; import google.registry.persistence.PersistenceModule.TransactionIsolationLevel; @@ -164,7 +165,10 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager { if (!getHibernateAllowNestedTransactions()) { throw new IllegalStateException(NESTED_TRANSACTION_MESSAGE); } - logger.atWarning().withStackTrace(StackSize.MEDIUM).log(NESTED_TRANSACTION_MESSAGE); + if (RegistryEnvironment.get() != RegistryEnvironment.PRODUCTION + && RegistryEnvironment.get() != RegistryEnvironment.UNITTEST) { + logger.atWarning().withStackTrace(StackSize.MEDIUM).log(NESTED_TRANSACTION_MESSAGE); + } // This prevents inner transaction from retrying, thus avoiding a cascade retry effect. return transactNoRetry(work, isolationLevel); }