HBASE-23987 NettyRpcClientConfigHelper will not share event loop by default which is incorrect (#1288)

Signed-off-by: stack <stack@apache.org>
This commit is contained in:
Duo Zhang 2020-03-14 13:47:41 +08:00 committed by GitHub
parent b9e74e0b0a
commit ba3f02629a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
import org.apache.hbase.thirdparty.io.netty.channel.Channel;
import org.apache.hbase.thirdparty.io.netty.channel.EventLoopGroup;
@ -73,20 +74,40 @@ public final class NettyRpcClientConfigHelper {
}
/**
* The {@code AsyncRpcClient} will create its own {@code NioEventLoopGroup}.
* The {@link NettyRpcClient} will create its own {@code NioEventLoopGroup}.
*/
public static void createEventLoopPerClient(Configuration conf) {
conf.set(EVENT_LOOP_CONFIG, "");
EVENT_LOOP_CONFIG_MAP.clear();
}
private static volatile Pair<EventLoopGroup, Class<? extends Channel>> DEFAULT_EVENT_LOOP;
private static Pair<EventLoopGroup, Class<? extends Channel>>
getDefaultEventLoopConfig(Configuration conf) {
Pair<EventLoopGroup, Class<? extends Channel>> eventLoop = DEFAULT_EVENT_LOOP;
if (eventLoop != null) {
return eventLoop;
}
synchronized (NettyRpcClientConfigHelper.class) {
eventLoop = DEFAULT_EVENT_LOOP;
if (eventLoop != null) {
return eventLoop;
}
int threadCount = conf.getInt(HBASE_NETTY_EVENTLOOP_RPCCLIENT_THREADCOUNT_KEY, 0);
eventLoop = new Pair<>(
new NioEventLoopGroup(threadCount,
new DefaultThreadFactory("RPCClient-NioEventLoopGroup", true, Thread.NORM_PRIORITY)),
NioSocketChannel.class);
DEFAULT_EVENT_LOOP = eventLoop;
}
return eventLoop;
}
static Pair<EventLoopGroup, Class<? extends Channel>> getEventLoopConfig(Configuration conf) {
String name = conf.get(EVENT_LOOP_CONFIG);
if (name == null) {
int threadCount = conf.getInt(HBASE_NETTY_EVENTLOOP_RPCCLIENT_THREADCOUNT_KEY, 0);
return new Pair<>(new NioEventLoopGroup(threadCount,
new DefaultThreadFactory("RPCClient-NioEventLoopGroup", true,
Thread.NORM_PRIORITY)), NioSocketChannel.class);
return getDefaultEventLoopConfig(conf);
}
if (StringUtils.isBlank(name)) {
return null;