Skip to content

Commit c012de8

Browse files
Deserialize deprecated thread pools compatibly with V9 (#118492)
ThreadPoolType.DIRECT and ThreadPoolType.FIXED_AUTO_QUEUE_SIZE are deprecated in V8 and will be removed in V9, but the types might still be used in transport messages from earlier versions. This change ensures that V8.18 can receive messages from earlier versions while still being able to communicate with V9 nodes where the types have been removed
1 parent 940ef77 commit c012de8

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,12 @@ public Info(String name, ThreadPoolType type, int min, int max, @Nullable TimeVa
941941

942942
public Info(StreamInput in) throws IOException {
943943
name = in.readString();
944-
type = ThreadPoolType.fromType(in.readString());
944+
ThreadPoolType receivedType = ThreadPoolType.fromType(in.readString());
945+
type = switch (receivedType) {
946+
case DIRECT, FIXED_AUTO_QUEUE_SIZE -> ThreadPoolType.FIXED;
947+
default -> receivedType;
948+
};
949+
945950
min = in.readInt();
946951
max = in.readInt();
947952
keepAlive = in.readOptionalTimeValue();

server/src/test/java/org/elasticsearch/nodesinfo/NodeInfoStreamingTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ private static NodeInfo createNodeInfo() {
138138
List<ThreadPool.Info> threadPoolInfos = new ArrayList<>(numThreadPools);
139139
for (int i = 0; i < numThreadPools; i++) {
140140
threadPoolInfos.add(
141-
new ThreadPool.Info(randomAlphaOfLengthBetween(3, 10), randomFrom(ThreadPool.ThreadPoolType.values()), randomInt())
141+
new ThreadPool.Info(
142+
randomAlphaOfLengthBetween(3, 10),
143+
randomFrom(ThreadPool.ThreadPoolType.FIXED, ThreadPool.ThreadPoolType.SCALING),
144+
randomInt()
145+
)
142146
);
143147
}
144148
threadPoolInfo = new ThreadPoolInfo(threadPoolInfos);

server/src/test/java/org/elasticsearch/threadpool/ThreadPoolSerializationTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ThreadPoolSerializationTests extends ESTestCase {
3737
@Before
3838
public void setUp() throws Exception {
3939
super.setUp();
40-
threadPoolType = randomFrom(ThreadPool.ThreadPoolType.values());
40+
threadPoolType = randomFrom(ThreadPool.ThreadPoolType.FIXED, ThreadPool.ThreadPoolType.SCALING);
4141
}
4242

4343
public void testThatQueueSizeSerializationWorks() throws Exception {
@@ -123,4 +123,15 @@ public void testThatThreadPoolTypeIsSerializedCorrectly() throws IOException {
123123

124124
assertThat(newInfo.getThreadPoolType(), is(threadPoolType));
125125
}
126+
127+
public void testThatDeprecatedTypesDeserializedAsFixed() throws IOException {
128+
ThreadPool.Info info = new ThreadPool.Info("foo", ThreadPool.ThreadPoolType.DIRECT);
129+
output.setTransportVersion(TransportVersion.current());
130+
info.writeTo(output);
131+
132+
StreamInput input = output.bytes().streamInput();
133+
ThreadPool.Info newInfo = new ThreadPool.Info(input);
134+
135+
assertThat(newInfo.getThreadPoolType(), is(ThreadPool.ThreadPoolType.FIXED));
136+
}
126137
}

0 commit comments

Comments
 (0)