Fix code to always set HistoryEntry modification time using txn time

Since HistoryEntry always represents a read-only log of mutation to a core resource, that mutation should always happen in a transaction, and the HistoryEntry should be saved in that transaction.  As such, it's always more accurate to use ofy().getTransactionTime() for the modificationTime of the HistoryEntry rather than just DateTime.now(UTC).

In addition, having these be the exact same timestamp makes it possible to align HistoryEntries with commit log manifests using modificationTime = transactionTime, which is useful for recovery and analysis purposes.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170136957
This commit is contained in:
nickfelt 2017-09-26 17:41:39 -07:00 committed by Ben McIlwain
parent ceadfea11f
commit 2702c3a7f3
3 changed files with 3 additions and 6 deletions

View file

@ -67,7 +67,6 @@ import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import org.joda.money.Money; import org.joda.money.Money;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
/** /**
* A mapreduce that expands {@link Recurring} billing events into synthetic {@link OneTime} events. * A mapreduce that expands {@link Recurring} billing events into synthetic {@link OneTime} events.
@ -192,7 +191,7 @@ public class ExpandRecurringBillingEventsAction implements Runnable {
HistoryEntry historyEntry = new HistoryEntry.Builder() HistoryEntry historyEntry = new HistoryEntry.Builder()
.setBySuperuser(false) .setBySuperuser(false)
.setClientId(recurring.getClientId()) .setClientId(recurring.getClientId())
.setModificationTime(DateTime.now(DateTimeZone.UTC)) .setModificationTime(ofy().getTransactionTime())
.setParent(domainKey) .setParent(domainKey)
.setPeriod(Period.create(1, YEARS)) .setPeriod(Period.create(1, YEARS))
.setReason("Domain autorenewal by ExpandRecurringBillingEventsAction") .setReason("Domain autorenewal by ExpandRecurringBillingEventsAction")

View file

@ -104,7 +104,7 @@ public class HistoryEntry extends ImmutableObject implements Buildable {
/** The actual EPP xml of the command, stored as bytes to be agnostic of encoding. */ /** The actual EPP xml of the command, stored as bytes to be agnostic of encoding. */
byte[] xmlBytes; byte[] xmlBytes;
/** The time the command occurred. */ /** The time the command occurred, represented by the ofy transaction time.*/
@Index @Index
DateTime modificationTime; DateTime modificationTime;

View file

@ -19,7 +19,6 @@ import static com.google.common.base.Predicates.not;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.rde.imports.RdeImportUtils.generateTridForImport; import static google.registry.rde.imports.RdeImportUtils.generateTridForImport;
import static google.registry.util.DomainNameUtils.canonicalizeDomainName; import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
@ -35,7 +34,6 @@ import google.registry.xjc.host.XjcHostStatusType;
import google.registry.xjc.rdehost.XjcRdeHost; import google.registry.xjc.rdehost.XjcRdeHost;
import google.registry.xjc.rdehost.XjcRdeHostElement; import google.registry.xjc.rdehost.XjcRdeHostElement;
import java.net.InetAddress; import java.net.InetAddress;
import org.joda.time.DateTime;
/** Utility class that converts an {@link XjcRdeHost} into a {@link HostResource}. */ /** Utility class that converts an {@link XjcRdeHost} into a {@link HostResource}. */
public class XjcToHostResourceConverter extends XjcToEppResourceConverter { public class XjcToHostResourceConverter extends XjcToEppResourceConverter {
@ -66,7 +64,7 @@ public class XjcToHostResourceConverter extends XjcToEppResourceConverter {
.setType(HistoryEntry.Type.RDE_IMPORT) .setType(HistoryEntry.Type.RDE_IMPORT)
.setClientId(host.getClID()) .setClientId(host.getClID())
.setTrid(generateTridForImport()) .setTrid(generateTridForImport())
.setModificationTime(DateTime.now(UTC)) .setModificationTime(ofy().getTransactionTime())
.setXmlBytes(getObjectXml(new XjcRdeHostElement(host))) .setXmlBytes(getObjectXml(new XjcRdeHostElement(host)))
.setBySuperuser(true) .setBySuperuser(true)
.setReason("RDE Import") .setReason("RDE Import")