Skip to content

Commit b21da6d

Browse files
committed
Fix issues with native transports
1 parent f5db30d commit b21da6d

File tree

5 files changed

+43
-33
lines changed

5 files changed

+43
-33
lines changed

pom.xml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,23 +267,19 @@
267267

268268
<dependency>
269269
<groupId>io.netty</groupId>
270-
<artifactId>netty-transport-native-epoll</artifactId>
271-
<classifier>linux-x86_64</classifier>
270+
<artifactId>netty-transport-classes-epoll</artifactId>
272271
<optional>true</optional>
273272
</dependency>
274273

275274
<dependency>
276275
<groupId>io.netty</groupId>
277-
<artifactId>netty-transport-native-kqueue</artifactId>
278-
<classifier>osx-x86_64</classifier>
276+
<artifactId>netty-transport-classes-kqueue</artifactId>
279277
<optional>true</optional>
280278
</dependency>
281279

282280
<dependency>
283-
<groupId>io.netty.incubator</groupId>
284-
<artifactId>netty-incubator-transport-native-io_uring</artifactId>
285-
<version>0.0.26.Final</version>
286-
<classifier>linux-x86_64</classifier>
281+
<groupId>io.netty</groupId>
282+
<artifactId>netty-transport-classes-io_uring</artifactId>
287283
<optional>true</optional>
288284
</dependency>
289285

src/main/java/io/lettuce/core/resource/EpollProvider.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
import io.netty.bootstrap.Bootstrap;
2828
import io.netty.channel.Channel;
2929
import io.netty.channel.EventLoopGroup;
30+
import io.netty.channel.MultiThreadIoEventLoopGroup;
3031
import io.netty.channel.epoll.Epoll;
3132
import io.netty.channel.epoll.EpollChannelOption;
3233
import io.netty.channel.epoll.EpollDatagramChannel;
3334
import io.netty.channel.epoll.EpollDomainSocketChannel;
3435
import io.netty.channel.epoll.EpollEventLoopGroup;
36+
import io.netty.channel.epoll.EpollIoHandler;
3537
import io.netty.channel.epoll.EpollSocketChannel;
3638
import io.netty.channel.socket.DatagramChannel;
3739
import io.netty.channel.unix.DomainSocketAddress;
@@ -145,17 +147,20 @@ public boolean matches(Class<? extends EventExecutorGroup> type) {
145147

146148
LettuceAssert.notNull(type, "EventLoopGroup type must not be null");
147149

148-
return type.equals(EpollEventLoopGroup.class);
150+
// Support both old deprecated EpollEventLoopGroup and new MultiThreadIoEventLoopGroup
151+
return type.equals(EpollEventLoopGroup.class) || type.equals(MultiThreadIoEventLoopGroup.class);
149152
}
150153

151154
@Override
152155
public Class<? extends EventLoopGroup> eventLoopGroupClass() {
153-
return EpollEventLoopGroup.class;
156+
// Return the new recommended class, but keep backward compatibility
157+
return MultiThreadIoEventLoopGroup.class;
154158
}
155159

156160
@Override
157161
public EventLoopGroup newEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
158-
return new EpollEventLoopGroup(nThreads, threadFactory);
162+
// Use the new Netty 4.2 approach with IoHandlerFactory
163+
return new MultiThreadIoEventLoopGroup(nThreads, threadFactory, EpollIoHandler.newFactory());
159164
}
160165

161166
@Override

src/main/java/io/lettuce/core/resource/EventLoopResources.java

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

2525
import io.netty.channel.Channel;
2626
import io.netty.channel.EventLoopGroup;
27-
import io.netty.channel.epoll.EpollEventLoopGroup;
2827
import io.netty.channel.socket.DatagramChannel;
2928
import io.netty.util.concurrent.EventExecutorGroup;
3029

