Skip to content

Commit 9aa9456

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 b590e33 commit 9aa9456

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
@@ -25,8 +25,21 @@
2525
import org.neo4j.driver.internal.BoltServerAddress;
2626
import org.neo4j.driver.internal.spi.ConnectionPool;
2727

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

3245
List<BoltServerAddress> resolve();

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
@@ -49,14 +49,13 @@
4949
import static org.neo4j.driver.internal.util.Futures.completedWithNull;
5050
import static org.neo4j.driver.internal.util.Futures.failedFuture;
5151

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

6160
private final BoltServerAddress initialRouter;
6261
private final RoutingSettings settings;
@@ -258,8 +257,9 @@ private ClusterComposition handleRoutingProcedureError( Throwable error, Routing
258257
// Retriable error happened during discovery.
259258
DiscoveryException discoveryError = new DiscoveryException( format( RECOVERABLE_ROUTING_ERROR, routerAddress ), error );
260259
Futures.combineErrors( baseError, discoveryError ); // we record each failure here
261-
logger.warn( format( "Received a recoverable discovery error with server '%s', will continue discovery with other routing servers if available.",
262-
routerAddress ), discoveryError );
260+
String warningMessage = format( RECOVERABLE_DISCOVERY_ERROR_WITH_SERVER, routerAddress );
261+
logger.warn( warningMessage );
262+
logger.debug( warningMessage, discoveryError );
263263
routingTable.forget( routerAddress );
264264
return null;
265265
}

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
@@ -52,7 +52,6 @@
5252
import static org.junit.jupiter.api.Assertions.assertNotNull;
5353
import static org.junit.jupiter.api.Assertions.assertThrows;
5454
import static org.mockito.ArgumentMatchers.any;
55-
import static org.mockito.ArgumentMatchers.anyString;
5655
import static org.mockito.Mockito.mock;
5756
import static org.mockito.Mockito.never;
5857
import static org.mockito.Mockito.startsWith;
@@ -182,9 +181,14 @@ void shouldFailImmediatelyWhenClusterCompositionProviderReturnsFailure()
182181
ClusterComposition composition = await( rediscovery.lookupClusterComposition( table, pool, empty() ) );
183182
assertEquals( validComposition, composition );
184183

185-
ArgumentCaptor<DiscoveryException> argument = ArgumentCaptor.forClass( DiscoveryException.class );
186-
verify( logger ).warn( anyString(), argument.capture() );
187-
assertThat( argument.getValue().getCause(), equalTo( protocolError ) );
184+
ArgumentCaptor<String> warningMessageCaptor = ArgumentCaptor.forClass( String.class );
185+
ArgumentCaptor<String> debugMessageCaptor = ArgumentCaptor.forClass( String.class );
186+
ArgumentCaptor<DiscoveryException> debugThrowableCaptor = ArgumentCaptor.forClass( DiscoveryException.class );
187+
verify( logger ).warn( warningMessageCaptor.capture() );
188+
verify( logger ).debug( debugMessageCaptor.capture(), debugThrowableCaptor.capture() );
189+
assertNotNull( warningMessageCaptor.getValue() );
190+
assertEquals( warningMessageCaptor.getValue(), debugMessageCaptor.getValue() );
191+
assertThat( debugThrowableCaptor.getValue().getCause(), equalTo( protocolError ) );
188192
}
189193

190194
@Test

0 commit comments

Comments
 (0)