88 */
99package org .elasticsearch .action .admin .cluster .allocation ;
1010
11- import org .elasticsearch .TransportVersion ;
12- import org .elasticsearch .TransportVersions ;
1311import org .elasticsearch .action .ActionResponse ;
1412import org .elasticsearch .cluster .ClusterInfo ;
15- import org .elasticsearch .cluster .routing .AllocationId ;
1613import org .elasticsearch .cluster .routing .ShardRoutingState ;
1714import org .elasticsearch .cluster .routing .allocation .allocator .ClusterBalanceStats ;
1815import org .elasticsearch .cluster .routing .allocation .allocator .DesiredBalanceStats ;
3835
3936public 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
0 commit comments