mirror of
https://github.com/google/nomulus.git
synced 2025-08-13 04:59:51 +02:00
Remove orphaned DomainTransactionRecords (#1444)
This is what's causing https://b.corp.google.com/issues/208274109, where there are DTR rows with null foreign key values. We should probably wait to make the columns officially non-null until we get this in and verify that we can do so.
This commit is contained in:
parent
cff8f9a1cd
commit
8a121a7b79
5 changed files with 22 additions and 43 deletions
|
@ -196,7 +196,8 @@ public class DomainHistory extends HistoryEntry implements SqlEntity {
|
||||||
@Access(AccessType.PROPERTY)
|
@Access(AccessType.PROPERTY)
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
cascade = {CascadeType.ALL},
|
cascade = {CascadeType.ALL},
|
||||||
fetch = FetchType.EAGER)
|
fetch = FetchType.EAGER,
|
||||||
|
orphanRemoval = true)
|
||||||
@JoinColumn(name = "historyRevisionId", referencedColumnName = "historyRevisionId")
|
@JoinColumn(name = "historyRevisionId", referencedColumnName = "historyRevisionId")
|
||||||
@JoinColumn(name = "domainRepoId", referencedColumnName = "domainRepoId")
|
@JoinColumn(name = "domainRepoId", referencedColumnName = "domainRepoId")
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
|
@ -95,22 +95,21 @@ public class ReplayQueue {
|
||||||
// Sort the changes into an order that will work for insertion into the database.
|
// Sort the changes into an order that will work for insertion into the database.
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() ->
|
||||||
changes.entrySet().stream()
|
changes.entrySet().stream()
|
||||||
.sorted(ReplayQueue::compareByPriority)
|
.sorted(ReplayQueue::compareByPriority)
|
||||||
.forEach(
|
.forEach(
|
||||||
entry -> {
|
entry -> {
|
||||||
if (entry.getValue().equals(TransactionInfo.Delete.SENTINEL)) {
|
if (entry.getValue().equals(TransactionInfo.Delete.SENTINEL)) {
|
||||||
VKey<?> vkey = VKey.from(entry.getKey());
|
VKey<?> vkey = VKey.from(entry.getKey());
|
||||||
ReplaySpecializer.beforeSqlDelete(vkey);
|
ReplaySpecializer.beforeSqlDelete(vkey);
|
||||||
jpaTm().delete(vkey);
|
jpaTm().delete(vkey);
|
||||||
} else {
|
} else {
|
||||||
((DatastoreEntity) entry.getValue())
|
((DatastoreEntity) entry.getValue())
|
||||||
.toSqlEntity()
|
.toSqlEntity()
|
||||||
.ifPresent(jpaTm()::put);
|
.ifPresent(jpaTm()::put);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1087,13 +1087,6 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
|
||||||
null));
|
null));
|
||||||
setUpGracePeriodDurations();
|
setUpGracePeriodDurations();
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
earlierHistoryEntry =
|
|
||||||
persistResource(
|
|
||||||
earlierHistoryEntry
|
|
||||||
.asBuilder()
|
|
||||||
.setType(DOMAIN_CREATE)
|
|
||||||
.setModificationTime(TIME_BEFORE_FLOW.minusDays(2))
|
|
||||||
.build());
|
|
||||||
runFlow();
|
runFlow();
|
||||||
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE);
|
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE);
|
||||||
// Transaction record should just be the grace period delete
|
// Transaction record should just be the grace period delete
|
||||||
|
|
|
@ -16,7 +16,6 @@ package google.registry.model.history;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
||||||
import static google.registry.model.ImmutableObjectSubject.immutableObjectCorrespondence;
|
|
||||||
import static google.registry.model.tld.Registry.TldState.GENERAL_AVAILABILITY;
|
import static google.registry.model.tld.Registry.TldState.GENERAL_AVAILABILITY;
|
||||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||||
|
@ -326,17 +325,10 @@ public class DomainHistoryTest extends EntityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void assertDomainHistoriesEqual(DomainHistory one, DomainHistory two) {
|
static void assertDomainHistoriesEqual(DomainHistory one, DomainHistory two) {
|
||||||
|
assertAboutImmutableObjects().that(one).isEqualExceptFields(two, "domainContent");
|
||||||
assertAboutImmutableObjects()
|
assertAboutImmutableObjects()
|
||||||
.that(one)
|
.that(one.getDomainContent().get())
|
||||||
.isEqualExceptFields(
|
.isEqualExceptFields(two.getDomainContent().get(), "updateTimestamp");
|
||||||
two, "domainContent", "domainRepoId", "nsHosts", "domainTransactionRecords");
|
|
||||||
assertThat(one.getDomainContent().map(DomainContent::getDomainName))
|
|
||||||
.isEqualTo(two.getDomainContent().map(DomainContent::getDomainName));
|
|
||||||
// NB: the record's ID gets reset by Hibernate, causing the hash code to differ so we have to
|
|
||||||
// compare it separately
|
|
||||||
assertThat(one.getDomainTransactionRecords())
|
|
||||||
.comparingElementsUsing(immutableObjectCorrespondence())
|
|
||||||
.containsExactlyElementsIn(two.getDomainTransactionRecords());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DomainHistory createDomainHistory(DomainContent domain) {
|
private DomainHistory createDomainHistory(DomainContent domain) {
|
||||||
|
|
|
@ -25,7 +25,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
import static org.junit.Assert.assertThrows;
|
import static org.junit.Assert.assertThrows;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import google.registry.model.EntityTestCase;
|
import google.registry.model.EntityTestCase;
|
||||||
import google.registry.model.contact.ContactHistory;
|
import google.registry.model.contact.ContactHistory;
|
||||||
import google.registry.model.domain.DomainBase;
|
import google.registry.model.domain.DomainBase;
|
||||||
|
@ -79,15 +78,10 @@ class HistoryEntryTest extends EntityTestCase {
|
||||||
void testPersistence() {
|
void testPersistence() {
|
||||||
transactIfJpaTm(
|
transactIfJpaTm(
|
||||||
() -> {
|
() -> {
|
||||||
HistoryEntry fromDatabase = tm().loadByEntity(domainHistory);
|
DomainHistory fromDatabase = tm().loadByEntity(domainHistory);
|
||||||
assertAboutImmutableObjects()
|
assertAboutImmutableObjects()
|
||||||
.that(fromDatabase)
|
.that(fromDatabase)
|
||||||
.isEqualExceptFields(
|
.isEqualExceptFields(domainHistory, "domainContent");
|
||||||
domainHistory, "nsHosts", "domainTransactionRecords", "domainContent");
|
|
||||||
assertAboutImmutableObjects()
|
|
||||||
.that(Iterables.getOnlyElement(fromDatabase.getDomainTransactionRecords()))
|
|
||||||
.isEqualExceptFields(
|
|
||||||
Iterables.getOnlyElement(domainHistory.getDomainTransactionRecords()), "id");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue