mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
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:
parent
9134e4407c
commit
3d5a6b808c
2 changed files with 64 additions and 29 deletions
|
@ -21,6 +21,7 @@ import static google.registry.util.CollectionUtils.isNullOrEmpty;
|
|||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.Work;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import google.registry.model.BackupGroupRoot;
|
||||
|
@ -32,9 +33,10 @@ import javax.annotation.Nullable;
|
|||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* Entity for tracking all domain applications with a given fully qualified domain name. Since this
|
||||
* resource is always kept up to date as additional domain applications are created, it is never
|
||||
* necessary to query them explicitly from Datastore.
|
||||
* Entity for tracking all domain applications with a given fully qualified domain name.
|
||||
*
|
||||
* <p>Since this resource is always kept up to date as additional domain applications are created,
|
||||
* it is never necessary to query them explicitly from Datastore.
|
||||
*/
|
||||
@ReportedOn
|
||||
@Entity
|
||||
|
@ -60,12 +62,12 @@ public class DomainApplicationIndex extends BackupGroupRoot {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a DomainApplicationIndex with the specified list of keys. Only use this method for data
|
||||
* migrations. You probably want {@link #createUpdatedInstance}.
|
||||
* Creates a DomainApplicationIndex with the specified list of keys.
|
||||
*
|
||||
* <p>Only use this method for data migrations. You probably want {@link #createUpdatedInstance}.
|
||||
*/
|
||||
public static DomainApplicationIndex createWithSpecifiedKeys(
|
||||
String fullyQualifiedDomainName,
|
||||
ImmutableSet<Key<DomainApplication>> keys) {
|
||||
String fullyQualifiedDomainName, ImmutableSet<Key<DomainApplication>> keys) {
|
||||
checkArgument(!isNullOrEmpty(fullyQualifiedDomainName),
|
||||
"fullyQualifiedDomainName must not be null or empty.");
|
||||
checkArgument(!isNullOrEmpty(keys), "Keys must not be null or empty.");
|
||||
|
@ -80,42 +82,54 @@ public class DomainApplicationIndex extends BackupGroupRoot {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the set of all DomainApplications for the given fully qualified domain name that do
|
||||
* not have a deletion time before the supplied DateTime.
|
||||
* Returns the set of all active DomainApplications for the given fully qualified domain name.
|
||||
*
|
||||
* <p>Note that loading the individual applications referenced by the keys are explicitly
|
||||
* non-transactional. This is to avoid potentially over-enlisting multiple entity groups within a
|
||||
* transaction.
|
||||
*
|
||||
* <p>Consequently within a transaction this method will not return any applications that are not
|
||||
* yet committed to datastore, even if called on an updated DomainApplicationIndex instance
|
||||
* storing keys to those applications.
|
||||
*
|
||||
*/
|
||||
public static ImmutableSet<DomainApplication> loadActiveApplicationsByDomainName(
|
||||
String fullyQualifiedDomainName, DateTime now) {
|
||||
DomainApplicationIndex index = load(fullyQualifiedDomainName);
|
||||
String fullyQualifiedDomainName, final DateTime now) {
|
||||
final DomainApplicationIndex index = load(fullyQualifiedDomainName);
|
||||
if (index == null) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
ImmutableSet.Builder<DomainApplication> apps = new ImmutableSet.Builder<>();
|
||||
for (DomainApplication app : ofy().load().keys(index.getKeys()).values()) {
|
||||
if (app.getDeletionTime().isAfter(now)) {
|
||||
apps.add(app);
|
||||
}
|
||||
}
|
||||
return apps.build();
|
||||
// Perform eventually consistent query, to avoid overenlisting cross entity groups
|
||||
return ofy().doTransactionless(new Work<ImmutableSet<DomainApplication>>() {
|
||||
@Override
|
||||
public ImmutableSet<DomainApplication> run() {
|
||||
ImmutableSet.Builder<DomainApplication> apps = new ImmutableSet.Builder<>();
|
||||
for (DomainApplication app : ofy().load().keys(index.getKeys()).values()) {
|
||||
if (app.getDeletionTime().isAfter(now)) {
|
||||
apps.add(app);
|
||||
}
|
||||
}
|
||||
return apps.build();
|
||||
}});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the DomainApplicationIndex for the given fully qualified domain name. Note that this
|
||||
* can return null if there are no domain applications for this fully qualified domain name.
|
||||
* Returns the DomainApplicationIndex for the given fully qualified domain name.
|
||||
*
|
||||
* <p>Note that this can return null if there are no domain applications for this fully qualified
|
||||
* domain name.
|
||||
*/
|
||||
@Nullable
|
||||
public static DomainApplicationIndex load(String fullyQualifiedDomainName) {
|
||||
return ofy()
|
||||
.load()
|
||||
.type(DomainApplicationIndex.class)
|
||||
.id(fullyQualifiedDomainName)
|
||||
.now();
|
||||
return ofy().load().type(DomainApplicationIndex.class).id(fullyQualifiedDomainName).now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a new DomainApplicationIndex for this resource or updates the existing one. This is
|
||||
* the preferred method for creating an instance of DomainApplicationIndex because this performs
|
||||
* the correct merging logic to add the given domain application to an existing index if there
|
||||
* is one.
|
||||
* Saves a new DomainApplicationIndex for this resource or updates the existing one.
|
||||
*
|
||||
* <p>This is the preferred method for creating an instance of DomainApplicationIndex because this
|
||||
* performs the correct merging logic to add the given domain application to an existing index if
|
||||
* there is one.
|
||||
*/
|
||||
public static DomainApplicationIndex createUpdatedInstance(DomainApplication application) {
|
||||
DomainApplicationIndex existing = load(application.getFullyQualifiedDomainName());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue