From 47d0b4a127657c8b27376934c378199c823300d4 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 19 Sep 2023 19:53:44 -0700 Subject: [PATCH] Make transport and index versions easier to extend When overriding transport and index versions, it is difficult to decide whether a version constant in serverless should be returned, or the latest version constant from serverless should be used, since the latest from serverless is not available. This commit adjust the version extension methods to pass in the latest serverless version constants. It also tweaks module and method visibility for a helper method needed. --- server/src/main/java/module-info.java | 6 +++++- .../main/java/org/elasticsearch/TransportVersion.java | 2 +- .../main/java/org/elasticsearch/TransportVersions.java | 2 +- .../java/org/elasticsearch/index/IndexVersion.java | 2 +- .../org/elasticsearch/internal/VersionExtension.java | 10 ++++++---- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/module-info.java b/server/src/main/java/module-info.java index 472707babf155..95749784afc45 100644 --- a/server/src/main/java/module-info.java +++ b/server/src/main/java/module-info.java @@ -279,7 +279,11 @@ exports org.elasticsearch.indices.recovery.plan; exports org.elasticsearch.indices.store; exports org.elasticsearch.ingest; - exports org.elasticsearch.internal to org.elasticsearch.serverless.version, org.elasticsearch.serverless.buildinfo; + exports org.elasticsearch.internal + to + org.elasticsearch.serverless.version, + org.elasticsearch.serverless.buildinfo, + org.elasticsearch.serverless.constants; exports org.elasticsearch.lucene.analysis.miscellaneous; exports org.elasticsearch.lucene.grouping; exports org.elasticsearch.lucene.queries; diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index 2aae6befb673a..92bb88f16385d 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -115,7 +115,7 @@ private static TransportVersion findCurrent() { if (versionExtension == null) { return TransportVersions.LATEST_DEFINED; } - var version = versionExtension.getCurrentTransportVersion(); + var version = versionExtension.getCurrentTransportVersion(TransportVersions.LATEST_DEFINED); assert version.onOrAfter(TransportVersions.LATEST_DEFINED); return version; } diff --git a/server/src/main/java/org/elasticsearch/TransportVersions.java b/server/src/main/java/org/elasticsearch/TransportVersions.java index 16a99d38f6623..989d57d7b6f6b 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersions.java +++ b/server/src/main/java/org/elasticsearch/TransportVersions.java @@ -216,7 +216,7 @@ static TransportVersion def(int id) { IDS = null; } - static NavigableMap getAllVersionIds(Class cls) { + public static NavigableMap getAllVersionIds(Class cls) { Map versionIdFields = new HashMap<>(); NavigableMap builder = new TreeMap<>(); diff --git a/server/src/main/java/org/elasticsearch/index/IndexVersion.java b/server/src/main/java/org/elasticsearch/index/IndexVersion.java index 49e2172b2f4b2..1cb03574afd86 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexVersion.java +++ b/server/src/main/java/org/elasticsearch/index/IndexVersion.java @@ -160,7 +160,7 @@ private static IndexVersion findCurrent() { if (versionExtension == null) { return LATEST_DEFINED; } - var version = versionExtension.getCurrentIndexVersion(); + var version = versionExtension.getCurrentIndexVersion(LATEST_DEFINED); assert version.onOrAfter(LATEST_DEFINED); assert version.luceneVersion.equals(Version.LATEST) diff --git a/server/src/main/java/org/elasticsearch/internal/VersionExtension.java b/server/src/main/java/org/elasticsearch/internal/VersionExtension.java index 83974b3b65158..9c1b515df4043 100644 --- a/server/src/main/java/org/elasticsearch/internal/VersionExtension.java +++ b/server/src/main/java/org/elasticsearch/internal/VersionExtension.java @@ -18,14 +18,16 @@ public interface VersionExtension { /** * Returns the {@link TransportVersion} that Elasticsearch should use. *

- * This must be at least equal to the latest version found in {@link TransportVersion} V_* constants. + * This must be at least as high as the given fallback. + * @param fallback The latest transport version from server */ - TransportVersion getCurrentTransportVersion(); + TransportVersion getCurrentTransportVersion(TransportVersion fallback); /** * Returns the {@link IndexVersion} that Elasticsearch should use. *

- * This must be at least equal to the latest version found in {@link IndexVersion} V_* constants. + * This must be at least as high as the given fallback. + * @param fallback The latest index version from server */ - IndexVersion getCurrentIndexVersion(); + IndexVersion getCurrentIndexVersion(IndexVersion fallback); }