-
Notifications
You must be signed in to change notification settings - Fork 103
Transition FormatVersion from constants to an enum #3304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The intent is to replace the constants in FDBRecordStore with this, but I wanted to introduce it on it's own, primarily to show that FormatVersionTest.testOrderingAlignment works with the constants. This is part of FoundationDB#710, but in order for that be complete, the constants will have to be updated too.
335fad3
to
f2c257c
Compare
This changes the constants in FDBRecordStore to call through to the enum. It also adds setters on the builders, and deprecates the old ones. With this change, I also went through and changed all the tests to use the enum rather than the constants. This leaves a couple places untouched: 1. The code within FDBRecordStore still uses the constants 2. getFormatVersion() still returns the integer 3. Code interacting with the result of getFormatVersion() also references the comments
This deprecates the remaining places that treat the FormatVersion as just an integer, and adds a new `FDBRecordStore.getFormatVersionEnum`. I did not change the code around rebuilding, or that interacts with a StoreHeader, because that felt like it was still bringing in a fair amount of risk.
final List<FormatVersion> sortedVersions = Arrays.stream(FormatVersion.values()).sorted().collect(Collectors.toList()); | ||
FormatVersion penultimateVersion = sortedVersions.get(sortedVersions.size() - 1); | ||
try (FDBRecordContext context = openContext()) { | ||
recordStore = getStoreBuilder(context, simpleMetaData(NO_HOOK)) | ||
.setFormatVersion(FDBRecordStore.MAX_SUPPORTED_FORMAT_VERSION - 1) | ||
.setFormatVersion(penultimateVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about introducing a FormatVersion.previous()
, but it would only be used for internal tests, and you can't change the numbers associated with the enums, so it seemed best to keep it simple.
I'm leaving one in the testing of upgrades, because it seems good to maintain tests of that method until we remove it.
This required changing a handful of methods to create a store builder first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few smaller comments about some things that could be improved or were a bit erroneous, but overall, this LGTM, and I like the way this refactoring evolves the API
...r-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/FDBRecordStore.java
Outdated
Show resolved
Hide resolved
...er-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/FormatVersion.java
Outdated
Show resolved
Hide resolved
...er-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/FormatVersion.java
Outdated
Show resolved
Hide resolved
...-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/IndexingByIndex.java
Outdated
Show resolved
Hide resolved
...re/src/main/java/com/apple/foundationdb/record/provider/foundationdb/FDBRecordStoreBase.java
Outdated
Show resolved
Hide resolved
...re/src/main/java/com/apple/foundationdb/record/provider/foundationdb/FDBRecordStoreBase.java
Outdated
Show resolved
Hide resolved
...re/src/main/java/com/apple/foundationdb/record/provider/foundationdb/FDBRecordStoreBase.java
Outdated
Show resolved
Hide resolved
...java/com/apple/foundationdb/record/provider/foundationdb/FDBRecordStoreSplitRecordsTest.java
Outdated
Show resolved
Hide resolved
This retrieves the format version previous to the given one, which is very useful for upgrade tests. Since this is only used for upgrade tests, I felt it was better to add as a test utils, rather than a method on FormatVersion itself
67cded1
to
2cb848e
Compare
Note: This changes a `protected` method of FDBRecordStore, and field, but the class is flagged `UNSTABLE`. It _feels_ to me like users should assume that extending classes is INTERNAL, and really anything protected.
a5a3da9
to
46aec46
Compare
FDBRecordStore.SAVE_UNSPLIT_WITH_SUFFIX_FORMAT_VERSION, | ||
FDBRecordStore.SAVE_VERSION_WITH_RECORD_FORMAT_VERSION, | ||
FDBRecordStore.MAX_SUPPORTED_FORMAT_VERSION | ||
FormatVersion.SAVE_UNSPLIT_WITH_SUFFIX, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was wrong, it should be the previous one.
...java/com/apple/foundationdb/record/provider/foundationdb/FDBRecordStoreSplitRecordsTest.java
Outdated
Show resolved
Hide resolved
...re/src/main/java/com/apple/foundationdb/record/provider/foundationdb/FDBRecordStoreBase.java
Outdated
Show resolved
Hide resolved
...er-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/FormatVersion.java
Outdated
Show resolved
Hide resolved
...r-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/FDBRecordStore.java
Outdated
Show resolved
Hide resolved
...re/src/main/java/com/apple/foundationdb/record/provider/foundationdb/FDBRecordStoreBase.java
Outdated
Show resolved
Hide resolved
...re/src/main/java/com/apple/foundationdb/record/provider/foundationdb/FDBRecordStoreBase.java
Outdated
Show resolved
Hide resolved
...-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/IndexingByIndex.java
Outdated
Show resolved
Hide resolved
@@ -2254,23 +2257,23 @@ public void withMetaDataRebuilds(int testFormatVersion, boolean testSplitLongRec | |||
List<FDBQueriedRecord<Message>> records = recordStore.executeQuery(plan).asList().join(); | |||
assertEquals(3, records.size()); | |||
|
|||
if (testFormatVersion < FDBRecordStore.SAVE_VERSION_WITH_RECORD_FORMAT_VERSION) { | |||
if (testFormatVersion.isAtLeast(FormatVersion.SAVE_VERSION_WITH_RECORD)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if/else block was inverted to avoid the negation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was one relatively minor typo, but otherwise, LGTM pending resolving the merge conflicts with #3309
...er-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/FormatVersion.java
Outdated
Show resolved
Hide resolved
This conflicted on FDBRecordStore.Builder.setFormatVersion The checks are now handled within the enum, so not needed explicitly in the setter. This still fails to compile because new tests on main use the deprecated constants.
Co-authored-by: Alec Grieser <[email protected]>
The FormatVersion was just an integers, with an associated set of constants, of the form:
FDBRecordStore.*_FORMAT_VERSION
. This PR starts the migration of the code to a new enum:FormatVersion
, and introduces setters and getters that align with this.This leaves around the existing constants, and methods to avoid being a breaking change, but they are all now flagged with
@API(API.Status.DEPRECATED)
and will be removed in the near future.I did not replace the integer usages in the internals of the record store, because I felt that code was complicated enough that it would be worth focusing on independently. I did change everything else to use the new code.
This also adds a bunch of documentation, and thus resolves: #710.
I also added a bunch of documentation to the
DatastoreInfo
, because a lot of the details of that are tightly coupled with the FormatVersion.Note: This is somewhat related to #3309 as some of the new paths will also throw an exception on invalid states, whereas the integer versions would not.