@@ -23,6 +23,7 @@ import Session from '../session'
2323import RoutingTable from './routing-table'
2424import Rediscovery from './rediscovery'
2525import RoutingUtil from './routing-util'
26+ import { HostNameResolver } from './node'
2627
2728const UNAUTHORIZED_ERROR_CODE = 'Neo.ClientError.Security.Unauthorized'
2829
@@ -43,15 +44,15 @@ class ConnectionProvider {
4344}
4445
4546export class DirectConnectionProvider extends ConnectionProvider {
46- constructor ( hostPort , connectionPool , driverOnErrorCallback ) {
47+ constructor ( address , connectionPool , driverOnErrorCallback ) {
4748 super ( )
48- this . _hostPort = hostPort
49+ this . _address = address
4950 this . _connectionPool = connectionPool
5051 this . _driverOnErrorCallback = driverOnErrorCallback
5152 }
5253
5354 acquireConnection ( accessMode , db ) {
54- const connectionPromise = this . _connectionPool . acquire ( this . _hostPort )
55+ const connectionPromise = this . _connectionPool . acquire ( this . _address )
5556 return this . _withAdditionalOnErrorCallback (
5657 connectionPromise ,
5758 this . _driverOnErrorCallback
@@ -61,7 +62,7 @@ export class DirectConnectionProvider extends ConnectionProvider {
6162
6263export class LoadBalancer extends ConnectionProvider {
6364 constructor (
64- hostPort ,
65+ address ,
6566 routingContext ,
6667 connectionPool ,
6768 loadBalancingStrategy ,
@@ -70,15 +71,16 @@ export class LoadBalancer extends ConnectionProvider {
7071 log
7172 ) {
7273 super ( )
73- this . _seedRouter = hostPort
74- this . _routingTable = new RoutingTable ( [ this . _seedRouter ] )
74+ this . _seedRouter = address
75+ this . _routingTable = new RoutingTable ( )
7576 this . _rediscovery = new Rediscovery ( new RoutingUtil ( routingContext ) )
7677 this . _connectionPool = connectionPool
7778 this . _driverOnErrorCallback = driverOnErrorCallback
7879 this . _loadBalancingStrategy = loadBalancingStrategy
7980 this . _hostNameResolver = hostNameResolver
81+ this . _dnsResolver = new HostNameResolver ( )
8082 this . _log = log
81- this . _useSeedRouter = false
83+ this . _useSeedRouter = true
8284 }
8385
8486 acquireConnection ( accessMode , db ) {
@@ -238,6 +240,20 @@ export class LoadBalancer extends ConnectionProvider {
238240 } )
239241 }
240242
243+ _resolveSeedRouter ( seedRouter ) {
244+ const customResolution = this . _hostNameResolver . resolve ( seedRouter )
245+ const dnsResolutions = customResolution . then ( resolvedAddresses => {
246+ return Promise . all (
247+ resolvedAddresses . map ( address => {
248+ return this . _dnsResolver . resolve ( address )
249+ } )
250+ )
251+ } )
252+ return dnsResolutions . then ( results => {
253+ return [ ] . concat . apply ( [ ] , results )
254+ } )
255+ }
256+
241257 _fetchRoutingTable ( routerAddresses , routingTable ) {
242258 return routerAddresses . reduce (
243259 ( refreshedTablePromise , currentRouter , currentIndex ) => {
@@ -260,10 +276,14 @@ export class LoadBalancer extends ConnectionProvider {
260276 return this . _createSessionForRediscovery ( currentRouter ) . then (
261277 session => {
262278 if ( session ) {
263- return this . _rediscovery . lookupRoutingTableOnRouter (
264- session ,
265- currentRouter
266- )
279+ return this . _rediscovery
280+ . lookupRoutingTableOnRouter ( session , currentRouter )
281+ . catch ( error => {
282+ this . _log . warn (
283+ `unable to fetch routing table because of an error ${ error } `
284+ )
285+ return null
286+ } )
267287 } else {
268288 // unable to acquire connection and create session towards the current router
269289 // return null to signal that the next router should be tried
@@ -315,11 +335,8 @@ export class LoadBalancer extends ConnectionProvider {
315335 }
316336
317337 _updateRoutingTable ( newRoutingTable ) {
318- const currentRoutingTable = this . _routingTable
319-
320338 // close old connections to servers not present in the new routing table
321- const staleServers = currentRoutingTable . serversDiff ( newRoutingTable )
322- staleServers . forEach ( server => this . _connectionPool . purge ( server ) )
339+ this . _connectionPool . keepAll ( newRoutingTable . allServers ( ) )
323340
324341 // make this driver instance aware of the new table
325342 this . _routingTable = newRoutingTable
0 commit comments