Skip to content

Commit 44b7f88

Browse files
authored
Reformat & extend comments on TransportVersion (#97171)
Reflows the text to a width of 140, and adds a section about avoiding inappropriate uses of `TransportVersion`.
1 parent b79e03a commit 44b7f88

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

server/src/main/java/org/elasticsearch/TransportVersion.java

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,43 @@
2525
import java.util.TreeMap;
2626

2727
/**
28-
* Represents the version of the wire protocol used to communicate between ES nodes.
28+
* Represents the version of the wire protocol used to communicate between a pair of ES nodes.
2929
* <p>
30-
* Prior to 8.8.0, the release {@link Version} was used everywhere. This class separates the wire protocol version
31-
* from the release version.
30+
* Prior to 8.8.0, the release {@link Version} was used everywhere. This class separates the wire protocol version from the release version.
3231
* <p>
33-
* Each transport version constant has an id number, which for versions prior to 8.9.0 is the same as the release version
34-
* for backwards compatibility. In 8.9.0 this is changed to an incrementing number, disconnected from the release version.
32+
* 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
33+
* compatibility. In 8.9.0 this is changed to an incrementing number, disconnected from the release version.
3534
* <p>
36-
* Each version constant has a unique id string. This is not actually used in the binary protocol, but is there to ensure
37-
* each protocol version is only added to the source file once. This string needs to be unique (normally a UUID,
38-
* but can be any other unique nonempty string).
39-
* If two concurrent PRs add the same transport version, the different unique ids cause a git conflict, ensuring the second PR to be merged
40-
* must be updated with the next free version first. Without the unique id string, git will happily merge the two versions together,
41-
* resulting in the same transport version being used across multiple commits,
42-
* causing problems when you try to upgrade between those two merged commits.
35+
* Each version constant has a unique id string. This is not actually used in the binary protocol, but is there to ensure each protocol
36+
* 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
37+
* string). If two concurrent PRs add the same transport version, the different unique ids cause a git conflict, ensuring that the second PR
38+
* to be merged must be updated with the next free version first. Without the unique id string, git will happily merge the two versions
39+
* together, resulting in the same transport version being used across multiple commits, causing problems when you try to upgrade between
40+
* those two merged commits.
4341
* <h2>Version compatibility</h2>
44-
* The earliest compatible version is hardcoded in the {@link #MINIMUM_COMPATIBLE} field. Previously, this was dynamically calculated
45-
* from the major/minor versions of {@link Version}, but {@code TransportVersion} does not have separate major/minor version numbers.
46-
* So the minimum compatible version is hard-coded as the transport version used by the highest minor release of the previous major version.
47-
* {@link #MINIMUM_COMPATIBLE} should be updated appropriately whenever a major release happens.
42+
* The earliest compatible version is hardcoded in the {@link #MINIMUM_COMPATIBLE} field. Previously, this was dynamically calculated from
43+
* the major/minor versions of {@link Version}, but {@code TransportVersion} does not have separate major/minor version numbers. So the
44+
* minimum compatible version is hard-coded as the transport version used by the highest minor release of the previous major version. {@link
45+
* #MINIMUM_COMPATIBLE} should be updated appropriately whenever a major release happens.
4846
* <p>
49-
* The earliest CCS compatible version is hardcoded at {@link #MINIMUM_CCS_VERSION}, as the transport version used by the
50-
* previous minor release. This should be updated appropriately whenever a minor release happens.
47+
* The earliest CCS compatible version is hardcoded at {@link #MINIMUM_CCS_VERSION}, as the transport version used by the previous minor
48+
* release. This should be updated appropriately whenever a minor release happens.
5149
* <h2>Adding a new version</h2>
52-
* A new transport version should be added <em>every time</em> a change is made to the serialization protocol of one or more classes.
53-
* Each transport version should only be used in a single merged commit (apart from BwC versions copied from {@link Version}).
50+
* A new transport version should be added <em>every time</em> a change is made to the serialization protocol of one or more classes. Each
51+
* transport version should only be used in a single merged commit (apart from BwC versions copied from {@link Version}).
5452
* <p>
55-
* To add a new transport version, add a new constant at the bottom of the list that is one greater than the current highest version,
56-
* ensure it has a unique id, and update the {@link CurrentHolder#CURRENT} constant to point to the new version.
53+
* To add a new transport version, add a new constant at the bottom of the list that is one greater than the current highest version, ensure
54+
* it has a unique id, and update the {@link CurrentHolder#CURRENT} constant to point to the new version.
5755
* <h2>Reverting a transport version</h2>
58-
* If you revert a commit with a transport version change, you <em>must</em> ensure there is a <em>new</em> transport version
59-
* representing the reverted change. <em>Do not</em> let the transport version go backwards, it must <em>always</em> be incremented.
56+
* If you revert a commit with a transport version change, you <em>must</em> ensure there is a <em>new</em> transport version representing
57+
* the reverted change. <em>Do not</em> let the transport version go backwards, it must <em>always</em> be incremented.
58+
* <h2>Scope of usefulness of {@link TransportVersion}</h2>
59+
* {@link TransportVersion} is a property of the transport connection between a pair of nodes, and should not be used as an indication of
60+
* the version of any single node. The {@link TransportVersion} of a connection is negotiated between the nodes via some logic that is not
61+
* totally trivial, and may change in future. Any other places that might make decisions based on this version effectively have to reproduce
62+
* 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
63+
* different version value. If you need to know whether the cluster as a whole speaks a new enough {@link TransportVersion} to understand a
64+
* newly-added feature, use {@link org.elasticsearch.cluster.ClusterState#getMinTransportVersion}.
6065
*/
6166
public record TransportVersion(int id) implements Comparable<TransportVersion> {
6267

0 commit comments

Comments
 (0)