Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<micrometer.version>1.14.2</micrometer.version>
<micrometer-tracing.version>1.2.4</micrometer-tracing.version>
<mockito.version>4.9.0</mockito.version>
<netty.version>4.1.118.Final</netty.version>
<netty.version>4.2.4.Final</netty.version>
<openwebbeans.version>2.0.27</openwebbeans.version>
<reactor.version>3.6.6</reactor.version>
<rxjava.version>1.3.8</rxjava.version>
Expand Down Expand Up @@ -267,23 +267,19 @@

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<classifier>linux-x86_64</classifier>
<artifactId>netty-transport-classes-epoll</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-kqueue</artifactId>
<classifier>osx-x86_64</classifier>
<artifactId>netty-transport-classes-kqueue</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.netty.incubator</groupId>
<artifactId>netty-incubator-transport-native-io_uring</artifactId>
<version>0.0.26.Final</version>
<classifier>linux-x86_64</classifier>
<groupId>io.netty</groupId>
<artifactId>netty-transport-classes-io_uring</artifactId>
<optional>true</optional>
</dependency>

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/io/lettuce/core/resource/EpollProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.MultiThreadIoEventLoopGroup;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollChannelOption;
import io.netty.channel.epoll.EpollDatagramChannel;
import io.netty.channel.epoll.EpollDomainSocketChannel;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollIoHandler;
import io.netty.channel.epoll.EpollSocketChannel;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.unix.DomainSocketAddress;
Expand Down Expand Up @@ -145,17 +147,20 @@ public boolean matches(Class<? extends EventExecutorGroup> type) {

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

return type.equals(EpollEventLoopGroup.class);
// Support both old deprecated EpollEventLoopGroup and new MultiThreadIoEventLoopGroup
return type.equals(EpollEventLoopGroup.class) || type.equals(MultiThreadIoEventLoopGroup.class);
}

@Override
public Class<? extends EventLoopGroup> eventLoopGroupClass() {
return EpollEventLoopGroup.class;
// Return the new recommended class, but keep backward compatibility
return MultiThreadIoEventLoopGroup.class;
}

@Override
public EventLoopGroup newEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
return new EpollEventLoopGroup(nThreads, threadFactory);
// Use the new Netty 4.2 approach with IoHandlerFactory
return new MultiThreadIoEventLoopGroup(nThreads, threadFactory, EpollIoHandler.newFactory());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.socket.DatagramChannel;
import io.netty.util.concurrent.EventExecutorGroup;

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

/**
* Create a new {@link EpollEventLoopGroup}.
* Create a new {@link EventLoopGroup}.
*
* @param nThreads number of threads.
* @param threadFactory the {@link ThreadFactory}.
Expand Down
39 changes: 22 additions & 17 deletions src/main/java/io/lettuce/core/resource/IOUringProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.MultiThreadIoEventLoopGroup;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.unix.DomainSocketAddress;
import io.netty.incubator.channel.uring.IOUring;
import io.netty.incubator.channel.uring.IOUringChannelOption;
import io.netty.incubator.channel.uring.IOUringDatagramChannel;
import io.netty.incubator.channel.uring.IOUringEventLoopGroup;
import io.netty.incubator.channel.uring.IOUringSocketChannel;
import io.netty.channel.uring.IoUring;
import io.netty.channel.uring.IoUringChannelOption;
import io.netty.channel.uring.IoUringDatagramChannel;

import io.netty.channel.uring.IoUringIoHandler;
import io.netty.channel.uring.IoUringSocketChannel;
import io.netty.util.concurrent.EventExecutorGroup;
import io.netty.util.internal.SystemPropertyUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;

/**
* Wraps and provides io_uring classes. This is to protect the user from {@link ClassNotFoundException}'s caused by the absence
* of the {@literal netty-incubator-transport-native-io_uring} library during runtime. Internal API.
* of the {@literal netty-transport-native-io_uring} library during runtime. Internal API.
*
* @author Mark Paluch
* @since 6.1
Expand All @@ -63,7 +65,7 @@ public class IOUringProvider {
boolean availability;
try {
Class.forName("io.netty.incubator.channel.uring.IOUring");
availability = IOUring.isAvailable();
availability = IoUring.isAvailable();
} catch (ClassNotFoundException e) {
availability = false;
}
Expand Down Expand Up @@ -119,16 +121,16 @@ public static EventLoopResources getResources() {
*/
public static void applyKeepAlive(Bootstrap bootstrap, int count, Duration idle, Duration interval) {

bootstrap.option(IOUringChannelOption.TCP_KEEPCNT, count);
bootstrap.option(IOUringChannelOption.TCP_KEEPIDLE, Math.toIntExact(idle.getSeconds()));
bootstrap.option(IOUringChannelOption.TCP_KEEPINTVL, Math.toIntExact(interval.getSeconds()));
bootstrap.option(IoUringChannelOption.TCP_KEEPCNT, count);
bootstrap.option(IoUringChannelOption.TCP_KEEPIDLE, Math.toIntExact(idle.getSeconds()));
bootstrap.option(IoUringChannelOption.TCP_KEEPINTVL, Math.toIntExact(interval.getSeconds()));
}

