Skip to content

Remove stacktrace from connection acquisition attempts in LoadBalancer #956

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

Merged
merged 2 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class RediscoveryImpl implements Rediscovery
private static final String RECOVERABLE_ROUTING_ERROR = "Failed to update routing table with server '%s'.";
private static final String RECOVERABLE_DISCOVERY_ERROR_WITH_SERVER = "Received a recoverable discovery error with server '%s', " +
"will continue discovery with other routing servers if available. " +
"Complete routing failures will be reported separately from this warning.";
"Complete failure is reported separately from this entry.";

private final BoltServerAddress initialRouter;
private final RoutingSettings settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import io.netty.util.concurrent.EventExecutorGroup;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
Expand Down Expand Up @@ -60,6 +61,11 @@
public class LoadBalancer implements ConnectionProvider
{
private static final String LOAD_BALANCER_LOG_NAME = "LoadBalancer";
private static final String CONNECTION_ACQUISITION_COMPLETION_FAILURE_MESSAGE = "Connection acquisition failed for all available addresses.";
private static final String CONNECTION_ACQUISITION_COMPLETION_EXCEPTION_MESSAGE =
"Failed to obtain connection towards %s server. Known routing table is: %s";
private static final String CONNECTION_ACQUISITION_ATTEMPT_FAILURE_MESSAGE =
"Failed to obtain a connection towards address %s, will try other addresses if available. Complete failure is reported separately from this entry.";
private final ConnectionPool connectionPool;
private final RoutingTableRegistry routingTables;
private final LoadBalancingStrategy loadBalancingStrategy;
Expand Down Expand Up @@ -177,19 +183,23 @@ private CompletionStage<Connection> acquire( AccessMode mode, RoutingTable routi
{
AddressSet addresses = addressSet( mode, routingTable );
CompletableFuture<Connection> result = new CompletableFuture<>();
acquire( mode, routingTable, addresses, result );
List<Throwable> attemptExceptions = new ArrayList<>();
acquire( mode, routingTable, addresses, result, attemptExceptions );
return result;
}

private void acquire( AccessMode mode, RoutingTable routingTable, AddressSet addresses, CompletableFuture<Connection> result )
private void acquire( AccessMode mode, RoutingTable routingTable, AddressSet addresses, CompletableFuture<Connection> result,
List<Throwable> attemptErrors )
{
BoltServerAddress address = selectAddress( mode, addresses );

if ( address == null )
{
result.completeExceptionally( new SessionExpiredException(
"Failed to obtain connection towards " + mode + " server. " +
"Known routing table is: " + routingTable ) );
SessionExpiredException completionError =
new SessionExpiredException( format( CONNECTION_ACQUISITION_COMPLETION_EXCEPTION_MESSAGE, mode, routingTable ) );
attemptErrors.forEach( completionError::addSuppressed );
log.error( CONNECTION_ACQUISITION_COMPLETION_FAILURE_MESSAGE, completionError );
result.completeExceptionally( completionError );
return;
}

Expand All @@ -200,10 +210,12 @@ private void acquire( AccessMode mode, RoutingTable routingTable, AddressSet add
{
if ( error instanceof ServiceUnavailableException )
{
SessionExpiredException errorToLog = new SessionExpiredException( format( "Server at %s is no longer available", address ), error );
log.warn( "Failed to obtain a connection towards address " + address, errorToLog );
String attemptMessage = format( CONNECTION_ACQUISITION_ATTEMPT_FAILURE_MESSAGE, address );
log.warn( attemptMessage );
log.debug( attemptMessage, error );
attemptErrors.add( error );
routingTable.forget( address );
eventExecutorGroup.next().execute( () -> acquire( mode, routingTable, addresses, result ) );
eventExecutorGroup.next().execute( () -> acquire( mode, routingTable, addresses, result, attemptErrors ) );
}
else
{
Expand Down
Loading