From 2702c3a7f3d65490364e80f2e9c82d8ff901dbd2 Mon Sep 17 00:00:00 2001 From: nickfelt Date: Tue, 26 Sep 2017 17:41:39 -0700 Subject: [PATCH] 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 --- .../registry/batch/ExpandRecurringBillingEventsAction.java | 3 +-- java/google/registry/model/reporting/HistoryEntry.java | 2 +- .../registry/rde/imports/XjcToHostResourceConverter.java | 4 +--- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/java/google/registry/batch/ExpandRecurringBillingEventsAction.java b/java/google/registry/batch/ExpandRecurringBillingEventsAction.java index fc925974f..b3ce51257 100644 --- a/java/google/registry/batch/ExpandRecurringBillingEventsAction.java +++ b/java/google/registry/batch/ExpandRecurringBillingEventsAction.java @@ -67,7 +67,6 @@ import java.util.Set; import javax.inject.Inject; import org.joda.money.Money; import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; /** * 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() .setBySuperuser(false) .setClientId(recurring.getClientId()) - .setModificationTime(DateTime.now(DateTimeZone.UTC)) + .setModificationTime(ofy().getTransactionTime()) .setParent(domainKey) .setPeriod(Period.create(1, YEARS)) .setReason("Domain autorenewal by ExpandRecurringBillingEventsAction") diff --git a/java/google/registry/model/reporting/HistoryEntry.java b/java/google/registry/model/reporting/HistoryEntry.java index 2301dcc2b..2ee7a998f 100644 --- a/java/google/registry/model/reporting/HistoryEntry.java +++ b/java/google/registry/model/reporting/HistoryEntry.java @@ -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. */ byte[] xmlBytes; - /** The time the command occurred. */ + /** The time the command occurred, represented by the ofy transaction time.*/ @Index DateTime modificationTime; diff --git a/java/google/registry/rde/imports/XjcToHostResourceConverter.java b/java/google/registry/rde/imports/XjcToHostResourceConverter.java index 9a53c8353..aa85f3323 100644 --- a/java/google/registry/rde/imports/XjcToHostResourceConverter.java +++ b/java/google/registry/rde/imports/XjcToHostResourceConverter.java @@ -19,7 +19,6 @@ import static com.google.common.base.Predicates.not; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.rde.imports.RdeImportUtils.generateTridForImport; import static google.registry.util.DomainNameUtils.canonicalizeDomainName; -import static org.joda.time.DateTimeZone.UTC; import com.google.common.base.Function; 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.XjcRdeHostElement; import java.net.InetAddress; -import org.joda.time.DateTime; /** Utility class that converts an {@link XjcRdeHost} into a {@link HostResource}. */ public class XjcToHostResourceConverter extends XjcToEppResourceConverter { @@ -66,7 +64,7 @@ public class XjcToHostResourceConverter extends XjcToEppResourceConverter { .setType(HistoryEntry.Type.RDE_IMPORT) .setClientId(host.getClID()) .setTrid(generateTridForImport()) - .setModificationTime(DateTime.now(UTC)) + .setModificationTime(ofy().getTransactionTime()) .setXmlBytes(getObjectXml(new XjcRdeHostElement(host))) .setBySuperuser(true) .setReason("RDE Import")