Skip to content

Commit b6802f8

Browse files
committed
Remove stacktrace from connection acquisition attempts in LoadBalancer (neo4j#944)
This is to reduce the noise in the logs on connection acquisition errors. Complete failures are reported separately.
1 parent e405491 commit b6802f8

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

driver/src/main/java/org/neo4j/driver/internal/cluster/RediscoveryImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public class RediscoveryImpl implements Rediscovery
6060
{
6161
private static final String NO_ROUTERS_AVAILABLE = "Could not perform discovery for database '%s'. No routing server available.";
6262
private static final String RECOVERABLE_ROUTING_ERROR = "Failed to update routing table with server '%s'.";
63+
private static final String RECOVERABLE_DISCOVERY_ERROR_WITH_SERVER = "Received a recoverable discovery error with server '%s', " +
64+
"will continue discovery with other routing servers if available. " +
65+
"Complete failure is reported separately from this entry.";
6366

6467
private final BoltServerAddress initialRouter;
6568
private final RoutingSettings settings;
@@ -291,8 +294,9 @@ private ClusterComposition handleRoutingProcedureError( Throwable error, Routing
291294
// Retriable error happened during discovery.
292295
DiscoveryException discoveryError = new DiscoveryException( format( RECOVERABLE_ROUTING_ERROR, routerAddress ), error );
293296
Futures.combineErrors( baseError, discoveryError ); // we record each failure here
294-
logger.warn( format( "Received a recoverable discovery error with server '%s', will continue discovery with other routing servers if available.",
295-
routerAddress ), discoveryError );
297+
String warningMessage = format( RECOVERABLE_DISCOVERY_ERROR_WITH_SERVER, routerAddress );
298+
logger.warn( warningMessage );
299+
logger.debug( warningMessage, discoveryError );
296300
routingTable.forget( routerAddress );
297301
return null;
298302
}

driver/src/main/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancer.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import io.netty.util.concurrent.EventExecutorGroup;
2222

23+
import java.util.LinkedList;
2324
import java.util.List;
2425
import java.util.concurrent.CompletableFuture;
2526
import java.util.concurrent.CompletionStage;
@@ -62,6 +63,11 @@
6263
public class LoadBalancer implements ConnectionProvider
6364
{
6465
private static final String LOAD_BALANCER_LOG_NAME = "LoadBalancer";
66+
private static final String CONNECTION_ACQUISITION_COMPLETION_FAILURE_MESSAGE = "Connection acquisition failed for all available addresses.";
67+
private static final String CONNECTION_ACQUISITION_COMPLETION_EXCEPTION_MESSAGE =
68+
"Failed to obtain connection towards %s server. Known routing table is: %s";
69+
private static final String CONNECTION_ACQUISITION_ATTEMPT_FAILURE_MESSAGE =
70+
"Failed to obtain a connection towards address %s, will try other addresses if available. Complete failure is reported separately from this entry.";
6571
private final ConnectionPool connectionPool;
6672
private final RoutingTableRegistry routingTables;
6773
private final LoadBalancingStrategy loadBalancingStrategy;
@@ -181,19 +187,23 @@ private CompletionStage<Connection> acquire( AccessMode mode, RoutingTable routi
181187
{
182188
AddressSet addresses = addressSet( mode, routingTable );
183189
CompletableFuture<Connection> result = new CompletableFuture<>();
184-
acquire( mode, routingTable, addresses, result );
190+
List<Throwable> attemptExceptions = new LinkedList<>();
191+
acquire( mode, routingTable, addresses, result, attemptExceptions );
185192
return result;
186193
}
187194

188-
private void acquire( AccessMode mode, RoutingTable routingTable, AddressSet addresses, CompletableFuture<Connection> result )
195+
private void acquire( AccessMode mode, RoutingTable routingTable, AddressSet addresses, CompletableFuture<Connection> result,
196+
List<Throwable> attemptErrors )
189197
{
190198
BoltServerAddress address = selectAddress( mode, addresses );
191199

192200
if ( address == null )
193201
{
194-
result.completeExceptionally( new SessionExpiredException(
195-
"Failed to obtain connection towards " + mode + " server. " +
196-
"Known routing table is: " + routingTable ) );
202+
SessionExpiredException completionError =
203+
new SessionExpiredException( format( CONNECTION_ACQUISITION_COMPLETION_EXCEPTION_MESSAGE, mode, routingTable ) );
204+
attemptErrors.forEach( completionError::addSuppressed );
205+
log.error( CONNECTION_ACQUISITION_COMPLETION_FAILURE_MESSAGE, completionError );
206+
result.completeExceptionally( completionError );
197207
return;
198208
}
199209

@@ -204,10 +214,12 @@ private void acquire( AccessMode mode, RoutingTable routingTable, AddressSet add
204214
{
205215
if ( error instanceof ServiceUnavailableException )
206216
{
207-
SessionExpiredException errorToLog = new SessionExpiredException( format( "Server at %s is no longer available", address ), error );
208-
log.warn( "Failed to obtain a connection towards address " + address, errorToLog );
217+
String attemptMessage = format( CONNECTION_ACQUISITION_ATTEMPT_FAILURE_MESSAGE, address );
218+
log.warn( attemptMessage );
219+
log.debug( attemptMessage, error );
220+
attemptErrors.add( error );
209221
routingTable.forget( address );
210-
eventExecutorGroup.next().execute( () -> acquire( mode, routingTable, addresses, result ) );
222+
eventExecutorGroup.next().execute( () -> acquire( mode, routingTable, addresses, result, attemptErrors ) );
211223
}
212224
else
213225
{

0 commit comments

Comments
 (0)