Skip to content

Commit

Permalink
Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
injectives committed Sep 10, 2024
1 parent 045ce93 commit cfb1911
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public void operationComplete(ChannelFuture future) {
error = new ServiceUnavailableException(
String.format("Unable to write Bolt handshake to %s.", this.address), error);
}
if (log.isTraceEnabled()) {
log.error(String.format("Failed to write handshake to %s", this.address), error);
}
this.handshakeCompletedPromise.setFailure(error);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class ConnectionPoolImpl implements ConnectionPool {
private final NettyChannelTracker nettyChannelTracker;
private final NettyChannelHealthChecker channelHealthChecker;
private final PoolSettings settings;
private final Logging logging;
private final Logger log;
private final MetricsListener metricsListener;
private final boolean ownsEventLoopGroup;
Expand Down Expand Up @@ -109,6 +110,7 @@ protected ConnectionPoolImpl(
this.channelHealthChecker = nettyChannelHealthChecker;
this.settings = settings;
this.metricsListener = metricsListener;
this.logging = logging;
this.log = logging.getLog(getClass());
this.ownsEventLoopGroup = ownsEventLoopGroup;
this.connectionFactory = connectionFactory;
Expand Down Expand Up @@ -263,7 +265,8 @@ ExtendedChannelPool newPool(BoltServerAddress address) {
nettyChannelTracker,
channelHealthChecker,
settings.connectionAcquisitionTimeout(),
settings.maxConnectionPoolSize());
settings.maxConnectionPoolSize(),
logging);
}

private ExtendedChannelPool getOrCreatePool(BoltServerAddress address) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.atomic.AtomicBoolean;
import org.neo4j.driver.Logger;
import org.neo4j.driver.Logging;
import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.async.connection.ChannelConnector;
import org.neo4j.driver.internal.metrics.ListenerEvent;
Expand All @@ -45,10 +47,12 @@ public class NettyChannelPool implements ExtendedChannelPool {
*/
private static final boolean RELEASE_HEALTH_CHECK = false;

private final Logger log;
private final FixedChannelPool delegate;
private final AtomicBoolean closed = new AtomicBoolean(false);
private final String id;
private final CompletableFuture<Void> closeFuture = new CompletableFuture<>();
private final int maxConnections;

NettyChannelPool(
BoltServerAddress address,
Expand All @@ -57,10 +61,12 @@ public class NettyChannelPool implements ExtendedChannelPool {
NettyChannelTracker handler,
ChannelHealthChecker healthCheck,
long acquireTimeoutMillis,
int maxConnections) {
int maxConnections,
Logging logging) {
requireNonNull(address);
requireNonNull(connector);
requireNonNull(handler);
this.log = logging.getLog(getClass());
this.id = poolId(address);
this.delegate =
new FixedChannelPool(
Expand Down Expand Up @@ -94,11 +100,14 @@ protected ChannelFuture connectChannel(Bootstrap bootstrap) {
return trackedChannelFuture;
}
};
this.maxConnections = maxConnections;
this.log.debug("Opened pool id=%s", id);
}

@Override
public CompletionStage<Void> close() {
if (closed.compareAndSet(false, true)) {
log.debug("Closing pool id=%s acquired=%d size=%d", id, delegate.acquiredChannelCount(), maxConnections);
asCompletionStage(delegate.closeAsync(), closeFuture);
}
return closeFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ChannelErrorLogger(Channel channel, Logging logging) {

public void traceOrDebug(String message, Throwable error) {
if (isTraceEnabled()) {
trace(message, error);
error(message, error);
} else {
debug(String.format(DEBUG_MESSAGE_FORMAT, message, error.getClass()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,14 @@ private NettyChannelPool newPool(AuthToken authToken, int maxConnections) {
RoutingContext.EMPTY,
DefaultDomainNameResolver.getInstance());
return new NettyChannelPool(
neo4j.address(), connector, bootstrap, poolHandler, ChannelHealthChecker.ACTIVE, 1_000, maxConnections);
neo4j.address(),
connector,
bootstrap,
poolHandler,
ChannelHealthChecker.ACTIVE,
1_000,
maxConnections,
DEV_NULL_LOGGING);
}

private static Channel acquire(NettyChannelPool pool) throws Exception {
Expand Down

0 comments on commit cfb1911

Please sign in to comment.