Skip to content
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

Add a class for comparing versions of the record layer #3036

Merged
merged 5 commits into from
Jan 16, 2025

Conversation

ScottDugas
Copy link
Contributor

This introduces a class for parsing and comparing versions of the Record Layer.
This can be combined with the work in #3031 to control what versions a yaml test will run against.

@foundationdb-ci
Copy link
Contributor

Result of fdb-record-layer-pr on Linux CentOS 7

  • Commit ID: db66999
  • Duration 0:56:52
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of fdb-record-layer-pr on Linux CentOS 7

  • Commit ID: 74a17b8
  • Duration 0:54:25
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@@ -55,6 +55,7 @@ dependencies {
implementation(libs.asciitable)
implementation(libs.jsr305)
implementation(libs.junit.api)
implementation(libs.junit.params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch. I think this will conflict with a similar change I made.

* Thus, this spec implements only slightly more than what the Record Layer needs, which is to say:
* a sequence of positive numbers ({@code 0|[1-9]\\d*} separated by {@code .}s, and an optional {@code -SNAPSHOT}
* at the end. Each version component is compared as integers, and versions with a different number of components
* are not comparable. A version with {@code -SNAPSHOT} version added to the less than the same set of numbers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last sentence is unclear.

"(?:\\+(?<buildMetadata>" + dotSeparated(BUILD_PART) + "))?$");
private static final Pattern NUMERIC_PATTERN = Pattern.compile("\\d+");

private final List<Integer> versionNumbers;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some explanation of the prerelease and metadata parts (with example) could be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment about versionNumbers and ``prerelease`. Some of that was in the class javadoc.

I decided to remove buildMetadata. It's part of semver, but we don't support it.

return false;
}
final SemanticVersion that = (SemanticVersion)o;
return Objects.equals(versionNumbers, that.versionNumbers) && Objects.equals(prerelease, that.prerelease) && Objects.equals(buildMetadata, that.buildMetadata);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is theoretical, but is there meaning to the order of prerelease strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I added some flavor text to the javadoc on prerelease that hopefully makes it clear that there is, but we don't really support it.

if (NUMERIC_PATTERN.matcher(otherPart).matches()) {
int thisNumber = Integer.parseInt(thisPart);
int otherNumber = Integer.parseInt(otherPart);
if (thisNumber < otherNumber) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may add extra cost of boxing and unboxing, but maybe Objects.compare() here may be clearer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int result = Objects.compare(thisNumber, otherNumber);
if (result != 0) {
    result result;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only support SNAPSHOT or nothing, I removed this whole section, but I took your change and applied a variant of it to the version comparison code.

final SemanticVersion versionB = SemanticVersion.parse(rawVersionB);
Assertions.assertAll(
() -> assertEquals(0, versionA.compareTo(versionB)),
() -> assertEquals(0, versionA.compareTo(versionB)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
() -> assertEquals(0, versionA.compareTo(versionB)));
() -> assertEquals(0, versionB.compareTo(versionA)));

void alignsWithComparator(int versionA, int versionB) {
// Ensure that the signage aligns with the standard `compare` methods
// the value doesn't have to, but it does, and this is easier than asserting that they have the same sign
assertEquals(Integer.compare(versionA, versionB),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use signum()?

assertEquals(
    Integer.compare(a, b).signum(), 
    SemanticVersion.parse(versionA + ".0.0").compareTo(
                         SemanticVersion.parse(versionB + ".0.0")).signum();

() -> assertThrows(IllegalArgumentException.class,
() -> versionA.compareTo(versionB)),
() -> assertThrows(IllegalArgumentException.class,
() -> versionA.compareTo(versionB)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
() -> versionA.compareTo(versionB)));
() -> versionB.compareTo(versionA)));

@ohadzeliger
Copy link
Contributor

Maybe add some tests with parse(null) and compare to(null)?

ScottDugas added a commit to ScottDugas/fdb-record-layer that referenced this pull request Jan 15, 2025
This does:
1. expands / cleans up comments in `SemanticVersion`
2. Removes buildMetadata from the regex, and the field.
3. Removes comparison of prerelease with more than one component.
   We already don't support parsing multiple components.
4. Take advantage of `Integer.compare` and `Integer.signum` in code
   and tests
5. Fix the tests that were supposed to alternate the comparison order
   but I accidentally put the same order in twice.
6. Test for null arguments, and add @nonnull annotations
@foundationdb-ci
Copy link
Contributor

Result of fdb-record-layer-pr on Linux CentOS 7

  • Commit ID: d99ad0e
  • Duration 0:51:14
  • Result: ❌ FAILED
  • Error: Error while executing command: ./gradlew --no-daemon --console=plain -b ./build.gradle build destructiveTest -PcoreNotStrict -PreleaseBuild=false -PpublishBuild=false -PspotbugsEnableHtmlReport. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

This does:
1. expands / cleans up comments in `SemanticVersion`
2. Removes buildMetadata from the regex, and the field.
3. Removes comparison of prerelease with more than one component.
   We already don't support parsing multiple components.
4. Take advantage of `Integer.compare` and `Integer.signum` in code
   and tests
5. Fix the tests that were supposed to alternate the comparison order
   but I accidentally put the same order in twice.
6. Test for null arguments, and add @nonnull annotations
Conflicted on yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/server/package-info.java
but it was just comments (years and javadoc)
@foundationdb-ci
Copy link
Contributor

Result of fdb-record-layer-pr on Linux CentOS 7

  • Commit ID: f291b97
  • Duration 0:53:27
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of fdb-record-layer-pr on Linux CentOS 7

  • Commit ID: 8f79f46
  • Duration 0:53:35
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

Copy link
Contributor

@ohadzeliger ohadzeliger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment change

ohadzeliger
ohadzeliger previously approved these changes Jan 15, 2025
@foundationdb-ci
Copy link
Contributor

Result of fdb-record-layer-pr on Linux CentOS 7

  • Commit ID: 9d90c7c
  • Duration 0:50:52
  • Result: ❌ FAILED
  • Error: Error while executing command: ./gradlew --no-daemon --console=plain -b ./build.gradle build destructiveTest -PcoreNotStrict -PreleaseBuild=false -PpublishBuild=false -PspotbugsEnableHtmlReport. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of fdb-record-layer-pr on Linux CentOS 7

  • Commit ID: fef2ded
  • Duration 0:54:00
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@ohadzeliger ohadzeliger merged commit a7468b1 into FoundationDB:main Jan 16, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants