Remove TmchCrl singleton from Datastore (#1419)

This commit is contained in:
sarahcaseybot 2021-11-17 14:53:29 -05:00 committed by GitHub
parent 573f14514a
commit 09271977c3
6 changed files with 16 additions and 48 deletions

View file

@ -43,7 +43,6 @@ import google.registry.model.reporting.HistoryEntry;
import google.registry.model.server.Lock; import google.registry.model.server.Lock;
import google.registry.model.server.ServerSecret; import google.registry.model.server.ServerSecret;
import google.registry.model.tld.Registry; import google.registry.model.tld.Registry;
import google.registry.model.tmch.TmchCrl;
/** Sets of classes of the Objectify-registered entities in use throughout the model. */ /** Sets of classes of the Objectify-registered entities in use throughout the model. */
public final class EntityClasses { public final class EntityClasses {
@ -85,8 +84,7 @@ public final class EntityClasses {
Registrar.class, Registrar.class,
RegistrarContact.class, RegistrarContact.class,
Registry.class, Registry.class,
ServerSecret.class, ServerSecret.class);
TmchCrl.class);
private EntityClasses() {} private EntityClasses() {}
} }

View file

@ -16,25 +16,18 @@ package google.registry.model.tmch;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.googlecode.objectify.annotation.Entity;
import google.registry.model.annotations.NotBackedUp;
import google.registry.model.annotations.NotBackedUp.Reason;
import google.registry.model.common.CrossTldSingleton; import google.registry.model.common.CrossTldSingleton;
import google.registry.model.replay.NonReplicatedEntity; import google.registry.model.replay.SqlOnlyEntity;
import java.util.Optional; import java.util.Optional;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import javax.persistence.Column; import javax.persistence.Column;
import org.joda.time.DateTime; import org.joda.time.DateTime;
/** Datastore singleton for ICANN's TMCH CA certificate revocation list (CRL). */ /** Singleton for ICANN's TMCH CA certificate revocation list (CRL). */
@Entity
@javax.persistence.Entity @javax.persistence.Entity
@Immutable @Immutable
@NotBackedUp(reason = Reason.EXTERNALLY_SOURCED) public final class TmchCrl extends CrossTldSingleton implements SqlOnlyEntity {
public final class TmchCrl extends CrossTldSingleton implements NonReplicatedEntity {
@Column(name = "certificateRevocations", nullable = false) @Column(name = "certificateRevocations", nullable = false)
String crl; String crl;
@ -47,25 +40,23 @@ public final class TmchCrl extends CrossTldSingleton implements NonReplicatedEnt
/** Returns the singleton instance of this entity, without memoization. */ /** Returns the singleton instance of this entity, without memoization. */
public static Optional<TmchCrl> get() { public static Optional<TmchCrl> get() {
return tm().transact(() -> tm().loadSingleton(TmchCrl.class)); return jpaTm().transact(() -> jpaTm().loadSingleton(TmchCrl.class));
} }
/** /**
* Change the Datastore singleton to a new ASCII-armored X.509 CRL. * Change the singleton to a new ASCII-armored X.509 CRL.
* *
* <p>Please do not call this function unless your CRL is properly formatted, signed by the root, * <p>Please do not call this function unless your CRL is properly formatted, signed by the root,
* and actually newer than the one currently in Datastore. * and actually newer than the one currently in Datastore.
*
* <p>During the dual-write period, we write to both Datastore and SQL
*/ */
public static void set(final String crl, final String url) { public static void set(final String crl, final String url) {
tm().transact( jpaTm()
.transact(
() -> { () -> {
TmchCrl tmchCrl = new TmchCrl(); TmchCrl tmchCrl = new TmchCrl();
tmchCrl.updated = tm().getTransactionTime(); tmchCrl.updated = jpaTm().getTransactionTime();
tmchCrl.crl = checkNotNull(crl, "crl"); tmchCrl.crl = checkNotNull(crl, "crl");
tmchCrl.url = checkNotNull(url, "url"); tmchCrl.url = checkNotNull(url, "url");
ofyTm().transactNew(() -> ofyTm().putWithoutBackup(tmchCrl));
jpaTm().transactNew(() -> jpaTm().putWithoutBackup(tmchCrl)); jpaTm().transactNew(() -> jpaTm().putWithoutBackup(tmchCrl));
}); });
} }
@ -80,7 +71,7 @@ public final class TmchCrl extends CrossTldSingleton implements NonReplicatedEnt
return crl; return crl;
} }
/** Time we last updated the Datastore with a newer ICANN CRL. */ /** Time we last updated the Database with a newer ICANN CRL. */
public final DateTime getUpdated() { public final DateTime getUpdated() {
return updated; return updated;
} }

View file

