-
Notifications
You must be signed in to change notification settings - Fork 25.3k
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 all commits
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 |
---|---|---|
|
@@ -18,13 +18,15 @@ | |
*/ | ||
package org.elasticsearch.cluster.coordination; | ||
|
||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.message.ParameterizedMessage; | ||
import org.elasticsearch.action.ActionListener; | ||
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; | ||
|
@@ -58,6 +60,7 @@ | |
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Function; | ||
import java.util.function.LongSupplier; | ||
|
@@ -83,6 +86,8 @@ public class JoinHelper { | |
|
||
private final Set<Tuple<DiscoveryNode, JoinRequest>> pendingOutgoingJoins = Collections.synchronizedSet(new HashSet<>()); | ||
|
||
private AtomicReference<FailedJoinAttempt> lastFailedJoinAttempt = new AtomicReference<>(); | ||
|
||
JoinHelper(Settings settings, AllocationService allocationService, MasterService masterService, | ||
TransportService transportService, LongSupplier currentTermSupplier, Supplier<ClusterState> currentStateSupplier, | ||
BiConsumer<JoinRequest, JoinCallback> joinHandler, Function<StartJoinRequest, Join> joinLeaderInTerm, | ||
|
@@ -172,7 +177,55 @@ boolean isJoinPending() { | |
return pendingOutgoingJoins.isEmpty() == false; | ||
} | ||
|
||
void sendJoinRequest(DiscoveryNode destination, Optional<Join> optionalJoin) { | ||
// package-private for testing | ||
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 logNow() { | ||
logger.log(getLogLevel(exception), | ||
() -> new ParameterizedMessage("failed to join {} with {}", destination, joinRequest), | ||
exception); | ||
} | ||
|
||
static Level getLogLevel(TransportException e) { | ||
Throwable cause = e.unwrapCause(); | ||
if (cause instanceof CoordinationStateRejectedException || | ||
cause instanceof FailedToCommitClusterStateException || | ||
cause instanceof NotMasterException) { | ||
return Level.DEBUG; | ||
} | ||
return Level.INFO; | ||
} | ||
|
||
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() { | ||
FailedJoinAttempt attempt = lastFailedJoinAttempt.get(); | ||
if (attempt != null) { | ||
attempt.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. should we avoid repeatedly logging the same failed join attempt? I wonder if we should set 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 that we need to log lastFailedJoinAttempt each time we log a warn in 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'm with @ywelsch on this one. Imagine one join attempt fails with an exception and then the network is disconnected. We will continue to log this join exception, with a new timestamp each time, and I think that's confusing because this exception has nothing to do with the ongoing failure to form a cluster. It's true that we log how many milliseconds ago the exception occurred but I think that could easily be overlooked. 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. Ok, I fixed it here 283fdea |
||
lastFailedJoinAttempt.compareAndSet(attempt, null); | ||
} | ||
} | ||
|
||
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 +243,15 @@ public Empty read(StreamInput in) { | |
public void handleResponse(Empty response) { | ||
pendingOutgoingJoins.remove(dedupKey); | ||
logger.debug("successfully joined {} with {}", destination, joinRequest); | ||
lastFailedJoinAttempt.set(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.logNow(); | ||
lastFailedJoinAttempt.set(attempt); | ||
} | ||
|
||
@Override | ||
|
Uh oh!
There was an error while loading. Please reload this page.