Change loadActiveApplicationsByDomainName to non-transactional

We can easily end up enlisting too many entity groups (separate
DomainApplications) in a TransactionalFlow when loading all applications
tracked by the DomainApplicationIndex. This makes the load operation
transactionless, to avoid overenlisting.

Potential problems:
1. We fail to prevent landrush applications, if a single sunrise application
exists. This is likely fine, except for a brief moment in Sunrush when a
sunrise application is made immediately prior to a landrush application. The
result is we accept an invalid application- which can be mediated manually.

2. We fail to prevent a domain create for a domain with an open application.
This is a little more sinister, but also unlikely unless someone submits an
application immediately before someone tries to create the same domain (sans
application?)

3. We return an invalid DomainCheck response (instead of 'pending allocation').
Not the worst outcome.

4. We reduce the AuctionStatusCommand and GetApplicationIdsCommand to
eventual consistency. Since they're internal tools, that's not too big a deal.

A better solution:
DomainApplications really should just be normalized under a virtualEntityGroup
by fullyQualifiedDomainName, or a hash-bucket like EppResources are. The
DomainApplication -> DomainBase -> EppResource hierarchy seems to be purely for
code reuse, at the cost of Datastore consistency. This would, however, require
quite some refactoring, and a custom resave operation across all
DomainApplications.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=169395586
This commit is contained in:
larryruili 2017-09-20 08:09:29 -07:00 committed by Ben McIlwain
parent 9134e4407c
commit 3d5a6b808c
2 changed files with 64 additions and 29 deletions

View file

@ -18,14 +18,17 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.index.DomainApplicationIndex.createUpdatedInstance;
import static google.registry.model.index.DomainApplicationIndex.createWithSpecifiedKeys;
import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainApplication;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DatastoreHelper.persistSimpleResource;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.VoidWork;
import google.registry.model.EntityTestCase;
import google.registry.model.domain.DomainApplication;
import google.registry.testing.ExceptionRule;
@ -118,4 +121,22 @@ public class DomainApplicationIndexTest extends EntityTestCase {
assertThat(loadActiveApplicationsByDomainName("example.com", DateTime.now(UTC)))
.containsExactly(application1);
}
/** Ensure loading over 25 applications still succeeds (despite being in a transaction.) */
@Test
public void testSuccess_overCrossTransactionLimit() {
ImmutableList.Builder<DomainApplication> applicationsBuilder = new ImmutableList.Builder<>();
for (int i = 0; i < 30; i++) {
DomainApplication application = persistSimpleResource(newDomainApplication("example.com"));
persistResource(createUpdatedInstance(application));
applicationsBuilder.add(application);
}
ofy().transact(new VoidWork() {
@Override
public void vrun() {
assertThat(DomainApplicationIndex.load("example.com")).isNotNull();
assertThat(loadActiveApplicationsByDomainName("example.com", clock.nowUtc()))
.containsExactlyElementsIn(applicationsBuilder.build());
}});
}
}