Skip to content

Commit

Permalink
getCurrentTransportVersion removed and other PR comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-ivanov-es committed Dec 2, 2024
1 parent 8ad7f3c commit eac4483
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
18 changes: 1 addition & 17 deletions server/src/main/java/org/elasticsearch/TransportVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
import org.elasticsearch.common.VersionId;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.internal.VersionExtension;
import org.elasticsearch.plugins.ExtensionLoader;

import java.io.IOException;
import java.util.ServiceLoader;

/**
* Represents the version of the wire protocol used to communicate between a pair of ES nodes.
Expand Down Expand Up @@ -95,7 +92,7 @@ public static boolean isCompatible(TransportVersion version) {
* This should be the transport version with the highest id.
*/
public static TransportVersion current() {
return CurrentHolder.CURRENT;
return TransportVersions.LATEST_DEFINED;
}

public static TransportVersion fromString(String str) {
Expand Down Expand Up @@ -138,17 +135,4 @@ public String toReleaseVersion() {
public String toString() {
return Integer.toString(id);
}

private static class CurrentHolder {
private static final TransportVersion CURRENT = findCurrent();

// finds the pluggable current version
private static TransportVersion findCurrent() {
var version = ExtensionLoader.loadSingleton(ServiceLoader.load(VersionExtension.class))
.map(e -> e.getCurrentTransportVersion(TransportVersions.LATEST_DEFINED))
.orElse(TransportVersions.LATEST_DEFINED);
assert version.onOrAfter(TransportVersions.LATEST_DEFINED);
return version;
}
}
}
8 changes: 4 additions & 4 deletions server/src/main/java/org/elasticsearch/TransportVersions.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static TransportVersion def(int id) {

static final NavigableMap<Integer, TransportVersion> VERSION_IDS = getAllVersionIds();

// the highest transport version constant defined in this file, used as a fallback for TransportVersion.current()
// the highest transport version constant defined
static final TransportVersion LATEST_DEFINED;
static {
LATEST_DEFINED = VERSION_IDS.lastEntry().getValue();
Expand All @@ -309,7 +309,7 @@ public static NavigableMap<Integer, TransportVersion> getAllVersionIds() {

public static NavigableMap<Integer, TransportVersion> collectAllVersionIdsDefinedInClass(Class<?> cls) {
Map<Integer, String> versionIdFields = new HashMap<>();
NavigableMap<Integer, TransportVersion> builder = new TreeMap<>();
NavigableMap<Integer, TransportVersion> definedTransportVersions = new TreeMap<>();

Set<String> ignore = Set.of("ZERO", "CURRENT", "MINIMUM_COMPATIBLE", "MINIMUM_CCS_VERSION");

Expand All @@ -326,7 +326,7 @@ public static NavigableMap<Integer, TransportVersion> collectAllVersionIdsDefine
} catch (IllegalAccessException e) {
throw new AssertionError(e);
}
builder.put(version.id(), version);
definedTransportVersions.put(version.id(), version);

if (Assertions.ENABLED) {
// check the version number is unique
Expand All @@ -343,7 +343,7 @@ public static NavigableMap<Integer, TransportVersion> collectAllVersionIdsDefine
}
}

return builder;
return definedTransportVersions;
}

static Collection<TransportVersion> getAllVersions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,15 @@
import org.elasticsearch.index.IndexVersion;

import java.util.Collection;
import java.util.Collections;

/**
* Allows plugging in current version elements.
*/
public interface VersionExtension {
/**
* Returns the {@link TransportVersion} that Elasticsearch should use.
* <p>
* This must be at least as high as the given fallback.
* @param fallback The latest transport version from server
*/
TransportVersion getCurrentTransportVersion(TransportVersion fallback);

/**
* Returns collection of {@link TransportVersion} defined by extension
*/
default Collection<TransportVersion> getTransportVersions() {
return Collections.emptyList();
}
Collection<TransportVersion> getTransportVersions();

/**
* Returns the {@link IndexVersion} that Elasticsearch should use.
Expand Down

0 comments on commit eac4483

Please sign in to comment.