8
8
*/
9
9
package org .elasticsearch .action .admin .cluster .allocation ;
10
10
11
- import org .elasticsearch .TransportVersion ;
12
- import org .elasticsearch .TransportVersions ;
13
11
import org .elasticsearch .action .ActionResponse ;
14
12
import org .elasticsearch .cluster .ClusterInfo ;
15
- import org .elasticsearch .cluster .routing .AllocationId ;
16
13
import org .elasticsearch .cluster .routing .ShardRoutingState ;
17
14
import org .elasticsearch .cluster .routing .allocation .allocator .ClusterBalanceStats ;
18
15
import org .elasticsearch .cluster .routing .allocation .allocator .DesiredBalanceStats ;
38
35
39
36
public class DesiredBalanceResponse extends ActionResponse implements ChunkedToXContentObject {
40
37
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
-
44
38
private final DesiredBalanceStats stats ;
45
39
private final ClusterBalanceStats clusterBalanceStats ;
46
40
private final Map <String , Map <Integer , DesiredShards >> routingTable ;
@@ -61,27 +55,21 @@ public DesiredBalanceResponse(
61
55
public static DesiredBalanceResponse from (StreamInput in ) throws IOException {
62
56
return new DesiredBalanceResponse (
63
57
DesiredBalanceStats .readFrom (in ),
64
- in .getTransportVersion ().onOrAfter (CLUSTER_BALANCE_STATS_VERSION )
65
- ? ClusterBalanceStats .readFrom (in )
66
- : ClusterBalanceStats .EMPTY ,
58
+ ClusterBalanceStats .readFrom (in ),
67
59
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 )
69
61
);
70
62
}
71
63
72
64
@ Override
73
65
public void writeTo (StreamOutput out ) throws IOException {
74
66
stats .writeTo (out );
75
- if (out .getTransportVersion ().onOrAfter (CLUSTER_BALANCE_STATS_VERSION )) {
76
- out .writeWriteable (clusterBalanceStats );
77
- }
67
+ out .writeWriteable (clusterBalanceStats );
78
68
out .writeMap (
79
69
routingTable ,
80
70
(shardsOut , shards ) -> shardsOut .writeMap (shards , StreamOutput ::writeVInt , StreamOutput ::writeWriteable )
81
71
);
82
- if (out .getTransportVersion ().onOrAfter (CLUSTER_INFO_VERSION )) {
83
- out .writeWriteable (clusterInfo );
84
- }
72
+ out .writeWriteable (clusterInfo );
85
73
}
86
74
87
75
@ Override
@@ -192,10 +180,6 @@ public record ShardView(
192
180
List <String > tierPreference
193
181
) implements Writeable , ToXContentObject {
194
182
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
-
199
183
public ShardView {
200
184
assert (relocatingNode == null ) == (relocatingNodeIsDesired == null )
201
185
: "relocatingNodeIsDesired should only be set when relocatingNode is set" ;
@@ -208,22 +192,12 @@ public static ShardView from(StreamInput in) throws IOException {
208
192
boolean nodeIsDesired = in .readBoolean ();
209
193
String relocatingNode = in .readOptionalString ();
210
194
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 ();
217
196
int shardId = in .readVInt ();
218
197
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 ();
227
201
return new ShardView (
228
202
state ,
229
203
primary ,
@@ -246,22 +220,12 @@ public void writeTo(StreamOutput out) throws IOException {
246
220
out .writeOptionalString (node );
247
221
out .writeBoolean (nodeIsDesired );
248
222
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 );
254
224
out .writeVInt (shardId );
255
225
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 );
265
229
}
266
230
267
231
@ Override
0 commit comments