Skip to content

Commit

Permalink
Use capped logger for connection issue warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarW committed Apr 11, 2018
1 parent c18c835 commit edf6ae7
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@
import io.netty.util.AttributeKey;
import io.netty.util.concurrent.Promise;

import java.time.Clock;
import java.util.Optional;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;

import org.neo4j.causalclustering.helper.ExponentialBackoffStrategy;
import org.neo4j.causalclustering.helper.TimeoutStrategy;
import org.neo4j.causalclustering.protocol.handshake.ProtocolStack;
import org.neo4j.helpers.SocketAddress;
import org.neo4j.kernel.impl.util.CappedLogger;
import org.neo4j.logging.Log;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
Expand All @@ -54,6 +57,7 @@ public class ReconnectingChannel implements Channel
private volatile boolean disposed;

private TimeoutStrategy.Timeout connectionBackoff;
private CappedLogger cappedLogger;

ReconnectingChannel( Bootstrap bootstrap, EventLoop eventLoop, SocketAddress destination, final Log log )
{
Expand All @@ -67,6 +71,7 @@ private ReconnectingChannel( Bootstrap bootstrap, EventLoop eventLoop, SocketAdd
this.eventLoop = eventLoop;
this.destination = destination;
this.log = log;
this.cappedLogger = new CappedLogger( log ).setTimeLimit( 20, TimeUnit.SECONDS, Clock.systemUTC() );
this.connectionBackoffStrategy = connectionBackoffStrategy;
this.connectionBackoff = connectionBackoffStrategy.newTimeout();
}
Expand Down Expand Up @@ -95,7 +100,7 @@ else if ( fChannel != null && !fChannel.isDone() )
if ( !f.isSuccess() )
{
long millis = connectionBackoff.getMillis();
log.warn( "Failed to connect to: %s. Retrying in %d ms", destination.socketAddress(), millis );
cappedLogger.warn( "Failed to connect to: " + destination.socketAddress() + ". Retrying in " + millis + " ms" );
f.channel().eventLoop().schedule( this::tryConnect, millis, MILLISECONDS );
connectionBackoff.increment();
}
Expand Down

0 comments on commit edf6ae7

Please sign in to comment.