Skip to content

Commit 54c4541

Browse files
authored
Remove RoutingTable#version (#112800)
This version was not actually being used anywhere.
1 parent 6fb1592 commit 54c4541

File tree

18 files changed

+42
-112
lines changed

18 files changed

+42
-112
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ public void testClusterStateDiffSerialization() throws Exception {
152152
}
153153

154154
// Check routing table
155-
assertThat(clusterStateFromDiffs.routingTable().version(), equalTo(clusterState.routingTable().version()));
156155
assertThat(clusterStateFromDiffs.routingTable().indicesRouting(), equalTo(clusterState.routingTable().indicesRouting()));
157156

158157
// Check cluster blocks

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ static TransportVersion def(int id) {
208208
public static final TransportVersion ESQL_AGGREGATE_EXEC_TRACKS_INTERMEDIATE_ATTRS = def(8_738_00_0);
209209
public static final TransportVersion CCS_TELEMETRY_STATS = def(8_739_00_0);
210210
public static final TransportVersion GLOBAL_RETENTION_TELEMETRY = def(8_740_00_0);
211+
public static final TransportVersion ROUTING_TABLE_VERSION_REMOVED = def(8_741_00_0);
211212

212213
/*
213214
* STOP! READ THIS FIRST! No, really,

server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.elasticsearch.cluster.routing;
1010

11+
import org.elasticsearch.TransportVersions;
1112
import org.elasticsearch.cluster.Diff;
1213
import org.elasticsearch.cluster.Diffable;
1314
import org.elasticsearch.cluster.DiffableUtils;
@@ -45,22 +46,15 @@
4546
*/
4647
public class RoutingTable implements Iterable<IndexRoutingTable>, Diffable<RoutingTable> {
4748

48-
public static final RoutingTable EMPTY_ROUTING_TABLE = new RoutingTable(0, ImmutableOpenMap.of());
49-
50-
private final long version;
49+
public static final RoutingTable EMPTY_ROUTING_TABLE = new RoutingTable(ImmutableOpenMap.of());
5150

5251
// index to IndexRoutingTable map
5352
private final ImmutableOpenMap<String, IndexRoutingTable> indicesRouting;
5453

55-
private RoutingTable(long version, ImmutableOpenMap<String, IndexRoutingTable> indicesRouting) {
56-
this.version = version;
54+
private RoutingTable(ImmutableOpenMap<String, IndexRoutingTable> indicesRouting) {
5755
this.indicesRouting = indicesRouting;
5856
}
5957

60-
public RoutingTable withIncrementedVersion() {
61-
return new RoutingTable(version + 1, indicesRouting);
62-
}
63-
6458
/**
6559
* Get's the {@link IndexShardRoutingTable} for the given shard id from the given {@link IndexRoutingTable}
6660
* or throws a {@link ShardNotFoundException} if no shard by the given id is found in the IndexRoutingTable.
@@ -77,15 +71,6 @@ public static IndexShardRoutingTable shardRoutingTable(IndexRoutingTable indexRo
7771
return indexShard;
7872
}
7973

80-
/**
81-
* Returns the version of the {@link RoutingTable}.
82-
*
83-
* @return version of the {@link RoutingTable}
84-
*/
85-
public long version() {
86-
return this.version;
87-
}
88-
8974
@Override
9075
public Iterator<IndexRoutingTable> iterator() {
9176
return indicesRouting.values().iterator();
@@ -331,7 +316,9 @@ public static Diff<RoutingTable> readDiffFrom(StreamInput in) throws IOException
331316

332317
public static RoutingTable readFrom(StreamInput in) throws IOException {
333318
Builder builder = new Builder();
334-
builder.version = in.readLong();
319+
if (in.getTransportVersion().before(TransportVersions.ROUTING_TABLE_VERSION_REMOVED)) {
320+
in.readLong(); // previously 'version', unused in all applicable versions so any number will do
321+
}
335322
int size = in.readVInt();
336323
for (int i = 0; i < size; i++) {
337324
IndexRoutingTable index = IndexRoutingTable.readFrom(in);
@@ -343,46 +330,49 @@ public static RoutingTable readFrom(StreamInput in) throws IOException {
343330

344331
@Override
345332
public void writeTo(StreamOutput out) throws IOException {
346-
out.writeLong(version);
333+
if (out.getTransportVersion().before(TransportVersions.ROUTING_TABLE_VERSION_REMOVED)) {
334+
out.writeLong(0); // previously 'version', unused in all applicable versions so any number will do
335+
}
347336
out.writeCollection(indicesRouting.values());
348337
}
349338

350339
private static class RoutingTableDiff implements Diff<RoutingTable> {
351340

352-
private final long version;
353-
354341
private final Diff<ImmutableOpenMap<String, IndexRoutingTable>> indicesRouting;
355342

356343
RoutingTableDiff(RoutingTable before, RoutingTable after) {
357-
version = after.version;
358344
indicesRouting = DiffableUtils.diff(before.indicesRouting, after.indicesRouting, DiffableUtils.getStringKeySerializer());
359345
}
360346

361347
private static final DiffableUtils.DiffableValueReader<String, IndexRoutingTable> DIFF_VALUE_READER =
362348
new DiffableUtils.DiffableValueReader<>(IndexRoutingTable::readFrom, IndexRoutingTable::readDiffFrom);
363349

364350
RoutingTableDiff(StreamInput in) throws IOException {
365-
version = in.readLong();
351+
if (in.getTransportVersion().before(TransportVersions.ROUTING_TABLE_VERSION_REMOVED)) {
352+
in.readLong(); // previously 'version', unused in all applicable versions so any number will do
353+
}
366354
indicesRouting = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), DIFF_VALUE_READER);
367355
}
368356

369357
@Override
370358
public RoutingTable apply(RoutingTable part) {
371359
final ImmutableOpenMap<String, IndexRoutingTable> updatedRouting = indicesRouting.apply(part.indicesRouting);
372-
if (part.version == version && updatedRouting == part.indicesRouting) {
360+
if (updatedRouting == part.indicesRouting) {
373361
return part;
374362
}
375-
return new RoutingTable(version, updatedRouting);
363+
return new RoutingTable(updatedRouting);
376364
}
377365

378366
@Override
379367
public void writeTo(StreamOutput out) throws IOException {
380-
out.writeLong(version);
368+
if (out.getTransportVersion().before(TransportVersions.ROUTING_TABLE_VERSION_REMOVED)) {
369+
out.writeLong(0); // previously 'version', unused in all applicable versions so any number will do
370+
}
381371
indicesRouting.writeTo(out);
382372
}
383373
}
384374

385-
public static RoutingTable of(long version, RoutingNodes routingNodes) {
375+
public static RoutingTable of(RoutingNodes routingNodes) {
386376
Map<String, IndexRoutingTable.Builder> indexRoutingTableBuilders = new HashMap<>();
387377
for (RoutingNode routingNode : routingNodes) {
388378
for (ShardRouting shardRoutingEntry : routingNode) {
@@ -404,7 +394,7 @@ public static RoutingTable of(long version, RoutingNodes routingNodes) {
404394
IndexRoutingTable indexRoutingTable = indexBuilder.build();
405395
indicesRouting.put(indexRoutingTable.getIndex().getName(), indexRoutingTable);
406396
}
407-
return new RoutingTable(version, indicesRouting.build());
397+
return new RoutingTable(indicesRouting.build());
408398
}
409399

410400
public static Builder builder() {
@@ -429,7 +419,6 @@ public static Builder builder(ShardRoutingRoleStrategy shardRoutingRoleStrategy,
429419
public static class Builder {
430420

431421
private final ShardRoutingRoleStrategy shardRoutingRoleStrategy;
432-
private long version;
433422
private ImmutableOpenMap.Builder<String, IndexRoutingTable> indicesRouting;
434423

435424
public Builder() {
@@ -447,7 +436,6 @@ public Builder(ShardRoutingRoleStrategy shardRoutingRoleStrategy) {
447436

448437
public Builder(ShardRoutingRoleStrategy shardRoutingRoleStrategy, RoutingTable routingTable) {
449438
this.shardRoutingRoleStrategy = shardRoutingRoleStrategy;
450-
this.version = routingTable.version;
451439
this.indicesRouting = ImmutableOpenMap.builder(routingTable.indicesRouting);
452440
}
453441

@@ -591,16 +579,6 @@ public Builder remove(String index) {
591579
return this;
592580
}
593581

594-
public Builder version(long version) {
595-
this.version = version;
596-
return this;
597-
}
598-
599-
public Builder incrementVersion() {
600-
this.version++;
601-
return this;
602-
}
603-
604582
/**
605583
* Builds the routing table. Note that once this is called the builder
606584
* must be thrown away. If you need to build a new RoutingTable as a
@@ -610,15 +588,15 @@ public RoutingTable build() {
610588
if (indicesRouting == null) {
611589
throw new IllegalStateException("once build is called the builder cannot be reused");
612590
}
613-
RoutingTable table = new RoutingTable(version, indicesRouting.build());
591+
RoutingTable table = new RoutingTable(indicesRouting.build());
614592
indicesRouting = null;
615593
return table;
616594
}
617595
}
618596

619597
@Override
620598
public String toString() {
621-
StringBuilder sb = new StringBuilder("routing_table (version ").append(version).append("):\n");
599+
StringBuilder sb = new StringBuilder("routing_table:\n");
622600
for (IndexRoutingTable entry : indicesRouting.values()) {
623601
sb.append(entry.prettyPrint()).append('\n');
624602
}

server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public ClusterState applyStartedShards(ClusterState clusterState, List<ShardRout
159159
private static ClusterState buildResultAndLogHealthChange(ClusterState oldState, RoutingAllocation allocation, String reason) {
160160
final RoutingTable oldRoutingTable = oldState.routingTable();
161161
final RoutingNodes newRoutingNodes = allocation.routingNodes();
162-
final RoutingTable newRoutingTable = RoutingTable.of(oldRoutingTable.version(), newRoutingNodes);
162+
final RoutingTable newRoutingTable = RoutingTable.of(newRoutingNodes);
163163
final Metadata newMetadata = allocation.updateMetadataWithRoutingChanges(newRoutingTable);
164164
assert newRoutingTable.validate(newMetadata); // validates the routing table is coherent with the cluster state metadata
165165

server/src/main/java/org/elasticsearch/cluster/routing/allocation/RoutingAllocation.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,7 @@ public void setSimulatedClusterInfo(ClusterInfo clusterInfo) {
429429
public RoutingAllocation immutableClone() {
430430
return new RoutingAllocation(
431431
deciders,
432-
routingNodesChanged()
433-
? ClusterState.builder(clusterState)
434-
.routingTable(RoutingTable.of(clusterState.routingTable().version(), routingNodes))
435-
.build()
436-
: clusterState,
432+
routingNodesChanged() ? ClusterState.builder(clusterState).routingTable(RoutingTable.of(routingNodes)).build() : clusterState,
437433
clusterInfo,
438434
shardSizeInfo,
439435
currentNanoTime

server/src/main/java/org/elasticsearch/cluster/service/MasterService.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,6 @@ private ClusterState patchVersions(ClusterState previousClusterState, ClusterSta
505505
if (previousClusterState != newClusterState) {
506506
// only the master controls the version numbers
507507
Builder builder = incrementVersion(newClusterState);
508-
if (previousClusterState.routingTable() != newClusterState.routingTable()) {
509-
builder.routingTable(newClusterState.routingTable().withIncrementedVersion());
510-
}
511508
if (previousClusterState.metadata() != newClusterState.metadata()) {
512509
builder.metadata(newClusterState.metadata().withIncrementedVersion());
513510
}
@@ -535,10 +532,6 @@ private static boolean versionNumbersPreserved(ClusterState oldState, ClusterSta
535532
if (oldState.metadata().version() != newState.metadata().version()) {
536533
return false;
537534
}
538-
if (oldState.routingTable().version() != newState.routingTable().version()) {
539-
// GatewayService is special and for odd legacy reasons gets to do this:
540-
return oldState.clusterRecovered() == false && newState.clusterRecovered() && newState.routingTable().version() == 0;
541-
}
542535
return true;
543536
}
544537

server/src/main/java/org/elasticsearch/gateway/ClusterStateUpdaters.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ static ClusterState updateRoutingTable(final ClusterState state, ShardRoutingRol
9898
for (final IndexMetadata indexMetadata : state.metadata().indices().values()) {
9999
routingTableBuilder.addAsRecovery(indexMetadata);
100100
}
101-
// start with 0 based versions for routing table
102-
routingTableBuilder.version(0);
103101
return ClusterState.builder(state).routingTable(routingTableBuilder.build()).build();
104102
}
105103

server/src/test/java/org/elasticsearch/cluster/ClusterChangedEventTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ private static ClusterState createState(final int numNodes, final boolean isLoca
343343
return ClusterState.builder(TEST_CLUSTER_NAME)
344344
.nodes(createDiscoveryNodes(numNodes, isLocalMaster))
345345
.metadata(metadata)
346-
.routingTable(createRoutingTable(1, metadata))
346+
.routingTable(createRoutingTable(metadata))
347347
.build();
348348
}
349349

@@ -498,8 +498,8 @@ private static IndexMetadata createIndexMetadata(final Index index, final long v
498498
}
499499

500500
// Create the routing table for a cluster state.
501-
private static RoutingTable createRoutingTable(final long version, final Metadata metadata) {
502-
final RoutingTable.Builder builder = RoutingTable.builder(TestShardRoutingRoleStrategies.DEFAULT_ROLE_ONLY).version(version);
501+
private static RoutingTable createRoutingTable(final Metadata metadata) {
502+
final RoutingTable.Builder builder = RoutingTable.builder(TestShardRoutingRoleStrategies.DEFAULT_ROLE_ONLY);
503503
for (IndexMetadata indexMetadata : metadata.indices().values()) {
504504
builder.addAsNew(indexMetadata);
505505
}

server/src/test/java/org/elasticsearch/cluster/routing/PrimaryTermsTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ private void applyRerouteResult(ClusterState newClusterState) {
119119
ClusterState previousClusterState = this.clusterState;
120120
ClusterState.Builder builder = ClusterState.builder(newClusterState).incrementVersion();
121121
if (previousClusterState.routingTable() != newClusterState.routingTable()) {
122-
builder.routingTable(
123-
RoutingTable.builder(newClusterState.routingTable()).version(newClusterState.routingTable().version() + 1).build()
124-
);
122+
builder.routingTable(RoutingTable.builder(newClusterState.routingTable()).build());
125123
}
126124
if (previousClusterState.metadata() != newClusterState.metadata()) {
127125
builder.metadata(Metadata.builder(newClusterState.metadata()).version(newClusterState.metadata().version() + 1));

server/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ public void testRemoveReplicasInRightOrder() {
497497
public void testRoutingNodesRoundtrip() {
498498
final RoutingTable originalTable = clusterState.getRoutingTable();
499499
final RoutingNodes routingNodes = clusterState.getRoutingNodes();
500-
final RoutingTable fromNodes = RoutingTable.of(originalTable.version(), routingNodes);
500+
final RoutingTable fromNodes = RoutingTable.of(routingNodes);
501501
// we don't have an equals implementation for the routing table so we assert equality by checking for a noop diff
502502
final Diff<RoutingTable> routingTableDiff = fromNodes.diff(originalTable);
503503
assertSame(originalTable, routingTableDiff.apply(originalTable));

0 commit comments

Comments
 (0)