Skip to content

Commit 9ce4be7

Browse files
committed
feat: fix netty 4.2 upgrade (#461)
1 parent 2ce805a commit 9ce4be7

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

camellia-redis-proxy/camellia-redis-proxy-core/src/main/java/com/netease/nim/camellia/redis/proxy/netty/GlobalRedisProxyEnv.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.netty.channel.uring.IoUring;
2020
import io.netty.channel.uring.IoUringIoHandler;
2121
import io.netty.channel.uring.IoUringServerSocketChannel;
22+
import io.netty.channel.uring.IoUringServerDomainSocketChannel;
2223
import io.netty.util.concurrent.DefaultThreadFactory;
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
@@ -124,9 +125,12 @@ public static void init(CamelliaServerProperties serverProperties, CamelliaTrans
124125
} else if (nettyTransportMode == NettyTransportMode.io_uring && isIOUringAvailable()) {
125126
bossThread = serverProperties.getBossThread();
126127
bossGroup = new MultiThreadIoEventLoopGroup(bossThread, new DefaultThreadFactory(BOSS_GROUP_NAME), IoUringIoHandler.newFactory());
128+
udsBossGroup = bossGroup;
127129
workThread = serverProperties.getWorkThread();
128130
workGroup = new MultiThreadIoEventLoopGroup(workThread, new DefaultThreadFactory(WORK_GROUP_NAME), IoUringIoHandler.newFactory());
131+
udsWorkGroup = workGroup;
129132
serverChannelClass = IoUringServerSocketChannel.class;
133+
serverUdsChannelClass = IoUringServerDomainSocketChannel.class;
130134
nettyTransportMode = NettyTransportMode.io_uring;
131135
} else {
132136
bossThread = serverProperties.getBossThread();
@@ -145,6 +149,10 @@ public static void init(CamelliaServerProperties serverProperties, CamelliaTrans
145149
udsBossGroup = new MultiThreadIoEventLoopGroup(bossThread, new DefaultThreadFactory(UDS_BOSS_GROUP_NAME), KQueueIoHandler.newFactory());
146150
udsWorkGroup = new MultiThreadIoEventLoopGroup(workThread, new DefaultThreadFactory(UDS_WORK_GROUP_NAME), KQueueIoHandler.newFactory());
147151
serverUdsChannelClass = KQueueServerDomainSocketChannel.class;
152+
} else if (isIOUringAvailable()) {
153+
udsBossGroup = new MultiThreadIoEventLoopGroup(bossThread, new DefaultThreadFactory(UDS_BOSS_GROUP_NAME), IoUringIoHandler.newFactory());
154+
udsWorkGroup = new MultiThreadIoEventLoopGroup(workThread, new DefaultThreadFactory(UDS_WORK_GROUP_NAME), IoUringIoHandler.newFactory());
155+
serverUdsChannelClass = IoUringServerDomainSocketChannel.class;
148156
}
149157
}
150158
queueFactory = (QueueFactory) serverProperties.getProxyBeanFactory()

camellia-redis-proxy/camellia-redis-proxy-core/src/main/java/com/netease/nim/camellia/redis/proxy/upstream/connection/RedisConnectionHub.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
import io.netty.channel.EventLoop;
2222
import io.netty.channel.EventLoopGroup;
2323
import io.netty.channel.MultiThreadIoEventLoopGroup;
24-
import io.netty.channel.epoll.EpollEventLoopGroup;
2524
import io.netty.channel.epoll.EpollIoHandler;
26-
import io.netty.channel.kqueue.KQueueEventLoopGroup;
2725
import io.netty.channel.kqueue.KQueueIoHandler;
2826
import io.netty.channel.nio.NioIoHandler;
2927
import io.netty.channel.uring.IoUringIoHandler;
@@ -107,6 +105,7 @@ public void init(CamelliaTranspondProperties properties, ProxyBeanFactory proxyB
107105
this.udsEventLoopGroup = eventLoopGroup;
108106
} else if (nettyTransportMode == NettyTransportMode.io_uring) {
109107
this.eventLoopGroup = new MultiThreadIoEventLoopGroup(redisConf.getDefaultTranspondWorkThread(), new DefaultThreadFactory("camellia-redis-connection"), IoUringIoHandler.newFactory());
108+
this.udsEventLoopGroup = eventLoopGroup;
110109
} else {
111110
this.eventLoopGroup = new MultiThreadIoEventLoopGroup(redisConf.getDefaultTranspondWorkThread(), new DefaultThreadFactory("camellia-redis-connection"), NioIoHandler.newFactory());
112111
}
@@ -115,6 +114,8 @@ public void init(CamelliaTranspondProperties properties, ProxyBeanFactory proxyB
115114
this.udsEventLoopGroup = new MultiThreadIoEventLoopGroup(redisConf.getDefaultTranspondWorkThread(), new DefaultThreadFactory("camellia-redis-connection-uds"), EpollIoHandler.newFactory());
116115
} else if (GlobalRedisProxyEnv.isKQueueAvailable()) {
117116
this.udsEventLoopGroup = new MultiThreadIoEventLoopGroup(redisConf.getDefaultTranspondWorkThread(), new DefaultThreadFactory("camellia-redis-connection-uds"), KQueueIoHandler.newFactory());
117+
} else if (GlobalRedisProxyEnv.isIOUringAvailable()) {
118+
this.udsEventLoopGroup = new MultiThreadIoEventLoopGroup(redisConf.getDefaultTranspondWorkThread(), new DefaultThreadFactory("camellia-redis-connection-uds"), IoUringIoHandler.newFactory());
118119
}
119120
}
120121

@@ -442,7 +443,11 @@ private boolean eventLoopMatch(RedisConnectionAddr addr, EventLoop eventLoop) {
442443
return true;
443444
} else if (channelType == ChannelType.uds) {
444445
EventLoopGroup parent = eventLoop.parent();
445-
return (parent instanceof EpollEventLoopGroup) || (parent instanceof KQueueEventLoopGroup);
446+
if (parent instanceof MultiThreadIoEventLoopGroup ioEventLoopGroup) {
447+
return ioEventLoopGroup.isIoType(EpollIoHandler.class) || ioEventLoopGroup.isIoType(KQueueIoHandler.class)
448+
|| ioEventLoopGroup.isIoType(IoUringIoHandler.class);
449+
}
450+
return false;
446451
}
447452
return false;
448453
}
@@ -461,11 +466,12 @@ private EventLoop selectEventLoop(RedisConnectionAddr addr) {
461466
return loop;
462467
} else if (channelType == ChannelType.uds) {
463468
EventLoopGroup parent = loop.parent();
464-
if (parent instanceof EpollEventLoopGroup) {
465-
return loop;
466-
}
467-
if (parent instanceof KQueueEventLoopGroup) {
468-
return loop;
469+
if (parent instanceof MultiThreadIoEventLoopGroup ioEventLoopGroup) {
470+
boolean match = ioEventLoopGroup.isIoType(EpollIoHandler.class) || ioEventLoopGroup.isIoType(KQueueIoHandler.class)
471+
|| ioEventLoopGroup.isIoType(IoUringIoHandler.class);
472+
if (match) {
473+
return loop;
474+
}
469475
}
470476
return udsEventLoopGroup.next();
471477
}

0 commit comments

Comments
 (0)