diff --git a/core/src/main/java/google/registry/rdap/RdapDomainAction.java b/core/src/main/java/google/registry/rdap/RdapDomainAction.java index bb5772761..a95bd6334 100644 --- a/core/src/main/java/google/registry/rdap/RdapDomainAction.java +++ b/core/src/main/java/google/registry/rdap/RdapDomainAction.java @@ -15,7 +15,7 @@ package google.registry.rdap; import static google.registry.flows.domain.DomainFlowUtils.validateDomainName; -import static google.registry.model.EppResourceUtils.loadByForeignKey; +import static google.registry.model.EppResourceUtils.loadByForeignKeyCached; import static google.registry.request.Action.Method.GET; import static google.registry.request.Action.Method.HEAD; import static google.registry.util.DateTimeUtils.START_OF_TIME; @@ -60,7 +60,7 @@ public class RdapDomainAction extends RdapActionBase { } // The query string is not used; the RDAP syntax is /rdap/domain/mydomain.com. Optional domain = - loadByForeignKey( + loadByForeignKeyCached( Domain.class, pathSearchString, shouldIncludeDeleted() ? START_OF_TIME : rdapJsonFormatter.getRequestTime()); diff --git a/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java b/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java index dfafb9901..86b0df057 100644 --- a/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java +++ b/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java @@ -15,7 +15,7 @@ package google.registry.rdap; import static com.google.common.collect.ImmutableSet.toImmutableSet; -import static google.registry.model.EppResourceUtils.loadByForeignKey; +import static google.registry.model.EppResourceUtils.loadByForeignKeyCached; import static google.registry.model.index.ForeignKeyIndex.loadAndGetKey; import static google.registry.model.ofy.ObjectifyService.auditedOfy; import static google.registry.persistence.transaction.TransactionManagerFactory.replicaJpaTm; @@ -188,7 +188,8 @@ public class RdapDomainSearchAction extends RdapSearchActionBase { private DomainSearchResponse searchByDomainNameWithoutWildcard( final RdapSearchPattern partialStringQuery) { Optional domain = - loadByForeignKey(Domain.class, partialStringQuery.getInitialString(), getRequestTime()); + loadByForeignKeyCached( + Domain.class, partialStringQuery.getInitialString(), getRequestTime()); return makeSearchResults( shouldBeVisible(domain) ? ImmutableList.of(domain.get()) : ImmutableList.of()); } @@ -389,7 +390,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase { Optional desiredRegistrar = getDesiredRegistrar(); if (desiredRegistrar.isPresent()) { Optional host = - loadByForeignKey( + loadByForeignKeyCached( Host.class, partialStringQuery.getInitialString(), shouldIncludeDeleted() ? START_OF_TIME : getRequestTime()); @@ -414,7 +415,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase { // through the subordinate hosts. This is more efficient, and lets us permit wildcard searches // with no initial string. Domain domain = - loadByForeignKey( + loadByForeignKeyCached( Domain.class, partialStringQuery.getSuffix(), shouldIncludeDeleted() ? START_OF_TIME : getRequestTime()) @@ -431,7 +432,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase { if (partialStringQuery.matches(fqhn)) { if (desiredRegistrar.isPresent()) { Optional host = - loadByForeignKey( + loadByForeignKeyCached( Host.class, fqhn, shouldIncludeDeleted() ? START_OF_TIME : getRequestTime()); if (host.isPresent() && desiredRegistrar diff --git a/core/src/main/java/google/registry/rdap/RdapEntityAction.java b/core/src/main/java/google/registry/rdap/RdapEntityAction.java index bbb99faf0..47967dfc9 100644 --- a/core/src/main/java/google/registry/rdap/RdapEntityAction.java +++ b/core/src/main/java/google/registry/rdap/RdapEntityAction.java @@ -14,7 +14,7 @@ package google.registry.rdap; -import static google.registry.persistence.transaction.TransactionManagerFactory.tm; +import static google.registry.persistence.transaction.TransactionManagerFactory.replicaJpaTm; import static google.registry.rdap.RdapUtils.getRegistrarByIanaIdentifier; import static google.registry.rdap.RdapUtils.getRegistrarByName; import static google.registry.request.Action.Method.GET; @@ -71,7 +71,7 @@ public class RdapEntityAction extends RdapActionBase { if (ROID_PATTERN.matcher(pathSearchString).matches()) { VKey contactVKey = VKey.create(ContactResource.class, pathSearchString); Optional contactResource = - tm().transact(() -> tm().loadByKeyIfPresent(contactVKey)); + replicaJpaTm().transact(() -> replicaJpaTm().loadByKeyIfPresent(contactVKey)); // As per Andy Newton on the regext mailing list, contacts by themselves have no role, since // they are global, and might have different roles for different domains. if (contactResource.isPresent() && isAuthorized(contactResource.get())) { diff --git a/core/src/main/java/google/registry/rdap/RdapEntitySearchAction.java b/core/src/main/java/google/registry/rdap/RdapEntitySearchAction.java index 521ec2c3d..8c7e68a3f 100644 --- a/core/src/main/java/google/registry/rdap/RdapEntitySearchAction.java +++ b/core/src/main/java/google/registry/rdap/RdapEntitySearchAction.java @@ -324,9 +324,11 @@ public class RdapEntitySearchAction extends RdapSearchActionBase { contactResourceList = ImmutableList.of(); } else { Optional contactResource = - tm().transact( + replicaJpaTm() + .transact( () -> - tm().loadByKeyIfPresent( + replicaJpaTm() + .loadByKeyIfPresent( VKey.create( ContactResource.class, partialStringQuery.getInitialString()))); contactResourceList = diff --git a/core/src/main/java/google/registry/rdap/RdapJsonFormatter.java b/core/src/main/java/google/registry/rdap/RdapJsonFormatter.java index 4408585e6..984c725dc 100644 --- a/core/src/main/java/google/registry/rdap/RdapJsonFormatter.java +++ b/core/src/main/java/google/registry/rdap/RdapJsonFormatter.java @@ -20,7 +20,7 @@ import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.ImmutableSetMultimap.toImmutableSetMultimap; import static google.registry.model.EppResourceUtils.isLinked; -import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; +import static google.registry.persistence.transaction.TransactionManagerFactory.replicaJpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.rdap.RdapIcannStandardInformation.CONTACT_REDACTED_VALUE; import static google.registry.util.CollectionUtils.union; @@ -357,10 +357,15 @@ public class RdapJsonFormatter { // Kick off the database loads of the nameservers that we will need, so it can load // asynchronously while we load and process the contacts. ImmutableSet loadedHosts = - tm().transact(() -> ImmutableSet.copyOf(tm().loadByKeys(domain.getNameservers()).values())); + replicaJpaTm() + .transact( + () -> + ImmutableSet.copyOf( + replicaJpaTm().loadByKeys(domain.getNameservers()).values())); // Load the registrant and other contacts and add them to the data. ImmutableMap, ContactResource> loadedContacts = - tm().transact(() -> tm().loadByKeysIfPresent(domain.getReferencedContacts())); + replicaJpaTm() + .transact(() -> replicaJpaTm().loadByKeysIfPresent(domain.getReferencedContacts())); // RDAP Response Profile 2.7.3, A domain MUST have the REGISTRANT, ADMIN, TECH roles and MAY // have others. We also add the BILLING. // @@ -439,9 +444,11 @@ public class RdapJsonFormatter { statuses.add(StatusValue.LINKED); } if (host.isSubordinate() - && tm().transact( + && replicaJpaTm() + .transact( () -> - tm().loadByKey(host.getSuperordinateDomain()) + replicaJpaTm() + .loadByKey(host.getSuperordinateDomain()) .cloneProjectedAtTime(getRequestTime()) .getStatusValues() .contains(StatusValue.PENDING_TRANSFER))) { @@ -899,7 +906,8 @@ public class RdapJsonFormatter { .replace("%repoIdField%", repoIdFieldName) .replace("%repoIdValue%", resourceVkey.getSqlKey().toString()); historyEntries = - jpaTm().transact(() -> jpaTm().getEntityManager().createQuery(jpql).getResultList()); + replicaJpaTm() + .transact(() -> replicaJpaTm().getEntityManager().createQuery(jpql).getResultList()); } for (HistoryEntry historyEntry : historyEntries) { EventAction rdapEventAction = diff --git a/core/src/main/java/google/registry/rdap/RdapNameserverAction.java b/core/src/main/java/google/registry/rdap/RdapNameserverAction.java index 445fccd1b..d5bee577c 100644 --- a/core/src/main/java/google/registry/rdap/RdapNameserverAction.java +++ b/core/src/main/java/google/registry/rdap/RdapNameserverAction.java @@ -15,7 +15,7 @@ package google.registry.rdap; import static google.registry.flows.host.HostFlowUtils.validateHostName; -import static google.registry.model.EppResourceUtils.loadByForeignKey; +import static google.registry.model.EppResourceUtils.loadByForeignKeyCached; import static google.registry.request.Action.Method.GET; import static google.registry.request.Action.Method.HEAD; import static google.registry.util.DateTimeUtils.START_OF_TIME; @@ -62,7 +62,7 @@ public class RdapNameserverAction extends RdapActionBase { // If there are no undeleted nameservers with the given name, the foreign key should point to // the most recently deleted one. Optional host = - loadByForeignKey( + loadByForeignKeyCached( Host.class, pathSearchString, shouldIncludeDeleted() ? START_OF_TIME : getRequestTime()); diff --git a/core/src/main/java/google/registry/rdap/RdapNameserverSearchAction.java b/core/src/main/java/google/registry/rdap/RdapNameserverSearchAction.java index f7bdc1c76..21992cca3 100644 --- a/core/src/main/java/google/registry/rdap/RdapNameserverSearchAction.java +++ b/core/src/main/java/google/registry/rdap/RdapNameserverSearchAction.java @@ -14,7 +14,7 @@ package google.registry.rdap; -import static google.registry.model.EppResourceUtils.loadByForeignKey; +import static google.registry.model.EppResourceUtils.loadByForeignKeyCached; import static google.registry.persistence.transaction.TransactionManagerFactory.replicaJpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.request.Action.Method.GET; @@ -160,7 +160,7 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase { .setIncompletenessWarningType(IncompletenessWarningType.COMPLETE); Optional host = - loadByForeignKey(Host.class, partialStringQuery.getInitialString(), getRequestTime()); + loadByForeignKeyCached(Host.class, partialStringQuery.getInitialString(), getRequestTime()); metricInformationBuilder.setNumHostsRetrieved(host.isPresent() ? 1 : 0); @@ -176,7 +176,7 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase { private NameserverSearchResponse searchByNameUsingSuperordinateDomain( RdapSearchPattern partialStringQuery) { Optional domain = - loadByForeignKey(Domain.class, partialStringQuery.getSuffix(), getRequestTime()); + loadByForeignKeyCached(Domain.class, partialStringQuery.getSuffix(), getRequestTime()); if (!domain.isPresent()) { // Don't allow wildcards with suffixes which are not domains we manage. That would risk a // table scan in many easily foreseeable cases. The user might ask for ns*.zombo.com, @@ -194,7 +194,7 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase { // We can't just check that the host name starts with the initial query string, because // then the query ns.exam*.example.com would match against nameserver ns.example.com. if (partialStringQuery.matches(fqhn)) { - Optional host = loadByForeignKey(Host.class, fqhn, getRequestTime()); + Optional host = loadByForeignKeyCached(Host.class, fqhn, getRequestTime()); if (shouldBeVisible(host)) { hostList.add(host.get()); if (hostList.size() > rdapResultSetMaxSize) { diff --git a/core/src/main/java/google/registry/whois/NameserverWhoisResponse.java b/core/src/main/java/google/registry/whois/NameserverWhoisResponse.java index eacc0b563..fd7fe06db 100644 --- a/core/src/main/java/google/registry/whois/NameserverWhoisResponse.java +++ b/core/src/main/java/google/registry/whois/NameserverWhoisResponse.java @@ -17,7 +17,7 @@ package google.registry.whois; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static com.google.common.collect.ImmutableList.toImmutableList; -import static google.registry.persistence.transaction.TransactionManagerFactory.tm; +import static google.registry.persistence.transaction.TransactionManagerFactory.replicaJpaTm; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -53,12 +53,14 @@ final class NameserverWhoisResponse extends WhoisResponseImpl { ImmutableMap hostRegistrars = subordinateHosts.isEmpty() ? ImmutableMap.of() - : tm().transact( + : replicaJpaTm() + .transact( () -> Maps.toMap( subordinateHosts.iterator(), host -> - tm().loadByKey(host.getSuperordinateDomain()) + replicaJpaTm() + .loadByKey(host.getSuperordinateDomain()) .cloneProjectedAtTime(getTimestamp()) .getCurrentSponsorRegistrarId()));