Fix DTR creation in one location and clean up replay comparison (#1529)

* Fix DTR creation in one location and clean up replay comparison
This commit is contained in:
gbrodman 2022-02-23 11:07:10 -05:00 committed by GitHub
parent 71b9b7fc7d
commit 5b7514096f
6 changed files with 22 additions and 15 deletions

View file

@ -1112,7 +1112,16 @@ public class DomainFlowUtils {
// Only cancel fields which are cancelable // Only cancel fields which are cancelable
if (cancelableFields.contains(record.getReportField())) { if (cancelableFields.contains(record.getReportField())) {
int cancelledAmount = -1 * record.getReportAmount(); int cancelledAmount = -1 * record.getReportAmount();
recordsBuilder.add(record.asBuilder().setReportAmount(cancelledAmount).build()); // NB: It's necessary to create a new DomainTransactionRecord from scratch so that we
// don't retain the ID of the previous record to cancel. If we keep the ID, Hibernate
// will remove that record from the DB entirely as the record will be re-parented on
// this DomainHistory being created now.
recordsBuilder.add(
DomainTransactionRecord.create(
record.getTld(),
record.getReportingTime(),
record.getReportField(),
cancelledAmount));
} }
} }
} }

View file

@ -64,7 +64,7 @@ public class ContactHistory extends HistoryEntry implements SqlEntity, UnsafeSer
// Store ContactBase instead of ContactResource so we don't pick up its @Id // Store ContactBase instead of ContactResource so we don't pick up its @Id
// Nullable for the sake of pre-Registry-3.0 history objects // Nullable for the sake of pre-Registry-3.0 history objects
@Nullable ContactBase contactBase; @DoNotCompare @Nullable ContactBase contactBase;
@Id @Id
@Access(AccessType.PROPERTY) @Access(AccessType.PROPERTY)

View file

@ -86,7 +86,7 @@ public class DomainHistory extends HistoryEntry implements SqlEntity {
// Store DomainContent instead of DomainBase so we don't pick up its @Id // Store DomainContent instead of DomainBase so we don't pick up its @Id
// Nullable for the sake of pre-Registry-3.0 history objects // Nullable for the sake of pre-Registry-3.0 history objects
@Nullable DomainContent domainContent; @DoNotCompare @Nullable DomainContent domainContent;
@Id @Id
@Access(AccessType.PROPERTY) @Access(AccessType.PROPERTY)
@ -105,6 +105,7 @@ public class DomainHistory extends HistoryEntry implements SqlEntity {
// We could have reused domainContent.nsHosts here, but Hibernate throws a weird exception after // We could have reused domainContent.nsHosts here, but Hibernate throws a weird exception after
// we change to use a composite primary key. // we change to use a composite primary key.
// TODO(b/166776754): Investigate if we can reuse domainContent.nsHosts for storing host keys. // TODO(b/166776754): Investigate if we can reuse domainContent.nsHosts for storing host keys.
@DoNotCompare
@ElementCollection @ElementCollection
@JoinTable( @JoinTable(
name = "DomainHistoryHost", name = "DomainHistoryHost",
@ -118,6 +119,7 @@ public class DomainHistory extends HistoryEntry implements SqlEntity {
@Column(name = "host_repo_id") @Column(name = "host_repo_id")
Set<VKey<HostResource>> nsHosts; Set<VKey<HostResource>> nsHosts;
@DoNotCompare
@OneToMany( @OneToMany(
cascade = {CascadeType.ALL}, cascade = {CascadeType.ALL},
fetch = FetchType.EAGER, fetch = FetchType.EAGER,
@ -137,6 +139,7 @@ public class DomainHistory extends HistoryEntry implements SqlEntity {
// HashSet rather than ImmutableSet so that Hibernate can fill them out lazily on request // HashSet rather than ImmutableSet so that Hibernate can fill them out lazily on request
Set<DomainDsDataHistory> dsDataHistories = new HashSet<>(); Set<DomainDsDataHistory> dsDataHistories = new HashSet<>();
@DoNotCompare
@OneToMany( @OneToMany(
cascade = {CascadeType.ALL}, cascade = {CascadeType.ALL},
fetch = FetchType.EAGER, fetch = FetchType.EAGER,

View file

@ -66,7 +66,7 @@ public class HostHistory extends HistoryEntry implements SqlEntity, UnsafeSerial
// Store HostBase instead of HostResource so we don't pick up its @Id // Store HostBase instead of HostResource so we don't pick up its @Id
// Nullable for the sake of pre-Registry-3.0 history objects // Nullable for the sake of pre-Registry-3.0 history objects
@Nullable HostBase hostBase; @DoNotCompare @Nullable HostBase hostBase;
@Id @Id
@Access(AccessType.PROPERTY) @Access(AccessType.PROPERTY)

View file

@ -324,7 +324,7 @@ public class HistoryEntry extends ImmutableObject
// Note: how we wish to treat this Hibernate setter depends on the current state of the object // Note: how we wish to treat this Hibernate setter depends on the current state of the object
// and what's passed in. The key principle is that we wish to maintain the link between parent // and what's passed in. The key principle is that we wish to maintain the link between parent
// and child objects, meaning that we should keep around whichever of the two sets (the // and child objects, meaning that we should keep around whichever of the two sets (the
// parameter vs the class variable and clear/populate that as appropriate. // parameter vs the class variable) and clear/populate that as appropriate.
// //
// If the class variable is a PersistentSet and we overwrite it here, Hibernate will throw // If the class variable is a PersistentSet and we overwrite it here, Hibernate will throw
// an exception "A collection with cascade=”all-delete-orphan” was no longer referenced by the // an exception "A collection with cascade=”all-delete-orphan” was no longer referenced by the
@ -539,7 +539,7 @@ public class HistoryEntry extends ImmutableObject
public B setDomainTransactionRecords( public B setDomainTransactionRecords(
ImmutableSet<DomainTransactionRecord> domainTransactionRecords) { ImmutableSet<DomainTransactionRecord> domainTransactionRecords) {
getInstance().domainTransactionRecords = domainTransactionRecords; getInstance().setDomainTransactionRecords(domainTransactionRecords);
return thisCastToDerived(); return thisCastToDerived();
} }
} }

View file

@ -100,17 +100,12 @@ public class ReplayExtension implements BeforeEachCallback, AfterEachCallback {
private static ImmutableSet<String> IGNORED_ENTITIES = private static ImmutableSet<String> IGNORED_ENTITIES =
Streams.concat( Streams.concat(
ImmutableSet.of( ImmutableSet.of(
// These entities *should* be comparable, but this isn't working yet so exclude // These entities are @Embed-ded in Datastore
// them so we can tackle them independently. "DelegationSignerData",
"DomainDsDataHistory",
"DomainTransactionRecord",
"GracePeriod", "GracePeriod",
"GracePeriodHistory", "GracePeriodHistory",
"HistoryEntry",
"DomainHistory",
"ContactHistory",
"HostHistory",
"DomainDsDataHistory",
"DelegationSignerData",
"DomainTransactionRecord",
// These entities are legitimately not comparable. // These entities are legitimately not comparable.
"ClaimsEntry", "ClaimsEntry",