mirror of
https://github.com/google/nomulus
synced 2026-09-20 06:54:43 +00:00
Add non-SQL removal code for Transaction and SqlReplayCheckpoint (#1700)
This commit is contained in:
@@ -32,8 +32,6 @@ import google.registry.model.index.ForeignKeyIndex;
|
||||
import google.registry.model.poll.PollMessage;
|
||||
import google.registry.model.rde.RdeRevision;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.replay.LastSqlTransaction;
|
||||
import google.registry.model.replay.ReplayGap;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.model.server.Lock;
|
||||
import google.registry.model.server.ServerSecret;
|
||||
@@ -64,14 +62,12 @@ public final class EntityClasses {
|
||||
HistoryEntry.class,
|
||||
HostHistory.class,
|
||||
HostResource.class,
|
||||
LastSqlTransaction.class,
|
||||
Lock.class,
|
||||
PollMessage.class,
|
||||
PollMessage.Autorenew.class,
|
||||
PollMessage.OneTime.class,
|
||||
RdeRevision.class,
|
||||
Registrar.class,
|
||||
ReplayGap.class,
|
||||
ServerSecret.class);
|
||||
|
||||
private EntityClasses() {}
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
// Copyright 2021 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model.replay;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.annotations.DeleteAfterMigration;
|
||||
|
||||
/** Datastore entity to keep track of the last SQL transaction imported into the datastore. */
|
||||
@Entity
|
||||
@DeleteAfterMigration
|
||||
public class LastSqlTransaction extends ImmutableObject {
|
||||
|
||||
/** The key for this singleton. */
|
||||
public static final Key<LastSqlTransaction> KEY = Key.create(LastSqlTransaction.class, 1);
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Id
|
||||
private long id = 1;
|
||||
|
||||
private long transactionId;
|
||||
|
||||
LastSqlTransaction() {}
|
||||
|
||||
@VisibleForTesting
|
||||
LastSqlTransaction(long newTransactionId) {
|
||||
transactionId = newTransactionId;
|
||||
}
|
||||
|
||||
LastSqlTransaction cloneWithNewTransactionId(long transactionId) {
|
||||
checkArgument(
|
||||
transactionId > this.transactionId,
|
||||
"New transaction id (%s) must be greater than the current transaction id (%s)",
|
||||
transactionId,
|
||||
this.transactionId);
|
||||
return new LastSqlTransaction(transactionId);
|
||||
}
|
||||
|
||||
long getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the instance.
|
||||
*
|
||||
* <p>Must be called within an Ofy transaction.
|
||||
*
|
||||
* <p>Creates a new instance of the singleton if it is not already present in Cloud Datastore,
|
||||
*/
|
||||
static LastSqlTransaction load() {
|
||||
auditedOfy().assertInTransaction();
|
||||
LastSqlTransaction result = auditedOfy().load().key(KEY).now();
|
||||
return result == null ? new LastSqlTransaction() : result;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
// Copyright 2022 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model.replay;
|
||||
|
||||
import static google.registry.model.annotations.NotBackedUp.Reason.TRANSIENT;
|
||||
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.annotations.DeleteAfterMigration;
|
||||
import google.registry.model.annotations.NotBackedUp;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* Tracks gaps in transaction ids when replicating from SQL to datastore.
|
||||
*
|
||||
* <p>SQL -> DS replication uses a Transaction table indexed by a SEQUENCE column, which normally
|
||||
* increments monotonically for each committed transaction. Gaps in this sequence can occur when a
|
||||
* transaction is rolled back or when a transaction has been initiated but not committed to the
|
||||
* table at the time of a query. To protect us from the latter scenario, we need to keep track of
|
||||
* these gaps and replay any of them that have been filled in since we processed their batch.
|
||||
*/
|
||||
@DeleteAfterMigration
|
||||
@NotBackedUp(reason = TRANSIENT)
|
||||
@Entity
|
||||
public class ReplayGap extends ImmutableObject {
|
||||
@Id long transactionId;
|
||||
|
||||
// We can't use a CreateAutoTimestamp here because this ends up getting persisted in an ofy
|
||||
// transaction that happens in JPA mode, so we don't end up getting an active transaction manager
|
||||
// when the timestamp needs to be set.
|
||||
DateTime timestamp;
|
||||
|
||||
ReplayGap() {}
|
||||
|
||||
ReplayGap(DateTime timestamp, long transactionId) {
|
||||
this.timestamp = timestamp;
|
||||
this.transactionId = transactionId;
|
||||
}
|
||||
|
||||
long getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
DateTime getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model.replay;
|
||||
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
|
||||
import google.registry.model.annotations.DeleteAfterMigration;
|
||||
import google.registry.model.common.CrossTldSingleton;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
@Entity
|
||||
@DeleteAfterMigration
|
||||
public class SqlReplayCheckpoint extends CrossTldSingleton {
|
||||
|
||||
@Column(nullable = false)
|
||||
private DateTime lastReplayTime;
|
||||
|
||||
public static DateTime get() {
|
||||
jpaTm().assertInTransaction();
|
||||
return jpaTm()
|
||||
.loadSingleton(SqlReplayCheckpoint.class)
|
||||
.map(checkpoint -> checkpoint.lastReplayTime)
|
||||
.orElse(START_OF_TIME);
|
||||
}
|
||||
|
||||
public static void set(DateTime lastReplayTime) {
|
||||
jpaTm().assertInTransaction();
|
||||
SqlReplayCheckpoint checkpoint = new SqlReplayCheckpoint();
|
||||
checkpoint.lastReplayTime = lastReplayTime;
|
||||
// this will overwrite the existing object due to the constant revisionId
|
||||
jpaTm().put(checkpoint);
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.persistence.transaction;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.annotations.DeleteAfterMigration;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* Object to be stored in the transaction table.
|
||||
*
|
||||
* <p>This consists of a sequential identifier and a serialized {@code Tranaction} object.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "Transaction")
|
||||
@DeleteAfterMigration
|
||||
public class TransactionEntity extends ImmutableObject {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
private byte[] contents;
|
||||
|
||||
TransactionEntity() {}
|
||||
|
||||
@VisibleForTesting
|
||||
public TransactionEntity(byte[] contents) {
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public byte[] getContents() {
|
||||
return contents;
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,6 @@ public final class RegistryTool {
|
||||
.put("save_sql_credential", SaveSqlCredentialCommand.class)
|
||||
.put("send_escrow_report_to_icann", SendEscrowReportToIcannCommand.class)
|
||||
.put("set_num_instances", SetNumInstancesCommand.class)
|
||||
.put("set_sql_replay_checkpoint", SetSqlReplayCheckpointCommand.class)
|
||||
.put("setup_ote", SetupOteCommand.class)
|
||||
.put("uniform_rapid_suspension", UniformRapidSuspensionCommand.class)
|
||||
.put("unlock_domain", UnlockDomainCommand.class)
|
||||
|
||||
@@ -142,8 +142,6 @@ interface RegistryToolComponent {
|
||||
|
||||
void inject(SetNumInstancesCommand command);
|
||||
|
||||
void inject(SetSqlReplayCheckpointCommand command);
|
||||
|
||||
void inject(SetupOteCommand command);
|
||||
|
||||
void inject(UnlockDomainCommand command);
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.collect.Iterables;
|
||||
import google.registry.model.replay.SqlReplayCheckpoint;
|
||||
import java.util.List;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** Command to set {@link SqlReplayCheckpoint} to a particular, post-initial-population time. */
|
||||
@Parameters(separators = " =", commandDescription = "Set SqlReplayCheckpoint to a particular time")
|
||||
public class SetSqlReplayCheckpointCommand extends ConfirmingCommand
|
||||
implements CommandWithRemoteApi {
|
||||
|
||||
@Parameter(description = "Time to which SqlReplayCheckpoint will be set", required = true)
|
||||
List<DateTime> mainParameters;
|
||||
|
||||
@Override
|
||||
protected String prompt() {
|
||||
checkArgument(mainParameters.size() == 1, "Must provide exactly one DateTime to set");
|
||||
return String.format(
|
||||
"Set SqlReplayCheckpoint to %s?", Iterables.getOnlyElement(mainParameters));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String execute() {
|
||||
DateTime dateTime = Iterables.getOnlyElement(mainParameters);
|
||||
jpaTm().transact(() -> SqlReplayCheckpoint.set(dateTime));
|
||||
return String.format("Set SqlReplayCheckpoint time to %s", dateTime);
|
||||
}
|
||||
}
|
||||
@@ -73,9 +73,7 @@
|
||||
<class>google.registry.model.tmch.ClaimsList</class>
|
||||
<class>google.registry.model.tmch.ClaimsEntry</class>
|
||||
<class>google.registry.model.tmch.TmchCrl</class>
|
||||
<class>google.registry.persistence.transaction.TransactionEntity</class>
|
||||
<class>google.registry.model.domain.RegistryLock</class>
|
||||
<class>google.registry.model.replay.SqlReplayCheckpoint</class>
|
||||
|
||||
<!-- Customized type converters -->
|
||||
<class>google.registry.persistence.converter.AllocationTokenStatusTransitionConverter</class>
|
||||
|
||||
Reference in New Issue
Block a user