Skip to content

Commit ec65910

Browse files
author
Zhen Li
committed
Use the supportMultiDb feature detection result, to choose the database to connect.
1 parent 19a4bd7 commit ec65910

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

driver/src/main/java/org/neo4j/driver/internal/async/ImmutableConnectionContext.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@
2424
import org.neo4j.driver.internal.spi.Connection;
2525

2626
import static org.neo4j.driver.internal.DatabaseNameUtil.defaultDatabase;
27+
import static org.neo4j.driver.internal.DatabaseNameUtil.systemDatabase;
2728
import static org.neo4j.driver.internal.InternalBookmark.empty;
2829

2930
/**
3031
* A {@link Connection} shall fulfil this {@link ImmutableConnectionContext} when acquired from a connection provider.
3132
*/
3233
public class ImmutableConnectionContext implements ConnectionContext
3334
{
34-
private static final ConnectionContext SIMPLE = new ImmutableConnectionContext( defaultDatabase(), empty(), AccessMode.READ );
35+
private static final ConnectionContext SINGLE_DB_CONTEXT = new ImmutableConnectionContext( defaultDatabase(), empty(), AccessMode.READ );
36+
private static final ConnectionContext MULTI_DB_CONTEXT = new ImmutableConnectionContext( systemDatabase(), empty(), AccessMode.READ );
3537

3638
private final DatabaseName databaseName;
3739
private final AccessMode mode;
@@ -65,10 +67,10 @@ public Bookmark rediscoveryBookmark()
6567
/**
6668
* A simple context is used to test connectivity with a remote server/cluster.
6769
* As long as there is a read only service, the connection shall be established successfully.
68-
* This context should be applicable for both bolt v4 and bolt v3 routing table rediscovery.
70+
* Depending on whether multidb is supported or not, this method returns different context for routing table discovery.
6971
*/
70-
public static ConnectionContext simple()
72+
public static ConnectionContext simple( boolean supportsMultiDb )
7173
{
72-
return SIMPLE;
74+
return supportsMultiDb ? MULTI_DB_CONTEXT : SINGLE_DB_CONTEXT;
7375
}
7476
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,20 @@ public CompletionStage<Connection> acquireConnection( ConnectionContext context
103103
@Override
104104
public CompletionStage<Void> verifyConnectivity()
105105
{
106-
return routingTables.refreshRoutingTable( simple() ).handle( ( ignored, error ) -> {
106+
return this.supportsMultiDbAsync().handle( ( supports, error ) -> {
107107
if ( error != null )
108108
{
109109
Throwable cause = Futures.completionExceptionCause( error );
110110
if ( cause instanceof ServiceUnavailableException )
111111
{
112112
throw Futures.asCompletionException( new ServiceUnavailableException(
113-
"Unable to connect to database, ensure the database is running and that there is a working network connection to it.", cause ) );
113+
"Unable to connect to database management service, ensure the database is running and that there is a working network connection to it.",
114+
cause ) );
114115
}
115116
throw Futures.asCompletionException( cause );
116117
}
117-
return null;
118-
} );
118+
return supports;
119+
} ).thenCompose( supports -> routingTables.refreshRoutingTable( simple( supports ) ) ).thenApply( ignored -> null );
119120
}
120121

121122
@Override

0 commit comments

Comments
 (0)