1010package org .elasticsearch .common .unit ;
1111
1212import org .elasticsearch .ElasticsearchParseException ;
13+ import org .elasticsearch .TransportVersion ;
1314import org .elasticsearch .common .Strings ;
1415import org .elasticsearch .common .io .stream .StreamInput ;
1516import org .elasticsearch .common .io .stream .StreamOutput ;
2425import java .util .Locale ;
2526import java .util .Objects ;
2627
27- import static org .elasticsearch .TransportVersions .BYTE_SIZE_VALUE_ALWAYS_USES_BYTES ;
28+ import static org .elasticsearch .TransportVersions .BYTE_SIZE_VALUE_ALWAYS_USES_BYTES_1 ;
29+ import static org .elasticsearch .TransportVersions .REVERT_BYTE_SIZE_VALUE_ALWAYS_USES_BYTES_1 ;
2830import static org .elasticsearch .common .unit .ByteSizeUnit .BYTES ;
2931import static org .elasticsearch .common .unit .ByteSizeUnit .GB ;
3032import static org .elasticsearch .common .unit .ByteSizeUnit .KB ;
@@ -111,7 +113,8 @@ static ByteSizeValue newByteSizeValue(long sizeInBytes, ByteSizeUnit desiredUnit
111113 public static ByteSizeValue readFrom (StreamInput in ) throws IOException {
112114 long size = in .readZLong ();
113115 ByteSizeUnit unit = ByteSizeUnit .readFrom (in );
114- if (in .getTransportVersion ().onOrAfter (BYTE_SIZE_VALUE_ALWAYS_USES_BYTES )) {
116+ TransportVersion tv = in .getTransportVersion ();
117+ if (tv .onOrAfter (BYTE_SIZE_VALUE_ALWAYS_USES_BYTES_1 ) && tv .before (REVERT_BYTE_SIZE_VALUE_ALWAYS_USES_BYTES_1 )) {
115118 return newByteSizeValue (size , unit );
116119 } else {
117120 return of (size , unit );
@@ -120,7 +123,8 @@ public static ByteSizeValue readFrom(StreamInput in) throws IOException {
120123
121124 @ Override
122125 public void writeTo (StreamOutput out ) throws IOException {
123- if (out .getTransportVersion ().onOrAfter (BYTE_SIZE_VALUE_ALWAYS_USES_BYTES )) {
126+ TransportVersion tv = out .getTransportVersion ();
127+ if (tv .onOrAfter (BYTE_SIZE_VALUE_ALWAYS_USES_BYTES_1 ) && tv .before (REVERT_BYTE_SIZE_VALUE_ALWAYS_USES_BYTES_1 )) {
124128 out .writeZLong (sizeInBytes );
125129 } else {
126130 out .writeZLong (Math .divideExact (sizeInBytes , desiredUnit .toBytes (1 )));
0 commit comments