|
38 | 38 | import org.apache.logging.log4j.message.ParameterizedMessage;
|
39 | 39 | import org.elasticsearch.ElasticsearchException;
|
40 | 40 | import org.elasticsearch.ExceptionsHelper;
|
41 |
| -import org.elasticsearch.action.ActionListener; |
| 41 | +import org.elasticsearch.Version; |
42 | 42 | import org.elasticsearch.cluster.node.DiscoveryNode;
|
43 | 43 | import org.elasticsearch.common.SuppressForbidden;
|
44 | 44 | import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
@@ -101,9 +101,9 @@ public class Netty4Transport extends TcpTransport {
|
101 | 101 | private volatile Bootstrap clientBootstrap;
|
102 | 102 | private volatile NioEventLoopGroup eventLoopGroup;
|
103 | 103 |
|
104 |
| - public Netty4Transport(Settings settings, ThreadPool threadPool, NetworkService networkService, BigArrays bigArrays, |
| 104 | + public Netty4Transport(Settings settings, Version version, ThreadPool threadPool, NetworkService networkService, BigArrays bigArrays, |
105 | 105 | NamedWriteableRegistry namedWriteableRegistry, CircuitBreakerService circuitBreakerService) {
|
106 |
| - super("netty", settings, threadPool, bigArrays, circuitBreakerService, namedWriteableRegistry, networkService); |
| 106 | + super("netty", settings, version, threadPool, bigArrays, circuitBreakerService, namedWriteableRegistry, networkService); |
107 | 107 | Netty4Utils.setAvailableProcessors(EsExecutors.PROCESSORS_SETTING.get(settings));
|
108 | 108 | this.workerCount = WORKER_COUNT.get(settings);
|
109 | 109 |
|
@@ -221,44 +221,31 @@ protected final void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
|
221 | 221 | }
|
222 | 222 |
|
223 | 223 | @Override
|
224 |
| - protected NettyTcpChannel initiateChannel(DiscoveryNode node, ActionListener<Void> listener) throws IOException { |
| 224 | + protected NettyTcpChannel initiateChannel(DiscoveryNode node) throws IOException { |
225 | 225 | InetSocketAddress address = node.getAddress().address();
|
226 | 226 | Bootstrap bootstrapWithHandler = clientBootstrap.clone();
|
227 | 227 | bootstrapWithHandler.handler(getClientChannelInitializer(node));
|
228 | 228 | bootstrapWithHandler.remoteAddress(address);
|
229 |
| - ChannelFuture channelFuture = bootstrapWithHandler.connect(); |
| 229 | + ChannelFuture connectFuture = bootstrapWithHandler.connect(); |
230 | 230 |
|
231 |
| - Channel channel = channelFuture.channel(); |
| 231 | + Channel channel = connectFuture.channel(); |
232 | 232 | if (channel == null) {
|
233 |
| - ExceptionsHelper.maybeDieOnAnotherThread(channelFuture.cause()); |
234 |
| - throw new IOException(channelFuture.cause()); |
| 233 | + ExceptionsHelper.maybeDieOnAnotherThread(connectFuture.cause()); |
| 234 | + throw new IOException(connectFuture.cause()); |
235 | 235 | }
|
236 | 236 | addClosedExceptionLogger(channel);
|
237 | 237 |
|
238 |
| - NettyTcpChannel nettyChannel = new NettyTcpChannel(channel); |
| 238 | + NettyTcpChannel nettyChannel = new NettyTcpChannel(channel, "default", connectFuture); |
239 | 239 | channel.attr(CHANNEL_KEY).set(nettyChannel);
|
240 | 240 |
|
241 |
| - channelFuture.addListener(f -> { |
242 |
| - if (f.isSuccess()) { |
243 |
| - listener.onResponse(null); |
244 |
| - } else { |
245 |
| - Throwable cause = f.cause(); |
246 |
| - if (cause instanceof Error) { |
247 |
| - ExceptionsHelper.maybeDieOnAnotherThread(cause); |
248 |
| - listener.onFailure(new Exception(cause)); |
249 |
| - } else { |
250 |
| - listener.onFailure((Exception) cause); |
251 |
| - } |
252 |
| - } |
253 |
| - }); |
254 |
| - |
255 | 241 | return nettyChannel;
|
256 | 242 | }
|
257 | 243 |
|
258 | 244 | @Override
|
259 | 245 | protected NettyTcpChannel bind(String name, InetSocketAddress address) {
|
260 | 246 | Channel channel = serverBootstraps.get(name).bind(address).syncUninterruptibly().channel();
|
261 |
| - NettyTcpChannel esChannel = new NettyTcpChannel(channel); |
| 247 | + // TODO: Switch to same server channels |
| 248 | + NettyTcpChannel esChannel = new NettyTcpChannel(channel, "server", channel.newSucceededFuture()); |
262 | 249 | channel.attr(CHANNEL_KEY).set(esChannel);
|
263 | 250 | return esChannel;
|
264 | 251 | }
|
@@ -314,7 +301,8 @@ protected ServerChannelInitializer(String name) {
|
314 | 301 | @Override
|
315 | 302 | protected void initChannel(Channel ch) throws Exception {
|
316 | 303 | addClosedExceptionLogger(ch);
|
317 |
| - NettyTcpChannel nettyTcpChannel = new NettyTcpChannel(ch); |
| 304 | + NettyTcpChannel nettyTcpChannel = new NettyTcpChannel(ch, name, ch.newSucceededFuture()); |
| 305 | + |
318 | 306 | ch.attr(CHANNEL_KEY).set(nettyTcpChannel);
|
319 | 307 | serverAcceptedChannel(nettyTcpChannel);
|
320 | 308 | ch.pipeline().addLast("logging", new ESLoggingHandler());
|
|
0 commit comments