Set clock precision to milliseconds for Datetime->Instant migration#2999
Set clock precision to milliseconds for Datetime->Instant migration#2999CydeWeys merged 1 commit intogoogle:masterfrom
Conversation
| AtomicInteger hardDeletedDomains = new AtomicInteger(); | ||
| AtomicReference<ImmutableList<Domain>> domainsBatch = new AtomicReference<>(); | ||
| DateTime startTime = DateTime.now(UTC); | ||
| DateTime startTime = clock.nowUtc(); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
|
|
||
| // Automatically kill the job if it is running for over 20 hours | ||
| } while (DateTime.now(UTC).isBefore(startTime.plusHours(20)) | ||
| } while (clock.nowUtc().isBefore(startTime.plusHours(20)) |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
| updateLastNotificationSentDate( | ||
| registrar, | ||
| DateTime.now(UTC).minusMinutes((int) UPDATE_TIME_OFFSET.getStandardMinutes()), | ||
| clock.nowUtc().minusMinutes((int) UPDATE_TIME_OFFSET.getStandardMinutes()), |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
|
|
||
| public Builder timeToLive(Duration duration) { | ||
| this.table.setExpirationTime(DateTime.now(UTC).plus(duration).getMillis()); | ||
| this.table.setExpirationTime(clock.nowUtc().plus(duration).getMillis()); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
| consoleApiParams | ||
| .response() | ||
| .setDateHeader("Expires", DateTime.now(UTC).withTimeAtStartOfDay().plusDays(1)); | ||
| .setDateHeader("Expires", clock.nowUtc().withTimeAtStartOfDay().plusDays(1)); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
| keyGen.generateKeyPair(), DEFAULT_ISSUER_FQDN, DEFAULT_NOT_BEFORE, DEFAULT_NOT_AFTER); | ||
| keyGen.generateKeyPair(), | ||
| DEFAULT_ISSUER_FQDN, | ||
| clock.nowUtc().minusHours(1), |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
| keyGen.generateKeyPair(), | ||
| DEFAULT_ISSUER_FQDN, | ||
| clock.nowUtc().minusHours(1), | ||
| clock.nowUtc().plusDays(1)); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
| public static SelfSignedCaCertificate create(String fqdn) throws Exception { | ||
| return create(fqdn, DEFAULT_NOT_BEFORE, DEFAULT_NOT_AFTER); | ||
| public static SelfSignedCaCertificate create(String fqdn, Clock clock) throws Exception { | ||
| return create(fqdn, clock.nowUtc().minusHours(1), clock.nowUtc().plusDays(1)); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
| public static SelfSignedCaCertificate create(String fqdn) throws Exception { | ||
| return create(fqdn, DEFAULT_NOT_BEFORE, DEFAULT_NOT_AFTER); | ||
| public static SelfSignedCaCertificate create(String fqdn, Clock clock) throws Exception { | ||
| return create(fqdn, clock.nowUtc().minusHours(1), clock.nowUtc().plusDays(1)); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
6334a05 to
07fae7b
Compare
07fae7b to
fc829f4
Compare
gbrodman
left a comment
There was a problem hiding this comment.
if we're trying to get rid of all the calls to DateTime.now() except in the special allowed Clock classes, we should add a presubmit check forbidding that except in those special cases
@gbrodman reviewed 56 files and all commit messages, and made 5 comments.
Reviewable status: all files reviewed, 21 unresolved discussions (waiting on CydeWeys and ptkach).
core/src/main/java/google/registry/model/tld/label/PremiumListDao.java line 132 at r4 (raw file):
public static PremiumList save(String name, CurrencyUnit currencyUnit, List<String> inputData) { checkArgument(!inputData.isEmpty(), "New premium list data cannot be empty"); return tm().transact(
need to use reTransact or refactor things to avoid nested transactions
core/src/test/java/google/registry/model/tld/label/PremiumListUtilsTest.java line 31 at r4 (raw file):
class PremiumListUtilsTest { private static final DateTime SAMPLE_TIME = DateTime.now(UTC);
use a constant instead of "now" to avoid potential random test failure as time goes on
core/src/test/java/google/registry/reporting/icann/IcannReportingStagerTest.java line 46 at r4 (raw file):
class IcannReportingStagerTest { private final FakeClock clock = new FakeClock(DateTime.now(UTC));
ditto comment about using a static time rather than a variable one
util/src/test/java/google/registry/util/PosixTarHeaderTest.java line 206 at r4 (raw file):
.setName("(◕‿◕).txt") .setSize(31337) .setMtime(DateTime.now(DateTimeZone.UTC))
we should probably use a clock in this test class too
fc829f4 to
4f440ec
Compare
gbrodman
left a comment
There was a problem hiding this comment.
@gbrodman reviewed 9 files and all commit messages.
Reviewable status: all files reviewed, 21 unresolved discussions (waiting on CydeWeys and ptkach).
CydeWeys
left a comment
There was a problem hiding this comment.
@CydeWeys made 1 comment.
Reviewable status: all files reviewed, 22 unresolved discussions (waiting on gbrodman and ptkach).
util/src/test/java/google/registry/util/PosixTarHeaderTest.java line 206 at r4 (raw file):
Previously, gbrodman wrote…
we should probably use a clock in this test class too
It doesn't really make sense to use a FakeClock instance solely for the purpose of getting the time in tests. A static method that handles the millisecond-chopping should be sufficient. Can do that in a follow-up. (There are a lot of calls of DateTime.now() in tests).
4f440ec to
968c9ac
Compare
CydeWeys
left a comment
There was a problem hiding this comment.
Seems right for a follow-up. Also it's more than just DateTime.now() -- it's in particular things like Instant.now() and the equivalent ZoneDateTime method, as those are the ones that include finer precision by default.
@CydeWeys made 1 comment.
Reviewable status: 62 of 64 files reviewed, 22 unresolved discussions (waiting on gbrodman and ptkach).
CydeWeys
left a comment
There was a problem hiding this comment.
Seems right for a follow-up. Also it's more than just DateTime.now() -- it's in particular things like Instant.now() and the equivalent ZoneDateTime method, as those are the ones that include finer precision by default.
@CydeWeys made 1 comment.
Reviewable status: 62 of 64 files reviewed, 22 unresolved discussions (waiting on gbrodman and ptkach).
CydeWeys
left a comment
There was a problem hiding this comment.
Seems right for a follow-up. Also it's more than just DateTime.now() -- it's in particular things like Instant.now() and the equivalent ZoneDateTime method, as those are the ones that include finer precision by default.
@CydeWeys made 1 comment.
Reviewable status: 62 of 64 files reviewed, 22 unresolved discussions (waiting on gbrodman and ptkach).
968c9ac to
565a39e
Compare
CydeWeys
left a comment
There was a problem hiding this comment.
@CydeWeys made 1 comment.
Reviewable status: 62 of 64 files reviewed, 22 unresolved discussions (waiting on gbrodman and ptkach).
core/src/main/java/google/registry/model/tld/label/PremiumListDao.java line 132 at r4 (raw file):
Previously, gbrodman wrote…
need to use reTransact or refactor things to avoid nested transactions
Fixed.
CydeWeys
left a comment
There was a problem hiding this comment.
@CydeWeys made 2 comments.
Reviewable status: 60 of 64 files reviewed, 22 unresolved discussions (waiting on gbrodman and ptkach).
core/src/test/java/google/registry/model/tld/label/PremiumListUtilsTest.java line 31 at r4 (raw file):
Previously, gbrodman wrote…
use a constant instead of "now" to avoid potential random test failure as time goes on
Done.
core/src/test/java/google/registry/reporting/icann/IcannReportingStagerTest.java line 46 at r4 (raw file):
Previously, gbrodman wrote…
ditto comment about using a static time rather than a variable one
Done.
CydeWeys
left a comment
There was a problem hiding this comment.
PTAL
@CydeWeys made 1 comment.
Reviewable status: 60 of 64 files reviewed, 22 unresolved discussions (waiting on gbrodman and ptkach).
565a39e to
7869a7d
Compare
gbrodman
left a comment
There was a problem hiding this comment.
@gbrodman reviewed 4 files and all commit messages, and resolved 4 discussions.
Reviewable status: all files reviewed, 19 unresolved discussions (waiting on CydeWeys and ptkach).
afcc312 to
ded9fa3
Compare
Our existing precision is milliseconds so we want to stick with that for Instants. If we want to increase the precision globally after that we can do so all in one go post-migration, but for now, it would be a bad thing to have mixed precision going on just depending on whether a class happens to be migrated yet or not. This PR also migrates all existing DateTime.nowUtc() calls to use the Clock interface, so that when they are migrated they will get the benefit of this precision-setting as well. BUG= http://b/496985355
ded9fa3 to
b377f41
Compare
|
PTAL, had to make some more changes related to transaction-handling because of tm() removals in PremiumListDao. |
gbrodman
left a comment
There was a problem hiding this comment.
@gbrodman reviewed 8 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 20 unresolved discussions (waiting on CydeWeys).
core/src/test/java/google/registry/testing/DatabaseHelper.java line 349 at r9 (raw file):
// unit tests. tm().reTransact(tm()::allocateId); tm().transact(() -> PremiumListDao.save(premiumList));
we probably want reTransact here and, if they exist, any other test-library places
CydeWeys
left a comment
There was a problem hiding this comment.
@CydeWeys made 1 comment.
Reviewable status: all files reviewed, 20 unresolved discussions (waiting on gbrodman).
core/src/test/java/google/registry/testing/DatabaseHelper.java line 349 at r9 (raw file):
Previously, gbrodman wrote…
we probably want reTransact here and, if they exist, any other test-library places
I'm actually not sure we do. (And the existing reTransact() call around allocateId should perhaps just be normal transact). We don't typically have a pattern in test classes of large wrapping transactions around multiple things happening, and none of the callers to persistPremiumList() are wrapping it in a transaction.
gbrodman
left a comment
There was a problem hiding this comment.
@gbrodman made 1 comment and resolved 1 discussion.
Reviewable status: all files reviewed, 19 unresolved discussions (waiting on CydeWeys).
Our existing precision is milliseconds so we want to stick with that for Instants. If we want to increase the precision globally after that we can do so all in one go post-migration, but for now, it would be a bad thing to have mixed precision going on just depending on whether a class happens to be migrated yet or not.
This PR also migrates all existing DateTime.nowUtc() calls to use the Clock interface, so that when they are migrated they will get the benefit of this precision-setting as well.
BUG= http://b/496985355
This change is