@@ -13,15 +13,14 @@ function PoolCluster(config) {
13
13
14
14
config = config || { } ;
15
15
this . _canRetry = typeof config . canRetry === 'undefined' ? true : config . canRetry ;
16
- this . _removeNodeErrorCount = config . removeNodeErrorCount || 5 ;
17
16
this . _defaultSelector = config . defaultSelector || 'RR' ;
17
+ this . _removeNodeErrorCount = config . removeNodeErrorCount || 5 ;
18
18
19
19
this . _closed = false ;
20
20
this . _findCaches = Object . create ( null ) ;
21
21
this . _lastId = 0 ;
22
22
this . _namespaces = Object . create ( null ) ;
23
23
this . _nodes = Object . create ( null ) ;
24
- this . _serviceableNodeIds = [ ] ;
25
24
}
26
25
27
26
Util . inherits ( PoolCluster , EventEmitter ) ;
@@ -49,8 +48,6 @@ PoolCluster.prototype.add = function add(id, config) {
49
48
pool : new Pool ( { config : poolConfig } )
50
49
} ;
51
50
52
- this . _serviceableNodeIds . push ( nodeId ) ;
53
-
54
51
this . _clearFindCaches ( ) ;
55
52
} ;
56
53
@@ -119,10 +116,8 @@ PoolCluster.prototype.remove = function remove(pattern) {
119
116
120
117
for ( var i = 0 ; i < foundNodeIds . length ; i ++ ) {
121
118
var node = this . _getNode ( foundNodeIds [ i ] ) ;
122
- var index = this . _serviceableNodeIds . indexOf ( node . id ) ;
123
119
124
- if ( index !== - 1 ) {
125
- this . _serviceableNodeIds . splice ( index , 1 ) ;
120
+ if ( node ) {
126
121
delete this . _nodes [ node . id ] ;
127
122
128
123
this . _clearFindCaches ( ) ;
@@ -155,16 +150,19 @@ PoolCluster.prototype._findNodeIds = function(pattern) {
155
150
}
156
151
157
152
var foundNodeIds ;
153
+ var nodeIds = Object . keys ( this . _nodes ) ;
158
154
159
- if ( pattern === '*' ) { // all
160
- foundNodeIds = this . _serviceableNodeIds ;
161
- } else if ( this . _serviceableNodeIds . indexOf ( pattern ) != - 1 ) { // one
155
+ if ( pattern === '*' ) {
156
+ // all
157
+ foundNodeIds = nodeIds ;
158
+ } else if ( nodeIds . indexOf ( pattern ) != - 1 ) {
159
+ // one
162
160
foundNodeIds = [ pattern ] ;
163
161
} else if ( pattern [ pattern . length - 1 ] === '*' ) {
164
- // wild matching
162
+ // wild-card matching
165
163
var keyword = pattern . substring ( pattern . length - 1 , 0 ) ;
166
164
167
- foundNodeIds = this . _serviceableNodeIds . filter ( function ( id ) {
165
+ foundNodeIds = nodeIds . filter ( function ( id ) {
168
166
return id . indexOf ( keyword ) === 0 ;
169
167
} ) ;
170
168
} else {
@@ -180,19 +178,15 @@ PoolCluster.prototype._getNode = function(id) {
180
178
return this . _nodes [ id ] || null ;
181
179
} ;
182
180
183
- PoolCluster . prototype . _increaseErrorCount = function ( node ) {
181
+ PoolCluster . prototype . _increaseErrorCount = function _increaseErrorCount ( node ) {
184
182
if ( ++ node . errorCount >= this . _removeNodeErrorCount ) {
185
- var index = this . _serviceableNodeIds . indexOf ( node . id ) ;
186
- if ( index !== - 1 ) {
187
- this . _serviceableNodeIds . splice ( index , 1 ) ;
188
- delete this . _nodes [ node . id ] ;
183
+ delete this . _nodes [ node . id ] ;
189
184
190
- this . _clearFindCaches ( ) ;
185
+ this . _clearFindCaches ( ) ;
191
186
192
- node . pool . end ( _noop ) ;
187
+ node . pool . end ( _noop ) ;
193
188
194
- this . emit ( 'remove' , node . id ) ;
195
- }
189
+ this . emit ( 'remove' , node . id ) ;
196
190
}
197
191
} ;
198
192
0 commit comments