@@ -51,7 +50,7 @@ public interface EventLoopResources {
5150
Class<? extends EventLoopGroup> eventLoopGroupClass();
5251

5352
/**
54-
* Create a new {@link EpollEventLoopGroup}.
53+
* Create a new {@link EventLoopGroup}.
5554
*
5655
* @param nThreads number of threads.
5756
* @param threadFactory the {@link ThreadFactory}.

src/main/java/io/lettuce/core/resource/IOUringProvider.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,23 @@
2727
import io.netty.bootstrap.Bootstrap;
2828
import io.netty.channel.Channel;
2929
import io.netty.channel.EventLoopGroup;
30+
import io.netty.channel.MultiThreadIoEventLoopGroup;
3031
import io.netty.channel.socket.DatagramChannel;
3132
import io.netty.channel.unix.DomainSocketAddress;
32-
import io.netty.incubator.channel.uring.IOUring;
33-
import io.netty.incubator.channel.uring.IOUringChannelOption;
34-
import io.netty.incubator.channel.uring.IOUringDatagramChannel;
35-
import io.netty.incubator.channel.uring.IOUringEventLoopGroup;
36-
import io.netty.incubator.channel.uring.IOUringSocketChannel;
33+
import io.netty.channel.uring.IoUring;
34+
import io.netty.channel.uring.IoUringChannelOption;
35+
import io.netty.channel.uring.IoUringDatagramChannel;
36+
37+
import io.netty.channel.uring.IoUringIoHandler;
38+
import io.netty.channel.uring.IoUringSocketChannel;
3739
import io.netty.util.concurrent.EventExecutorGroup;
3840
import io.netty.util.internal.SystemPropertyUtil;
3941
import io.netty.util.internal.logging.InternalLogger;
4042
import io.netty.util.internal.logging.InternalLoggerFactory;
4143

4244
/**
4345
* Wraps and provides io_uring classes. This is to protect the user from {@link ClassNotFoundException}'s caused by the absence
44-
* of the {@literal netty-incubator-transport-native-io_uring} library during runtime. Internal API.
46+
* of the {@literal netty-transport-native-io_uring} library during runtime. Internal API.
4547
*
4648
* @author Mark Paluch
4749
* @since 6.1
@@ -63,7 +65,7 @@ public class IOUringProvider {
6365
boolean availability;
6466
try {
6567
Class.forName("io.netty.incubator.channel.uring.IOUring");
66-
availability = IOUring.isAvailable();
68+
availability = IoUring.isAvailable();
6769
} catch (ClassNotFoundException e) {
6870
availability = false;
6971
}
@@ -119,16 +121,16 @@ public static EventLoopResources getResources() {
119121
*/
120122
public static void applyKeepAlive(Bootstrap bootstrap, int count, Duration idle, Duration interval) {
121123

122-
bootstrap.option(IOUringChannelOption.TCP_KEEPCNT, count);
123-
bootstrap.option(IOUringChannelOption.TCP_KEEPIDLE, Math.toIntExact(idle.getSeconds()));
124-
bootstrap.option(IOUringChannelOption.TCP_KEEPINTVL, Math.toIntExact(interval.getSeconds()));
124+
bootstrap.option(IoUringChannelOption.TCP_KEEPCNT, count);
125+
bootstrap.option(IoUringChannelOption.TCP_KEEPIDLE, Math.toIntExact(idle.getSeconds()));
126+
bootstrap.option(IoUringChannelOption.TCP_KEEPINTVL, Math.toIntExact(interval.getSeconds()));
125127
}
126128

127129
/**
128130
* Apply TcpUserTimeout options.
129131
*/
130132
public static void applyTcpUserTimeout(Bootstrap bootstrap, Duration timeout) {
131-
bootstrap.option(IOUringChannelOption.TCP_USER_TIMEOUT, Math.toIntExact(timeout.toMillis()));
133+
bootstrap.option(IoUringChannelOption.TCP_USER_TIMEOUT, Math.toIntExact(timeout.toMillis()));
132134
}
133135

134136
/**
@@ -143,32 +145,35 @@ public boolean matches(Class<? extends EventExecutorGroup> type) {
143145

144146
LettuceAssert.notNull(type, "EventLoopGroup type must not be null");
145147

146-
return type.equals(eventLoopGroupClass());
148+
// In Netty 4.2, IoUringEventLoopGroup doesn't exist, only MultiThreadIoEventLoopGroup
149+
return type.equals(MultiThreadIoEventLoopGroup.class);
147150
}
148151

149152
@Override
150153
public Class<? extends EventLoopGroup> eventLoopGroupClass() {
151-
return IOUringEventLoopGroup.class;
154+
// Return the new recommended class, but keep backward compatibility
155+
return MultiThreadIoEventLoopGroup.class;
152156
}
153157

154158
@Override
155159
public EventLoopGroup newEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
156-
return new IOUringEventLoopGroup(nThreads, threadFactory);
160+
// Use the new Netty 4.2 approach with IoHandlerFactory
161+
return new MultiThreadIoEventLoopGroup(nThreads, threadFactory, IoUringIoHandler.newFactory());
157162
}
158163

159164
@Override
160165
public Class<? extends Channel> socketChannelClass() {
161-
return IOUringSocketChannel.class;
166+
return IoUringSocketChannel.class;
162167
}
163168

164169
@Override
165170
public Class<? extends Channel> domainSocketChannelClass() {
166-
return IOUringSocketChannel.class;
171+
return IoUringSocketChannel.class;
167172
}
168173

169174
@Override
170175
public Class<? extends DatagramChannel> datagramChannelClass() {
171-
return IOUringDatagramChannel.class;
176+
return IoUringDatagramChannel.class;
172177
}
173178

174179
@Override

src/main/java/io/lettuce/core/resource/KqueueProvider.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import io.lettuce.core.internal.LettuceAssert;
2626
import io.netty.channel.Channel;
2727
import io.netty.channel.EventLoopGroup;
28+
import io.netty.channel.MultiThreadIoEventLoopGroup;
2829
import io.netty.channel.kqueue.KQueue;
2930
import io.netty.channel.kqueue.KQueueDatagramChannel;
3031
import io.netty.channel.kqueue.KQueueDomainSocketChannel;
3132
import io.netty.channel.kqueue.KQueueEventLoopGroup;
33+
import io.netty.channel.kqueue.KQueueIoHandler;
3234
import io.netty.channel.kqueue.KQueueSocketChannel;
3335
import io.netty.channel.socket.DatagramChannel;
3436
import io.netty.channel.unix.DomainSocketAddress;
@@ -182,23 +184,26 @@ public boolean matches(Class<? extends EventExecutorGroup> type) {
182184

183185
LettuceAssert.notNull(type, "EventLoopGroup type must not be null");
184186

185-
return type.equals(eventLoopGroupClass());
187+
// Support both old deprecated KQueueEventLoopGroup and new MultiThreadIoEventLoopGroup
188+
return type.equals(KQueueEventLoopGroup.class) || type.equals(MultiThreadIoEventLoopGroup.class);
186189
}
187190

188191
@Override
189192
public Class<? extends EventLoopGroup> eventLoopGroupClass() {
190193

191194
checkForKqueueLibrary();
192195

193-
return KQueueEventLoopGroup.class;
196+
// Return the new recommended class, but keep backward compatibility
197+
return MultiThreadIoEventLoopGroup.class;
194198
}
195199

196200
@Override
197201
public EventLoopGroup newEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
198202

199203
checkForKqueueLibrary();
200204

201-
return new KQueueEventLoopGroup(nThreads, threadFactory);
205+
// Use the new Netty 4.2 approach with IoHandlerFactory
206+
return new MultiThreadIoEventLoopGroup(nThreads, threadFactory, KQueueIoHandler.newFactory());
202207
}
203208

204209
@Override

0 commit comments

Comments
 (0)