Skip to content

Commit 1accaf3

Browse files
authored
Remove SizeValue (#134871)
In principle this utility class lets us format potentially-large numbers nicely in API responses, but in practice it is wholly unused for that purpose. Nor is it used to accept user input (e.g. setting values) that could potentially be large. In the few places it appears in the codebase we can just use `Long` instead.
1 parent ebc291e commit 1accaf3

File tree

10 files changed

+15
-307
lines changed

10 files changed

+15
-307
lines changed

modules/kibana/src/internalClusterTest/java/org/elasticsearch/kibana/KibanaThreadPoolIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private static void blockThreadPool(String threadPoolName, ThreadPool threadPool
233233
private static void fillThreadPoolQueues(String threadPoolName, ThreadPool threadPool) {
234234
ThreadPool.Info info = threadPool.info(threadPoolName);
235235

236-
for (int i = 0; i < info.getQueueSize().singles(); i++) {
236+
for (int i = 0; i < info.getQueueSize(); i++) {
237237
try {
238238
threadPool.executor(threadPoolName).execute(() -> {});
239239
} catch (EsRejectedExecutionException e) {

server/src/internalClusterTest/java/org/elasticsearch/action/bulk/IncrementalBulkIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ public boolean isForceExecution() {
558558
}
559559

560560
private static void fillWriteCoordinationQueue(ThreadPool threadPool) {
561-
final var queueSize = Math.toIntExact(threadPool.info(ThreadPool.Names.WRITE_COORDINATION).getQueueSize().singles());
561+
final var queueSize = Math.toIntExact(threadPool.info(ThreadPool.Names.WRITE_COORDINATION).getQueueSize());
562562
final var queueFilled = new AtomicBoolean(false);
563563
final var queueFillingTask = new AbstractRunnable() {
564564
@Override

server/src/main/java/org/elasticsearch/common/unit/SizeValue.java

Lines changed: 0 additions & 164 deletions
This file was deleted.

server/src/main/java/org/elasticsearch/rest/action/cat/RestTable.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.common.collect.Iterators;
1515
import org.elasticsearch.common.regex.Regex;
1616
import org.elasticsearch.common.unit.ByteSizeValue;
17-
import org.elasticsearch.common.unit.SizeValue;
1817
import org.elasticsearch.common.util.set.Sets;
1918
import org.elasticsearch.core.Booleans;
2019
import org.elasticsearch.core.TimeValue;
@@ -370,24 +369,6 @@ private static String renderValue(RestRequest request, Object value) {
370369
return v.toString();
371370
}
372371
}
373-
if (value instanceof SizeValue v) {
374-
String resolution = request.param("size");
375-
if ("".equals(resolution)) {
376-
return Long.toString(v.singles());
377-
} else if ("k".equals(resolution)) {
378-
return Long.toString(v.kilo());
379-
} else if ("m".equals(resolution)) {
380-
return Long.toString(v.mega());
381-
} else if ("g".equals(resolution)) {
382-
return Long.toString(v.giga());
383-
} else if ("t".equals(resolution)) {
384-
return Long.toString(v.tera());
385-
} else if ("p".equals(resolution)) {
386-
return Long.toString(v.peta());
387-
} else {
388-
return v.toString();
389-
}
390-
}
391372
if (value instanceof TimeValue v) {
392373
String resolution = request.param("time");
393374
if ("nanos".equals(resolution)) {

server/src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoR
207207
Integer size = null;
208208

209209
if (poolInfo != null) {
210-
if (poolInfo.getQueueSize() != null) {
211-
maxQueueSize = poolInfo.getQueueSize().singles();
212-
}
210+
maxQueueSize = poolInfo.getQueueSize();
213211
if (poolInfo.getKeepAlive() != null) {
214212
keepAlive = poolInfo.getKeepAlive();
215213
}

server/src/main/java/org/elasticsearch/threadpool/FixedExecutorBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import org.elasticsearch.common.settings.Setting;
1313
import org.elasticsearch.common.settings.Settings;
14-
import org.elasticsearch.common.unit.SizeValue;
1514
import org.elasticsearch.common.util.concurrent.EsExecutors;
1615
import org.elasticsearch.common.util.concurrent.EsExecutors.TaskTrackingConfig;
1716
import org.elasticsearch.common.util.concurrent.ThreadContext;
@@ -160,7 +159,7 @@ ThreadPool.ExecutorHolder build(final FixedExecutorSettings settings, final Thre
160159
size,
161160
size,
162161
null,
163-
queueSize < 0 ? null : new SizeValue(queueSize)
162+
queueSize < 0 ? null : (long) queueSize
164163
);
165164
return new ThreadPool.ExecutorHolder(executor, info);
166165
}

server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.elasticsearch.common.time.TimeProvider;
2020
import org.elasticsearch.common.unit.ByteSizeUnit;
2121
import org.elasticsearch.common.unit.ByteSizeValue;
22-
import org.elasticsearch.common.unit.SizeValue;
2322
import org.elasticsearch.common.util.concurrent.EsExecutors;
2423
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
2524
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionHandler;
@@ -934,7 +933,7 @@ public static class Info implements Writeable, ToXContentFragment {
934933
private final int min;
935934
private final int max;
936935
private final TimeValue keepAlive;
937-
private final SizeValue queueSize;
936+
private final Long queueSize;
938937

939938
public Info(String name, ThreadPoolType type) {
940939
this(name, type, -1);
@@ -944,7 +943,7 @@ public Info(String name, ThreadPoolType type, int size) {
944943
this(name, type, size, size, null, null);
945944
}
946945

947-
public Info(String name, ThreadPoolType type, int min, int max, @Nullable TimeValue keepAlive, @Nullable SizeValue queueSize) {
946+
public Info(String name, ThreadPoolType type, int min, int max, @Nullable TimeValue keepAlive, @Nullable Long queueSize) {
948947
this.name = name;
949948
this.type = type;
950949
this.min = min;
@@ -959,7 +958,7 @@ public Info(StreamInput in) throws IOException {
959958
min = in.readInt();
960959
max = in.readInt();
961960
keepAlive = in.readOptionalTimeValue();
962-
queueSize = in.readOptionalWriteable(SizeValue::new);
961+
queueSize = in.readOptionalVLong();
963962
}
964963

965964
@Override
@@ -969,7 +968,7 @@ public void writeTo(StreamOutput out) throws IOException {
969968
out.writeInt(min);
970969
out.writeInt(max);
971970
out.writeOptionalTimeValue(keepAlive);
972-
out.writeOptionalWriteable(queueSize);
971+
out.writeOptionalVLong(queueSize);
973972
}
974973

975974
public String getName() {
@@ -994,7 +993,7 @@ public TimeValue getKeepAlive() {
994993
}
995994

996995
@Nullable
997-
public SizeValue getQueueSize() {
996+
public Long getQueueSize() {
998997
return this.queueSize;
999998
}
1000999

@@ -1018,7 +1017,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
10181017
if (queueSize == null) {
10191018
builder.field("queue_size", -1);
10201019
} else {
1021-
builder.field("queue_size", queueSize.singles());
1020+
builder.field("queue_size", queueSize);
10221021
}
10231022
builder.endObject();
10241023
return builder;

server/src/test/java/org/elasticsearch/common/unit/SizeValueTests.java

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)