Skip to content

Commit b981203

Browse files
authored
Fix Netty deprecation warnings in transport-reactor-netty4 module (#20429)
* Fix Netty deprecation warnings in transport-reactor-netty4 module Signed-off-by: Sergei Ustimenko <fdesu@proton.me> * Add the CHANGELOG entry Signed-off-by: Sergei Ustimenko <fdesu@proton.me> --------- Signed-off-by: Sergei Ustimenko <fdesu@proton.me>
1 parent be7b387 commit b981203

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3535
- Allow removing plugin that's optionally extended ([#20417](https://github.com/opensearch-project/OpenSearch/pull/20417))
3636
- Fix indexing regression and bug fixes for grouping criteria. ([20145](https://github.com/opensearch-project/OpenSearch/pull/20145))
3737
- LeafReader should not remove SubReaderWrappers incase IndexWriter encounters a non aborting Exception ([#20193](https://github.com/opensearch-project/OpenSearch/pull/20193))
38+
- Fix Netty deprecation warnings in transport-reactor-netty4 module ([20429](https://github.com/opensearch-project/OpenSearch/pull/20429))
3839

3940
### Dependencies
4041
- Bump `com.google.auth:google-auth-library-oauth2-http` from 1.38.0 to 1.41.0 ([#20183](https://github.com/opensearch-project/OpenSearch/pull/20183))

plugins/transport-reactor-netty4/src/main/java/org/opensearch/transport/reactor/SharedGroupFactory.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import java.util.concurrent.atomic.AtomicBoolean;
2727

2828
import io.netty.channel.EventLoopGroup;
29-
import io.netty.channel.nio.NioEventLoopGroup;
29+
import io.netty.channel.MultiThreadIoEventLoopGroup;
30+
import io.netty.channel.nio.NioIoHandler;
3031
import io.netty.util.concurrent.Future;
3132

3233
import static org.opensearch.common.util.concurrent.OpenSearchExecutors.daemonThreadFactory;
@@ -87,9 +88,10 @@ public synchronized SharedGroup getHttpGroup() {
8788
return getGenericGroup();
8889
} else {
8990
if (dedicatedHttpGroup == null) {
90-
NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(
91+
EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(
9192
httpWorkerCount,
92-
daemonThreadFactory(settings, HttpServerTransport.HTTP_SERVER_WORKER_THREAD_NAME_PREFIX)
93+
daemonThreadFactory(settings, HttpServerTransport.HTTP_SERVER_WORKER_THREAD_NAME_PREFIX),
94+
NioIoHandler.newFactory()
9395
);
9496
dedicatedHttpGroup = new SharedGroup(new RefCountedGroup(eventLoopGroup));
9597
}
@@ -99,9 +101,10 @@ public synchronized SharedGroup getHttpGroup() {
99101

100102
private SharedGroup getGenericGroup() {
101103
if (genericGroup == null) {
102-
EventLoopGroup eventLoopGroup = new NioEventLoopGroup(
104+
EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(
103105
workerCount,
104-
daemonThreadFactory(settings, TcpTransport.TRANSPORT_WORKER_THREAD_NAME_PREFIX)
106+
daemonThreadFactory(settings, TcpTransport.TRANSPORT_WORKER_THREAD_NAME_PREFIX),
107+
NioIoHandler.newFactory()
105108
);
106109
this.genericGroup = new RefCountedGroup(eventLoopGroup);
107110
} else {

plugins/transport-reactor-netty4/src/test/java/org/opensearch/http/reactor/netty4/ReactorHttpClient.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636

3737
import io.netty.buffer.ByteBuf;
3838
import io.netty.buffer.Unpooled;
39-
import io.netty.channel.nio.NioEventLoopGroup;
39+
import io.netty.channel.EventLoopGroup;
40+
import io.netty.channel.MultiThreadIoEventLoopGroup;
41+
import io.netty.channel.nio.NioIoHandler;
4042
import io.netty.handler.codec.http.DefaultFullHttpRequest;
4143
import io.netty.handler.codec.http.DefaultFullHttpResponse;
4244
import io.netty.handler.codec.http.EmptyHttpHeaders;
@@ -199,15 +201,15 @@ private List<FullHttpResponse> sendRequests(
199201
final Collection<FullHttpRequest> requests,
200202
boolean ordered
201203
) {
202-
final NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(1);
204+
final EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory());
203205
try {
204206
final HttpClient client = createClient(remoteAddress, eventLoopGroup);
205207

206208
@SuppressWarnings("unchecked")
207209
final Mono<FullHttpResponse>[] monos = requests.stream()
208210
.map(
209211
request -> client.headers(h -> h.add(request.headers()))
210-
.baseUrl(request.getUri())
212+
.baseUrl(request.uri())
211213
.request(request.method())
212214
.send(Mono.fromSupplier(() -> request.content()))
213215
.responseSingle(
@@ -240,12 +242,12 @@ private FullHttpResponse sendRequestStream(
240242
final HttpRequest request,
241243
final Stream<ToXContent> stream
242244
) {
243-
final NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(1);
245+
final EventLoopGroup eventLoopGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory());
244246
try {
245247
final HttpClient client = createClient(remoteAddress, eventLoopGroup);
246248

247249
return client.headers(h -> h.add(request.headers()))
248-
.baseUrl(request.getUri())
250+
.baseUrl(request.uri())
249251
.request(request.method())
250252
.send(Flux.fromStream(stream).map(s -> {
251253
try (XContentBuilder builder = XContentType.JSON.contentBuilder()) {
@@ -276,7 +278,7 @@ private FullHttpResponse sendRequestStream(
276278
}
277279
}
278280

279-
private HttpClient createClient(final InetSocketAddress remoteAddress, final NioEventLoopGroup eventLoopGroup) {
281+
private HttpClient createClient(final InetSocketAddress remoteAddress, final EventLoopGroup eventLoopGroup) {
280282
final HttpClient client = HttpClient.newConnection()
281283
.resolver(DefaultAddressResolverGroup.INSTANCE)
282284
.runOn(eventLoopGroup)

plugins/transport-reactor-netty4/src/test/java/org/opensearch/http/reactor/netty4/ReactorNetty4HttpServerTransportTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@
7575
import io.netty.channel.ChannelHandlerAdapter;
7676
import io.netty.channel.ChannelInitializer;
7777
import io.netty.channel.ChannelOption;
78-
import io.netty.channel.nio.NioEventLoopGroup;
78+
import io.netty.channel.EventLoopGroup;
79+
import io.netty.channel.MultiThreadIoEventLoopGroup;
80+
import io.netty.channel.nio.NioIoHandler;
7981
import io.netty.channel.socket.SocketChannel;
8082
import io.netty.channel.socket.nio.NioSocketChannel;
8183
import io.netty.handler.codec.http.DefaultFullHttpRequest;
@@ -504,7 +506,7 @@ public void testConnectTimeout() throws Exception {
504506
new TimeValue(randomIntBetween(100, 300))
505507
).build();
506508

507-
NioEventLoopGroup group = new NioEventLoopGroup();
509+
EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
508510
try (
509511
ReactorNetty4HttpServerTransport transport = new ReactorNetty4HttpServerTransport(
510512
settings,

plugins/transport-reactor-netty4/src/test/java/org/opensearch/http/reactor/netty4/ssl/SecureReactorNetty4HttpServerTransportTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
import io.netty.channel.ChannelHandlerAdapter;
6868
import io.netty.channel.ChannelInitializer;
6969
import io.netty.channel.ChannelOption;
70-
import io.netty.channel.nio.NioEventLoopGroup;
70+
import io.netty.channel.EventLoopGroup;
71+
import io.netty.channel.MultiThreadIoEventLoopGroup;
72+
import io.netty.channel.nio.NioIoHandler;
7173
import io.netty.channel.socket.SocketChannel;
7274
import io.netty.channel.socket.nio.NioSocketChannel;
7375
import io.netty.handler.codec.http.DefaultFullHttpRequest;
@@ -511,7 +513,7 @@ public void testConnectTimeout() throws Exception {
511513
new TimeValue(randomIntBetween(100, 300))
512514
).build();
513515

514-
NioEventLoopGroup group = new NioEventLoopGroup();
516+
EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
515517
try (
516518
ReactorNetty4HttpServerTransport transport = new ReactorNetty4HttpServerTransport(
517519
settings,

0 commit comments

Comments
 (0)