Skip to content

Commit

Permalink
Add fields needed to implement pull queue alternative (#1915)
Browse files Browse the repository at this point in the history
  • Loading branch information
jianglai committed Jan 25, 2023
1 parent de8c6fd commit d8a882d
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 41 deletions.
37 changes: 37 additions & 0 deletions core/src/main/java/google/registry/model/EppResource.java
Expand Up @@ -32,6 +32,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import google.registry.config.RegistryConfig;
import google.registry.dns.RefreshDnsAction;
import google.registry.model.annotations.IdAllocation;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.transfer.TransferData;
Expand All @@ -41,6 +42,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.AttributeOverride;
Expand Down Expand Up @@ -134,6 +136,23 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
/** Status values associated with this resource. */
Set<StatusValue> statuses;

/**
* When this domain/host's DNS was requested to be refreshed, or null if its DNS is up-to-date.
*
* <p>This will almost always be null except in the couple of minutes' interval between when a
* DNS-affecting create or update operation takes place and when the {@link RefreshDnsAction}
* runs, which resets this back to null upon completion of the DNS refresh task. This is a {@link
* DateTime} rather than a simple dirty boolean so that the DNS refresh action can order by the
* DNS refresh request time and take action on the oldest ones first.
*
* <p>Note that in the {@code DomainHistory}/{@code HostHistory} table this value means something
* slightly different: It means that the given domain/host action requested a DNS update. Unlike
* on the {@code Domain}/{code Host} table, this value is not then subsequently nulled out once
* the DNS refresh is complete; rather, it remains as a permanent record of which actions were
* DNS-affecting and which were not.
*/
@Transient @Nullable protected DateTime dnsRefreshRequestTime;

public String getRepoId() {
return repoId;
}
Expand Down Expand Up @@ -185,6 +204,19 @@ public DateTime getDeletionTime() {
return deletionTime;
}

/**
* Returns the DNS refresh request time iff this domain/host's DNS needs refreshing, otherwise
* absent.
*/
public Optional<DateTime> getDnsRefreshRequestTime() {
return Optional.ofNullable(dnsRefreshRequestTime);
}

@SuppressWarnings("unused")
private void setInternalDnsRefreshRequestTime(DateTime time) {
dnsRefreshRequestTime = time;
}

/** Return a clone of the resource with timed status values modified using the given time. */
public abstract EppResource cloneProjectedAtTime(DateTime now);

Expand Down Expand Up @@ -338,6 +370,11 @@ public B setUpdateTimestamp(UpdateAutoTimestamp updateTimestamp) {
return thisCastToDerived();
}

public B setDnsRefreshRequestTime(Optional<DateTime> dnsRefreshRequestTime) {
getInstance().dnsRefreshRequestTime = dnsRefreshRequestTime.orElse(null);
return thisCastToDerived();
}

/** Build the resource, nullifying empty strings and sets and setting defaults. */
@Override
public T build() {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/google/registry/model/domain/Domain.java
Expand Up @@ -59,6 +59,7 @@
@Index(columnList = "tld"),
@Index(columnList = "registrantContact"),
@Index(columnList = "dnsRefreshRequestTime"),
@Index(columnList = "lordnPhase"),
@Index(columnList = "billing_recurrence_id"),
@Index(columnList = "transfer_billing_event_id"),
@Index(columnList = "transfer_billing_recurrence_id")
Expand Down Expand Up @@ -200,6 +201,7 @@ public Builder copyFrom(DomainBase domainBase) {
.setStatusValues(domainBase.getStatusValues())
.setTransferData(domainBase.getTransferData())
.setDnsRefreshRequestTime(domainBase.getDnsRefreshRequestTime())
.setLordnPhase(domainBase.getLordnPhase())
.setCurrentPackageToken(domainBase.getCurrentPackageToken().orElse(null));
}
}
Expand Down
51 changes: 27 additions & 24 deletions core/src/main/java/google/registry/model/domain/DomainBase.java
Expand Up @@ -40,7 +40,6 @@
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import google.registry.dns.RefreshDnsAction;
import google.registry.flows.ResourceFlowUtils;
import google.registry.model.EppResource;
import google.registry.model.EppResource.ResourceWithTransferData;
Expand All @@ -61,6 +60,8 @@
import google.registry.model.transfer.TransferStatus;
import google.registry.persistence.VKey;
import google.registry.tldconfig.idn.IdnLabelValidator;
import google.registry.tmch.LordnTaskUtils.LordnPhase;
import google.registry.tmch.NordnUploadAction;
import google.registry.util.CollectionUtils;
import google.registry.util.DateTimeUtils;
import java.util.HashSet;
Expand All @@ -76,6 +77,8 @@
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Embedded;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
Expand Down Expand Up @@ -247,34 +250,34 @@ public class DomainBase extends EppResource
DateTime autorenewEndTime;

/**
* When this domain's DNS was requested to be refreshed, or null if its DNS is up-to-date.
* Which Lordn phase the domain is in after it is created but before the Nordn upload has
* processed the domain.
*
* <p>This will almost always be null except in the couple of minutes' interval between when a
* DNS-affecting create or update operation takes place and when the {@link RefreshDnsAction}
* runs, which resets this back to null upon completion of the DNS refresh task. This is a {@link
* DateTime} rather than a simple dirty boolean so that the DNS refresh action can order by the
* DNS refresh request time and take action on the oldest ones first.
* <p>This will almost always be {@code NONE} except in the interval between when a domain that
* contains a signed mark or claims notice has been created, and when {@link NordnUploadAction}
* runs, which includes the domain in the CSV uploaded to TMCH and sets this back to {@code NONE}.
*
* <p>Note that this is a Cloud SQL-based replacement for the {@code dns-pull} task queue. The
* domains that have a non-null value for this field should be exactly the same as the tasks that
* would be in the {@code dns-pull} queue.
*
* <p>Note that in the {@link DomainHistory} table this value means something slightly different:
* It means that the given domain action requested a DNS update. Unlike on the {@code Domain}
* table, this value is not then subsequently nulled out once the DNS refresh is complete; rather,
* it remains as a permanent record of which actions were DNS-affecting and which were not.
* <p>Note that in the {@code DomainHistory} table this value means something slightly different:
* It means that the given domain was created with a signed mark ({@code SUNRISE} or a claims
* notice ({@code CLAIMS}. Unlike on the {@code Domain} table, this value is not then subsequently
* set back to {@code NONE} once the Nordn upload is complete; rather, it remains as a permanent
* record of when which phase the domain is in when created.
*/
// TODO(mcilwain): Start using this field once we are further along in the DB migration.
DateTime dnsRefreshRequestTime;
@Enumerated(EnumType.STRING)
LordnPhase lordnPhase = LordnPhase.NONE;

/** The {@link AllocationToken} for the package this domain is currently a part of. */
@Nullable VKey<AllocationToken> currentPackageToken;

/**
* Returns the DNS refresh request time iff this domain's DNS needs refreshing, otherwise absent.
*/
public Optional<DateTime> getDnsRefreshRequestTime() {
return Optional.ofNullable(dnsRefreshRequestTime);
public LordnPhase getLordnPhase() {
return lordnPhase;
}

@Access(AccessType.PROPERTY)
@SuppressWarnings("unused")
@Column(name = "dnsRefreshRequestTime")
private DateTime getInternalDnsRefreshRequestTime() {
return getDnsRefreshRequestTime().orElse(null);
}

public ImmutableSet<String> getSubordinateHosts() {
Expand Down Expand Up @@ -861,8 +864,8 @@ public B setAutorenewPollMessage(@Nullable VKey<Autorenew> autorenewPollMessage)
return thisCastToDerived();
}

public B setDnsRefreshRequestTime(Optional<DateTime> dnsRefreshRequestTime) {
getInstance().dnsRefreshRequestTime = dnsRefreshRequestTime.orElse(null);
public B setLordnPhase(LordnPhase lordnPhase) {
getInstance().lordnPhase = lordnPhase;
return thisCastToDerived();
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/google/registry/model/host/Host.java
Expand Up @@ -28,7 +28,7 @@
/**
* A persistable Host resource including mutable and non-mutable fields.
*
* <p>The {@link javax.persistence.Id} of the Host is the repoId.
* <p>The {@link Id} of the Host is the repoId.
*/
@Entity(name = "Host")
@Table(
Expand All @@ -48,7 +48,8 @@
@Index(columnList = "hostName"),
@Index(columnList = "creationTime"),
@Index(columnList = "deletionTime"),
@Index(columnList = "currentSponsorRegistrarId")
@Index(columnList = "currentSponsorRegistrarId"),
@Index(columnList = "dnsRefreshRequestTime")
})
@ExternalMessagingName("host")
@WithVKey(String.class)
Expand Down Expand Up @@ -81,7 +82,7 @@ private Builder(Host instance) {
}

public Builder copyFrom(HostBase hostBase) {
return this.setCreationRegistrarId(hostBase.getCreationRegistrarId())
return setCreationRegistrarId(hostBase.getCreationRegistrarId())
.setCreationTime(hostBase.getCreationTime())
.setDeletionTime(hostBase.getDeletionTime())
.setHostName(hostBase.getHostName())
Expand All @@ -93,6 +94,7 @@ public Builder copyFrom(HostBase hostBase) {
.setPersistedCurrentSponsorRegistrarId(hostBase.getPersistedCurrentSponsorRegistrarId())
.setRepoId(hostBase.getRepoId())
.setSuperordinateDomain(hostBase.getSuperordinateDomain())
.setDnsRefreshRequestTime(hostBase.getDnsRefreshRequestTime())
.setStatusValues(hostBase.getStatusValues());
}
}
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/google/registry/model/host/HostBase.java
Expand Up @@ -32,6 +32,7 @@
import javax.annotation.Nullable;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.MappedSuperclass;
import org.joda.time.DateTime;
Expand Down Expand Up @@ -85,6 +86,13 @@ public class HostBase extends EppResource {
*/
DateTime lastSuperordinateChange;

@Access(AccessType.PROPERTY)
@SuppressWarnings("unused")
@Column(name = "dnsRefreshRequestTime")
private DateTime getInternalDnsRefreshRequestTime() {
return getDnsRefreshRequestTime().orElse(null);
}

public String getHostName() {
return hostName;
}
Expand Down
41 changes: 29 additions & 12 deletions core/src/main/java/google/registry/tmch/LordnTaskUtils.java
Expand Up @@ -38,10 +38,11 @@ public final class LordnTaskUtils {

public static final String QUEUE_SUNRISE = "lordn-sunrise";
public static final String QUEUE_CLAIMS = "lordn-claims";
public static final String COLUMNS_CLAIMS = "roid,domain-name,notice-id,registrar-id,"
+ "registration-datetime,ack-datetime,application-datetime";
public static final String COLUMNS_SUNRISE = "roid,domain-name,SMD-id,registrar-id,"
+ "registration-datetime,application-datetime";
public static final String COLUMNS_CLAIMS =
"roid,domain-name,notice-id,registrar-id,"
+ "registration-datetime,ack-datetime,application-datetime";
public static final String COLUMNS_SUNRISE =
"roid,domain-name,SMD-id,registrar-id," + "registration-datetime,application-datetime";

/** Enqueues a task in the LORDN queue representing a line of CSV for LORDN export. */
public static void enqueueDomainTask(Domain domain) {
Expand All @@ -50,15 +51,17 @@ public static void enqueueDomainTask(Domain domain) {
// isn't yet populated when this method is called during the resource flow.
String tld = domain.getTld();
if (domain.getLaunchNotice() == null) {
getQueue(QUEUE_SUNRISE).add(TaskOptions.Builder
.withTag(tld)
.method(Method.PULL)
.payload(getCsvLineForSunriseDomain(domain, tm().getTransactionTime())));
getQueue(QUEUE_SUNRISE)
.add(
TaskOptions.Builder.withTag(tld)
.method(Method.PULL)
.payload(getCsvLineForSunriseDomain(domain, tm().getTransactionTime())));
} else {
getQueue(QUEUE_CLAIMS).add(TaskOptions.Builder
.withTag(tld)
.method(Method.PULL)
.payload(getCsvLineForClaimsDomain(domain, tm().getTransactionTime())));
getQueue(QUEUE_CLAIMS)
.add(
TaskOptions.Builder.withTag(tld)
.method(Method.PULL)
.payload(getCsvLineForClaimsDomain(domain, tm().getTransactionTime())));
}
}

Expand Down Expand Up @@ -95,4 +98,18 @@ private static String getIanaIdentifier(String registrarId) {
}

private LordnTaskUtils() {}

public enum LordnPhase {
SUNRISE(QUEUE_SUNRISE),

CLAIMS(QUEUE_CLAIMS),

NONE(null);

final String queue;

LordnPhase(String queue) {
this.queue = queue;
}
}
}
10 changes: 8 additions & 2 deletions db/src/main/resources/sql/schema/db-schema.sql.generated
Expand Up @@ -274,14 +274,15 @@
billing_contact text,
current_package_token text,
deletion_poll_message_id int8,
dns_refresh_request_time timestamptz,
domain_name text,
idn_table_name text,
dns_refresh_request_time timestamptz,
last_transfer_time timestamptz,
launch_notice_accepted_time timestamptz,
launch_notice_expiration_time timestamptz,
launch_notice_tcn_id text,
launch_notice_validator_id text,
lordn_phase text,
registrant_contact text,
registration_expiration_time timestamptz,
smd_id text,
Expand Down Expand Up @@ -346,14 +347,15 @@
billing_contact text,
current_package_token text,
deletion_poll_message_id int8,
dns_refresh_request_time timestamptz,
domain_name text,
idn_table_name text,
dns_refresh_request_time timestamptz,
last_transfer_time timestamptz,
launch_notice_accepted_time timestamptz,
launch_notice_expiration_time timestamptz,
launch_notice_tcn_id text,
launch_notice_validator_id text,
lordn_phase text,
registrant_contact text,
registration_expiration_time timestamptz,
smd_id text,
Expand Down Expand Up @@ -449,6 +451,7 @@
statuses text[],
host_name text,
inet_addresses text[],
dns_refresh_request_time timestamptz,
last_superordinate_change timestamptz,
last_transfer_time timestamptz,
superordinate_domain text,
Expand All @@ -469,6 +472,7 @@
history_xml_bytes bytea,
host_name text,
inet_addresses text[],
dns_refresh_request_time timestamptz,
last_superordinate_change timestamptz,
last_transfer_time timestamptz,
superordinate_domain text,
Expand Down Expand Up @@ -798,6 +802,7 @@ create index IDXr22ciyccwi9rrqmt1ro0s59qf on "Domain" (tech_contact);
create index IDXrwl38wwkli1j7gkvtywi9jokq on "Domain" (tld);
create index IDXa7fu0bqynfb79rr80528b4jqt on "Domain" (registrant_contact);
create index IDXcws5mvmpl8o10wrhde780ors2 on "Domain" (dns_refresh_request_time);
create index IDXnjhib7v6fj7dhj5qydkefkl2u on "Domain" (lordn_phase);
create index IDXsfci08jgsymxy6ovh4k7r358c on "Domain" (billing_recurrence_id);
create index IDX3y3k7m2bkgahm9sixiohgyrga on "Domain" (transfer_billing_event_id);
create index IDXcju58vqascbpve1t7fem53ctl on "Domain" (transfer_billing_recurrence_id);
Expand All @@ -820,6 +825,7 @@ create index IDXkpkh68n6dy5v51047yr6b0e9l on "Host" (host_name);
create index IDXy98mebut8ix1v07fjxxdkqcx on "Host" (creation_time);
create index IDXovmntef6l45tw2bsfl56tcugx on "Host" (deletion_time);
create index IDXl49vydnq0h5j1piefwjy4i8er on "Host" (current_sponsor_registrar_id);
create index IDX7wg0yn3wdux3xsc4pfaljqf08 on "Host" (dns_refresh_request_time);
create index IDXfg2nnjlujxo6cb9fha971bq2n on "HostHistory" (creation_time);
create index IDX1iy7njgb7wjmj9piml4l2g0qi on "HostHistory" (history_registrar_id);
create index IDXkkwbwcwvrdkkqothkiye4jiff on "HostHistory" (host_name);
Expand Down

0 comments on commit d8a882d

Please sign in to comment.