-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Do not log unsuccessful join attempt each time #39756
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 1 commit
a48b6ca
452af96
0b19f03
737e7f8
ce3e69a
7c0798f
765f66f
5409831
83f1bb5
283fdea
463a9b2
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.ClusterStateTaskConfig; | ||
import org.elasticsearch.cluster.ClusterStateTaskListener; | ||
import org.elasticsearch.cluster.NotMasterException; | ||
import org.elasticsearch.cluster.coordination.Coordinator.Mode; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
|
@@ -40,6 +41,7 @@ | |
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.threadpool.ThreadPool.Names; | ||
import org.elasticsearch.transport.EmptyTransportResponseHandler; | ||
import org.elasticsearch.transport.RemoteTransportException; | ||
import org.elasticsearch.transport.TransportChannel; | ||
import org.elasticsearch.transport.TransportException; | ||
import org.elasticsearch.transport.TransportRequest; | ||
|
@@ -82,6 +84,8 @@ public class JoinHelper { | |
|
||
final Set<Tuple<DiscoveryNode, JoinRequest>> pendingOutgoingJoins = ConcurrentCollections.newConcurrentSet(); | ||
|
||
private volatile FailedJoinAttempt lastFailedJoinAttempt; | ||
|
||
JoinHelper(Settings settings, AllocationService allocationService, MasterService masterService, | ||
TransportService transportService, LongSupplier currentTermSupplier, Supplier<ClusterState> currentStateSupplier, | ||
BiConsumer<JoinRequest, JoinCallback> joinHandler, Function<StartJoinRequest, Join> joinLeaderInTerm, | ||
|
@@ -172,7 +176,57 @@ boolean isJoinPending() { | |
return pendingOutgoingJoins.iterator().hasNext(); | ||
} | ||
|
||
void sendJoinRequest(DiscoveryNode destination, Optional<Join> optionalJoin) { | ||
private static class FailedJoinAttempt { | ||
private final DiscoveryNode destination; | ||
private final JoinRequest joinRequest; | ||
private final TransportException exception; | ||
private final long timestamp; | ||
|
||
FailedJoinAttempt(DiscoveryNode destination, JoinRequest joinRequest, TransportException exception) { | ||
this.destination = destination; | ||
this.joinRequest = joinRequest; | ||
this.exception = exception; | ||
this.timestamp = System.nanoTime(); | ||
} | ||
|
||
void maybeLogNow() { | ||
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. If you make 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. Good idea, done as a part of this commit. 737e7f8 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. Maybe inline this? At least rename it to avoid using |
||
if (isSuspiciousTransportException(exception)) { | ||
logger.info(() -> new ParameterizedMessage("failed to join {} with {}", destination, joinRequest), exception); | ||
} else { | ||
logger.debug(() -> new ParameterizedMessage("failed to join {} with {}", destination, joinRequest), exception); | ||
} | ||
} | ||
|
||
boolean isSuspiciousTransportException(TransportException e) { | ||
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. Can this be 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. Done as a part of this commit 737e7f8 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. Testing is added here ce3e69a |
||
if (e instanceof RemoteTransportException) { | ||
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. perhaps simpler (and more streamlined with other similar code) is to just call unwrapCause on TransportException, i.e. 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. Good idea, 5409831 |
||
Throwable cause = e.getCause(); | ||
if (cause != null && | ||
DaveCTurner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cause instanceof CoordinationStateRejectedException || | ||
cause instanceof FailedToCommitClusterStateException || | ||
cause instanceof NotMasterException) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
void logWarnWithTimestamp() { | ||
logger.info(() -> new ParameterizedMessage("last failed join attempt was {} ms ago, failed to join {} with {}", | ||
TimeValue.timeValueMillis(TimeValue.nsecToMSec(System.nanoTime() - timestamp)), | ||
destination, | ||
joinRequest), | ||
exception); | ||
} | ||
} | ||
|
||
|
||
void logLastFailedJoinAttempt() { | ||
if (lastFailedJoinAttempt != null) { | ||
lastFailedJoinAttempt.logWarnWithTimestamp(); | ||
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. I think this can throw a NPE because we read the volatile field twice. 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. Good catch! 0b19f03 |
||
} | ||
} | ||
|
||
public void sendJoinRequest(DiscoveryNode destination, Optional<Join> optionalJoin) { | ||
assert destination.isMasterNode() : "trying to join master-ineligible " + destination; | ||
final JoinRequest joinRequest = new JoinRequest(transportService.getLocalNode(), optionalJoin); | ||
final Tuple<DiscoveryNode, JoinRequest> dedupKey = Tuple.tuple(destination, joinRequest); | ||
|
@@ -190,12 +244,15 @@ public Empty read(StreamInput in) { | |
public void handleResponse(Empty response) { | ||
pendingOutgoingJoins.remove(dedupKey); | ||
logger.debug("successfully joined {} with {}", destination, joinRequest); | ||
lastFailedJoinAttempt = null; | ||
} | ||
|
||
@Override | ||
public void handleException(TransportException exp) { | ||
pendingOutgoingJoins.remove(dedupKey); | ||
logger.info(() -> new ParameterizedMessage("failed to join {} with {}", destination, joinRequest), exp); | ||
FailedJoinAttempt attempt = new FailedJoinAttempt(destination, joinRequest, exp); | ||
attempt.maybeLogNow(); | ||
lastFailedJoinAttempt = attempt; | ||
} | ||
|
||
@Override | ||
|
Uh oh!
There was an error while loading. Please reload this page.