Add fields needed to implement pull queue alternative (#1915)

This commit is contained in:
Lai Jiang 2023-01-25 15:26:00 -05:00 committed by GitHub
parent 5a3aa9fa52
commit ab146c4bf8
7 changed files with 116 additions and 41 deletions

View file

@ -32,6 +32,7 @@ import com.google.common.annotations.VisibleForTesting;
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;
@ -41,6 +42,7 @@ import java.time.Duration;
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;
@ -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;
}
@ -185,6 +204,19 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
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);
@ -338,6 +370,11 @@ public abstract class EppResource extends UpdateAutoTimestampEntity implements B
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() {

View file

@ -59,6 +59,7 @@ import org.joda.time.DateTime;
@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")
@ -200,6 +201,7 @@ public class Domain extends DomainBase implements ForeignKeyedEppResource {
.setStatusValues(domainBase.getStatusValues())
.setTransferData(domainBase.getTransferData())
.setDnsRefreshRequestTime(domainBase.getDnsRefreshRequestTime())
.setLordnPhase(domainBase.getLordnPhase())
.setCurrentPackageToken(domainBase.getCurrentPackageToken().orElse(null));
}
}

View file

@ -40,7 +40,6 @@ import com.google.common.collect.ImmutableSet;
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;
@ -61,6 +60,8 @@ import google.registry.model.transfer.DomainTransferData;
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;
@ -76,6 +77,8 @@ import javax.persistence.AttributeOverrides;
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;
@ -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() {
@ -861,8 +864,8 @@ public class DomainBase extends EppResource
return thisCastToDerived();
}
public B setDnsRefreshRequestTime(Optional<DateTime> dnsRefreshRequestTime) {
getInstance().dnsRefreshRequestTime = dnsRefreshRequestTime.orElse(null);
public B setLordnPhase(LordnPhase lordnPhase) {
getInstance().lordnPhase = lordnPhase;
return thisCastToDerived();
}

View file

@ -28,7 +28,7 @@ import javax.persistence.Table;
/**
* 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(
@ -48,7 +48,8 @@ import javax.persistence.Table;
@Index(columnList = "hostName"),
@Index(columnList = "creationTime"),
@Index(columnList = "deletionTime"),
@Index(columnList = "currentSponsorRegistrarId")
@Index(columnList = "currentSponsorRegistrarId"),
@Index(columnList = "dnsRefreshRequestTime")
})
@ExternalMessagingName("host")
@WithVKey(String.class)
@ -81,7 +82,7 @@ public class Host extends HostBase implements ForeignKeyedEppResource {
}
public Builder copyFrom(HostBase hostBase) {
return this.setCreationRegistrarId(hostBase.getCreationRegistrarId())
return setCreationRegistrarId(hostBase.getCreationRegistrarId())
.setCreationTime(hostBase.getCreationTime())
.setDeletionTime(hostBase.getDeletionTime())
.setHostName(hostBase.getHostName())
@ -93,6 +94,7 @@ public class Host extends HostBase implements ForeignKeyedEppResource {
.setPersistedCurrentSponsorRegistrarId(hostBase.getPersistedCurrentSponsorRegistrarId())
.setRepoId(hostBase.getRepoId())
.setSuperordinateDomain(hostBase.getSuperordinateDomain())
.setDnsRefreshRequestTime(hostBase.getDnsRefreshRequestTime())
.setStatusValues(hostBase.getStatusValues());
}
}

View file

@ -32,6 +32,7 @@ import java.util.Set;
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;
@ -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;
}

View file

@ -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) {
@ -50,15 +51,17 @@ public final class LordnTaskUtils {
// 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())));
}
}
@ -95,4 +98,18 @@ public final class LordnTaskUtils {
}
private LordnTaskUtils() {}
public enum LordnPhase {
SUNRISE(QUEUE_SUNRISE),
CLAIMS(QUEUE_CLAIMS),
NONE(null);
final String queue;
LordnPhase(String queue) {
this.queue = queue;
}
}
}

View file

@ -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,
@ -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,
@ -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,
@ -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,
@ -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);
@ -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);