Skip to content

Commit

Permalink
Refactor some more uses of inferred versions to explicitly specify in…
Browse files Browse the repository at this point in the history
…dex versions (#98588)
  • Loading branch information
thecoop authored Aug 17, 2023
1 parent 2b838ae commit 4e7113f
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.node.DiscoveryNodeUtils;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.monitor.jvm.JvmInfo;
import org.elasticsearch.monitor.os.OsInfo;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.test.index.IndexVersionUtils;

import static java.util.Collections.emptySet;
import static org.hamcrest.Matchers.notNullValue;
Expand All @@ -37,7 +39,10 @@ public void testGetInfo() {
Version.CURRENT,
TransportVersion.current(),
Build.current(),
DiscoveryNodeUtils.builder("test_node").roles(emptySet()).version(VersionUtils.randomVersion(random())).build(),
DiscoveryNodeUtils.builder("test_node")
.roles(emptySet())
.version(VersionUtils.randomVersion(random()), IndexVersion.ZERO, IndexVersionUtils.randomCompatibleVersion(random()))
.build(),
null,
null,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodeUtils;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.index.IndexVersionUtils;

import java.util.Set;

Expand Down Expand Up @@ -58,6 +60,10 @@ public void testResolveNodes() {
}

private DiscoveryNode randomNode(String nodeName, String nodeId) {
return DiscoveryNodeUtils.builder(nodeId).name(nodeName).roles(emptySet()).version(randomVersion(random())).build();
return DiscoveryNodeUtils.builder(nodeId)
.name(nodeName)
.roles(emptySet())
.version(randomVersion(random()), IndexVersion.ZERO, IndexVersionUtils.randomVersion())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.elasticsearch.discovery.DiscoveryStats;
import org.elasticsearch.http.HttpStats;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.bulk.stats.BulkStats;
import org.elasticsearch.index.cache.query.QueryCacheStats;
import org.elasticsearch.index.cache.request.RequestCacheStats;
Expand Down Expand Up @@ -73,6 +74,7 @@
import org.elasticsearch.search.suggest.completion.CompletionStats;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.test.index.IndexVersionUtils;
import org.elasticsearch.threadpool.ThreadPoolStats;
import org.elasticsearch.transport.TransportActionStats;
import org.elasticsearch.transport.TransportStats;
Expand Down Expand Up @@ -661,7 +663,7 @@ private static ShardStats createShardStats(ShardId shardId) {
public static NodeStats createNodeStats() {
DiscoveryNode node = DiscoveryNodeUtils.builder("test_node")
.roles(emptySet())
.version(VersionUtils.randomVersion(random()))
.version(VersionUtils.randomVersion(random()), IndexVersion.ZERO, IndexVersionUtils.randomVersion())
.build();
NodeIndicesStats nodeIndicesStats = null;
if (frequently()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskId;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.test.gateway.TestGatewayAllocator;
import org.elasticsearch.test.index.IndexVersionUtils;
import org.elasticsearch.threadpool.TestThreadPool;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TcpTransport;
Expand Down Expand Up @@ -80,7 +82,6 @@
import java.util.stream.IntStream;

import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings;
import static org.elasticsearch.test.VersionUtils.randomVersion;
import static org.hamcrest.Matchers.anEmptyMap;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.everyItem;
Expand All @@ -107,7 +108,7 @@ public void testHappyCluster() throws Exception {
DiscoveryNodes.Builder discoNodes = DiscoveryNodes.builder();
int numNodes = randomIntBetween(1, 10);
for (int i = 0; i < numNodes; i++) {
discoNodes.add(newNode("node_" + i, randomVersion(random())));
discoNodes.add(newNode("node_" + i, VersionUtils.randomVersion(random()), IndexVersionUtils.randomVersion()));
}
Metadata.Builder metadata = Metadata.builder();
for (String index : allIndices) {
Expand Down Expand Up @@ -176,7 +177,7 @@ public void testRetryThenOk() throws Exception {
DiscoveryNodes.Builder discoNodes = DiscoveryNodes.builder();
int numNodes = randomIntBetween(2, 10);
for (int i = 0; i < numNodes; i++) {
discoNodes.add(newNode("node_" + i, randomVersion(random())));
discoNodes.add(newNode("node_" + i, VersionUtils.randomVersion(random()), IndexVersionUtils.randomVersion()));
}
Metadata.Builder metadata = Metadata.builder();
for (String index : allIndices) {
Expand Down Expand Up @@ -296,7 +297,7 @@ public void testRetryButFails() throws Exception {
DiscoveryNodes.Builder discoNodes = DiscoveryNodes.builder();
int numNodes = randomIntBetween(1, 10);
for (int i = 0; i < numNodes; i++) {
discoNodes.add(newNode("node_" + i, randomVersion(random())));
discoNodes.add(newNode("node_" + i, VersionUtils.randomVersion(random()), IndexVersionUtils.randomVersion()));
}
Metadata.Builder metadata = Metadata.builder();
for (String index : allIndices) {
Expand Down Expand Up @@ -418,7 +419,7 @@ public void testSuccessWithAnyMatch() throws Exception {
DiscoveryNodes.Builder discoNodes = DiscoveryNodes.builder();
int numNodes = randomIntBetween(1, 10);
for (int i = 0; i < numNodes; i++) {
discoNodes.add(newNode("node_" + i, randomVersion(random())));
discoNodes.add(newNode("node_" + i, VersionUtils.randomVersion(random()), IndexVersionUtils.randomVersion()));
}
Metadata.Builder metadata = Metadata.builder();
for (String index : allIndices) {
Expand Down Expand Up @@ -514,7 +515,7 @@ public void testStopAfterAllShardsUnmatched() throws Exception {
DiscoveryNodes.Builder discoNodes = DiscoveryNodes.builder();
int numNodes = randomIntBetween(1, 10);
for (int i = 0; i < numNodes; i++) {
discoNodes.add(newNode("node_" + i, randomVersion(random())));
discoNodes.add(newNode("node_" + i, VersionUtils.randomVersion(random()), IndexVersionUtils.randomVersion()));
}
Metadata.Builder metadata = Metadata.builder();
for (String index : allIndices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,14 @@ public void testPreventJoinClusterWithUnsupportedIndices() {
public void testPreventJoinClusterWithUnsupportedNodeVersions() {
DiscoveryNodes.Builder builder = DiscoveryNodes.builder();
final Version version = randomCompatibleVersion(random(), Version.CURRENT);
builder.add(DiscoveryNodeUtils.builder(UUIDs.base64UUID()).version(version).build());
builder.add(DiscoveryNodeUtils.builder(UUIDs.base64UUID()).version(randomCompatibleVersion(random(), version)).build());
builder.add(
DiscoveryNodeUtils.builder(UUIDs.base64UUID()).version(version, IndexVersion.MINIMUM_COMPATIBLE, IndexVersion.current()).build()
);
builder.add(
DiscoveryNodeUtils.builder(UUIDs.base64UUID())
.version(randomCompatibleVersion(random(), version), IndexVersion.MINIMUM_COMPATIBLE, IndexVersion.current())
.build()
);
DiscoveryNodes nodes = builder.build();

final Version maxNodeVersion = nodes.getMaxNodeVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.elasticsearch.snapshots.SnapshotShardSizeInfo;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.test.gateway.TestGatewayAllocator;
import org.elasticsearch.test.index.IndexVersionUtils;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -69,7 +70,6 @@
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
import static org.elasticsearch.test.VersionUtils.randomVersion;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
Expand Down Expand Up @@ -144,7 +144,10 @@ public void testDoNotAllocateFromPrimary() {
}

clusterState = ClusterState.builder(clusterState)
.nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3", VersionUtils.getPreviousVersion())))
.nodes(
DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3", VersionUtils.getPreviousVersion(), IndexVersionUtils.getPreviousVersion()))
)
.build();
clusterState = strategy.reroute(clusterState, "reroute", ActionListener.noop());

Expand Down Expand Up @@ -216,9 +219,15 @@ public void testRandom() {
} else {
for (int j = nodes.size(); j < numNodes; j++) {
if (frequently()) {
nodes.add(newNode("node" + (nodeIdx++), randomBoolean() ? VersionUtils.getPreviousVersion() : Version.CURRENT));
if (randomBoolean()) {
nodes.add(
newNode("node" + (nodeIdx++), VersionUtils.getPreviousVersion(), IndexVersionUtils.getPreviousVersion())
);
} else {
nodes.add(newNode("node" + (nodeIdx++), Version.CURRENT, IndexVersion.current()));
}
} else {
nodes.add(newNode("node" + (nodeIdx++), randomVersion(random())));
nodes.add(newNode("node" + (nodeIdx++), VersionUtils.randomVersion(random()), IndexVersionUtils.randomVersion()));
}
}
}
Expand Down Expand Up @@ -264,18 +273,18 @@ public void testRollingRestart() {
clusterState = ClusterState.builder(clusterState)
.nodes(
DiscoveryNodes.builder()
.add(newNode("old0", VersionUtils.getPreviousVersion()))
.add(newNode("old1", VersionUtils.getPreviousVersion()))
.add(newNode("old2", VersionUtils.getPreviousVersion()))
.add(newNode("old0", VersionUtils.getPreviousVersion(), IndexVersionUtils.getPreviousVersion()))
.add(newNode("old1", VersionUtils.getPreviousVersion(), IndexVersionUtils.getPreviousVersion()))
.add(newNode("old2", VersionUtils.getPreviousVersion(), IndexVersionUtils.getPreviousVersion()))
)
.build();
clusterState = stabilize(clusterState, service);

clusterState = ClusterState.builder(clusterState)
.nodes(
DiscoveryNodes.builder()
.add(newNode("old0", VersionUtils.getPreviousVersion()))
.add(newNode("old1", VersionUtils.getPreviousVersion()))
.add(newNode("old0", VersionUtils.getPreviousVersion(), IndexVersionUtils.getPreviousVersion()))
.add(newNode("old1", VersionUtils.getPreviousVersion(), IndexVersionUtils.getPreviousVersion()))
.add(newNode("new0"))
)
.build();
Expand All @@ -284,7 +293,10 @@ public void testRollingRestart() {

clusterState = ClusterState.builder(clusterState)
.nodes(
DiscoveryNodes.builder().add(newNode("node0", VersionUtils.getPreviousVersion())).add(newNode("new1")).add(newNode("new0"))
DiscoveryNodes.builder()
.add(newNode("node0", VersionUtils.getPreviousVersion(), IndexVersionUtils.getPreviousVersion()))
.add(newNode("new1"))
.add(newNode("new0"))
)
.build();

Expand Down Expand Up @@ -312,11 +324,11 @@ public void testRebalanceDoesNotAllocatePrimaryAndReplicasOnDifferentVersionNode
final DiscoveryNode newNode = DiscoveryNodeUtils.builder("newNode").roles(MASTER_DATA_ROLES).build();
final DiscoveryNode oldNode1 = DiscoveryNodeUtils.builder("oldNode1")
.roles(MASTER_DATA_ROLES)
.version(VersionUtils.getPreviousVersion())
.version(VersionUtils.getPreviousVersion(), IndexVersion.MINIMUM_COMPATIBLE, IndexVersionUtils.getPreviousVersion())
.build();
final DiscoveryNode oldNode2 = DiscoveryNodeUtils.builder("oldNode2")
.roles(MASTER_DATA_ROLES)
.version(VersionUtils.getPreviousVersion())
.version(VersionUtils.getPreviousVersion(), IndexVersion.MINIMUM_COMPATIBLE, IndexVersionUtils.getPreviousVersion())
.build();
AllocationId allocationId1P = AllocationId.newInitializing();
AllocationId allocationId1R = AllocationId.newInitializing();
Expand Down Expand Up @@ -417,11 +429,11 @@ public void testRestoreDoesNotAllocateSnapshotOnOlderNodes() {
final DiscoveryNode newNode = DiscoveryNodeUtils.builder("newNode").roles(MASTER_DATA_ROLES).build();
final DiscoveryNode oldNode1 = DiscoveryNodeUtils.builder("oldNode1")
.roles(MASTER_DATA_ROLES)
.version(VersionUtils.getPreviousVersion())
.version(VersionUtils.getPreviousVersion(), IndexVersion.MINIMUM_COMPATIBLE, IndexVersionUtils.getPreviousVersion())
.build();
final DiscoveryNode oldNode2 = DiscoveryNodeUtils.builder("oldNode2")
.roles(MASTER_DATA_ROLES)
.version(VersionUtils.getPreviousVersion())
.version(VersionUtils.getPreviousVersion(), IndexVersion.MINIMUM_COMPATIBLE, IndexVersionUtils.getPreviousVersion())
.build();

final Snapshot snapshot = new Snapshot("rep1", new SnapshotId("snp1", UUIDs.randomBase64UUID()));
Expand Down Expand Up @@ -557,8 +569,11 @@ public void testMessages() {
.addAsNew(metadata.index("test"))
.build();

RoutingNode newNode = RoutingNodesHelper.routingNode("newNode", newNode("newNode", Version.CURRENT));
RoutingNode oldNode = RoutingNodesHelper.routingNode("oldNode", newNode("oldNode", VersionUtils.getPreviousVersion()));
RoutingNode newNode = RoutingNodesHelper.routingNode("newNode", newNode("newNode", Version.CURRENT, IndexVersion.current()));
RoutingNode oldNode = RoutingNodesHelper.routingNode(
"oldNode",
newNode("oldNode", VersionUtils.getPreviousVersion(), IndexVersionUtils.getPreviousVersion())
);

final ClusterName clusterName = ClusterName.DEFAULT;
ClusterState clusterState = ClusterState.builder(clusterName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
import org.elasticsearch.common.io.stream.OutputStreamStreamOutput;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.seqno.SequenceNumbers;
import org.elasticsearch.index.shard.ShardId;
Expand Down Expand Up @@ -44,8 +45,8 @@ public void testSerialization() throws Exception {
final StartRecoveryRequest outRequest = new StartRecoveryRequest(
new ShardId("test", "_na_", 0),
UUIDs.randomBase64UUID(),
DiscoveryNodeUtils.builder("a").roles(emptySet()).version(targetNodeVersion).build(),
DiscoveryNodeUtils.builder("b").roles(emptySet()).version(targetNodeVersion).build(),
DiscoveryNodeUtils.builder("a").roles(emptySet()).version(targetNodeVersion, IndexVersion.ZERO, IndexVersion.current()).build(),
DiscoveryNodeUtils.builder("b").roles(emptySet()).version(targetNodeVersion, IndexVersion.ZERO, IndexVersion.current()).build(),
metadataSnapshot,
randomBoolean(),
randomNonNegativeLong(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.Processors;
import org.elasticsearch.http.HttpInfo;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.ingest.IngestInfo;
import org.elasticsearch.ingest.ProcessorInfo;
import org.elasticsearch.monitor.jvm.JvmInfo;
Expand All @@ -34,6 +35,7 @@
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.TransportVersionUtils;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.test.index.IndexVersionUtils;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.threadpool.ThreadPoolInfo;
import org.elasticsearch.transport.RemoteClusterServerInfo;
Expand Down Expand Up @@ -106,7 +108,7 @@ private static NodeInfo createNodeInfo() {
Build build = Build.current();
DiscoveryNode node = DiscoveryNodeUtils.builder("test_node")
.roles(emptySet())
.version(VersionUtils.randomVersion(random()))
.version(VersionUtils.randomVersion(random()), IndexVersion.ZERO, IndexVersionUtils.randomVersion())
.build();
Settings settings = randomBoolean() ? null : Settings.builder().put("test", "setting").build();
OsInfo osInfo = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,10 @@ public void testGetNodePredicateNodeVersion() {
TransportAddress address = new TransportAddress(TransportAddress.META_ADDRESS, 0);
Predicate<DiscoveryNode> nodePredicate = SniffConnectionStrategy.getNodePredicate(Settings.EMPTY);
Version version = VersionUtils.randomVersion(random());
DiscoveryNode node = DiscoveryNodeUtils.builder("id").address(address).version(version).build();
DiscoveryNode node = DiscoveryNodeUtils.builder("id")
.address(address)
.version(version, IndexVersion.ZERO, IndexVersion.current())
.build();
assertThat(nodePredicate.test(node), equalTo(Version.CURRENT.isCompatible(version)));
}

Expand Down
Loading

0 comments on commit 4e7113f

Please sign in to comment.