@ -67,7 +67,6 @@ import google.registry.model.replay.SqlReplayCheckpoint;
import google.registry.model.server.Lock; import google.registry.model.server.Lock;
import google.registry.model.tld.label.PremiumList; import google.registry.model.tld.label.PremiumList;
import google.registry.model.tld.label.PremiumList.PremiumEntry; import google.registry.model.tld.label.PremiumList.PremiumEntry;
import google.registry.model.tmch.TmchCrl;
import google.registry.model.translators.VKeyTranslatorFactory; import google.registry.model.translators.VKeyTranslatorFactory;
import google.registry.persistence.VKey; import google.registry.persistence.VKey;
import google.registry.persistence.transaction.JpaTransactionManager; import google.registry.persistence.transaction.JpaTransactionManager;
@ -482,7 +481,8 @@ public class ReplayCommitLogsToSqlActionTest {
jpaTm().transact(() -> SqlReplayCheckpoint.set(now.minusMinutes(1).minusMillis(1))); jpaTm().transact(() -> SqlReplayCheckpoint.set(now.minusMinutes(1).minusMillis(1)));
// Save a couple deletes that aren't propagated to SQL (the objects deleted are irrelevant) // Save a couple deletes that aren't propagated to SQL (the objects deleted are irrelevant)
Key<TmchCrl> tmchCrlKey = Key.create(TmchCrl.class, 1L); Key<CommitLogManifest> manifestKey =
CommitLogManifest.createKey(getBucketKey(1), now.minusMinutes(1));
saveDiffFile( saveDiffFile(
gcsUtils, gcsUtils,
createCheckpoint(now.minusMinutes(1)), createCheckpoint(now.minusMinutes(1)),
@ -490,7 +490,7 @@ public class ReplayCommitLogsToSqlActionTest {
getBucketKey(1), getBucketKey(1),
now.minusMinutes(1), now.minusMinutes(1),
// one object only exists in Datastore, one is dually-written (so isn't replicated) // one object only exists in Datastore, one is dually-written (so isn't replicated)
ImmutableSet.of(getCrossTldKey(), tmchCrlKey))); ImmutableSet.of(getCrossTldKey(), manifestKey)));
runAndAssertSuccess(now.minusMinutes(1), 1, 1); runAndAssertSuccess(now.minusMinutes(1), 1, 1);
verify(spy, times(0)).delete(any(VKey.class)); verify(spy, times(0)).delete(any(VKey.class));

View file

@ -15,39 +15,26 @@
package google.registry.model.tmch; package google.registry.model.tmch;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatabaseHelper.loadByEntity;
import google.registry.model.EntityTestCase; import google.registry.model.EntityTestCase;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.TestOfyAndSql;
import java.util.Optional; import java.util.Optional;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link TmchCrl}. */ /** Unit tests for {@link TmchCrl}. */
@DualDatabaseTest
public class TmchCrlTest extends EntityTestCase { public class TmchCrlTest extends EntityTestCase {
TmchCrlTest() { TmchCrlTest() {
super(JpaEntityCoverageCheck.ENABLED); super(JpaEntityCoverageCheck.ENABLED);
} }
@TestOfyAndSql @Test
void testSuccess() { void testSuccess() {
assertThat(TmchCrl.get()).isEqualTo(Optional.empty()); assertThat(TmchCrl.get()).isEqualTo(Optional.empty());
TmchCrl.set("lolcat", "https://lol.cat"); TmchCrl.set("lolcat", "https://lol.cat");
assertThat(TmchCrl.get().get().getCrl()).isEqualTo("lolcat"); assertThat(TmchCrl.get().get().getCrl()).isEqualTo("lolcat");
} }
@TestOfyAndSql @Test
void testDualWrite() {
TmchCrl expected = new TmchCrl();
expected.crl = "lolcat";
expected.url = "https://lol.cat";
expected.updated = fakeClock.nowUtc();
TmchCrl.set("lolcat", "https://lol.cat");
assertThat(loadByEntity(new TmchCrl())).isEqualTo(expected);
}
@TestOfyAndSql
void testMultipleWrites() { void testMultipleWrites() {
TmchCrl.set("first", "https://first.cat"); TmchCrl.set("first", "https://first.cat");
assertThat(TmchCrl.get().get().getCrl()).isEqualTo("first"); assertThat(TmchCrl.get().get().getCrl()).isEqualTo("first");

View file

@ -3,4 +3,3 @@ Registrar
RegistrarContact RegistrarContact
Registry Registry
ServerSecret ServerSecret
TmchCrl

View file

@ -789,13 +789,6 @@ enum google.registry.model.tld.Registry$TldType {
REAL; REAL;
TEST; TEST;
} }
class google.registry.model.tmch.TmchCrl {
@Id long id;
@Parent com.googlecode.objectify.Key<google.registry.model.common.EntityGroupRoot> parent;
java.lang.String crl;
java.lang.String url;
org.joda.time.DateTime updated;
}
class google.registry.model.transfer.ContactTransferData { class google.registry.model.transfer.ContactTransferData {
google.registry.model.eppcommon.Trid transferRequestTrid; google.registry.model.eppcommon.Trid transferRequestTrid;
google.registry.model.transfer.TransferStatus transferStatus; google.registry.model.transfer.TransferStatus transferStatus;