1818import org .elasticsearch .common .unit .ByteSizeValue ;
1919import org .elasticsearch .common .xcontent .ChunkedToXContent ;
2020import org .elasticsearch .core .TimeValue ;
21- import org .elasticsearch .core .UpdateForV9 ;
2221import org .elasticsearch .xcontent .ToXContent ;
2322import org .elasticsearch .xcontent .XContentBuilder ;
2423
@@ -70,18 +69,16 @@ public TransportStats(StreamInput in) throws IOException {
7069 rxSize = in .readVLong ();
7170 txCount = in .readVLong ();
7271 txSize = in .readVLong ();
73- if (in .getTransportVersion ().onOrAfter (TransportVersions .V_8_1_0 ) && in .readBoolean ()) {
74- inboundHandlingTimeBucketFrequencies = new long [HandlingTimeTracker .BUCKET_COUNT ];
75- for (int i = 0 ; i < inboundHandlingTimeBucketFrequencies .length ; i ++) {
76- inboundHandlingTimeBucketFrequencies [i ] = in .readVLong ();
77- }
78- outboundHandlingTimeBucketFrequencies = new long [HandlingTimeTracker .BUCKET_COUNT ];
79- for (int i = 0 ; i < inboundHandlingTimeBucketFrequencies .length ; i ++) {
80- outboundHandlingTimeBucketFrequencies [i ] = in .readVLong ();
81- }
82- } else {
83- inboundHandlingTimeBucketFrequencies = new long [0 ];
84- outboundHandlingTimeBucketFrequencies = new long [0 ];
72+ if (in .getTransportVersion ().before (TransportVersions .TRANSPORT_STATS_HANDLING_TIME_REQUIRED )) {
73+ in .readBoolean ();
74+ }
75+ inboundHandlingTimeBucketFrequencies = new long [HandlingTimeTracker .BUCKET_COUNT ];
76+ for (int i = 0 ; i < inboundHandlingTimeBucketFrequencies .length ; i ++) {
77+ inboundHandlingTimeBucketFrequencies [i ] = in .readVLong ();
78+ }
79+ outboundHandlingTimeBucketFrequencies = new long [HandlingTimeTracker .BUCKET_COUNT ];
80+ for (int i = 0 ; i < inboundHandlingTimeBucketFrequencies .length ; i ++) {
81+ outboundHandlingTimeBucketFrequencies [i ] = in .readVLong ();
8582 }
8683 if (in .getTransportVersion ().onOrAfter (TransportVersions .V_8_8_0 )) {
8784 transportActionStats = Collections .unmodifiableMap (in .readOrderedMap (StreamInput ::readString , TransportActionStats ::new ));
@@ -99,15 +96,16 @@ public void writeTo(StreamOutput out) throws IOException {
9996 out .writeVLong (rxSize );
10097 out .writeVLong (txCount );
10198 out .writeVLong (txSize );
102- if (out .getTransportVersion ().onOrAfter (TransportVersions .V_8_1_0 )) {
103- assert (inboundHandlingTimeBucketFrequencies .length > 0 ) == (outboundHandlingTimeBucketFrequencies .length > 0 );
104- out .writeBoolean (inboundHandlingTimeBucketFrequencies .length > 0 );
105- for (long handlingTimeBucketFrequency : inboundHandlingTimeBucketFrequencies ) {
106- out .writeVLong (handlingTimeBucketFrequency );
107- }
108- for (long handlingTimeBucketFrequency : outboundHandlingTimeBucketFrequencies ) {
109- out .writeVLong (handlingTimeBucketFrequency );
110- }
99+ assert inboundHandlingTimeBucketFrequencies .length == HandlingTimeTracker .BUCKET_COUNT ;
100+ assert outboundHandlingTimeBucketFrequencies .length == HandlingTimeTracker .BUCKET_COUNT ;
101+ if (out .getTransportVersion ().before (TransportVersions .TRANSPORT_STATS_HANDLING_TIME_REQUIRED )) {
102+ out .writeBoolean (true );
103+ }
104+ for (long handlingTimeBucketFrequency : inboundHandlingTimeBucketFrequencies ) {
105+ out .writeVLong (handlingTimeBucketFrequency );
106+ }
107+ for (long handlingTimeBucketFrequency : outboundHandlingTimeBucketFrequencies ) {
108+ out .writeVLong (handlingTimeBucketFrequency );
111109 }
112110 if (out .getTransportVersion ().onOrAfter (TransportVersions .V_8_8_0 )) {
113111 out .writeMap (transportActionStats , StreamOutput ::writeWriteable );
@@ -166,24 +164,13 @@ public Map<String, TransportActionStats> getTransportActionStats() {
166164 return transportActionStats ;
167165 }
168166
169- @ UpdateForV9 (owner = UpdateForV9 .Owner .DISTRIBUTED_COORDINATION )
170- // Review and simplify the if-else blocks containing this symbol once v9 is released
171- private static final boolean IMPOSSIBLE_IN_V9 = true ;
172-
173167 private boolean assertHistogramsConsistent () {
174168 assert inboundHandlingTimeBucketFrequencies .length == outboundHandlingTimeBucketFrequencies .length ;
175- if (inboundHandlingTimeBucketFrequencies .length == 0 ) {
176- // Stats came from before v8.1
177- assert IMPOSSIBLE_IN_V9 ;
178- } else {
179- assert inboundHandlingTimeBucketFrequencies .length == HandlingTimeTracker .BUCKET_COUNT ;
180- }
169+ assert inboundHandlingTimeBucketFrequencies .length == HandlingTimeTracker .BUCKET_COUNT ;
181170 return true ;
182171 }
183172
184173 @ Override
185- @ UpdateForV9 (owner = UpdateForV9 .Owner .DISTRIBUTED_COORDINATION )
186- // review the "if" blocks checking for non-empty once we have
187174 public Iterator <? extends ToXContent > toXContentChunked (ToXContent .Params outerParams ) {
188175 return Iterators .concat (Iterators .single ((builder , params ) -> {
189176 builder .startObject (Fields .TRANSPORT );
@@ -193,19 +180,10 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params outerP
193180 builder .humanReadableField (Fields .RX_SIZE_IN_BYTES , Fields .RX_SIZE , ByteSizeValue .ofBytes (rxSize ));
194181 builder .field (Fields .TX_COUNT , txCount );
195182 builder .humanReadableField (Fields .TX_SIZE_IN_BYTES , Fields .TX_SIZE , ByteSizeValue .ofBytes (txSize ));
196- if (inboundHandlingTimeBucketFrequencies .length > 0 ) {
197- histogramToXContent (builder , inboundHandlingTimeBucketFrequencies , Fields .INBOUND_HANDLING_TIME_HISTOGRAM );
198- histogramToXContent (builder , outboundHandlingTimeBucketFrequencies , Fields .OUTBOUND_HANDLING_TIME_HISTOGRAM );
199- } else {
200- // Stats came from before v8.1
201- assert IMPOSSIBLE_IN_V9 ;
202- }
203- if (transportActionStats .isEmpty () == false ) {
204- builder .startObject (Fields .ACTIONS );
205- } else {
206- // Stats came from before v8.8
207- assert IMPOSSIBLE_IN_V9 ;
208- }
183+ assert inboundHandlingTimeBucketFrequencies .length > 0 ;
184+ histogramToXContent (builder , inboundHandlingTimeBucketFrequencies , Fields .INBOUND_HANDLING_TIME_HISTOGRAM );
185+ histogramToXContent (builder , outboundHandlingTimeBucketFrequencies , Fields .OUTBOUND_HANDLING_TIME_HISTOGRAM );
186+ builder .startObject (Fields .ACTIONS );
209187 return builder ;
210188 }),
211189
@@ -215,12 +193,7 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params outerP
215193 return builder ;
216194 }),
217195
218- Iterators .single ((builder , params ) -> {
219- if (transportActionStats .isEmpty () == false ) {
220- builder .endObject ();
221- }
222- return builder .endObject ();
223- })
196+ Iterators .single ((builder , params ) -> { return builder .endObject ().endObject (); })
224197 );
225198 }
226199
0 commit comments