-
Notifications
You must be signed in to change notification settings - Fork 25.2k
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
Open
schase-es
wants to merge
8
commits into
elastic:main
Choose a base branch
from
schase-es:ES-11448_log-network-disruption-reconnects
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7d54620
transport: log network reconnects with same peer process
schase-es bd688bb
[CI] Auto commit changes from spotless
elasticsearchmachine 11347ca
Addressed review feedback:
schase-es 0cc8084
Addressed 2nd round review feedback:
schase-es ab7f490
Addressed next round of feedback:
schase-es 81cbcdc
Merge remote-tracking branch 'origin/main' into ES-11448_log-network-…
schase-es 27438d6
Addressed next set of review feedback:
schase-es 0514724
[CI] Auto commit changes from spotless
elasticsearchmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
@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 \ | ||
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. Ah this could be minutes/hours/days too, not just seconds - we should convert to a |
||
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; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