Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Resolves #1639: Support a configurable FDB API version This makes the FDB API version configurable through the `FDBDatabaseFactory`. We'll need some better way of testing this, I think. I've tried running the tests at both the 6.3 and 7.1 API versions, and it passed, but this value cannot be changed after the client has been initiated, which makes this somewhat complex to test with our normal approach. We might be able to use a test-only implementation of `FDBDatabaseFactory` if we wanted to, say, test future work that had feature flags on the API version. Another approach might be to run the tests multiple times, once per API version. Also added the ability to make the API version a gradle configuration property. Setting `-PapiVersion=N` will run the tests at API version `N`. We could hook this up later to run the tests multiple times at different API versions if we wish This resolves #1639.
- Loading branch information
1 parent
36768b7
commit d19f7b2
Showing
15 changed files
with
398 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
...er-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/APIVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* APIVersion.java | ||
* | ||
* This source file is part of the FoundationDB open source project | ||
* | ||
* Copyright 2015-2022 Apple Inc. and the FoundationDB project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.apple.foundationdb.record.provider.foundationdb; | ||
|
||
import com.apple.foundationdb.annotation.API; | ||
import com.apple.foundationdb.record.RecordCoreArgumentException; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* An enum representing the different supported FDB API versions. The | ||
* <a href="https://apple.github.io/foundationdb/api-general.html#api-versions">FDB API version</a> | ||
* controls the minimum FDB server version that can be successfully connected to, as well as | ||
* what features are supported by the FDB client. It is therefore important that in scenarios where | ||
* there are FDB servers on different versions that the API version be configured to not exceed the | ||
* lowest FDB server version. If the API version is set too high, the FDB client may hang when | ||
* trying to connect to the server. | ||
* | ||
* <p> | ||
* Because FDB API versions also control which features are guaranteed to be supported, there may | ||
* be Record Layer features that are gated on specific FDB API versions. For that reason, if there | ||
* is a new feature that relies on specific FDB server features being available, the client may | ||
* need to be configured with the appropriate API version before that feature can be used. | ||
* </p> | ||
* | ||
* <p> | ||
* A note on Record Layer API stability: the elements of this enum are expected to shift as support | ||
* for FDB versions are deprecated and removed. As a result, the elements of this enum will be added | ||
* and removed as support for old FDB versions is dropped and new FDB versions is added. Setting the | ||
* API version to a non-default value is also currently an experimental feature as additional testing | ||
* and validation work to evaluate the library at various FDB API versions is developed. | ||
* </p> | ||
* | ||
* @see FDBDatabaseFactory#setAPIVersion(APIVersion) | ||
*/ | ||
@API(API.Status.EXPERIMENTAL) | ||
public enum APIVersion { | ||
/** | ||
* API version corresponding to FoundationDB 6.3. | ||
*/ | ||
API_VERSION_6_3(630), | ||
/** | ||
* API version corresponding to FoundationDB 7.0. | ||
*/ | ||
API_VERSION_7_0(700), | ||
/** | ||
* API version corresponding to FoundationDB 7.1. | ||
*/ | ||
API_VERSION_7_1(710), | ||
; | ||
|
||
private final int versionNumber; | ||
|
||
APIVersion(int versionNumber) { | ||
this.versionNumber = versionNumber; | ||
} | ||
|
||
/** | ||
* Get the API version number. This is the value passed to FDB during client initialization. | ||
* @return the version number associated with this version of the API | ||
*/ | ||
public int getVersionNumber() { | ||
return versionNumber; | ||
} | ||
|
||
/** | ||
* Whether this API version is at least as new as another API version. This is | ||
* useful for determining if a feature added at a certain API version is available. | ||
* | ||
* @param other the API version to compare against | ||
* @return whether this API version is at least the provided API version | ||
*/ | ||
public boolean isAtLeast(@Nonnull APIVersion other) { | ||
return versionNumber >= other.getVersionNumber(); | ||
} | ||
|
||
/** | ||
* Get the default API version. Unless the adopter overrides this value by calling | ||
* {@link FDBDatabaseFactory#setAPIVersion(APIVersion)}, this is the API version that will | ||
* be used to initialize the FDB client connection. | ||
* | ||
* <p> | ||
* This is currently {@link #API_VERSION_6_3}. | ||
* </p> | ||
* | ||
* @return the default API version | ||
*/ | ||
public static APIVersion getDefault() { | ||
return API_VERSION_6_3; | ||
} | ||
|
||
/** | ||
* Get the {@code APIVersion} enum from the version number. | ||
* @param versionNumber the FDB API version number | ||
* @return the corresponding enum value | ||
*/ | ||
public static APIVersion fromVersionNumber(int versionNumber) { | ||
for (APIVersion version : values()) { | ||
if (version.getVersionNumber() == versionNumber) { | ||
return version; | ||
} | ||
} | ||
throw new RecordCoreArgumentException("api version not supported"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.