use of io.netty.util.internal.logging.InternalLogLevel in project lettuce-core by lettuce-io.
the class ConnectionWatchdog method run.
/**
* Reconnect to the remote address that the closed channel was connected to. This creates a new {@link ChannelPipeline} with
* the same handler instances contained in the old channel's pipeline.
*
* @param attempt attempt counter.
* @param delay retry delay.
*
* @throws Exception when reconnection fails.
*/
private void run(int attempt, Duration delay) throws Exception {
reconnectSchedulerSync.set(false);
reconnectScheduleTimeout = null;
if (!isEventLoopGroupActive()) {
logger.debug("isEventLoopGroupActive() == false");
return;
}
if (!isListenOnChannelInactive()) {
logger.debug("Skip reconnect scheduling, listener disabled");
return;
}
if (isReconnectSuspended()) {
logger.debug("Skip reconnect scheduling, reconnect is suspended");
return;
}
boolean shouldLog = shouldLog();
InternalLogLevel infoLevel = InternalLogLevel.INFO;
InternalLogLevel warnLevel = InternalLogLevel.WARN;
if (shouldLog) {
lastReconnectionLogging = System.currentTimeMillis();
} else {
warnLevel = InternalLogLevel.DEBUG;
infoLevel = InternalLogLevel.DEBUG;
}
InternalLogLevel warnLevelToUse = warnLevel;
try {
reconnectionListener.onReconnectAttempt(new ConnectionEvents.Reconnect(attempt));
eventBus.publish(new ReconnectAttemptEvent(redisUri, epid, LocalAddress.ANY, remoteAddress, attempt, delay));
logger.log(infoLevel, "Reconnecting, last destination was {}", remoteAddress);
Tuple2<CompletableFuture<Channel>, CompletableFuture<SocketAddress>> tuple = reconnectionHandler.reconnect();
CompletableFuture<Channel> future = tuple.getT1();
future.whenComplete((c, t) -> {
if (c != null && t == null) {
return;
}
CompletableFuture<SocketAddress> remoteAddressFuture = tuple.getT2();
SocketAddress remote = remoteAddress;
if (remoteAddressFuture.isDone() && !remoteAddressFuture.isCompletedExceptionally() && !remoteAddressFuture.isCancelled()) {
remote = remoteAddressFuture.join();
}
String message = String.format("Cannot reconnect to [%s]: %s", remote, t.getMessage() != null ? t.getMessage() : t.toString());
if (ReconnectionHandler.isExecutionException(t)) {
if (logger.isDebugEnabled()) {
logger.debug(message, t);
} else {
logger.log(warnLevelToUse, message);
}
} else {
logger.log(warnLevelToUse, message, t);
}
eventBus.publish(new ReconnectFailedEvent(redisUri, epid, LocalAddress.ANY, remote, t, attempt));
if (!isReconnectSuspended()) {
scheduleReconnect();
}
});
} catch (Exception e) {
logger.log(warnLevel, "Cannot reconnect: {}", e.toString());
eventBus.publish(new ReconnectFailedEvent(redisUri, epid, LocalAddress.ANY, remoteAddress, e, attempt));
}
}
use of io.netty.util.internal.logging.InternalLogLevel in project lettuce-core by lettuce-io.
the class CommandHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
InternalLogLevel logLevel = InternalLogLevel.WARN;
if (!stack.isEmpty()) {
RedisCommand<?, ?, ?> command = stack.poll();
if (debugEnabled) {
logger.debug("{} Storing exception in {}", logPrefix(), command);
}
logLevel = InternalLogLevel.DEBUG;
try {
command.completeExceptionally(cause);
} catch (Exception ex) {
logger.warn("{} Unexpected exception during command completion exceptionally: {}", logPrefix, ex.toString(), ex);
}
}
if (channel == null || !channel.isActive() || !isConnected()) {
if (debugEnabled) {
logger.debug("{} Storing exception in connectionError", logPrefix());
}
logLevel = InternalLogLevel.DEBUG;
endpoint.notifyException(cause);
}
if (cause instanceof IOException && logLevel.ordinal() > InternalLogLevel.INFO.ordinal()) {
logLevel = InternalLogLevel.INFO;
if (SUPPRESS_IO_EXCEPTION_MESSAGES.contains(cause.getMessage())) {
logLevel = InternalLogLevel.DEBUG;
}
}
logger.log(logLevel, "{} Unexpected exception during request: {}", logPrefix, cause.toString(), cause);
}
Aggregations