Skip to content

Commit a9f8200

Browse files
committed
Remove stacktrace from recoverable discovery log warnings (neo4j#943)
* Remove stacktrace from recoverable discovery log warnings This is to reduce the noise in the logs when recoverable discovery exceptions occur. Complete discovery failures are expected to be reported separately. * Update class comment on RediscoveryImpl
1 parent e405491 commit a9f8200

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,21 @@
2626
import org.neo4j.driver.internal.BoltServerAddress;
2727
import org.neo4j.driver.internal.spi.ConnectionPool;
2828

29+
/**
30+
* Provides cluster composition lookup capabilities and initial router address resolution.
31+
*/
2932
public interface Rediscovery
3033
{
34+
/**
35+
* Fetches cluster composition using the provided routing table.
36+
* <p>
37+
* Implementation must be thread safe to be called with distinct routing tables concurrently. The routing table instance may be modified.
38+
*
39+
* @param routingTable the routing table for cluster composition lookup
40+
* @param connectionPool the connection pool for connection acquisition
41+
* @param bookmark the bookmark that is presented to the server
42+
* @return cluster composition lookup result
43+
*/
3144
CompletionStage<ClusterCompositionLookupResult> lookupClusterComposition( RoutingTable routingTable, ConnectionPool connectionPool, Bookmark bookmark );
3245

3346
List<BoltServerAddress> resolve() throws UnknownHostException;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@
5252
import static org.neo4j.driver.internal.util.Futures.completedWithNull;
5353
import static org.neo4j.driver.internal.util.Futures.failedFuture;
5454

55-
/**
56-
* This class is used by all router tables to perform discovery.
57-
* In other words, the methods in this class could be called by multiple threads concurrently.
58-
*/
5955
public class RediscoveryImpl implements Rediscovery
6056
{
6157
private static final String NO_ROUTERS_AVAILABLE = "Could not perform discovery for database '%s'. No routing server available.";
6258
private static final String RECOVERABLE_ROUTING_ERROR = "Failed to update routing table with server '%s'.";
59+
private static final String RECOVERABLE_DISCOVERY_ERROR_WITH_SERVER = "Received a recoverable discovery error with server '%s', " +
60+
"will continue discovery with other routing servers if available. " +
61+
"Complete routing failures will be reported separately from this warning.";
6362

6463
private final BoltServerAddress initialRouter;
6564
private final RoutingSettings settings;
@@ -291,8 +290,9 @@ private ClusterComposition handleRoutingProcedureError( Throwable error, Routing
291290
// Retriable error happened during discovery.
292291
DiscoveryException discoveryError = new DiscoveryException( format( RECOVERABLE_ROUTING_ERROR, routerAddress ), error );
293292
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 );
293+
String warningMessage = format( RECOVERABLE_DISCOVERY_ERROR_WITH_SERVER, routerAddress );
294+
logger.warn( warningMessage );
295+
logger.debug( warningMessage, discoveryError );
296296
routingTable.forget( routerAddress );
297297
return null;
298298
}

driver/src/test/java/org/neo4j/driver/internal/cluster/RediscoveryTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import static org.junit.jupiter.api.Assertions.assertNotNull;
5858
import static org.junit.jupiter.api.Assertions.assertThrows;
5959
import static org.mockito.ArgumentMatchers.any;
60-
import static org.mockito.ArgumentMatchers.anyString;
6160
import static org.mockito.Mockito.mock;
6261
import static org.mockito.Mockito.never;
6362
import static org.mockito.Mockito.startsWith;
@@ -187,9 +186,14 @@ void shouldFailImmediatelyWhenClusterCompositionProviderReturnsFailure()
187186
ClusterComposition composition = await( rediscovery.lookupClusterComposition( table, pool, empty() ) ).getClusterComposition();
188187
assertEquals( validComposition, composition );
189188

190-
ArgumentCaptor<DiscoveryException> argument = ArgumentCaptor.forClass( DiscoveryException.class );
191-
verify( logger ).warn( anyString(), argument.capture() );
192-
assertThat( argument.getValue().getCause(), equalTo( protocolError ) );
189+
ArgumentCaptor<String> warningMessageCaptor = ArgumentCaptor.forClass( String.class );
190+
ArgumentCaptor<String> debugMessageCaptor = ArgumentCaptor.forClass( String.class );
191+
ArgumentCaptor<DiscoveryException> debugThrowableCaptor = ArgumentCaptor.forClass( DiscoveryException.class );
192+
verify( logger ).warn( warningMessageCaptor.capture() );
193+
verify( logger ).debug( debugMessageCaptor.capture(), debugThrowableCaptor.capture() );
194+
assertNotNull( warningMessageCaptor.getValue() );
195+
assertEquals( warningMessageCaptor.getValue(), debugMessageCaptor.getValue() );
196+
assertThat( debugThrowableCaptor.getValue().getCause(), equalTo( protocolError ) );
193197
}
194198

195199
@Test

0 commit comments

Comments
 (0)