Skip to content

Commit bc270bd

Browse files
authored
Add BuildVersion to DiscoveryNode VersionInformation (#115434)
1 parent e9f3add commit bc270bd

File tree

17 files changed

+95
-92
lines changed

17 files changed

+95
-92
lines changed

server/src/internalClusterTest/java/org/elasticsearch/cluster/ClusterStateDiffIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void testClusterStateDiffSerialization() throws Exception {
147147
for (Map.Entry<String, DiscoveryNode> node : clusterStateFromDiffs.nodes().getNodes().entrySet()) {
148148
DiscoveryNode node1 = clusterState.nodes().get(node.getKey());
149149
DiscoveryNode node2 = clusterStateFromDiffs.nodes().get(node.getKey());
150-
assertThat(node1.getVersion(), equalTo(node2.getVersion()));
150+
assertThat(node1.getBuildVersion(), equalTo(node2.getBuildVersion()));
151151
assertThat(node1.getAddress(), equalTo(node2.getAddress()));
152152
assertThat(node1.getAttributes(), equalTo(node2.getAttributes()));
153153
}

server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import org.elasticsearch.common.transport.TransportAddress;
2222
import org.elasticsearch.common.util.StringLiteralDeduplicator;
2323
import org.elasticsearch.core.Nullable;
24+
import org.elasticsearch.env.BuildVersion;
2425
import org.elasticsearch.index.IndexVersion;
25-
import org.elasticsearch.index.IndexVersions;
2626
import org.elasticsearch.node.Node;
2727
import org.elasticsearch.xcontent.ToXContentFragment;
2828
import org.elasticsearch.xcontent.XContentBuilder;
@@ -33,7 +33,6 @@
3333
import java.util.Map;
3434
import java.util.Objects;
3535
import java.util.Optional;
36-
import java.util.OptionalInt;
3736
import java.util.Set;
3837
import java.util.SortedSet;
3938
import java.util.TreeSet;
@@ -290,18 +289,6 @@ public static Set<DiscoveryNodeRole> getRolesFromSettings(final Settings setting
290289
return Set.copyOf(NODE_ROLES_SETTING.get(settings));
291290
}
292291

293-
private static VersionInformation inferVersionInformation(Version version) {
294-
if (version.before(Version.V_8_10_0)) {
295-
return new VersionInformation(
296-
version,
297-
IndexVersion.getMinimumCompatibleIndexVersion(version.id),
298-
IndexVersion.fromId(version.id)
299-
);
300-
} else {
301-
return new VersionInformation(version, IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current());
302-
}
303-
}
304-
305292
private static final Writeable.Reader<String> readStringLiteral = s -> nodeStringDeduplicator.deduplicate(s.readString());
306293

307294
/**
@@ -338,11 +325,7 @@ public DiscoveryNode(StreamInput in) throws IOException {
338325
}
339326
}
340327
this.roles = Collections.unmodifiableSortedSet(roles);
341-
if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_10_X)) {
342-
versionInfo = new VersionInformation(Version.readVersion(in), IndexVersion.readVersion(in), IndexVersion.readVersion(in));
343-
} else {
344-
versionInfo = inferVersionInformation(Version.readVersion(in));
345-
}
328+
versionInfo = new VersionInformation(Version.readVersion(in), IndexVersion.readVersion(in), IndexVersion.readVersion(in));
346329
if (in.getTransportVersion().onOrAfter(EXTERNAL_ID_VERSION)) {
347330
this.externalId = readStringLiteral.read(in);
348331
} else {
@@ -375,13 +358,9 @@ public void writeTo(StreamOutput out) throws IOException {
375358
o.writeString(role.roleNameAbbreviation());
376359
o.writeBoolean(role.canContainData());
377360
});
378-
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_10_X)) {
379-
Version.writeVersion(versionInfo.nodeVersion(), out);
380-
IndexVersion.writeVersion(versionInfo.minIndexVersion(), out);
381-
IndexVersion.writeVersion(versionInfo.maxIndexVersion(), out);
382-
} else {
383-
Version.writeVersion(versionInfo.nodeVersion(), out);
384-
}
361+
Version.writeVersion(versionInfo.nodeVersion(), out);
362+
IndexVersion.writeVersion(versionInfo.minIndexVersion(), out);
363+
IndexVersion.writeVersion(versionInfo.maxIndexVersion(), out);
385364
if (out.getTransportVersion().onOrAfter(EXTERNAL_ID_VERSION)) {
386365
out.writeString(externalId);
387366
}
@@ -486,18 +465,13 @@ public VersionInformation getVersionInformation() {
486465
return this.versionInfo;
487466
}
488467

489-
public Version getVersion() {
490-
return this.versionInfo.nodeVersion();
468+
public BuildVersion getBuildVersion() {
469+
return versionInfo.buildVersion();
491470
}
492471

493-
public OptionalInt getPre811VersionId() {
494-
// Even if Version is removed from this class completely it will need to read the version ID
495-
// off the wire for old node versions, so the value of this variable can be obtained from that
496-
int versionId = versionInfo.nodeVersion().id;
497-
if (versionId >= Version.V_8_11_0.id) {
498-
return OptionalInt.empty();
499-
}
500-
return OptionalInt.of(versionId);
472+
@Deprecated
473+
public Version getVersion() {
474+
return this.versionInfo.nodeVersion();
501475
}
502476

503477
public IndexVersion getMinIndexVersion() {
@@ -564,7 +538,7 @@ public void appendDescriptionWithoutAttributes(StringBuilder stringBuilder) {
564538
appendRoleAbbreviations(stringBuilder, "");
565539
stringBuilder.append('}');
566540
}
567-
stringBuilder.append('{').append(versionInfo.nodeVersion()).append('}');
541+
stringBuilder.append('{').append(versionInfo.buildVersion()).append('}');
568542
stringBuilder.append('{').append(versionInfo.minIndexVersion()).append('-').append(versionInfo.maxIndexVersion()).append('}');
569543
}
570544

@@ -601,7 +575,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
601575
builder.value(role.roleName());
602576
}
603577
builder.endArray();
604-
builder.field("version", versionInfo.nodeVersion());
578+
builder.field("version", versionInfo.buildVersion().toString());
605579
builder.field("min_index_version", versionInfo.minIndexVersion());
606580
builder.field("max_index_version", versionInfo.maxIndexVersion());
607581
builder.endObject();

server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ public boolean hasByName(String name) {
339339
return false;
340340
}
341341

342+
/**
343+
* {@code true} if this cluster consists of nodes with several release versions
344+
*/
345+
public boolean isMixedVersionCluster() {
346+
return minNodeVersion.equals(maxNodeVersion) == false;
347+
}
348+
342349
/**
343350
* Returns the version of the node with the oldest version in the cluster that is not a client node
344351
*

server/src/main/java/org/elasticsearch/cluster/node/VersionInformation.java

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,57 @@
1010
package org.elasticsearch.cluster.node;
1111

1212
import org.elasticsearch.Version;
13+
import org.elasticsearch.env.BuildVersion;
1314
import org.elasticsearch.index.IndexVersion;
1415
import org.elasticsearch.index.IndexVersions;
1516

1617
import java.util.Objects;
1718

1819
/**
1920
* Represents the versions of various aspects of an Elasticsearch node.
20-
* @param nodeVersion The node {@link Version}
21+
* @param buildVersion The node {@link BuildVersion}
2122
* @param minIndexVersion The minimum {@link IndexVersion} supported by this node
2223
* @param maxIndexVersion The maximum {@link IndexVersion} supported by this node
2324
*/
24-
public record VersionInformation(Version nodeVersion, IndexVersion minIndexVersion, IndexVersion maxIndexVersion) {
25+
public record VersionInformation(
26+
BuildVersion buildVersion,
27+
Version nodeVersion,
28+
IndexVersion minIndexVersion,
29+
IndexVersion maxIndexVersion
30+
) {
2531

2632
public static final VersionInformation CURRENT = new VersionInformation(
27-
Version.CURRENT,
33+
BuildVersion.current(),
2834
IndexVersions.MINIMUM_COMPATIBLE,
2935
IndexVersion.current()
3036
);
3137

38+
public VersionInformation {
39+
Objects.requireNonNull(buildVersion);
40+
Objects.requireNonNull(nodeVersion);
41+
Objects.requireNonNull(minIndexVersion);
42+
Objects.requireNonNull(maxIndexVersion);
43+
}
44+
45+
public VersionInformation(BuildVersion version, IndexVersion minIndexVersion, IndexVersion maxIndexVersion) {
46+
this(version, Version.CURRENT, minIndexVersion, maxIndexVersion);
47+
/*
48+
* Whilst DiscoveryNode.getVersion exists, we need to be able to get a Version from VersionInfo
49+
* This needs to be consistent - on serverless, BuildVersion has an id of -1, which translates
50+
* to a nonsensical Version. So all consumers of Version need to be moved to BuildVersion
51+
* before we can remove Version from here.
52+
*/
53+
// for the moment, check this is only called with current() so the implied Version is correct
54+
// TODO: work out what needs to happen for other versions. Maybe we can only remove this once the nodeVersion field is gone
55+
assert version.equals(BuildVersion.current()) : version + " is not " + BuildVersion.current();
56+
}
57+
58+
@Deprecated
59+
public VersionInformation(Version version, IndexVersion minIndexVersion, IndexVersion maxIndexVersion) {
60+
this(BuildVersion.fromVersionId(version.id()), version, minIndexVersion, maxIndexVersion);
61+
}
62+
63+
@Deprecated
3264
public static VersionInformation inferVersions(Version nodeVersion) {
3365
if (nodeVersion == null) {
3466
return null;
@@ -44,10 +76,4 @@ public static VersionInformation inferVersions(Version nodeVersion) {
4476
throw new IllegalArgumentException("Node versions can only be inferred before release version 8.10.0");
4577
}
4678
}
47-
48-
public VersionInformation {
49-
Objects.requireNonNull(nodeVersion);
50-
Objects.requireNonNull(minIndexVersion);
51-
Objects.requireNonNull(maxIndexVersion);
52-
}
5379
}

server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ Table buildTable(
367367
table.addCell("-");
368368
}
369369

370-
table.addCell(node.getVersion().toString());
370+
table.addCell(node.getBuildVersion().toString());
371371
table.addCell(info == null ? null : info.getBuild().type().displayName());
372372
table.addCell(info == null ? null : info.getBuild().hash());
373373
table.addCell(jvmInfo == null ? null : jvmInfo.version());

server/src/main/java/org/elasticsearch/rest/action/cat/RestTasksAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private static void buildRow(Table table, boolean fullId, boolean detailed, Disc
140140
table.addCell(node == null ? "-" : node.getHostAddress());
141141
table.addCell(node.getAddress().address().getPort());
142142
table.addCell(node == null ? "-" : node.getName());
143-
table.addCell(node == null ? "-" : node.getVersion().toString());
143+
table.addCell(node == null ? "-" : node.getBuildVersion().toString());
144144
table.addCell(taskInfo.headers().getOrDefault(Task.X_OPAQUE_ID_HTTP_HEADER, "-"));
145145

146146
if (detailed) {

server/src/test/java/org/elasticsearch/action/support/master/TransportMasterNodeActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ public void testDelegateToFailingMaster() throws ExecutionException, Interrupted
576576
// simulate master restart followed by a state recovery - this will reset the cluster state version
577577
final DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder(clusterService.state().nodes());
578578
nodesBuilder.remove(masterNode);
579-
masterNode = DiscoveryNodeUtils.create(masterNode.getId(), masterNode.getAddress(), masterNode.getVersion());
579+
masterNode = DiscoveryNodeUtils.create(masterNode.getId(), masterNode.getAddress(), masterNode.getVersionInformation());
580580
nodesBuilder.add(masterNode);
581581
nodesBuilder.masterNodeId(masterNode.getId());
582582
final ClusterState.Builder builder = ClusterState.builder(clusterService.state()).nodes(nodesBuilder);

server/src/test/java/org/elasticsearch/cluster/metadata/AutoExpandReplicasTests.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package org.elasticsearch.cluster.metadata;
1010

1111
import org.elasticsearch.TransportVersion;
12-
import org.elasticsearch.Version;
1312
import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest;
1413
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
1514
import org.elasticsearch.action.support.ActiveShardCount;
@@ -98,15 +97,11 @@ public void testInvalidValues() {
9897

9998
private static final AtomicInteger nodeIdGenerator = new AtomicInteger();
10099

101-
protected DiscoveryNode createNode(Version version, DiscoveryNodeRole... mustHaveRoles) {
100+
protected DiscoveryNode createNode(DiscoveryNodeRole... mustHaveRoles) {
102101
Set<DiscoveryNodeRole> roles = new HashSet<>(randomSubsetOf(DiscoveryNodeRole.roles()));
103102
Collections.addAll(roles, mustHaveRoles);
104103
final String id = Strings.format("node_%03d", nodeIdGenerator.incrementAndGet());
105-
return DiscoveryNodeUtils.builder(id).name(id).roles(roles).version(version).build();
106-
}
107-
108-
protected DiscoveryNode createNode(DiscoveryNodeRole... mustHaveRoles) {
109-
return createNode(Version.CURRENT, mustHaveRoles);
104+
return DiscoveryNodeUtils.builder(id).name(id).roles(roles).build();
110105
}
111106

112107
/**

server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public void testDiscoveryNodeToString() {
247247
assertThat(toString, containsString("{" + node.getEphemeralId() + "}"));
248248
assertThat(toString, containsString("{" + node.getAddress() + "}"));
249249
assertThat(toString, containsString("{IScdfhilmrstvw}"));// roles
250-
assertThat(toString, containsString("{" + node.getVersion() + "}"));
250+
assertThat(toString, containsString("{" + node.getBuildVersion() + "}"));
251251
assertThat(toString, containsString("{test-attr=val}"));// attributes
252252
}
253253
}

server/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ public void testRandomClusterPromotesNewestReplica() throws InterruptedException
130130

131131
// Log the node versions (for debugging if necessary)
132132
for (DiscoveryNode discoveryNode : state.nodes().getDataNodes().values()) {
133-
Version nodeVer = discoveryNode.getVersion();
134-
logger.info("--> node [{}] has version [{}]", discoveryNode.getId(), nodeVer);
133+
logger.info("--> node [{}] has version [{}]", discoveryNode.getId(), discoveryNode.getBuildVersion());
135134
}
136135

137136
// randomly create some indices

0 commit comments

Comments
 (0)