Record Class TransportVersion

java.lang.Object
java.lang.Record
org.elasticsearch.TransportVersion
All Implemented Interfaces:
Comparable<TransportVersion>, VersionId<TransportVersion>

public record TransportVersion(String name, int id, TransportVersion nextPatchVersion) extends Record implements VersionId<TransportVersion>
Represents the version of the wire protocol used to communicate between a pair of ES nodes.

Note: We are currently transitioning to a file-based system to load and maintain transport versions. These file-based transport versions are named and are referred to as named transport versions. Named transport versions also maintain a linked list of their own patch versions to simplify transport version compatibility checks. Transport versions that continue to be loaded through TransportVersions are referred to as unnamed transport versions. Unnamed transport versions will continue being used over the wire as we only need the id for compatibility checks even against named transport versions. There are changes throughout TransportVersion that are for this transition. For now, continue to use the existing system of adding unnamed transport versions to TransportVersions.

Prior to 8.8.0, the release Version was used everywhere. This class separates the wire protocol version from the release version.

Each transport version constant has an id number, which for versions prior to 8.9.0 is the same as the release version for backwards compatibility. In 8.9.0 this is changed to an incrementing number, disconnected from the release version.

Each version constant has a unique id string. This is not actually used in the binary protocol, but is there to ensure each protocol version is only added to the source file once. This string needs to be unique (normally a UUID, but can be any other unique nonempty string). If two concurrent PRs add the same transport version, the different unique ids cause a git conflict, ensuring that the second PR to be merged must be updated with the next free version first. Without the unique id string, git will happily merge the two versions together, resulting in the same transport version being used across multiple commits, causing problems when you try to upgrade between those two merged commits.

Version compatibility

The earliest compatible version is hardcoded in the TransportVersion.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 Details

    • TransportVersion

      public TransportVersion(int id)
      Constructs an unnamed transport version.
    • TransportVersion

      public TransportVersion(String name, int id, TransportVersion nextPatchVersion)
      Creates an instance of a TransportVersion record class.
      Parameters:
      name - the value for the name record component
      id - the value for the id record component
      nextPatchVersion - the value for the nextPatchVersion record component
  • Method Details

    • fromBufferedReader

      public static TransportVersion fromBufferedReader(String component, String path, boolean nameInFile, boolean isNamed, BufferedReader bufferedReader, Integer upperBound)
      Constructs a named transport version along with its set of compatible patch versions from x-content. This method takes in the parameter upperBound which is the highest transport version id that will be loaded by this node.
    • collectFromInputStreams

      public static List<TransportVersion> collectFromInputStreams(String component, String resourceRoot, Function<String,InputStream> resourceLoader, String upperBoundFileName)
    • readVersion

      public static TransportVersion readVersion(StreamInput in) throws IOException
      Throws:
      IOException
    • fromId

      public static TransportVersion fromId(int id)
      Finds a TransportVersion by its id. If a transport version with the specified ID does not exist, this method creates and returns a new instance of TransportVersion with the specified ID. The new instance is not registered in TransportVersion.getAllVersions.
    • fromName

      public static TransportVersion fromName(String name)
      Finds a TransportVersion by its name. The parameter name must be a String direct 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

      public static void writeVersion(TransportVersion version, StreamOutput out) throws IOException
      Throws:
      IOException
    • min

      public static TransportVersion min(TransportVersion version1, TransportVersion version2)
      Returns the minimum version of version1 and version2
    • max

      public static TransportVersion max(TransportVersion version1, TransportVersion version2)
      Returns the maximum version of version1 and version2
    • isCompatible

      public static boolean isCompatible(TransportVersion version)
      Returns true if the specified version is compatible with this running version of Elasticsearch.
    • current

      public static TransportVersion current()
      Reference to the most recent transport version. This should be the transport version with the highest id.
    • zero

      public static TransportVersion zero()
      Sentinel value for lowest possible transport version
    • minimumCompatible

      public static TransportVersion 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

      public static TransportVersion 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

      public static List<TransportVersion> getAllVersions()
      Sorted list of all defined transport versions
    • isKnown

      public boolean isKnown()
      Returns:
      whether this is a known TransportVersion, i.e. one declared in TransportVersions. 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

      public TransportVersion bestKnownVersion()
      Returns:
      the newest known TransportVersion which is no older than this instance. Returns TransportVersion.VersionsHolder.ZERO if there are no such versions.
    • fromString

      public static TransportVersion fromString(String str)
    • isPatchFrom

      public boolean isPatchFrom(TransportVersion version)
      Returns true if this version is a patch version at or after version.

      This should not be used normally. It is used for matching patch versions of the same base version, using the standard version number format specified in TransportVersions. When a patch version of an existing transport version is created, transportVersion.isPatchFrom(patchVersion) will match any transport version at or above patchVersion that is also of the same base version.

      For example, version.isPatchFrom(8_800_0_04) will return the following for the given version:

      • 8_799_0_00.isPatchFrom(8_800_0_04): false
      • 8_799_0_09.isPatchFrom(8_800_0_04): false
      • 8_800_0_00.isPatchFrom(8_800_0_04): false
      • 8_800_0_03.isPatchFrom(8_800_0_04): false
      • 8_800_0_04.isPatchFrom(8_800_0_04): true
      • 8_800_0_49.isPatchFrom(8_800_0_04): true
      • 8_800_1_00.isPatchFrom(8_800_0_04): false
      • 8_801_0_00.isPatchFrom(8_800_0_04): false
    • supports

      public boolean supports(TransportVersion version)
      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 of wireTV.onOrAfter(TV_FEATURE) || wireTV.isPatchFrom(TV_FEATURE_BACKPORT) || ... for unnamed transport versions with wireTV.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 TransportVersion as 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

      public String toReleaseVersion()
      Returns a string representing the Elasticsearch release version of this transport version, if applicable for this deployment, otherwise the raw version number.
    • equals

      public boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • toString

      public String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • id

      public int id()
      Returns the value of the id record component.
      Specified by:
      id in interface VersionId<TransportVersion>
      Returns:
      the value of the id record component
    • nextPatchVersion

      public TransportVersion nextPatchVersion()
      Returns the value of the nextPatchVersion record component.
      Returns:
      the value of the nextPatchVersion record component