Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/112242.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 112242
summary: Fix toReleaseVersion() when called on the current version id
area: Infra/Core
type: bug
issues: [111900]
9 changes: 6 additions & 3 deletions server/src/main/java/org/elasticsearch/ReleaseVersions.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ReleaseVersions {

private static final Pattern VERSION_LINE = Pattern.compile("(\\d+\\.\\d+\\.\\d+),(\\d+)");

public static IntFunction<String> generateVersionsLookup(Class<?> versionContainer) {
public static IntFunction<String> generateVersionsLookup(Class<?> versionContainer, int current) {
if (USES_VERSIONS == false) return Integer::toString;

try {
Expand All @@ -52,6 +52,9 @@ public static IntFunction<String> generateVersionsLookup(Class<?> versionContain
}

NavigableMap<Integer, List<Version>> versions = new TreeMap<>();
// add the current version id, which won't be in the csv
versions.computeIfAbsent(current, k -> new ArrayList<>()).add(Version.CURRENT);

try (BufferedReader reader = new BufferedReader(new InputStreamReader(versionsFile, StandardCharsets.UTF_8))) {
String line;
while ((line = reader.readLine()) != null) {
Expand Down Expand Up @@ -121,8 +124,8 @@ private static IntFunction<String> lookupFunction(NavigableMap<Integer, List<Ver
// too hard to guess what version this id might be for using the next version - just use it directly
upperBound = upperRange.getValue().get(0).toString();
} else {
// likely a version created after the last release tagged version - ok
upperBound = "snapshot[" + id + "]";
// a newer version than all we know about? Can't map it...
upperBound = "[" + id + "]";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ static Collection<TransportVersion> getAllVersions() {
return VERSION_IDS.values();
}

static final IntFunction<String> VERSION_LOOKUP = ReleaseVersions.generateVersionsLookup(TransportVersions.class);
static final IntFunction<String> VERSION_LOOKUP = ReleaseVersions.generateVersionsLookup(TransportVersions.class, LATEST_DEFINED.id());

// no instance
private TransportVersions() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static Collection<IndexVersion> getAllVersions() {
return VERSION_IDS.values();
}

static final IntFunction<String> VERSION_LOOKUP = ReleaseVersions.generateVersionsLookup(IndexVersions.class);
static final IntFunction<String> VERSION_LOOKUP = ReleaseVersions.generateVersionsLookup(IndexVersions.class, LATEST_DEFINED.id());

// no instance
private IndexVersions() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@
public class ReleaseVersionsTests extends ESTestCase {

public void testReleaseVersions() {
IntFunction<String> versions = ReleaseVersions.generateVersionsLookup(ReleaseVersionsTests.class);
IntFunction<String> versions = ReleaseVersions.generateVersionsLookup(ReleaseVersionsTests.class, 23);

assertThat(versions.apply(10), equalTo("8.0.0"));
assertThat(versions.apply(14), equalTo("8.1.0-8.1.1"));
assertThat(versions.apply(21), equalTo("8.2.0"));
assertThat(versions.apply(22), equalTo("8.2.1"));
assertThat(versions.apply(23), equalTo(Version.CURRENT.toString()));
}

public void testReturnsRange() {
IntFunction<String> versions = ReleaseVersions.generateVersionsLookup(ReleaseVersionsTests.class);
IntFunction<String> versions = ReleaseVersions.generateVersionsLookup(ReleaseVersionsTests.class, 23);

assertThat(versions.apply(17), equalTo("8.1.2-8.2.0"));
assertThat(versions.apply(9), equalTo("0.0.0"));
assertThat(versions.apply(24), equalTo("8.2.2-snapshot[24]"));
assertThat(versions.apply(24), equalTo(new Version(Version.CURRENT.id + 100) + "-[24]"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.regex.Pattern;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -186,6 +187,10 @@ public void testCURRENTIsLatest() {
assertThat(Collections.max(TransportVersions.getAllVersions()), is(TransportVersion.current()));
}

public void testToReleaseVersion() {
assertThat(TransportVersion.current().toReleaseVersion(), endsWith(Version.CURRENT.toString()));
}

public void testToString() {
assertEquals("5000099", TransportVersion.fromId(5_00_00_99).toString());
assertEquals("2030099", TransportVersion.fromId(2_03_00_99).toString());
Expand Down