Make failfastForCreate for domain and application creates explicitly hit memcache

TESTED=For all tests, I added @Cache to DomainBase because otherwise the tests will
    fail. We aren't ready to do this in prod yet, which is why the tests are still
    marked @Ignore. The new tests fail if you change line 134 in Ofy to not use memcache
    and either use the unchanged original DomainCreateFlow code, or use the new
    inlined code and change loadWithMemcache() to load(). They pass with the new
    inlined code that calls loadWithMemcache(), as long as the @Cache is added to
    DomainResource.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=154224748
This commit is contained in:
cgoldfeder 2017-04-25 14:50:08 -07:00 committed by Ben McIlwain
parent cb145e0721
commit 9e61f1d6ef
5 changed files with 119 additions and 26 deletions

View file

@ -22,7 +22,7 @@ import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.intersection;
import static com.google.common.collect.Sets.union;
import static google.registry.flows.domain.DomainPricingLogic.getMatchingLrpToken;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.EppResourceUtils.loadByForeignKeyWithMemcache;
import static google.registry.model.domain.DomainResource.MAX_REGISTRATION_YEARS;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.Registries.findTldForName;
@ -800,8 +800,11 @@ public class DomainFlowUtils {
DomainResource domain = ofy().doTransactionless(new Work<DomainResource>() {
@Override
public DomainResource run() {
// This is cacheable because we are outside of a transaction.
return loadByForeignKey(DomainResource.class, targetId, now);
// We want to load the ForeignKeyIndex and DomainResource from memcache if possible so that
// repeated create attempts of the same domain will not put load on datastore. This is safe
// because this is only a failfast method, and if memcache is stale the worst case scenario
// is that we will fall through to the regular transactional flow and fail there.
return loadByForeignKeyWithMemcache(DomainResource.class, targetId, now);
}});
// If the domain exists already and isn't in the add grace period then there is no way it will
// be suddenly deleted and therefore the create must fail.