-
Notifications
You must be signed in to change notification settings - Fork 25.6k
transport: log network reconnects with same peer process #128415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
7d54620
bd688bb
11347ca
0cc8084
ab7f490
81cbcdc
27438d6
0514724
a56e728
d03eb4d
f7f8f72
2becaf1
8cf607e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,15 +17,19 @@ | |
| import org.elasticsearch.cluster.node.DiscoveryNode; | ||
| import org.elasticsearch.cluster.node.DiscoveryNodes; | ||
| import org.elasticsearch.cluster.service.ClusterApplier; | ||
| import org.elasticsearch.common.ReferenceDocs; | ||
| import org.elasticsearch.common.component.AbstractLifecycleComponent; | ||
| import org.elasticsearch.common.settings.Setting; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.util.concurrent.AbstractRunnable; | ||
| import org.elasticsearch.core.Nullable; | ||
| import org.elasticsearch.core.Releasable; | ||
| import org.elasticsearch.core.Releasables; | ||
| import org.elasticsearch.core.TimeValue; | ||
| import org.elasticsearch.injection.guice.Inject; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
| import org.elasticsearch.transport.Transport; | ||
| import org.elasticsearch.transport.TransportConnectionListener; | ||
| import org.elasticsearch.transport.TransportService; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
@@ -188,6 +192,7 @@ public String toString() { | |
|
|
||
| @Override | ||
| protected void doStart() { | ||
| transportService.addConnectionListener(new ConnectionChangeListener()); | ||
| final ConnectionChecker connectionChecker = new ConnectionChecker(); | ||
| this.connectionChecker = connectionChecker; | ||
| connectionChecker.scheduleNextCheck(); | ||
|
|
@@ -209,12 +214,41 @@ public void reconnectToNodes(DiscoveryNodes discoveryNodes, Runnable onCompletio | |
| }); | ||
| } | ||
|
|
||
| // exposed for testing | ||
| protected DisconnectionHistory disconnectionHistoryForNode(DiscoveryNode node) { | ||
| synchronized (mutex) { | ||
| ConnectionTarget connectionTarget = targetsByNode.get(node); | ||
| if (connectionTarget != null) { | ||
| return connectionTarget.disconnectionHistory; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Time of disconnect in absolute time ({@link ThreadPool#absoluteTimeInMillis()}), | ||
| * and disconnect-causing exception, if any | ||
| */ | ||
| record DisconnectionHistory(long disconnectTimeMillis, @Nullable Exception disconnectCause) { | ||
| public long getDisconnectTimeMillis() { | ||
| return disconnectTimeMillis; | ||
| } | ||
|
|
||
| public Exception getDisconnectCause() { | ||
| return disconnectCause; | ||
| } | ||
| } | ||
|
|
||
| private class ConnectionTarget { | ||
| private final DiscoveryNode discoveryNode; | ||
|
|
||
| private final AtomicInteger consecutiveFailureCount = new AtomicInteger(); | ||
| private final AtomicReference<Releasable> connectionRef = new AtomicReference<>(); | ||
|
|
||
| // access is synchronized by the service mutex | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| @Nullable // null when node is connected or initialized; non-null in between disconnects and connects | ||
| private DisconnectionHistory disconnectionHistory = null; | ||
|
|
||
| // all access to these fields is synchronized | ||
| private List<Releasable> pendingRefs; | ||
| private boolean connectionInProgress; | ||
|
|
@@ -345,4 +379,70 @@ public String toString() { | |
| return "ConnectionTarget{discoveryNode=" + discoveryNode + '}'; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Receives connection/disconnection events from the transport, and records them in per-node DisconnectionHistory | ||
| * structures for logging network issues. DisconnectionHistory records are stored their node's ConnectionTarget. | ||
|
||
| * | ||
| * Network issues (that this listener monitors for) occur whenever a reconnection to a node succeeds, | ||
| * and it has the same ephemeral ID as it did during the last connection; this happens when a connection event | ||
| * occurs, and its ConnectionTarget entry has a previous DisconnectionHistory stored. | ||
| */ | ||
| private class ConnectionChangeListener implements TransportConnectionListener { | ||
| @Override | ||
| public void onNodeConnected(DiscoveryNode node, Transport.Connection connection) { | ||
| DisconnectionHistory disconnectionHistory = null; | ||
| synchronized (mutex) { | ||
| ConnectionTarget connectionTarget = targetsByNode.get(node); | ||
| if (connectionTarget != null) { | ||
| disconnectionHistory = connectionTarget.disconnectionHistory; | ||
| connectionTarget.disconnectionHistory = null; | ||
| } | ||
| } | ||
|
|
||
| if (disconnectionHistory != null) { | ||
| long millisSinceDisconnect = threadPool.absoluteTimeInMillis() - disconnectionHistory.disconnectTimeMillis; | ||
| long secondsSinceDisconnect = millisSinceDisconnect / 1000; | ||
| if (disconnectionHistory.disconnectCause != null) { | ||
| logger.warn( | ||
| () -> format( | ||
| """ | ||
| reopened transport connection to node [%s] \ | ||
| which disconnected exceptionally [%ds/%dms] ago but did not \ | ||
|
||
| restart, so the disconnection is unexpected; \ | ||
| see [%s] for troubleshooting guidance""", | ||
| node.descriptionWithoutAttributes(), | ||
| secondsSinceDisconnect, | ||
| millisSinceDisconnect, | ||
| ReferenceDocs.NETWORK_DISCONNECT_TROUBLESHOOTING | ||
| ), | ||
| disconnectionHistory.disconnectCause | ||
| ); | ||
| } else { | ||
| logger.warn( | ||
| """ | ||
| reopened transport connection to node [{}] \ | ||
| which disconnected gracefully [{}s/{}ms] ago but did not \ | ||
| restart, so the disconnection is unexpected; \ | ||
| see [{}] for troubleshooting guidance""", | ||
| node.descriptionWithoutAttributes(), | ||
| secondsSinceDisconnect, | ||
| millisSinceDisconnect, | ||
| ReferenceDocs.NETWORK_DISCONNECT_TROUBLESHOOTING | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onNodeDisconnected(DiscoveryNode node, @Nullable Exception closeException) { | ||
| DisconnectionHistory disconnectionHistory = new DisconnectionHistory(threadPool.absoluteTimeInMillis(), closeException); | ||
| synchronized (mutex) { | ||
| ConnectionTarget connectionTarget = targetsByNode.get(node); | ||
| if (connectionTarget != null) { | ||
| connectionTarget.disconnectionHistory = disconnectionHistory; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: These methods do not seem necessary for a record class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks for this -- I did look up making record fields public after accessing them from the test, but for some reason came away thinking I needed to write my own accessors. This helped me realize that I can just do
disconnectTimeMillis()instead...