Skip to content

Remove support for fractional byte size values #53927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/reference/migration/migrate_8_0/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ processors. As this leads to more context switches and more threads but without
an increase in the number of physical CPUs on which to schedule these additional
threads, the `node.processors` setting is now bounded by the number of available
processors.

[float]
==== Fractional byte size values are no longer supported

Using fractional byte size values such as `23.5pb` have been deprecated since
Elasticsearch 6.2.0. As of Elasticsearch 8.0.0, fractional byte size values are
now rejected.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.ingest.common;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.ingest.IngestDocument;
Expand All @@ -28,6 +29,7 @@
import org.hamcrest.CoreMatchers;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;

public class BytesProcessorTests extends AbstractStringProcessorTestCase<Long> {

Expand Down Expand Up @@ -90,9 +92,10 @@ public void testFractional() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "1.1kb");
Processor processor = newProcessor(fieldName, randomBoolean(), fieldName);
processor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue(fieldName, expectedResultType()), equalTo(1126L));
assertWarnings("Fractional bytes values are deprecated. Use non-fractional bytes values instead: [1.1kb] found for setting " +
"[Ingest Field]");
final ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> processor.execute(ingestDocument));
assertThat(e.getMessage(), equalTo("failed to parse [1.1kb]"));
assertThat(e.getCause(), instanceOf(NumberFormatException.class));
assertThat(e.getCause().getMessage(), equalTo("For input string: \"1.1\""));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ static boolean parseBoolean(String b, String key, boolean isFiltered) {
}

public static Setting<ByteSizeValue> byteSizeSetting(String key, ByteSizeValue value, Property... properties) {
return byteSizeSetting(key, (s) -> value.toString(), properties);
return byteSizeSetting(key, (s) -> value.getStringRep(), properties);
}

public static Setting<ByteSizeValue> byteSizeSetting(String key, Setting<ByteSizeValue> fallbackSetting,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@

package org.elasticsearch.common.unit;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder;

Expand All @@ -35,8 +33,6 @@

public class ByteSizeValue implements Writeable, Comparable<ByteSizeValue>, ToXContentFragment {

private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(ByteSizeValue.class));

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

private final long size;
Expand Down Expand Up @@ -225,15 +221,7 @@ private static ByteSizeValue parse(final String initialInput, final String norma
try {
return new ByteSizeValue(Long.parseLong(s), unit);
} catch (final NumberFormatException e) {
try {
final double doubleValue = Double.parseDouble(s);
deprecationLogger.deprecated(
"Fractional bytes values are deprecated. Use non-fractional bytes values instead: [{}] found for setting [{}]",
initialInput, settingName);
return new ByteSizeValue((long) (doubleValue * unit.toBytes(1)));
} catch (final NumberFormatException ignored) {
throw new ElasticsearchParseException("failed to parse [{}]", e, initialInput);
}
throw new ElasticsearchParseException("failed to parse [{}]", e, initialInput);
}
} catch (IllegalArgumentException e) {
throw new ElasticsearchParseException("failed to parse setting [{}] with value [{}] as a size in bytes", e, settingName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;

public class ByteSizeValueTests extends AbstractWireSerializingTestCase<ByteSizeValue> {
Expand Down Expand Up @@ -300,10 +301,11 @@ 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]");
final ElasticsearchParseException e =
expectThrows(ElasticsearchParseException.class, () -> ByteSizeValue.parseBytesSizeValue(fractionalValue, "test"));
assertThat(e.getMessage(), equalTo("failed to parse [" + fractionalValue + "]"));
assertThat(e.getCause(), instanceOf(NumberFormatException.class));
assertThat(e.getCause().getMessage(), equalTo("For input string: \"23.5\""));
}

public void testGetBytesAsInt() {
Expand Down