Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Add IntervalDescriptor and change DurationConverter to use Interval datatype #653
Conversation
core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 27 at r1 (raw file):
The Note: can be in a separate core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 30 at r1 (raw file):
Why Object instead of PGInterval? |
|
+reviewer:@hstonec +reviewer:@mindhog Adding some other reviewers who might know more about Cloud SQL converters than I do.
|
core/src/main/java/google/registry/persistence/converter/IntervalDescriptor.java, line 41 at r1 (raw file):
I'm just curious how this number was selected? db/src/main/resources/sql/flyway/V20__add_relock_duration.sql, line 15 at r1 (raw file):
we should create a new flyway file instead of modifying the existing ones. db/src/main/resources/sql/schema/db-schema.sql.generated, line 386 at r1 (raw file):
do we have data in this table? if so, we may want to follow our procedure to change the column. db/src/main/resources/sql/schema/nomulus.golden.sql, line 593 at r1 (raw file):
do we have data in this table? if so, we may want to follow our procedure to change the column. |
core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 36 at r1 (raw file):
Don't we typically return null in this case? Does that not work for interval columns? core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 43 at r1 (raw file):
I suspect you're going to lose millisecond precision, here. It looks like joda Duration has seconds and milliseconds as integers whereas PGInterval has double-precision seconds. if so, you'll want to convert seconds + milliseconds / 1000 to a double. core/src/main/java/google/registry/schema/domain/RegistryLock.java, line 217 at r1 (raw file):
This seems orthogonal to this PR? core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java, line 55 at r1 (raw file):
Per my earlier statement, you should do this with a duration of 6 days + some odd number of millis |
db/src/main/resources/sql/schema/nomulus.golden.sql, line 593 at r1 (raw file): Previously, hstonec (Shicong Huang) wrote…
When we need to change the type of the Given that we haven't launched registry lock yet, is there a simpler way to change the schema? |
957e26c
to
69f1c2c
|
LGTM modulo concerns expressed by Ben & Shicong.
|
c52b9f8
to
4cbc86a
core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 27 at r1 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
Done. core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 30 at r1 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
Done. core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 36 at r1 (raw file): Previously, mindhog (Michael Muller) wrote…
Returning null causes a PSQLException so I changed converter to use an empty interval when creating a database column, and turn an empty interval into a null duration when converting it back core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 43 at r1 (raw file): Previously, mindhog (Michael Muller) wrote…
Done. core/src/main/java/google/registry/persistence/converter/IntervalDescriptor.java, line 41 at r1 (raw file): Previously, hstonec (Shicong Huang) wrote…
I believe that is the number for the Interval type, but I changed it to use JAVA_OBJECT which is 2000 core/src/main/java/google/registry/schema/domain/RegistryLock.java, line 217 at r1 (raw file): Previously, mindhog (Michael Muller) wrote…
Done. core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java, line 55 at r1 (raw file): Previously, mindhog (Michael Muller) wrote…
Done. db/src/main/resources/sql/flyway/V20__add_relock_duration.sql, line 15 at r1 (raw file): Previously, hstonec (Shicong Huang) wrote…
Done. db/src/main/resources/sql/schema/db-schema.sql.generated, line 386 at r1 (raw file): Previously, hstonec (Shicong Huang) wrote…
dropped the column and added a new one db/src/main/resources/sql/schema/nomulus.golden.sql, line 593 at r1 (raw file): Previously, hstonec (Shicong Huang) wrote…
Talked to Weimin and Gus, since it hasn't been pushed to production yet, I dropped the column and added a new one. |
core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 28 at r3 (raw file):
Is this comment still accurate? Why are we throwing away years and milliseconds? We use both of those in our codebase. core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 41 at r3 (raw file):
Why no |
4cbc86a
to
18c25d8
core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 28 at r3 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
Removed core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 41 at r3 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
added years and months |
core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 41 at r3 (raw file): Previously, sarahcaseybot wrote…
I'm not seeing a test that all of this works? I see a test that does 6 days plus 7 millis, but what about years, months, hours, minutes, and seconds? core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java, line 50 at r4 (raw file):
Can you add a test that core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java, line 61 at r4 (raw file):
You should probably rename this to something like |
18c25d8
to
a284a0c
core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 41 at r3 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
Added a test. Realized that years and months do not work since a duration is simply an amount of millis, and since years and months are not a standard size, they cannot be accurately converted to years and months values. Instead, these values will be represented int he days field. core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java, line 50 at r4 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
Done. core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java, line 61 at r4 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
Done. |
a284a0c
to
da7e0a5
core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 41 at r3 (raw file): Previously, sarahcaseybot wrote…
Are you still working on adding this? I don't see it in here. core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 25 at r5 (raw file):
The Javadoc needs more explanation as to how exactly all the different parts of a Joda Time Duration is stored, seeing as how there appears to be a mismatch between that and how PGInterval works. |
da7e0a5
to
1c0840f
core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 41 at r3 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
I added values for days, hours, minutes, and seconds in the test roundtrip test core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 25 at r5 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
Done. core/src/main/java/google/registry/persistence/converter/IntervalDescriptor.java, line 41 at r1 (raw file): Previously, sarahcaseybot wrote…
Done. |
core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 31 at r6 (raw file):
There's one final part missing here in the explanation, which is what happens when the Duration does include months or years. Are they ignored? Just stored as days using some flat conversion factor? Is an exception thrown? (Maybe an exception should be thrown rather than silently ignoring them?) core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java, line 32 at r6 (raw file):
Still needs tests for what happens when the |
db/src/main/resources/sql/flyway/V42__update_relock_duration_type.sql, line 1 at r6 (raw file):
I checked in V42 yesterday, you might want to hold off on rebasing and further renaming this file until you're ready to commit. |
|
core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 31 at r6 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
Per out of band chat, |
core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 31 at r6 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
Regarding nanoseconds, never mind. I was looking at the wrong |
1c0840f
to
da62a47
core/src/main/java/google/registry/persistence/converter/DurationConverter.java, line 31 at r6 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
Done. core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java, line 32 at r6 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
This is not necessary since there is no way for Duration to have months or years db/src/main/resources/sql/schema/db-schema.sql.generated, line 386 at r1 (raw file): Previously, sarahcaseybot wrote…
Done. db/src/main/resources/sql/schema/nomulus.golden.sql, line 593 at r1 (raw file): Previously, sarahcaseybot wrote…
Done. db/src/main/resources/sql/flyway/V42__update_relock_duration_type.sql, line 1 at r6 (raw file): Previously, mindhog (Michael Muller) wrote…
Done. |
core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java, line 69 at r7 (raw file):
Hrmmm ... I just realized .... you could put in a Duration containing hours, minutes, seconds, etc., but when you get it back out, everything has been converted to millis. So we need tests that explicitly verify that the days, hours, minutes, seconds, and millis that you put in are exactly what you get back out. |
|
core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java, line 69 at r7 (raw file): Previously, CydeWeys (Ben McIlwain) wrote…
I don't agree with this. The joda Duration class is simply an amount of milliseconds. It does not store fields such as days, hours, minutes. It has methods for adding values such as days or hours, but all those methods do is multiply the number of milliseconds in that time type by the number of that time type. When getting days, hours, etc. from a duration, it is simply received from a division of the millis in the total duration by the time type that is being asked for. The only way I would think to write a test like that would be to convert to a period. But the way that a duration is converted to a period will not preserve the specific number of each timetype that had been initially added to the duration since those are not stored anywhere. |
|
|
4ad7f97
into
google:master
This change is