@@ -37,10 +37,6 @@ var _session = require('../session');
37
37
38
38
var _session2 = _interopRequireDefault ( _session ) ;
39
39
40
- var _roundRobinArray = require ( './round-robin-array' ) ;
41
-
42
- var _roundRobinArray2 = _interopRequireDefault ( _roundRobinArray ) ;
43
-
44
40
var _routingTable = require ( './routing-table' ) ;
45
41
46
42
var _routingTable2 = _interopRequireDefault ( _routingTable ) ;
@@ -61,6 +57,25 @@ var _routingUtil2 = _interopRequireDefault(_routingUtil);
61
57
62
58
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
63
59
60
+ /**
61
+ * Copyright (c) 2002-2017 "Neo Technology,","
62
+ * Network Engine for Objects in Lund AB [http://neotechnology.com]
63
+ *
64
+ * This file is part of Neo4j.
65
+ *
66
+ * Licensed under the Apache License, Version 2.0 (the "License");
67
+ * you may not use this file except in compliance with the License.
68
+ * You may obtain a copy of the License at
69
+ *
70
+ * http://www.apache.org/licenses/LICENSE-2.0
71
+ *
72
+ * Unless required by applicable law or agreed to in writing, software
73
+ * distributed under the License is distributed on an "AS IS" BASIS,
74
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
75
+ * See the License for the specific language governing permissions and
76
+ * limitations under the License.
77
+ */
78
+
64
79
var ConnectionProvider = function ( ) {
65
80
function ConnectionProvider ( ) {
66
81
( 0 , _classCallCheck3 . default ) ( this , ConnectionProvider ) ;
@@ -84,24 +99,7 @@ var ConnectionProvider = function () {
84
99
}
85
100
} ] ) ;
86
101
return ConnectionProvider ;
87
- } ( ) ; /**
88
- * Copyright (c) 2002-2017 "Neo Technology,","
89
- * Network Engine for Objects in Lund AB [http://neotechnology.com]
90
- *
91
- * This file is part of Neo4j.
92
- *
93
- * Licensed under the Apache License, Version 2.0 (the "License");
94
- * you may not use this file except in compliance with the License.
95
- * You may obtain a copy of the License at
96
- *
97
- * http://www.apache.org/licenses/LICENSE-2.0
98
- *
99
- * Unless required by applicable law or agreed to in writing, software
100
- * distributed under the License is distributed on an "AS IS" BASIS,
101
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
102
- * See the License for the specific language governing permissions and
103
- * limitations under the License.
104
- */
102
+ } ( ) ;
105
103
106
104
var DirectConnectionProvider = exports . DirectConnectionProvider = function ( _ConnectionProvider ) {
107
105
( 0 , _inherits3 . default ) ( DirectConnectionProvider , _ConnectionProvider ) ;
@@ -131,17 +129,18 @@ var DirectConnectionProvider = exports.DirectConnectionProvider = function (_Con
131
129
var LoadBalancer = exports . LoadBalancer = function ( _ConnectionProvider2 ) {
132
130
( 0 , _inherits3 . default ) ( LoadBalancer , _ConnectionProvider2 ) ;
133
131
134
- function LoadBalancer ( address , routingContext , connectionPool , driverOnErrorCallback ) {
132
+ function LoadBalancer ( address , routingContext , connectionPool , loadBalancingStrategy , driverOnErrorCallback ) {
135
133
( 0 , _classCallCheck3 . default ) ( this , LoadBalancer ) ;
136
134
137
135
var _this2 = ( 0 , _possibleConstructorReturn3 . default ) ( this , ( LoadBalancer . __proto__ || ( 0 , _getPrototypeOf2 . default ) ( LoadBalancer ) ) . call ( this ) ) ;
138
136
139
137
_this2 . _seedRouter = address ;
140
- _this2 . _routingTable = new _routingTable2 . default ( new _roundRobinArray2 . default ( [ _this2 . _seedRouter ] ) ) ;
138
+ _this2 . _routingTable = new _routingTable2 . default ( [ _this2 . _seedRouter ] ) ;
141
139
_this2 . _rediscovery = new _rediscovery2 . default ( new _routingUtil2 . default ( routingContext ) ) ;
142
140
_this2 . _connectionPool = connectionPool ;
143
141
_this2 . _driverOnErrorCallback = driverOnErrorCallback ;
144
142
_this2 . _hostNameResolver = LoadBalancer . _createHostNameResolver ( ) ;
143
+ _this2 . _loadBalancingStrategy = loadBalancingStrategy ;
145
144
_this2 . _useSeedRouter = false ;
146
145
return _this2 ;
147
146
}
@@ -153,9 +152,11 @@ var LoadBalancer = exports.LoadBalancer = function (_ConnectionProvider2) {
153
152
154
153
var connectionPromise = this . _freshRoutingTable ( accessMode ) . then ( function ( routingTable ) {
155
154
if ( accessMode === _driver . READ ) {
156
- return _this3 . _acquireConnectionToServer ( routingTable . readers , 'read' ) ;
155
+ var address = _this3 . _loadBalancingStrategy . selectReader ( routingTable . readers ) ;
156
+ return _this3 . _acquireConnectionToServer ( address , 'read' ) ;
157
157
} else if ( accessMode === _driver . WRITE ) {
158
- return _this3 . _acquireConnectionToServer ( routingTable . writers , 'write' ) ;
158
+ var _address = _this3 . _loadBalancingStrategy . selectWriter ( routingTable . writers ) ;
159
+ return _this3 . _acquireConnectionToServer ( _address , 'write' ) ;
159
160
} else {
160
161
throw ( 0 , _error . newError ) ( 'Illegal mode ' + accessMode ) ;
161
162
}
@@ -175,8 +176,7 @@ var LoadBalancer = exports.LoadBalancer = function (_ConnectionProvider2) {
175
176
}
176
177
} , {
177
178
key : '_acquireConnectionToServer' ,
178
- value : function _acquireConnectionToServer ( serversRoundRobinArray , serverName ) {
179
- var address = serversRoundRobinArray . next ( ) ;
179
+ value : function _acquireConnectionToServer ( address , serverName ) {
180
180
if ( ! address ) {
181
181
return _promise2 . default . reject ( ( 0 , _error . newError ) ( 'Failed to obtain connection towards ' + serverName + ' server. Known routing table is: ' + this . _routingTable , _error . SESSION_EXPIRED ) ) ;
182
182
}
@@ -195,7 +195,7 @@ var LoadBalancer = exports.LoadBalancer = function (_ConnectionProvider2) {
195
195
} , {
196
196
key : '_refreshRoutingTable' ,
197
197
value : function _refreshRoutingTable ( currentRoutingTable ) {
198
- var knownRouters = currentRoutingTable . routers . toArray ( ) ;
198
+ var knownRouters = currentRoutingTable . routers ;
199
199
200
200
if ( this . _useSeedRouter ) {
201
201
return this . _fetchRoutingTableFromSeedRouterFallbackToKnownRouters ( knownRouters , currentRoutingTable ) ;
@@ -310,7 +310,7 @@ var LoadBalancer = exports.LoadBalancer = function (_ConnectionProvider2) {
310
310
throw ( 0 , _error . newError ) ( 'Could not perform discovery. No routing servers available. Known routing table: ' + this . _routingTable , _error . SERVICE_UNAVAILABLE ) ;
311
311
}
312
312
313
- if ( newRoutingTable . writers . isEmpty ( ) ) {
313
+ if ( newRoutingTable . writers . length === 0 ) {
314
314
// use seed router next time. this is important when cluster is partitioned. it tries to make sure driver
315
315
// does not always get routing table without writers because it talks exclusively to a minority partition
316
316
this . _useSeedRouter = true ;
0 commit comments