Skip to content

Commit b9406fa

Browse files
committed
Remove unnecessary _serviceableNodeIds from PoolCluster
1 parent 62d7ba9 commit b9406fa

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

lib/PoolCluster.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ function PoolCluster(config) {
1313

1414
config = config || {};
1515
this._canRetry = typeof config.canRetry === 'undefined' ? true : config.canRetry;
16-
this._removeNodeErrorCount = config.removeNodeErrorCount || 5;
1716
this._defaultSelector = config.defaultSelector || 'RR';
17+
this._removeNodeErrorCount = config.removeNodeErrorCount || 5;
1818

1919
this._closed = false;
2020
this._findCaches = Object.create(null);
2121
this._lastId = 0;
2222
this._namespaces = Object.create(null);
2323
this._nodes = Object.create(null);
24-
this._serviceableNodeIds = [];
2524
}
2625

2726
Util.inherits(PoolCluster, EventEmitter);
@@ -49,8 +48,6 @@ PoolCluster.prototype.add = function add(id, config) {
4948
pool: new Pool({config: poolConfig})
5049
};
5150

52-
this._serviceableNodeIds.push(nodeId);
53-
5451
this._clearFindCaches();
5552
};
5653

@@ -119,10 +116,8 @@ PoolCluster.prototype.remove = function remove(pattern) {
119116

120117
for (var i = 0; i < foundNodeIds.length; i++) {
121118
var node = this._getNode(foundNodeIds[i]);
122-
var index = this._serviceableNodeIds.indexOf(node.id);
123119

124-
if (index !== -1) {
125-
this._serviceableNodeIds.splice(index, 1);
120+
if (node) {
126121
delete this._nodes[node.id];
127122

128123
this._clearFindCaches();
@@ -155,16 +150,19 @@ PoolCluster.prototype._findNodeIds = function(pattern) {
155150
}
156151

157152
var foundNodeIds;
153+
var nodeIds = Object.keys(this._nodes);
158154

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
162160
foundNodeIds = [pattern];
163161
} else if (pattern[pattern.length - 1] === '*') {
164-
// wild matching
162+
// wild-card matching
165163
var keyword = pattern.substring(pattern.length - 1, 0);
166164

167-
foundNodeIds = this._serviceableNodeIds.filter(function (id) {
165+
foundNodeIds = nodeIds.filter(function (id) {
168166
return id.indexOf(keyword) === 0;
169167
});
170168
} else {
@@ -180,19 +178,15 @@ PoolCluster.prototype._getNode = function(id) {
180178
return this._nodes[id] || null;
181179
};
182180

183-
PoolCluster.prototype._increaseErrorCount = function(node) {
181+
PoolCluster.prototype._increaseErrorCount = function _increaseErrorCount(node) {
184182
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];
189184

190-
this._clearFindCaches();
185+
this._clearFindCaches();
191186

192-
node.pool.end(_noop);
187+
node.pool.end(_noop);
193188

194-
this.emit('remove', node.id);
195-
}
189+
this.emit('remove', node.id);
196190
}
197191
};
198192

test/unit/pool-cluster/test-internals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ server.listen(common.fakeServerPort, function(err) {
1313
assert.ifError(err);
1414

1515
// added nodes
16-
assert.deepEqual(cluster._serviceableNodeIds, ['CLUSTER::1', 'MASTER', 'SLAVE1', 'SLAVE2']);
16+
assert.deepEqual(Object.keys(cluster._nodes), ['CLUSTER::1', 'MASTER', 'SLAVE1', 'SLAVE2']);
1717

1818
// _findNodeIds
1919
assert.deepEqual(cluster._findNodeIds('MASTER'), ['MASTER']);

0 commit comments

Comments
 (0)