- All Implemented Interfaces:
Comparable<TransportVersion>,VersionId<TransportVersion>
Defining transport versions
Transport versions can be defined anywhere, including in plugins/modules. Defining a new transport version is done via thefromName(String) method, for example:
private static final TransportVersion MY_NEW_TRANSPORT_VERSION = TransportVersion.fromName("my-new-transport-version");
Names must be logically unique. The same name must not be used to represent two transport versions with differing behavior. However,
the same name may be used to define the same constant at multiple use-sites. Alternatively, a single constant can be shared across
multiple use sites.
Version compatibility
The earliest compatible version is hardcoded in theTransportVersion.VersionsHolder.MINIMUM_COMPATIBLE field. Previously, this was dynamically
calculated from the major/minor versions of Version, but TransportVersion does not have separate major/minor version
numbers. So the minimum compatible version is hard-coded as the transport version used by the highest minor release of the previous
major version. TransportVersion.VersionsHolder.MINIMUM_COMPATIBLE should be updated appropriately whenever a major release happens.
The earliest CCS compatible version is hardcoded at TransportVersion.VersionsHolder.MINIMUM_CCS_VERSION, as the transport version used by the
previous minor release. This should be updated appropriately whenever a minor release happens.
Scope of usefulness of TransportVersion
TransportVersion is a property of the transport connection between a pair of nodes, and should not be used as an indication of
the version of any single node. The TransportVersion of a connection is negotiated between the nodes via some logic that is not
totally trivial, and may change in future. Any other places that might make decisions based on this version effectively have to reproduce
this negotiation logic, which would be fragile. If you need to make decisions based on the version of a single node, do so using a
different version value. If you need to know whether the cluster as a whole speaks a new enough TransportVersion to understand a
newly-added feature, use ClusterState.getMinTransportVersion().-
Constructor Summary
ConstructorsConstructorDescriptionTransportVersion(int id) Constructs an unnamed transport version.TransportVersion(String name, int id, TransportVersion nextPatchVersion) Creates an instance of aTransportVersionrecord class. -
Method Summary
Modifier and TypeMethodDescriptionbooleanafter(TransportVersion version) Deprecated, for removal: This API element is subject to removal in a future version.booleanbetween(TransportVersion lowerInclusive, TransportVersion upperExclusive) Deprecated, for removal: This API element is subject to removal in a future version.static List<TransportVersion> collectFromResources(String component, String resourceRoot, Function<String, InputStream> resourceLoader, String upperBoundFileName) static TransportVersioncurrent()Reference to the most recent transport version.booleanIndicates whether some other object is "equal to" this one.static TransportVersionfromId(int id) Finds aTransportVersionby its id.static TransportVersionFinds aTransportVersionby its name.static TransportVersionfromString(String str) static List<TransportVersion> Sorted list of all defined transport versionsinthashCode()Returns a hash code value for this object.intid()Returns the value of theidrecord component.static booleanisCompatible(TransportVersion version) Returnstrueif the specified version is compatible with this running version of Elasticsearch.booleanisKnown()booleanisPatchFrom(TransportVersion version) Returnstrueif this version is a patch version at or afterversion.static TransportVersionmax(TransportVersion version1, TransportVersion version2) Returns the maximum version ofversion1andversion2static TransportVersionmin(TransportVersion version1, TransportVersion version2) Returns the minimum version ofversion1andversion2static TransportVersionReference to the minimum transport version that can be used with CCS.static TransportVersionReference to the earliest compatible transport version to this version of the codebase.name()Returns the value of thenamerecord component.Returns the value of thenextPatchVersionrecord component.booleanonOrAfter(TransportVersion version) Deprecated, for removal: This API element is subject to removal in a future version.static TransportVersionbooleansupports(TransportVersion version) Supports is used to determine if a named transport version is supported by a caller transport version.Returns a string representing the Elasticsearch release version of this transport version, if applicable for this deployment, otherwise the raw version number.toString()Returns a string representation of this record class.static voidwriteVersion(TransportVersion version, StreamOutput out) static TransportVersionzero()Sentinel value for lowest possible transport versionMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.common.VersionId
before, compareTo, onOrBefore
-
Constructor Details
-
TransportVersion
public TransportVersion(int id) Constructs an unnamed transport version. -
TransportVersion
Creates an instance of aTransportVersionrecord class.- Parameters:
name- the value for thenamerecord componentid- the value for theidrecord componentnextPatchVersion- the value for thenextPatchVersionrecord component
-
-
Method Details
-
after
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
afterin interfaceVersionId<TransportVersion>
-
onOrAfter
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
onOrAfterin interfaceVersionId<TransportVersion>
-
between
@Deprecated(forRemoval=true) public boolean between(TransportVersion lowerInclusive, TransportVersion upperExclusive) Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
betweenin interfaceVersionId<TransportVersion>
-
collectFromResources
public static List<TransportVersion> collectFromResources(String component, String resourceRoot, Function<String, InputStream> resourceLoader, String upperBoundFileName) -
readVersion
- Throws:
IOException
-
fromId
Finds aTransportVersionby its id. If a transport version with the specified ID does not exist, this method creates and returns a new instance ofTransportVersionwith the specified ID. The new instance is not registered inTransportVersion.getAllVersions. -
fromName
Finds aTransportVersionby its name. The parameternamemust be aStringdirect value or validation checks will fail.TransportVersion.fromName("direct_value").This will only return the latest known referable transport version for a given name and not its patch versions. Patch versions are constructed as a linked list internally and may be found by cycling through them in a loop using
nextPatchVersion(). -
writeVersion
- Throws:
IOException
-
min
Returns the minimum version ofversion1andversion2 -
max
Returns the maximum version ofversion1andversion2 -
isCompatible
Returnstrueif the specified version is compatible with this running version of Elasticsearch. -
current
Reference to the most recent transport version. This should be the transport version with the highest id. -
zero
Sentinel value for lowest possible transport version -
minimumCompatible
Reference to the earliest compatible transport version to this version of the codebase. This should be the transport version used by the highest minor version of the previous major. -
minimumCCSVersion
Reference to the minimum transport version that can be used with CCS. This should be the transport version used by the previous minor release. -
getAllVersions
Sorted list of all defined transport versions -
isKnown
public boolean isKnown()- Returns:
- whether this is a known
TransportVersion, i.e. one declared viafromName(String). Other versions may exist in the wild (they're sent over the wire by numeric ID) but we don't know how to communicate using such versions.
-
bestKnownVersion
- Returns:
- the newest known
TransportVersionwhich is no older than this instance. ReturnsTransportVersion.VersionsHolder.ZEROif there are no such versions.
-
fromString
-
isPatchFrom
Returnstrueif this version is a patch version at or afterversion. -
supports
Supports is used to determine if a named transport version is supported by a caller transport version. This will check both the latest id and all of its patch ids for compatibility. This replaces the pattern ofwireTV.onOrAfter(TV_FEATURE) || wireTV.isPatchFrom(TV_FEATURE_BACKPORT) || ...for unnamed transport versions withwireTV.supports(TV_FEATURE)for named transport versions (since referable versions know about their own patch versions).The recommended use of this method is to declare a static final
TransportVersionas part of the file that it's used in. This constant is then used in conjunction with this method to check transport version compatability.An example:
public class ExampleClass { ... TransportVersion TV_FEATURE = TransportVersion.fromName("tv_feature"); ... public static ExampleClass readFrom(InputStream in) { ... if (in.getTransportVersion().supports(TV_FEATURE) { // read newer values } ... } ... public void writeTo(OutputStream out) { ... if (out.getTransportVersion().supports(TV_FEATURE) { // write newer values } ... } ... } -
toReleaseVersion
Returns a string representing the Elasticsearch release version of this transport version, if applicable for this deployment, otherwise the raw version number. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
hashCode
public int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
name
Returns the value of thenamerecord component.- Returns:
- the value of the
namerecord component
-
id
public int id()Returns the value of theidrecord component.- Specified by:
idin interfaceVersionId<TransportVersion>- Returns:
- the value of the
idrecord component
-
nextPatchVersion
Returns the value of thenextPatchVersionrecord component.- Returns:
- the value of the
nextPatchVersionrecord component
-