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