Skip to content

Commit 3504c27

Browse files
authored
Remove exception-mangling in connect/close listeners (#127954)
The close-listeners are never completed exceptionally today so they do not need the exception mangling of a `ListenableFuture`. The connect- and remove-listeners sometimes see an exception if the connection attempt fails, but they also do not need any exception-mangling. This commit removes the exception-mangling by replacing these `ListenableFuture` instances with `SubscribableListener` ones.
1 parent 445c3ea commit 3504c27

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed

modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import io.netty.channel.Channel;
1313

1414
import org.elasticsearch.action.ActionListener;
15-
import org.elasticsearch.common.util.concurrent.ListenableFuture;
15+
import org.elasticsearch.action.support.SubscribableListener;
1616
import org.elasticsearch.http.HttpChannel;
1717
import org.elasticsearch.http.HttpResponse;
1818

@@ -25,7 +25,7 @@
2525
public class Netty4HttpChannel implements HttpChannel {
2626

2727
private final Channel channel;
28-
private final ListenableFuture<Void> closeContext = new ListenableFuture<>();
28+
private final SubscribableListener<Void> closeContext = new SubscribableListener<>();
2929

3030
Netty4HttpChannel(Channel channel) {
3131
this.channel = channel;

modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import io.netty.channel.Channel;
1313

1414
import org.elasticsearch.action.ActionListener;
15-
import org.elasticsearch.common.util.concurrent.ListenableFuture;
15+
import org.elasticsearch.action.support.SubscribableListener;
1616
import org.elasticsearch.http.HttpServerChannel;
1717

1818
import java.net.InetSocketAddress;
@@ -22,7 +22,7 @@
2222
public class Netty4HttpServerChannel implements HttpServerChannel {
2323

2424
private final Channel channel;
25-
private final ListenableFuture<Void> closeContext = new ListenableFuture<>();
25+
private final SubscribableListener<Void> closeContext = new SubscribableListener<>();
2626

2727
Netty4HttpServerChannel(Channel channel) {
2828
this.channel = channel;

modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4TcpChannel.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import io.netty.channel.ChannelOption;
1515

1616
import org.elasticsearch.action.ActionListener;
17+
import org.elasticsearch.action.support.SubscribableListener;
1718
import org.elasticsearch.common.bytes.BytesReference;
18-
import org.elasticsearch.common.util.concurrent.ListenableFuture;
1919
import org.elasticsearch.core.IOUtils;
2020
import org.elasticsearch.core.Releasables;
2121
import org.elasticsearch.transport.TcpChannel;
@@ -30,8 +30,8 @@ public class Netty4TcpChannel implements TcpChannel {
3030
private final Channel channel;
3131
private final boolean isServer;
3232
private final String profile;
33-
private final ListenableFuture<Void> connectContext;
34-
private final ListenableFuture<Void> closeContext = new ListenableFuture<>();
33+
private final SubscribableListener<Void> connectContext = new SubscribableListener<>();
34+
private final SubscribableListener<Void> closeContext = new SubscribableListener<>();
3535
private final ChannelStats stats = new ChannelStats();
3636
private final boolean rstOnClose;
3737
/**
@@ -43,7 +43,6 @@ public class Netty4TcpChannel implements TcpChannel {
4343
this.channel = channel;
4444
this.isServer = isServer;
4545
this.profile = profile;
46-
this.connectContext = new ListenableFuture<>();
4746
this.rstOnClose = rstOnClose;
4847
addListener(connectFuture, connectContext);
4948
addListener(this.channel.closeFuture(), new ActionListener<>() {

modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4TcpServerChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import io.netty.channel.Channel;
1313

1414
import org.elasticsearch.action.ActionListener;
15-
import org.elasticsearch.common.util.concurrent.ListenableFuture;
15+
import org.elasticsearch.action.support.SubscribableListener;
1616
import org.elasticsearch.transport.TcpServerChannel;
1717

1818
import java.net.InetSocketAddress;
@@ -22,7 +22,7 @@
2222
public class Netty4TcpServerChannel implements TcpServerChannel {
2323

2424
private final Channel channel;
25-
private final ListenableFuture<Void> closeContext = new ListenableFuture<>();
25+
private final SubscribableListener<Void> closeContext = new SubscribableListener<>();
2626

2727
Netty4TcpServerChannel(Channel channel) {
2828
this.channel = channel;

server/src/main/java/org/elasticsearch/transport/CloseableConnection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
package org.elasticsearch.transport;
1111

1212
import org.elasticsearch.action.ActionListener;
13-
import org.elasticsearch.common.util.concurrent.ListenableFuture;
13+
import org.elasticsearch.action.support.SubscribableListener;
1414
import org.elasticsearch.core.AbstractRefCounted;
1515

1616
import java.util.concurrent.atomic.AtomicBoolean;
@@ -20,8 +20,8 @@
2020
*/
2121
public abstract class CloseableConnection extends AbstractRefCounted implements Transport.Connection {
2222

23-
private final ListenableFuture<Void> closeContext = new ListenableFuture<>();
24-
private final ListenableFuture<Void> removeContext = new ListenableFuture<>();
23+
private final SubscribableListener<Void> closeContext = new SubscribableListener<>();
24+
private final SubscribableListener<Void> removeContext = new SubscribableListener<>();
2525

2626
private final AtomicBoolean closed = new AtomicBoolean(false);
2727
private final AtomicBoolean removed = new AtomicBoolean(false);

server/src/main/java/org/elasticsearch/transport/ClusterConnectionManager.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import org.apache.logging.log4j.Logger;
1313
import org.elasticsearch.action.ActionListener;
1414
import org.elasticsearch.action.support.ContextPreservingActionListener;
15+
import org.elasticsearch.action.support.SubscribableListener;
1516
import org.elasticsearch.cluster.node.DiscoveryNode;
1617
import org.elasticsearch.common.ReferenceDocs;
1718
import org.elasticsearch.common.settings.Settings;
1819
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
19-
import org.elasticsearch.common.util.concurrent.ListenableFuture;
2020
import org.elasticsearch.common.util.concurrent.RunOnce;
2121
import org.elasticsearch.common.util.concurrent.ThreadContext;
2222
import org.elasticsearch.core.AbstractRefCounted;
@@ -43,7 +43,7 @@ public class ClusterConnectionManager implements ConnectionManager {
4343
private static final Logger logger = LogManager.getLogger(ClusterConnectionManager.class);
4444

4545
private final ConcurrentMap<DiscoveryNode, Transport.Connection> connectedNodes = ConcurrentCollections.newConcurrentMap();
46-
private final ConcurrentMap<DiscoveryNode, ListenableFuture<Transport.Connection>> pendingConnections = ConcurrentCollections
46+
private final ConcurrentMap<DiscoveryNode, SubscribableListener<Transport.Connection>> pendingConnections = ConcurrentCollections
4747
.newConcurrentMap();
4848
private final AbstractRefCounted connectingRefCounter = AbstractRefCounted.of(this::pendingConnectionsComplete);
4949

@@ -184,8 +184,8 @@ private void connectToNodeOrRetry(
184184
return;
185185
}
186186

187-
final ListenableFuture<Transport.Connection> currentListener = new ListenableFuture<>();
188-
final ListenableFuture<Transport.Connection> existingListener = pendingConnections.putIfAbsent(node, currentListener);
187+
final SubscribableListener<Transport.Connection> currentListener = new SubscribableListener<>();
188+
final SubscribableListener<Transport.Connection> existingListener = pendingConnections.putIfAbsent(node, currentListener);
189189
if (existingListener != null) {
190190
try {
191191
// wait on previous entry to complete connection attempt
@@ -203,7 +203,7 @@ private void connectToNodeOrRetry(
203203
// extra connection to the node. We could _just_ check here, but checking up front skips the work to mark the connection as pending.
204204
final Transport.Connection existingConnectionRecheck = connectedNodes.get(node);
205205
if (existingConnectionRecheck != null) {
206-
ListenableFuture<Transport.Connection> future = pendingConnections.remove(node);
206+
var future = pendingConnections.remove(node);
207207
assert future == currentListener : "Listener in pending map is different than the expected listener";
208208
connectingRefCounter.decRef();
209209
future.onResponse(existingConnectionRecheck);
@@ -257,7 +257,7 @@ private void connectToNodeOrRetry(
257257
}
258258
}
259259
} finally {
260-
ListenableFuture<Transport.Connection> future = pendingConnections.remove(node);
260+
var future = pendingConnections.remove(node);
261261
assert future == currentListener : "Listener in pending map is different than the expected listener";
262262
managerRefs.decRef();
263263
releaseOnce.run();
@@ -387,9 +387,9 @@ private void failConnectionListener(
387387
DiscoveryNode node,
388388
RunOnce releaseOnce,
389389
Exception e,
390-
ListenableFuture<Transport.Connection> expectedListener
390+
SubscribableListener<Transport.Connection> expectedListener
391391
) {
392-
ListenableFuture<Transport.Connection> future = pendingConnections.remove(node);
392+
final var future = pendingConnections.remove(node);
393393
releaseOnce.run();
394394
if (future != null) {
395395
assert future == expectedListener : "Listener in pending map is different than the expected listener";

0 commit comments

Comments
 (0)