Skip to content

Commit

Permalink
[Remove] Deprecated Fractional ByteSizeValue support
Browse files Browse the repository at this point in the history
This commit removes the deprecation warning for fractional bytes size
values. This leniency was deprecated a long time ago in Legacy 6.2. The
removal should come as no surprise to users.

Signed-off-by: Nicholas Walter Knize <[email protected]>
  • Loading branch information
nknize committed Jul 31, 2023
1 parent 0750907 commit fbc7544
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
24 changes: 5 additions & 19 deletions server/src/main/java/org/opensearch/common/unit/ByteSizeValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.logging.LogConfigurator;
import org.opensearch.common.network.NetworkService;
import org.opensearch.core.xcontent.ToXContentFragment;
import org.opensearch.core.xcontent.XContentBuilder;

Expand All @@ -54,17 +51,6 @@
*/
public class ByteSizeValue implements Writeable, Comparable<ByteSizeValue>, ToXContentFragment {

/**
* We have to lazy initialize the deprecation logger as otherwise a static logger here would be constructed before logging is configured
* leading to a runtime failure (see {@link LogConfigurator#checkErrorListener()} ). The premature construction would come from any
* {@link ByteSizeValue} object constructed in, for example, settings in {@link NetworkService}.
*
* @opensearch.internal
*/
static class DeprecationLoggerHolder {
static DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(ByteSizeValue.class);
}

public static final ByteSizeValue ZERO = new ByteSizeValue(0, ByteSizeUnit.BYTES);

private final long size;
Expand Down Expand Up @@ -262,14 +248,14 @@ private static ByteSizeValue parse(
return new ByteSizeValue(Long.parseLong(s), unit);
} catch (final NumberFormatException e) {
try {
final double doubleValue = Double.parseDouble(s);
DeprecationLoggerHolder.deprecationLogger.deprecate(
"fractional_byte_values",
"Fractional bytes values are deprecated. Use non-fractional bytes values instead: [{}] found for setting [{}]",
Double.parseDouble(s);
throw new OpenSearchParseException(
"Failed to parse bytes value [{}]. Fractional bytes values have been "
+ "deprecated since Legacy 6.2. Use non-fractional bytes values instead: found for setting [{}]",
e,
initialInput,
settingName
);
return new ByteSizeValue((long) (doubleValue * unit.toBytes(1)));
} catch (final NumberFormatException ignored) {
throw new OpenSearchParseException("failed to parse [{}]", e, initialInput);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,10 @@ public void testParseInvalidNumber() throws IOException {
public void testParseFractionalNumber() throws IOException {
ByteSizeUnit unit = randomValueOtherThan(ByteSizeUnit.BYTES, () -> randomFrom(ByteSizeUnit.values()));
String fractionalValue = "23.5" + unit.getSuffix();
ByteSizeValue instance = ByteSizeValue.parseBytesSizeValue(fractionalValue, "test");
assertEquals(fractionalValue, instance.toString());
assertWarnings(
"Fractional bytes values are deprecated. Use non-fractional bytes values instead: ["
+ fractionalValue
+ "] found for setting [test]"
// test exception is thrown: fractional byte size values has been deprecated since Legacy 6.2
OpenSearchParseException e = expectThrows(
OpenSearchParseException.class,
() -> ByteSizeValue.parseBytesSizeValue(fractionalValue, "test")
);
}

Expand Down

0 comments on commit fbc7544

Please sign in to comment.