/**
* Apply TcpUserTimeout options.
*/
public static void applyTcpUserTimeout(Bootstrap bootstrap, Duration timeout) {
bootstrap.option(IOUringChannelOption.TCP_USER_TIMEOUT, Math.toIntExact(timeout.toMillis()));
bootstrap.option(IoUringChannelOption.TCP_USER_TIMEOUT, Math.toIntExact(timeout.toMillis()));
}

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

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

return type.equals(eventLoopGroupClass());
// In Netty 4.2, IoUringEventLoopGroup doesn't exist, only MultiThreadIoEventLoopGroup
return type.equals(MultiThreadIoEventLoopGroup.class);
}

@Override
public Class<? extends EventLoopGroup> eventLoopGroupClass() {
return IOUringEventLoopGroup.class;
// Return the new recommended class, but keep backward compatibility
return MultiThreadIoEventLoopGroup.class;
}

@Override
public EventLoopGroup newEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
return new IOUringEventLoopGroup(nThreads, threadFactory);
// Use the new Netty 4.2 approach with IoHandlerFactory
return new MultiThreadIoEventLoopGroup(nThreads, threadFactory, IoUringIoHandler.newFactory());
}

@Override
public Class<? extends Channel> socketChannelClass() {
return IOUringSocketChannel.class;
return IoUringSocketChannel.class;
}

@Override
public Class<? extends Channel> domainSocketChannelClass() {
return IOUringSocketChannel.class;
return IoUringSocketChannel.class;
}

@Override
public Class<? extends DatagramChannel> datagramChannelClass() {
return IOUringDatagramChannel.class;
return IoUringDatagramChannel.class;
}

@Override
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/io/lettuce/core/resource/KqueueProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
import io.lettuce.core.internal.LettuceAssert;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.MultiThreadIoEventLoopGroup;
import io.netty.channel.kqueue.KQueue;
import io.netty.channel.kqueue.KQueueDatagramChannel;
import io.netty.channel.kqueue.KQueueDomainSocketChannel;
import io.netty.channel.kqueue.KQueueEventLoopGroup;
import io.netty.channel.kqueue.KQueueIoHandler;
import io.netty.channel.kqueue.KQueueSocketChannel;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.unix.DomainSocketAddress;
Expand Down Expand Up @@ -182,23 +184,26 @@ public boolean matches(Class<? extends EventExecutorGroup> type) {

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

return type.equals(eventLoopGroupClass());
// Support both old deprecated KQueueEventLoopGroup and new MultiThreadIoEventLoopGroup
return type.equals(KQueueEventLoopGroup.class) || type.equals(MultiThreadIoEventLoopGroup.class);
}

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

checkForKqueueLibrary();

return KQueueEventLoopGroup.class;
// Return the new recommended class, but keep backward compatibility
return MultiThreadIoEventLoopGroup.class;
}

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

checkForKqueueLibrary();

return new KQueueEventLoopGroup(nThreads, threadFactory);
// Use the new Netty 4.2 approach with IoHandlerFactory
return new MultiThreadIoEventLoopGroup(nThreads, threadFactory, KQueueIoHandler.newFactory());
}

@Override
Expand Down