Skip to content

Commit b36a042

Browse files
prdoylerjernst
authored andcommitted
Limit ByteSizeUnit to 2 decimals (elastic#120142)
* Exhaustive testParseFractionalNumber * Refactor: encapsulate ByteSizeUnit constructor * Refactor: store size in bytes * Support up to 2 decimals in parsed ByteSizeValue * Fix test for rounding up with no warnings * ByteSizeUnit transport changes * Update docs/changelog/120142.yaml * Changelog details and impact * Fix change log breaking.area * Address PR comments
1 parent f968c9f commit b36a042

File tree

119 files changed

+643
-490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+643
-490
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/bytes/BytesArrayReadLongBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class BytesArrayReadLongBenchmark {
4747
@Setup
4848
public void initResults() throws IOException {
4949
final BytesStreamOutput tmp = new BytesStreamOutput();
50-
final long bytes = new ByteSizeValue(dataMb, ByteSizeUnit.MB).getBytes();
50+
final long bytes = ByteSizeValue.of(dataMb, ByteSizeUnit.MB).getBytes();
5151
for (int i = 0; i < bytes / 8; i++) {
5252
tmp.writeLong(i);
5353
}

benchmarks/src/main/java/org/elasticsearch/benchmark/bytes/PagedBytesReferenceReadLongBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class PagedBytesReferenceReadLongBenchmark {
4747
@Setup
4848
public void initResults() throws IOException {
4949
final BytesStreamOutput tmp = new BytesStreamOutput();
50-
final long bytes = new ByteSizeValue(dataMb, ByteSizeUnit.MB).getBytes();
50+
final long bytes = ByteSizeValue.of(dataMb, ByteSizeUnit.MB).getBytes();
5151
for (int i = 0; i < bytes / 8; i++) {
5252
tmp.writeLong(i);
5353
}

docs/changelog/120142.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pr: 120142
2+
summary: Limit `ByteSizeUnit` to 2 decimals
3+
area: Infra/Core
4+
type: breaking
5+
issues: []
6+
breaking:
7+
title: Limit `ByteSizeUnit` to 2 decimals
8+
area: Cluster and node setting
9+
details: In the past, byte values like `1.25 mb` were allowed but deprecated. Now, values with up to two decimal places are allowed,
10+
unless the unit is bytes, in which case no decimals are allowed. Values with too many decimal places result in an error.
11+
impact: Values with more than two decimal places, like `0.123 mb` will be rejected as an error,
12+
where in the past, they'd be accepted with a deprecation warning.
13+
notable: false

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ public void testFractional() throws Exception {
7777
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "1.1kb");
7878
Processor processor = newProcessor(fieldName, randomBoolean(), fieldName);
7979
processor.execute(ingestDocument);
80-
assertThat(ingestDocument.getFieldValue(fieldName, expectedResultType()), equalTo(1126L));
81-
assertWarnings(
82-
"Fractional bytes values are deprecated. Use non-fractional bytes values instead: [1.1kb] found for setting " + "[Ingest Field]"
83-
);
80+
assertThat(ingestDocument.getFieldValue(fieldName, expectedResultType()), equalTo(1127L));
8481
}
8582
}

modules/reindex/src/test/java/org/elasticsearch/reindex/remote/RemoteScrollableHitSourceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ public void testTooLargeResponse() throws Exception {
438438
public Future<HttpResponse> answer(InvocationOnMock invocationOnMock) throws Throwable {
439439
HeapBufferedAsyncResponseConsumer consumer = (HeapBufferedAsyncResponseConsumer) invocationOnMock.getArguments()[1];
440440
FutureCallback callback = (FutureCallback) invocationOnMock.getArguments()[3];
441-
assertEquals(new ByteSizeValue(100, ByteSizeUnit.MB).bytesAsInt(), consumer.getBufferLimit());
441+
assertEquals(ByteSizeValue.of(100, ByteSizeUnit.MB).bytesAsInt(), consumer.getBufferLimit());
442442
callback.failed(tooLong);
443443
return null;
444444
}

modules/repository-azure/src/internalClusterTest/java/org/elasticsearch/repositories/azure/AzureBlobStoreRepositoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected String repositoryType() {
9090
protected Settings repositorySettings(String repoName) {
9191
Settings.Builder settingsBuilder = Settings.builder()
9292
.put(super.repositorySettings(repoName))
93-
.put(AzureRepository.Repository.MAX_SINGLE_PART_UPLOAD_SIZE_SETTING.getKey(), new ByteSizeValue(1, ByteSizeUnit.MB))
93+
.put(AzureRepository.Repository.MAX_SINGLE_PART_UPLOAD_SIZE_SETTING.getKey(), ByteSizeValue.of(1, ByteSizeUnit.MB))
9494
.put(AzureRepository.Repository.CONTAINER_SETTING.getKey(), "container")
9595
.put(AzureStorageSettings.ACCOUNT_SETTING.getKey(), "test")
9696
.put(AzureRepository.Repository.DELETION_BATCH_SIZE_SETTING.getKey(), randomIntBetween(5, 256))

modules/repository-azure/src/internalClusterTest/java/org/elasticsearch/repositories/azure/AzureStorageCleanupThirdPartyTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected void createRepository(String repoName) {
115115
Settings.builder()
116116
.put("container", System.getProperty("test.azure.container"))
117117
.put("base_path", System.getProperty("test.azure.base") + randomAlphaOfLength(8))
118-
.put("max_single_part_upload_size", new ByteSizeValue(1, ByteSizeUnit.MB))
118+
.put("max_single_part_upload_size", ByteSizeValue.of(1, ByteSizeUnit.MB))
119119
)
120120
.get();
121121
assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));

modules/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public class AzureBlobStore implements BlobStore {
107107
private static final Logger logger = LogManager.getLogger(AzureBlobStore.class);
108108
// See https://learn.microsoft.com/en-us/rest/api/storageservices/blob-batch#request-body
109109
public static final int MAX_ELEMENTS_PER_BATCH = 256;
110-
private static final long DEFAULT_READ_CHUNK_SIZE = new ByteSizeValue(32, ByteSizeUnit.MB).getBytes();
111-
private static final int DEFAULT_UPLOAD_BUFFERS_SIZE = (int) new ByteSizeValue(64, ByteSizeUnit.KB).getBytes();
110+
private static final long DEFAULT_READ_CHUNK_SIZE = ByteSizeValue.of(32, ByteSizeUnit.MB).getBytes();
111+
private static final int DEFAULT_UPLOAD_BUFFERS_SIZE = (int) ByteSizeValue.of(64, ByteSizeUnit.KB).getBytes();
112112

113113
private final AzureStorageService service;
114114
private final BigArrays bigArrays;

modules/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static final class Repository {
8181
);
8282
public static final Setting<Boolean> READONLY_SETTING = Setting.boolSetting(READONLY_SETTING_KEY, false, Property.NodeScope);
8383
// see ModelHelper.BLOB_DEFAULT_MAX_SINGLE_UPLOAD_SIZE
84-
private static final ByteSizeValue DEFAULT_MAX_SINGLE_UPLOAD_SIZE = new ByteSizeValue(256, ByteSizeUnit.MB);
84+
private static final ByteSizeValue DEFAULT_MAX_SINGLE_UPLOAD_SIZE = ByteSizeValue.of(256, ByteSizeUnit.MB);
8585
public static final Setting<ByteSizeValue> MAX_SINGLE_PART_UPLOAD_SIZE_SETTING = Setting.byteSizeSetting(
8686
"max_single_part_upload_size",
8787
DEFAULT_MAX_SINGLE_UPLOAD_SIZE,

modules/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureStorageService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class AzureStorageService {
3737
* The maximum size of a BlockBlob block.
3838
* See https://docs.microsoft.com/en-us/rest/api/storageservices/understanding-block-blobs--append-blobs--and-page-blobs
3939
*/
40-
public static final ByteSizeValue MAX_BLOCK_SIZE = new ByteSizeValue(100, ByteSizeUnit.MB);
40+
public static final ByteSizeValue MAX_BLOCK_SIZE = ByteSizeValue.of(100, ByteSizeUnit.MB);
4141

4242
/**
4343
* The maximum number of blocks.

0 commit comments

Comments
 (0)