Skip to content

Commit 6e47095

Browse files
authored
[Backport 2.x] [Remove] Deprecated Fractional ByteSizeValue support (opensearch-project#9005) (opensearch-project#9007)
This commit removes the deprecation warning for fractional bytes size values and, instead, throws an OpenSearchParseException if a user passes in a fraction byte value (e.g., 5.2b).. This leniency was deprecated a long time ago in Legacy 6.2 so the removal should come as no surprise to users. Signed-off-by: Nicholas Walter Knize <[email protected]> (cherry picked from commit 0b1f875)
1 parent ffb871c commit 6e47095

File tree

5 files changed

+22
-34
lines changed

5 files changed

+22
-34
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1919
- Bump `org.gradle.test-retry` from 1.5.3 to 1.5.4 ([#8842](https://github.com/opensearch-project/OpenSearch/pull/8842))
2020
- Bump `com.netflix.nebula.ospackage-base` from 11.3.0 to 11.4.0 ([#8838](https://github.com/opensearch-project/OpenSearch/pull/8838))
2121
- Bump `com.google.http-client:google-http-client-gson` from 1.43.2 to 1.43.3 ([#8840](https://github.com/opensearch-project/OpenSearch/pull/8840))
22-
- OpenJDK Update (July 2023 Patch releases) ([#8869](https://github.com/opensearch-project/OpenSearch/pull/8869)
22+
- OpenJDK Update (July 2023 Patch releases) ([#8869](https://github.com/opensearch-project/OpenSearch/pull/8869))
2323
- Bump `hadoop` libraries from 3.3.4 to 3.3.6 ([#6995](https://github.com/opensearch-project/OpenSearch/pull/6995))
2424
- Bump `com.gradle.enterprise` from 3.13.3 to 3.14.1 ([#8996](https://github.com/opensearch-project/OpenSearch/pull/8996))
2525
- Bump `org.apache.commons:commons-lang3` from 3.12.0 to 3.13.0 ([#8995](https://github.com/opensearch-project/OpenSearch/pull/8995))
@@ -38,6 +38,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3838
- Replace the deprecated IndexReader APIs with new storedFields() & termVectors() ([#7792](https://github.com/opensearch-project/OpenSearch/pull/7792))
3939
- [Remote Store] Add support to restore only unassigned shards of an index ([#8792](https://github.com/opensearch-project/OpenSearch/pull/8792))
4040
- Add safeguard limits for file cache during node level allocation ([#8208](https://github.com/opensearch-project/OpenSearch/pull/8208))
41+
- Add support for aggregation profiler with concurrent aggregation ([#8801](https://github.com/opensearch-project/OpenSearch/pull/8801))
42+
- [Remove] Deprecated Fractional ByteSizeValue support #9005 ([#9005](https://github.com/opensearch-project/OpenSearch/pull/9005))
4143

4244
### Deprecated
4345

modules/ingest-common/src/test/java/org/opensearch/ingest/common/BytesProcessorTests.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@
3333
package org.opensearch.ingest.common;
3434

3535
import org.opensearch.OpenSearchException;
36+
import org.opensearch.OpenSearchParseException;
3637
import org.opensearch.common.unit.ByteSizeUnit;
3738
import org.opensearch.common.unit.ByteSizeValue;
3839
import org.opensearch.ingest.IngestDocument;
3940
import org.opensearch.ingest.Processor;
4041
import org.opensearch.ingest.RandomDocumentPicks;
4142
import org.hamcrest.CoreMatchers;
4243

43-
import static org.hamcrest.Matchers.equalTo;
44-
4544
public class BytesProcessorTests extends AbstractStringProcessorTestCase<Long> {
4645

4746
private String modifiedInput;
@@ -101,14 +100,16 @@ public void testMissingUnits() {
101100
assertThat(exception.getMessage(), CoreMatchers.containsString("unit is missing or unrecognized"));
102101
}
103102

104-
public void testFractional() throws Exception {
103+
public void testFractional() {
105104
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
106105
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "1.1kb");
107106
Processor processor = newProcessor(fieldName, randomBoolean(), fieldName);
108-
processor.execute(ingestDocument);
109-
assertThat(ingestDocument.getFieldValue(fieldName, expectedResultType()), equalTo(1126L));
110-
assertWarnings(
111-
"Fractional bytes values are deprecated. Use non-fractional bytes values instead: [1.1kb] found for setting " + "[Ingest Field]"
107+
OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> processor.execute(ingestDocument));
108+
assertThat(
109+
e.getMessage(),
110+
CoreMatchers.containsString(
111+
"Fractional bytes values have been deprecated since Legacy 6.2. " + "Use non-fractional bytes values instead:"
112+
)
112113
);
113114
}
114115
}

server/src/main/java/org/opensearch/common/settings/Setting.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.opensearch.common.Nullable;
4141
import org.opensearch.common.Strings;
4242
import org.opensearch.common.collect.Tuple;
43+
import org.opensearch.common.unit.ByteSizeUnit;
4344
import org.opensearch.core.common.io.stream.StreamInput;
4445
import org.opensearch.core.common.io.stream.StreamOutput;
4546
import org.opensearch.core.common.io.stream.Writeable;
@@ -2047,7 +2048,7 @@ static boolean parseBoolean(String b, String key, boolean isFiltered) {
20472048
}
20482049

20492050
public static Setting<ByteSizeValue> byteSizeSetting(String key, ByteSizeValue value, Property... properties) {
2050-
return byteSizeSetting(key, (s) -> value.toString(), properties);
2051+
return byteSizeSetting(key, (s) -> value.getBytes() + ByteSizeUnit.BYTES.getSuffix(), properties);
20512052
}
20522053

20532054
public static Setting<ByteSizeValue> byteSizeSetting(String key, Setting<ByteSizeValue> fallbackSetting, Property... properties) {

server/src/main/java/org/opensearch/common/unit/ByteSizeValue.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
import org.opensearch.core.common.io.stream.StreamInput;
3838
import org.opensearch.core.common.io.stream.StreamOutput;
3939
import org.opensearch.core.common.io.stream.Writeable;
40-
import org.opensearch.common.logging.DeprecationLogger;
41-
import org.opensearch.common.logging.LogConfigurator;
42-
import org.opensearch.common.network.NetworkService;
4340
import org.opensearch.core.xcontent.ToXContentFragment;
4441
import org.opensearch.core.xcontent.XContentBuilder;
4542

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

57-
/**
58-
* We have to lazy initialize the deprecation logger as otherwise a static logger here would be constructed before logging is configured
59-
* leading to a runtime failure (see {@link LogConfigurator#checkErrorListener()} ). The premature construction would come from any
60-
* {@link ByteSizeValue} object constructed in, for example, settings in {@link NetworkService}.
61-
*
62-
* @opensearch.internal
63-
*/
64-
static class DeprecationLoggerHolder {
65-
static DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(ByteSizeValue.class);
66-
}
67-
6854
public static final ByteSizeValue ZERO = new ByteSizeValue(0, ByteSizeUnit.BYTES);
6955

7056
private final long size;
@@ -262,14 +248,14 @@ private static ByteSizeValue parse(
262248
return new ByteSizeValue(Long.parseLong(s), unit);
263249
} catch (final NumberFormatException e) {
264250
try {
265-
final double doubleValue = Double.parseDouble(s);
266-
DeprecationLoggerHolder.deprecationLogger.deprecate(
267-
"fractional_byte_values",
268-
"Fractional bytes values are deprecated. Use non-fractional bytes values instead: [{}] found for setting [{}]",
251+
Double.parseDouble(s);
252+
throw new OpenSearchParseException(
253+
"Failed to parse bytes value [{}]. Fractional bytes values have been "
254+
+ "deprecated since Legacy 6.2. Use non-fractional bytes values instead: found for setting [{}]",
255+
e,
269256
initialInput,
270257
settingName
271258
);
272-
return new ByteSizeValue((long) (doubleValue * unit.toBytes(1)));
273259
} catch (final NumberFormatException ignored) {
274260
throw new OpenSearchParseException("failed to parse [{}]", e, initialInput);
275261
}

server/src/test/java/org/opensearch/common/unit/ByteSizeValueTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,10 @@ public void testParseInvalidNumber() throws IOException {
336336
public void testParseFractionalNumber() throws IOException {
337337
ByteSizeUnit unit = randomValueOtherThan(ByteSizeUnit.BYTES, () -> randomFrom(ByteSizeUnit.values()));
338338
String fractionalValue = "23.5" + unit.getSuffix();
339-
ByteSizeValue instance = ByteSizeValue.parseBytesSizeValue(fractionalValue, "test");
340-
assertEquals(fractionalValue, instance.toString());
341-
assertWarnings(
342-
"Fractional bytes values are deprecated. Use non-fractional bytes values instead: ["
343-
+ fractionalValue
344-
+ "] found for setting [test]"
339+
// test exception is thrown: fractional byte size values has been deprecated since Legacy 6.2
340+
OpenSearchParseException e = expectThrows(
341+
OpenSearchParseException.class,
342+
() -> ByteSizeValue.parseBytesSizeValue(fractionalValue, "test")
345343
);
346344
}
347345

0 commit comments

Comments
 (0)