Skip to content

Commit 2ba3474

Browse files
committed
Fix pool cluster wildcard matching
fixes #627
1 parent bdde6d2 commit 2ba3474

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ you spot any mistakes.
1919
* Fix SSL handshake error to be catchable #800
2020
* Add `connection.threadId` to get MySQL connection ID #602
2121
* Ensure `pool.getConnection` retrieves good connections #434 #557 #778
22+
* Fix pool cluster wildcard matching #627
2223

2324
## v2.1.1 (2014-03-13)
2425

lib/PoolCluster.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,15 @@ PoolCluster.prototype._findNodeIds = function(pattern) {
103103
foundNodeIds = this._serviceableNodeIds;
104104
} else if (this._serviceableNodeIds.indexOf(pattern) != -1) { // one
105105
foundNodeIds = [pattern];
106-
} else { // wild matching
106+
} else if (pattern[pattern.length - 1] === '*') {
107+
// wild matching
107108
var keyword = pattern.substring(pattern.length - 1, 0);
108109

109110
foundNodeIds = this._serviceableNodeIds.filter(function (id) {
110111
return id.indexOf(keyword) === 0;
111112
});
113+
} else {
114+
foundNodeIds = [];
112115
}
113116

114117
this._findCaches[pattern] = foundNodeIds;
@@ -181,7 +184,7 @@ PoolNamespace.prototype.getConnection = function(cb) {
181184
var clusterNode = this._getClusterNode();
182185

183186
if (clusterNode === null) {
184-
return cb(new Error('Pool does Not exists.'));
187+
return cb(new Error('Pool does not exist.'));
185188
}
186189

187190
this._cluster._getConnection(clusterNode, function(err, connection) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var cluster = common.createPoolCluster();
4+
var server = common.createFakeServer();
5+
6+
var poolConfig = common.getTestConfig({port: common.fakeServerPort});
7+
cluster.add('MASTER', poolConfig);
8+
cluster.add('SLAVE' , poolConfig);
9+
cluster.add('SLAVE1', poolConfig);
10+
cluster.add('SLAVE2', poolConfig);
11+
12+
server.listen(common.fakeServerPort, function(err) {
13+
assert.ifError(err);
14+
15+
cluster.getConnection('SLAVE4', function(err, conn){
16+
assert.ok(err);
17+
assert.equal(err.message, 'Pool does not exist.');
18+
server.destroy();
19+
});
20+
});
21+
22+
server.on('connection', function(incomingConnection) {
23+
incomingConnection.handshake();
24+
});

0 commit comments

Comments
 (0)