File tree 3 files changed +30
-2
lines changed
3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ you spot any mistakes.
19
19
* Fix SSL handshake error to be catchable #800
20
20
* Add ` connection.threadId ` to get MySQL connection ID #602
21
21
* Ensure ` pool.getConnection ` retrieves good connections #434 #557 #778
22
+ * Fix pool cluster wildcard matching #627
22
23
23
24
## v2.1.1 (2014-03-13)
24
25
Original file line number Diff line number Diff line change @@ -103,12 +103,15 @@ PoolCluster.prototype._findNodeIds = function(pattern) {
103
103
foundNodeIds = this . _serviceableNodeIds ;
104
104
} else if ( this . _serviceableNodeIds . indexOf ( pattern ) != - 1 ) { // one
105
105
foundNodeIds = [ pattern ] ;
106
- } else { // wild matching
106
+ } else if ( pattern [ pattern . length - 1 ] === '*' ) {
107
+ // wild matching
107
108
var keyword = pattern . substring ( pattern . length - 1 , 0 ) ;
108
109
109
110
foundNodeIds = this . _serviceableNodeIds . filter ( function ( id ) {
110
111
return id . indexOf ( keyword ) === 0 ;
111
112
} ) ;
113
+ } else {
114
+ foundNodeIds = [ ] ;
112
115
}
113
116
114
117
this . _findCaches [ pattern ] = foundNodeIds ;
@@ -181,7 +184,7 @@ PoolNamespace.prototype.getConnection = function(cb) {
181
184
var clusterNode = this . _getClusterNode ( ) ;
182
185
183
186
if ( clusterNode === null ) {
184
- return cb ( new Error ( 'Pool does Not exists .' ) ) ;
187
+ return cb ( new Error ( 'Pool does not exist .' ) ) ;
185
188
}
186
189
187
190
this . _cluster . _getConnection ( clusterNode , function ( err , connection ) {
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments