From ec65910627e42f2f4c93ee3c330fe6ce32c9dd03 Mon Sep 17 00:00:00 2001 From: Zhen Li Date: Fri, 29 Nov 2019 17:56:16 +0100 Subject: [PATCH] Use the supportMultiDb feature detection result, to choose the database to connect. --- .../internal/async/ImmutableConnectionContext.java | 10 ++++++---- .../internal/cluster/loadbalancing/LoadBalancer.java | 9 +++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/driver/src/main/java/org/neo4j/driver/internal/async/ImmutableConnectionContext.java b/driver/src/main/java/org/neo4j/driver/internal/async/ImmutableConnectionContext.java index e031fdb3bd..633d9cf20a 100644 --- a/driver/src/main/java/org/neo4j/driver/internal/async/ImmutableConnectionContext.java +++ b/driver/src/main/java/org/neo4j/driver/internal/async/ImmutableConnectionContext.java @@ -24,6 +24,7 @@ import org.neo4j.driver.internal.spi.Connection; import static org.neo4j.driver.internal.DatabaseNameUtil.defaultDatabase; +import static org.neo4j.driver.internal.DatabaseNameUtil.systemDatabase; import static org.neo4j.driver.internal.InternalBookmark.empty; /** @@ -31,7 +32,8 @@ */ public class ImmutableConnectionContext implements ConnectionContext { - private static final ConnectionContext SIMPLE = new ImmutableConnectionContext( defaultDatabase(), empty(), AccessMode.READ ); + private static final ConnectionContext SINGLE_DB_CONTEXT = new ImmutableConnectionContext( defaultDatabase(), empty(), AccessMode.READ ); + private static final ConnectionContext MULTI_DB_CONTEXT = new ImmutableConnectionContext( systemDatabase(), empty(), AccessMode.READ ); private final DatabaseName databaseName; private final AccessMode mode; @@ -65,10 +67,10 @@ public Bookmark rediscoveryBookmark() /** * A simple context is used to test connectivity with a remote server/cluster. * As long as there is a read only service, the connection shall be established successfully. - * This context should be applicable for both bolt v4 and bolt v3 routing table rediscovery. + * Depending on whether multidb is supported or not, this method returns different context for routing table discovery. */ - public static ConnectionContext simple() + public static ConnectionContext simple( boolean supportsMultiDb ) { - return SIMPLE; + return supportsMultiDb ? MULTI_DB_CONTEXT : SINGLE_DB_CONTEXT; } } diff --git a/driver/src/main/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancer.java b/driver/src/main/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancer.java index c5bf67f885..6a31cf964a 100644 --- a/driver/src/main/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancer.java +++ b/driver/src/main/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancer.java @@ -103,19 +103,20 @@ public CompletionStage acquireConnection( ConnectionContext context @Override public CompletionStage verifyConnectivity() { - return routingTables.refreshRoutingTable( simple() ).handle( ( ignored, error ) -> { + return this.supportsMultiDbAsync().handle( ( supports, error ) -> { if ( error != null ) { Throwable cause = Futures.completionExceptionCause( error ); if ( cause instanceof ServiceUnavailableException ) { throw Futures.asCompletionException( new ServiceUnavailableException( - "Unable to connect to database, ensure the database is running and that there is a working network connection to it.", cause ) ); + "Unable to connect to database management service, ensure the database is running and that there is a working network connection to it.", + cause ) ); } throw Futures.asCompletionException( cause ); } - return null; - } ); + return supports; + } ).thenCompose( supports -> routingTables.refreshRoutingTable( simple( supports ) ) ).thenApply( ignored -> null ); } @Override