Skip to content

Commit 1e120b5

Browse files
Remove Transport Version from Serialization (#131758)
Removes conditional logic from `DesiredBalanceResponse` and all classes used in the response (`DesiredBalanceStats`, `ClusterBalanceStats` and `ClusterInfo`) that altered serialization based on transport versions <= `V_8_18_0` since these are outdated. Jira: ES-10337
1 parent 3ecfed1 commit 1e120b5

File tree

4 files changed

+25
-84
lines changed

4 files changed

+25
-84
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/DesiredBalanceResponse.java

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
*/
99
package org.elasticsearch.action.admin.cluster.allocation;
1010

11-
import org.elasticsearch.TransportVersion;
12-
import org.elasticsearch.TransportVersions;
1311
import org.elasticsearch.action.ActionResponse;
1412
import org.elasticsearch.cluster.ClusterInfo;
15-
import org.elasticsearch.cluster.routing.AllocationId;
1613
import org.elasticsearch.cluster.routing.ShardRoutingState;
1714
import org.elasticsearch.cluster.routing.allocation.allocator.ClusterBalanceStats;
1815
import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalanceStats;
@@ -38,9 +35,6 @@
3835

3936
public class DesiredBalanceResponse extends ActionResponse implements ChunkedToXContentObject {
4037

41-
private static final TransportVersion CLUSTER_BALANCE_STATS_VERSION = TransportVersions.V_8_7_0;
42-
private static final TransportVersion CLUSTER_INFO_VERSION = TransportVersions.V_8_8_0;
43-
4438
private final DesiredBalanceStats stats;
4539
private final ClusterBalanceStats clusterBalanceStats;
4640
private final Map<String, Map<Integer, DesiredShards>> routingTable;
@@ -61,27 +55,21 @@ public DesiredBalanceResponse(
6155
public static DesiredBalanceResponse from(StreamInput in) throws IOException {
6256
return new DesiredBalanceResponse(
6357
DesiredBalanceStats.readFrom(in),
64-
in.getTransportVersion().onOrAfter(CLUSTER_BALANCE_STATS_VERSION)
65-
? ClusterBalanceStats.readFrom(in)
66-
: ClusterBalanceStats.EMPTY,
58+
ClusterBalanceStats.readFrom(in),
6759
in.readImmutableMap(v -> v.readImmutableMap(StreamInput::readVInt, DesiredShards::from)),
68-
in.getTransportVersion().onOrAfter(CLUSTER_INFO_VERSION) ? new ClusterInfo(in) : ClusterInfo.EMPTY
60+
new ClusterInfo(in)
6961
);
7062
}
7163

7264
@Override
7365
public void writeTo(StreamOutput out) throws IOException {
7466
stats.writeTo(out);
75-
if (out.getTransportVersion().onOrAfter(CLUSTER_BALANCE_STATS_VERSION)) {
76-
out.writeWriteable(clusterBalanceStats);
77-
}
67+
out.writeWriteable(clusterBalanceStats);
7868
out.writeMap(
7969
routingTable,
8070
(shardsOut, shards) -> shardsOut.writeMap(shards, StreamOutput::writeVInt, StreamOutput::writeWriteable)
8171
);
82-
if (out.getTransportVersion().onOrAfter(CLUSTER_INFO_VERSION)) {
83-
out.writeWriteable(clusterInfo);
84-
}
72+
out.writeWriteable(clusterInfo);
8573
}
8674

8775
@Override
@@ -192,10 +180,6 @@ public record ShardView(
192180
List<String> tierPreference
193181
) implements Writeable, ToXContentObject {
194182

195-
private static final TransportVersion ADD_FORECASTS_VERSION = TransportVersions.V_8_7_0;
196-
private static final TransportVersion ADD_TIER_PREFERENCE = TransportVersions.V_8_8_0;
197-
private static final TransportVersion NULLABLE_RELOCATING_NODE_IS_DESIRED = TransportVersions.V_8_8_0;
198-
199183
public ShardView {
200184
assert (relocatingNode == null) == (relocatingNodeIsDesired == null)
201185
: "relocatingNodeIsDesired should only be set when relocatingNode is set";
@@ -208,22 +192,12 @@ public static ShardView from(StreamInput in) throws IOException {
208192
boolean nodeIsDesired = in.readBoolean();
209193
String relocatingNode = in.readOptionalString();
210194
Boolean relocatingNodeIsDesired;
211-
if (in.getTransportVersion().onOrAfter(NULLABLE_RELOCATING_NODE_IS_DESIRED)) {
212-
relocatingNodeIsDesired = in.readOptionalBoolean();
213-
} else {
214-
boolean wireRelocatingNodeIsDesired = in.readBoolean();
215-
relocatingNodeIsDesired = relocatingNode == null ? null : wireRelocatingNodeIsDesired;
216-
}
195+
relocatingNodeIsDesired = in.readOptionalBoolean();
217196
int shardId = in.readVInt();
218197
String index = in.readString();
219-
Double forecastWriteLoad = in.getTransportVersion().onOrAfter(ADD_FORECASTS_VERSION) ? in.readOptionalDouble() : null;
220-
Long forecastShardSizeInBytes = in.getTransportVersion().onOrAfter(ADD_FORECASTS_VERSION) ? in.readOptionalLong() : null;
221-
if (in.getTransportVersion().onOrAfter(ADD_FORECASTS_VERSION) == false) {
222-
in.readOptionalWriteable(AllocationId::new);
223-
}
224-
List<String> tierPreference = in.getTransportVersion().onOrAfter(ADD_TIER_PREFERENCE)
225-
? in.readStringCollectionAsList()
226-
: List.of();
198+
Double forecastWriteLoad = in.readOptionalDouble();
199+
Long forecastShardSizeInBytes = in.readOptionalLong();
200+
List<String> tierPreference = in.readStringCollectionAsList();
227201
return new ShardView(
228202
state,
229203
primary,
@@ -246,22 +220,12 @@ public void writeTo(StreamOutput out) throws IOException {
246220
out.writeOptionalString(node);
247221
out.writeBoolean(nodeIsDesired);
248222
out.writeOptionalString(relocatingNode);
249-
if (out.getTransportVersion().onOrAfter(NULLABLE_RELOCATING_NODE_IS_DESIRED)) {
250-
out.writeOptionalBoolean(relocatingNodeIsDesired);
251-
} else {
252-
out.writeBoolean(relocatingNodeIsDesired != null && relocatingNodeIsDesired);
253-
}
223+
out.writeOptionalBoolean(relocatingNodeIsDesired);
254224
out.writeVInt(shardId);
255225
out.writeString(index);
256-
if (out.getTransportVersion().onOrAfter(ADD_FORECASTS_VERSION)) {
257-
out.writeOptionalDouble(forecastWriteLoad);
258-
out.writeOptionalLong(forecastShardSizeInBytes);
259-
} else {
260-
out.writeMissingWriteable(AllocationId.class);
261-
}
262-
if (out.getTransportVersion().onOrAfter(ADD_TIER_PREFERENCE)) {
263-
out.writeStringCollection(tierPreference);
264-
}
226+
out.writeOptionalDouble(forecastWriteLoad);
227+
out.writeOptionalLong(forecastShardSizeInBytes);
228+
out.writeStringCollection(tierPreference);
265229
}
266230

267231
@Override

server/src/main/java/org/elasticsearch/cluster/ClusterInfo.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
package org.elasticsearch.cluster;
1111

12-
import org.elasticsearch.TransportVersion;
1312
import org.elasticsearch.TransportVersions;
1413
import org.elasticsearch.cluster.routing.RecoverySource;
1514
import org.elasticsearch.cluster.routing.ShardRouting;
@@ -49,8 +48,6 @@ public class ClusterInfo implements ChunkedToXContent, Writeable {
4948

5049
public static final ClusterInfo EMPTY = new ClusterInfo();
5150

52-
public static final TransportVersion DATA_PATH_NEW_KEY_VERSION = TransportVersions.V_8_6_0;
53-
5451
private final Map<String, DiskUsage> leastAvailableSpaceUsage;
5552
private final Map<String, DiskUsage> mostAvailableSpaceUsage;
5653
final Map<String, Long> shardSizes;
@@ -105,9 +102,7 @@ public ClusterInfo(StreamInput in) throws IOException {
105102
this.mostAvailableSpaceUsage = in.readImmutableMap(DiskUsage::new);
106103
this.shardSizes = in.readImmutableMap(StreamInput::readLong);
107104
this.shardDataSetSizes = in.readImmutableMap(ShardId::new, StreamInput::readLong);
108-
this.dataPath = in.getTransportVersion().onOrAfter(DATA_PATH_NEW_KEY_VERSION)
109-
? in.readImmutableMap(NodeAndShard::new, StreamInput::readString)
110-
: in.readImmutableMap(nested -> NodeAndShard.from(new ShardRouting(nested)), StreamInput::readString);
105+
this.dataPath = in.readImmutableMap(NodeAndShard::new, StreamInput::readString);
111106
this.reservedSpace = in.readImmutableMap(NodeAndPath::new, ReservedSpace::new);
112107
if (in.getTransportVersion().onOrAfter(TransportVersions.HEAP_USAGE_IN_CLUSTER_INFO)) {
113108
this.estimatedHeapUsages = in.readImmutableMap(EstimatedHeapUsage::new);
@@ -132,11 +127,7 @@ public void writeTo(StreamOutput out) throws IOException {
132127
out.writeMap(this.mostAvailableSpaceUsage, StreamOutput::writeWriteable);
133128
out.writeMap(this.shardSizes, (o, v) -> o.writeLong(v == null ? -1 : v));
134129
out.writeMap(this.shardDataSetSizes, StreamOutput::writeWriteable, StreamOutput::writeLong);
135-
if (out.getTransportVersion().onOrAfter(DATA_PATH_NEW_KEY_VERSION)) {
136-
out.writeMap(this.dataPath, StreamOutput::writeWriteable, StreamOutput::writeString);
137-
} else {
138-
out.writeMap(this.dataPath, (o, k) -> createFakeShardRoutingFromNodeAndShard(k).writeTo(o), StreamOutput::writeString);
139-
}
130+
out.writeMap(this.dataPath, StreamOutput::writeWriteable, StreamOutput::writeString);
140131
out.writeMap(this.reservedSpace);
141132
if (out.getTransportVersion().onOrAfter(TransportVersions.HEAP_USAGE_IN_CLUSTER_INFO)) {
142133
out.writeMap(this.estimatedHeapUsages, StreamOutput::writeWriteable);

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterBalanceStats.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,17 @@ public static ClusterBalanceStats createFrom(
7777

7878
public static ClusterBalanceStats readFrom(StreamInput in) throws IOException {
7979
return new ClusterBalanceStats(
80-
in.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0) ? in.readVInt() : -1,
81-
in.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0) ? in.readVInt() : -1,
80+
in.readVInt(),
81+
in.readVInt(),
8282
in.readImmutableMap(TierBalanceStats::readFrom),
8383
in.readImmutableMap(NodeBalanceStats::readFrom)
8484
);
8585
}
8686

8787
@Override
8888
public void writeTo(StreamOutput out) throws IOException {
89-
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0)) {
90-
out.writeVInt(shards);
91-
out.writeVInt(undesiredShardAllocations);
92-
}
89+
out.writeVInt(shards);
90+
out.writeVInt(undesiredShardAllocations);
9391
out.writeMap(tiers, StreamOutput::writeWriteable);
9492
out.writeMap(nodes, StreamOutput::writeWriteable);
9593
}
@@ -125,9 +123,7 @@ private static TierBalanceStats createFrom(List<NodeBalanceStats> nodes) {
125123
public static TierBalanceStats readFrom(StreamInput in) throws IOException {
126124
return new TierBalanceStats(
127125
MetricStats.readFrom(in),
128-
in.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0)
129-
? MetricStats.readFrom(in)
130-
: new MetricStats(0.0, 0.0, 0.0, 0.0, 0.0),
126+
MetricStats.readFrom(in),
131127
MetricStats.readFrom(in),
132128
MetricStats.readFrom(in),
133129
MetricStats.readFrom(in)
@@ -137,9 +133,7 @@ public static TierBalanceStats readFrom(StreamInput in) throws IOException {
137133
@Override
138134
public void writeTo(StreamOutput out) throws IOException {
139135
shardCount.writeTo(out);
140-
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0)) {
141-
undesiredShardAllocations.writeTo(out);
142-
}
136+
undesiredShardAllocations.writeTo(out);
143137
forecastWriteLoad.writeTo(out);
144138
forecastShardSize.writeTo(out);
145139
actualShardSize.writeTo(out);

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceStats.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
package org.elasticsearch.cluster.routing.allocation.allocator;
1111

12-
import org.elasticsearch.TransportVersion;
13-
import org.elasticsearch.TransportVersions;
1412
import org.elasticsearch.common.io.stream.StreamInput;
1513
import org.elasticsearch.common.io.stream.StreamOutput;
1614
import org.elasticsearch.common.io.stream.Writeable;
@@ -37,8 +35,6 @@ public record DesiredBalanceStats(
3735
long undesiredAllocations
3836
) implements Writeable, ToXContentObject {
3937

40-
private static final TransportVersion COMPUTED_SHARD_MOVEMENTS_VERSION = TransportVersions.V_8_8_0;
41-
4238
public DesiredBalanceStats {
4339
if (lastConvergedIndex < 0) {
4440
assert false : lastConvergedIndex;
@@ -54,7 +50,7 @@ public static DesiredBalanceStats readFrom(StreamInput in) throws IOException {
5450
in.readVLong(),
5551
in.readVLong(),
5652
in.readVLong(),
57-
in.getTransportVersion().onOrAfter(COMPUTED_SHARD_MOVEMENTS_VERSION) ? in.readVLong() : -1,
53+
in.readVLong(),
5854
in.readVLong(),
5955
in.readVLong(),
6056
in.getTransportVersion().onOrAfter(V_8_12_0) ? in.readVLong() : -1,
@@ -71,16 +67,12 @@ public void writeTo(StreamOutput out) throws IOException {
7167
out.writeVLong(computationExecuted);
7268
out.writeVLong(computationConverged);
7369
out.writeVLong(computationIterations);
74-
if (out.getTransportVersion().onOrAfter(COMPUTED_SHARD_MOVEMENTS_VERSION)) {
75-
out.writeVLong(computedShardMovements);
76-
}
70+
out.writeVLong(computedShardMovements);
7771
out.writeVLong(cumulativeComputationTime);
7872
out.writeVLong(cumulativeReconciliationTime);
79-
if (out.getTransportVersion().onOrAfter(V_8_12_0)) {
80-
out.writeVLong(unassignedShards);
81-
out.writeVLong(totalAllocations);
82-
out.writeVLong(undesiredAllocations);
83-
}
73+
out.writeVLong(unassignedShards);
74+
out.writeVLong(totalAllocations);
75+
out.writeVLong(undesiredAllocations);
8476
}
8577

8678
@Override

0 commit comments

Comments
 (0)