@@ -28,7 +28,6 @@ import {
28
28
ConnectionErrorHandler ,
29
29
DelegateConnection
30
30
} from '../connection'
31
- import { object } from '../lang'
32
31
33
32
const { SERVICE_UNAVAILABLE , SESSION_EXPIRED } = error
34
33
const {
@@ -52,6 +51,7 @@ const AUTHORIZATION_EXPIRED_CODE =
52
51
const INVALID_ARGUMENT_ERROR = 'Neo.ClientError.Statement.ArgumentError'
53
52
const INVALID_REQUEST_ERROR = 'Neo.ClientError.Request.Invalid'
54
53
const STATEMENT_TYPE_ERROR = 'Neo.ClientError.Statement.TypeError'
54
+ const NOT_AVAILABLE = 'N/A'
55
55
56
56
const SYSTEM_DB_NAME = 'system'
57
57
const DEFAULT_DB_NAME = null
@@ -143,7 +143,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
143
143
* See {@link ConnectionProvider} for more information about this method and
144
144
* its arguments.
145
145
*/
146
- async acquireConnection ( { accessMode, database, bookmarks, impersonatedUser, onDatabaseNameResolved, auth } = { } ) {
146
+ async acquireConnection ( { accessMode, database, bookmarks, impersonatedUser, onDatabaseNameResolved, auth, allowStickyConnection } = { } ) {
147
147
let name
148
148
let address
149
149
const context = { database : database || DEFAULT_DB_NAME }
@@ -162,6 +162,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
162
162
bookmarks,
163
163
impersonatedUser,
164
164
auth,
165
+ allowStickyConnection,
165
166
onDatabaseNameResolved : ( databaseName ) => {
166
167
context . database = context . database || databaseName
167
168
if ( onDatabaseNameResolved ) {
@@ -192,9 +193,11 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
192
193
try {
193
194
const connection = await this . _connectionPool . acquire ( { auth } , address )
194
195
195
- if ( auth && ! object . equals ( auth , connection . authToken ) ) {
196
- await connection . _release ( )
197
- return await this . _createStickyConnection ( { address, auth } )
196
+ if ( auth ) {
197
+ const stickyConnection = await this . _getStickyConnection ( { auth, connection, allowStickyConnection } )
198
+ if ( stickyConnection ) {
199
+ return stickyConnection
200
+ }
198
201
}
199
202
200
203
return new DelegateConnection ( connection , databaseSpecificErrorHandler )
@@ -312,7 +315,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
312
315
} )
313
316
}
314
317
315
- _freshRoutingTable ( { accessMode, database, bookmarks, impersonatedUser, onDatabaseNameResolved, auth } = { } ) {
318
+ _freshRoutingTable ( { accessMode, database, bookmarks, impersonatedUser, onDatabaseNameResolved, auth, allowStickyConnection } = { } ) {
316
319
const currentRoutingTable = this . _routingTableRegistry . get (
317
320
database ,
318
321
( ) => new RoutingTable ( { database } )
@@ -324,10 +327,10 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
324
327
this . _log . info (
325
328
`Routing table is stale for database: "${ database } " and access mode: "${ accessMode } ": ${ currentRoutingTable } `
326
329
)
327
- return this . _refreshRoutingTable ( currentRoutingTable , bookmarks , impersonatedUser , onDatabaseNameResolved , auth )
330
+ return this . _refreshRoutingTable ( currentRoutingTable , bookmarks , impersonatedUser , onDatabaseNameResolved , auth , allowStickyConnection )
328
331
}
329
332
330
- _refreshRoutingTable ( currentRoutingTable , bookmarks , impersonatedUser , onDatabaseNameResolved , auth ) {
333
+ _refreshRoutingTable ( currentRoutingTable , bookmarks , impersonatedUser , onDatabaseNameResolved , auth , allowStickyConnection ) {
331
334
const knownRouters = currentRoutingTable . routers
332
335
333
336
if ( this . _useSeedRouter ) {
@@ -337,7 +340,8 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
337
340
bookmarks ,
338
341
impersonatedUser ,
339
342
onDatabaseNameResolved ,
340
- auth
343
+ auth ,
344
+ allowStickyConnection
341
345
)
342
346
}
343
347
return this . _fetchRoutingTableFromKnownRoutersFallbackToSeedRouter (
@@ -346,7 +350,8 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
346
350
bookmarks ,
347
351
impersonatedUser ,
348
352
onDatabaseNameResolved ,
349
- auth
353
+ auth ,
354
+ allowStickyConnection
350
355
)
351
356
}
352
357
@@ -356,7 +361,8 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
356
361
bookmarks ,
357
362
impersonatedUser ,
358
363
onDatabaseNameResolved ,
359
- auth
364
+ auth ,
365
+ allowStickyConnection
360
366
) {
361
367
// we start with seed router, no routers were probed before
362
368
const seenRouters = [ ]
@@ -366,7 +372,8 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
366
372
currentRoutingTable ,
367
373
bookmarks ,
368
374
impersonatedUser ,
369
- auth
375
+ auth ,
376
+ allowStickyConnection
370
377
)
371
378
372
379
if ( newRoutingTable ) {
@@ -378,7 +385,8 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
378
385
currentRoutingTable ,
379
386
bookmarks ,
380
387
impersonatedUser ,
381
- auth
388
+ auth ,
389
+ allowStickyConnection
382
390
)
383
391
newRoutingTable = newRoutingTable2
384
392
error = error2 || error
@@ -398,14 +406,16 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
398
406
bookmarks ,
399
407
impersonatedUser ,
400
408
onDatabaseNameResolved ,
401
- auth
409
+ auth ,
410
+ allowStickyConnection
402
411
) {
403
412
let [ newRoutingTable , error ] = await this . _fetchRoutingTableUsingKnownRouters (
404
413
knownRouters ,
405
414
currentRoutingTable ,
406
415
bookmarks ,
407
416
impersonatedUser ,
408
- auth
417
+ auth ,
418
+ allowStickyConnection
409
419
)
410
420
411
421
if ( ! newRoutingTable ) {
@@ -416,7 +426,8 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
416
426
currentRoutingTable ,
417
427
bookmarks ,
418
428
impersonatedUser ,
419
- auth
429
+ auth ,
430
+ allowStickyConnection
420
431
)
421
432
}
422
433
@@ -433,14 +444,16 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
433
444
currentRoutingTable ,
434
445
bookmarks ,
435
446
impersonatedUser ,
436
- auth
447
+ auth ,
448
+ allowStickyConnection
437
449
) {
438
450
const [ newRoutingTable , error ] = await this . _fetchRoutingTable (
439
451
knownRouters ,
440
452
currentRoutingTable ,
441
453
bookmarks ,
442
454
impersonatedUser ,
443
- auth
455
+ auth ,
456
+ allowStickyConnection
444
457
)
445
458
446
459
if ( newRoutingTable ) {
@@ -466,7 +479,8 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
466
479
routingTable ,
467
480
bookmarks ,
468
481
impersonatedUser ,
469
- auth
482
+ auth ,
483
+ allowStickyConnection
470
484
) {
471
485
const resolvedAddresses = await this . _resolveSeedRouter ( seedRouter )
472
486
@@ -475,7 +489,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
475
489
address => seenRouters . indexOf ( address ) < 0
476
490
)
477
491
478
- return await this . _fetchRoutingTable ( newAddresses , routingTable , bookmarks , impersonatedUser , auth )
492
+ return await this . _fetchRoutingTable ( newAddresses , routingTable , bookmarks , impersonatedUser , auth , allowStickyConnection )
479
493
}
480
494
481
495
async _resolveSeedRouter ( seedRouter ) {
@@ -487,7 +501,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
487
501
return [ ] . concat . apply ( [ ] , dnsResolvedAddresses )
488
502
}
489
503
490
- async _fetchRoutingTable ( routerAddresses , routingTable , bookmarks , impersonatedUser , auth ) {
504
+ async _fetchRoutingTable ( routerAddresses , routingTable , bookmarks , impersonatedUser , auth , allowStickyConnection ) {
491
505
return routerAddresses . reduce (
492
506
async ( refreshedTablePromise , currentRouter , currentIndex ) => {
493
507
const [ newRoutingTable ] = await refreshedTablePromise
@@ -511,7 +525,8 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
511
525
currentRouter ,
512
526
bookmarks ,
513
527
impersonatedUser ,
514
- auth
528
+ auth ,
529
+ allowStickyConnection
515
530
)
516
531
if ( session ) {
517
532
try {
@@ -536,16 +551,15 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
536
551
)
537
552
}
538
553
539
- async _createSessionForRediscovery ( routerAddress , bookmarks , impersonatedUser , auth ) {
554
+ async _createSessionForRediscovery ( routerAddress , bookmarks , impersonatedUser , auth , allowStickyConnection ) {
540
555
try {
541
- let connection = await this . _connectionPool . acquire ( { auth } , routerAddress )
542
-
543
- if ( auth && ! object . equals ( auth , connection . authToken ) ) {
544
- await connection . _release ( )
545
- connection = await this . _createStickyConnection ( {
546
- address : routerAddress ,
547
- auth
548
- } )
556
+ const connection = await this . _connectionPool . acquire ( { auth } , routerAddress )
557
+
558
+ if ( auth ) {
559
+ const stickyConnection = await this . _getStickyConnection ( { auth, connection, allowStickyConnection } )
560
+ if ( stickyConnection ) {
561
+ return stickyConnection
562
+ }
549
563
}
550
564
551
565
const databaseSpecificErrorHandler = ConnectionErrorHandler . create ( {
@@ -737,7 +751,8 @@ function _isFailFastError (error) {
737
751
INVALID_BOOKMARK_MIXTURE_CODE ,
738
752
INVALID_ARGUMENT_ERROR ,
739
753
INVALID_REQUEST_ERROR ,
740
- STATEMENT_TYPE_ERROR
754
+ STATEMENT_TYPE_ERROR ,
755
+ NOT_AVAILABLE
741
756
] . includes ( error . code )
742
757
}
743
758
0 commit comments