@@ -66,6 +66,7 @@ public int compare( BoltServerAddress o1, BoltServerAddress o2 )
66
66
}
67
67
};
68
68
private static final int MIN_SERVERS = 1 ;
69
+ private static final int CONNECTION_RETRIES = 3 ;
69
70
private final ConnectionPool connections ;
70
71
private final BiFunction <Connection ,Logger ,Session > sessionProvider ;
71
72
private final Clock clock ;
@@ -138,11 +139,11 @@ private void getServers()
138
139
{
139
140
boolean success = false ;
140
141
141
- ConcurrentRoundRobinSet <BoltServerAddress > routers = new ConcurrentRoundRobinSet <>( routingServers );
142
+ final ConcurrentRoundRobinSet <BoltServerAddress > newRouters = new ConcurrentRoundRobinSet <>( );
142
143
final Set <BoltServerAddress > seen = forgetAllServers ();
143
- while ( !routers .isEmpty () && !success )
144
+ while ( !routingServers .isEmpty () && !success )
144
145
{
145
- address = routers .hop ();
146
+ address = routingServers .hop ();
146
147
success = call ( address , GET_SERVERS , new Consumer <Record >()
147
148
{
148
149
@ Override
@@ -162,12 +163,19 @@ public void accept( Record record )
162
163
writeServers .addAll ( server .addresses () );
163
164
break ;
164
165
case "ROUTE" :
165
- routingServers .addAll ( server .addresses () );
166
+ newRouters .addAll ( server .addresses () );
166
167
break ;
167
168
}
168
169
}
169
170
}
170
171
} );
172
+ //We got trough but server gave us an empty list of routers
173
+ if (success && newRouters .isEmpty ()) {
174
+ success = false ;
175
+ } else if (success ) {
176
+ routingServers .clear ();
177
+ routingServers .addAll ( newRouters );
178
+ }
171
179
}
172
180
if ( !success )
173
181
{
@@ -249,7 +257,7 @@ private boolean call( BoltServerAddress address, String procedureName, Consumer<
249
257
recorder .accept ( records .next () );
250
258
}
251
259
}
252
- catch ( ConnectionFailureException e )
260
+ catch ( Throwable e )
253
261
{
254
262
forget ( address );
255
263
return false ;
@@ -306,18 +314,36 @@ public void onWriteFailure( BoltServerAddress address )
306
314
307
315
private Connection acquireConnection ( AccessMode role )
308
316
{
309
- //Potentially rediscover servers if we are not happy with our current knowledge
310
- checkServers ();
311
-
317
+ ConcurrentRoundRobinSet <BoltServerAddress > servers ;
312
318
switch ( role )
313
319
{
314
320
case READ :
315
- return connections .acquire ( readServers .hop () );
321
+ servers = readServers ;
322
+ break ;
316
323
case WRITE :
317
- return connections .acquire ( writeServers .hop () );
324
+ servers = writeServers ;
325
+ break ;
318
326
default :
319
327
throw new ClientException ( role + " is not supported for creating new sessions" );
320
328
}
329
+
330
+ //Potentially rediscover servers if we are not happy with our current knowledge
331
+ checkServers ();
332
+ int numberOfServers = servers .size ();
333
+ for ( int i = 0 ; i < numberOfServers ; i ++ )
334
+ {
335
+ BoltServerAddress address = servers .hop ();
336
+ try
337
+ {
338
+ return connections .acquire ( address );
339
+ }
340
+ catch ( ConnectionFailureException e )
341
+ {
342
+ forget ( address );
343
+ }
344
+ }
345
+
346
+ throw new ConnectionFailureException ( "Failed to connect to any servers" );
321
347
}
322
348
323
349
@ Override
0 commit comments