Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.core.CheckedRunnable;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.monitor.NodeHealthService;
import org.elasticsearch.monitor.StatusInfo;
import org.elasticsearch.threadpool.ThreadPool.Names;
import org.elasticsearch.transport.ConnectTransportException;
import org.elasticsearch.transport.ReceiveTimeoutTransportException;
import org.elasticsearch.transport.Transport;
import org.elasticsearch.transport.TransportConnectionListener;
import org.elasticsearch.transport.TransportException;
import org.elasticsearch.transport.TransportRequest;
Expand Down Expand Up @@ -137,7 +137,7 @@ public FollowersChecker(
);
transportService.addConnectionListener(new TransportConnectionListener() {
@Override
public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {
handleDisconnectedNode(node);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.elasticsearch.transport.ConnectTransportException;
import org.elasticsearch.transport.NodeDisconnectedException;
import org.elasticsearch.transport.ReceiveTimeoutTransportException;
import org.elasticsearch.transport.Transport;
import org.elasticsearch.transport.TransportConnectionListener;
import org.elasticsearch.transport.TransportException;
import org.elasticsearch.transport.TransportRequest;
Expand Down Expand Up @@ -124,7 +123,7 @@ public class LeaderChecker {

transportService.addConnectionListener(new TransportConnectionListener() {
@Override
public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {
handleDisconnectedNode(node);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,26 @@ private void connectToNodeOrRetry(
try {
connectionListener.onNodeConnected(node, conn);
} finally {
conn.addCloseListener(ActionListener.running(() -> {
connectedNodes.remove(node, conn);
connectionListener.onNodeDisconnected(node, conn);
managerRefs.decRef();
}));
conn.addCloseListener(new ActionListener<Void>() {
@Override
public void onResponse(Void ignored) {
handleClose(null);
}

@Override
public void onFailure(Exception e) {
handleClose(e);
}

void handleClose(@Nullable Exception e) {
connectedNodes.remove(node, conn);
try {
connectionListener.onNodeDisconnected(node, e);
} finally {
managerRefs.decRef();
}
}
});

conn.addCloseListener(ActionListener.running(() -> {
if (connectingRefCounter.hasReferences() == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ final class DelegatingNodeConnectionListener implements TransportConnectionListe
private final CopyOnWriteArrayList<TransportConnectionListener> listeners = new CopyOnWriteArrayList<>();

@Override
public void onNodeDisconnected(DiscoveryNode key, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode key, @Nullable Exception closeException) {
for (TransportConnectionListener listener : listeners) {
listener.onNodeDisconnected(key, connection);
listener.onNodeDisconnected(key, closeException);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void onNodeConnected(DiscoveryNode node, Transport.Connection connection)
}

@Override
public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {
removeConnectedNode(node);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.threadpool.ThreadPool;

Expand Down Expand Up @@ -339,7 +340,7 @@ boolean shouldRebuildConnection(Settings newSettings) {
protected abstract ConnectionStrategy strategyType();

@Override
public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {
if (shouldOpenMoreConnections()) {
// try to reconnect and fill up the slot of the disconnected node
connect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.elasticsearch.transport;

import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.core.Nullable;

/**
* A listener interface that allows to react on transport events. All methods may be
Expand Down Expand Up @@ -38,5 +39,5 @@ default void onNodeConnected(DiscoveryNode node, Transport.Connection connection
/**
* Called once a node connection is closed and unregistered.
*/
default void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {}
default void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.index.Index;
Expand Down Expand Up @@ -829,7 +830,7 @@ public void testCCSRemoteReduceWithDisconnectedRemoteClusters() throws Exception
CountDownLatch disconnectedLatch = new CountDownLatch(numDisconnectedClusters);
RemoteClusterServiceTests.addConnectionListener(remoteClusterService, new TransportConnectionListener() {
@Override
public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {
if (disconnectedNodes.remove(node)) {
disconnectedLatch.countDown();
}
Expand Down Expand Up @@ -1132,7 +1133,7 @@ public void testCollectSearchShards() throws Exception {
CountDownLatch disconnectedLatch = new CountDownLatch(numDisconnectedClusters);
RemoteClusterServiceTests.addConnectionListener(remoteClusterService, new TransportConnectionListener() {
@Override
public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {
if (disconnectedNodes.remove(node)) {
disconnectedLatch.countDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.elasticsearch.common.util.concurrent.DeterministicTaskQueue;
import org.elasticsearch.core.AbstractRefCounted;
import org.elasticsearch.core.CheckedRunnable;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.RefCounted;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.test.ESTestCase;
Expand Down Expand Up @@ -251,7 +252,7 @@ public void testOnlyBlocksOnConnectionsToNewNodes() throws Exception {
final AtomicReference<ActionListener<DiscoveryNode>> disconnectListenerRef = new AtomicReference<>();
transportService.addConnectionListener(new TransportConnectionListener() {
@Override
public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {
final ActionListener<DiscoveryNode> disconnectListener = disconnectListenerRef.getAndSet(null);
if (disconnectListener != null) {
disconnectListener.onResponse(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.common.util.concurrent.RunOnce;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.AbstractRefCounted;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.Releasable;
import org.elasticsearch.core.Releasables;
import org.elasticsearch.core.TimeValue;
Expand Down Expand Up @@ -101,7 +102,7 @@ public void onNodeConnected(DiscoveryNode node, Transport.Connection connection)
}

@Override
public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {
nodeDisconnectedCount.incrementAndGet();
}
});
Expand Down Expand Up @@ -658,7 +659,7 @@ public void onNodeConnected(DiscoveryNode node, Transport.Connection connection)
}

@Override
public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {
nodeDisconnectedCount.incrementAndGet();
}
});
Expand Down Expand Up @@ -698,7 +699,7 @@ public void onNodeConnected(DiscoveryNode node, Transport.Connection connection)
}

@Override
public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {
nodeDisconnectedCount.incrementAndGet();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void onNodeConnected(DiscoveryNode node, Transport.Connection connection)
}

@Override
public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {
fail("disconnect should not be called " + node);
}
};
Expand Down Expand Up @@ -924,7 +924,7 @@ public void onNodeConnected(DiscoveryNode node, Transport.Connection connection)
}

@Override
public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {
latch.countDown();
}
};
Expand Down Expand Up @@ -2124,7 +2124,7 @@ public void onNodeConnected(DiscoveryNode node, Transport.Connection connection)
}

@Override
public void onNodeDisconnected(DiscoveryNode node, Transport.Connection connection) {
public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) {
fail("disconnect should not be called " + node);
}
};
Expand Down