Skip to content
This repository has been archived by the owner on Feb 22, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/simplereach/helenus
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin French-Owen committed Sep 27, 2012
2 parents 18c466f + e050e04 commit 2646b35
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
node_modules node_modules
*.sock *.sock
lib-cov/ lib-cov/
*.iml
.idea
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ node_js:


env: env:
- CASSANDRA_VERSION=1.0.11 - CASSANDRA_VERSION=1.0.11
- CASSANDRA_VERSION=1.1.3 - CASSANDRA_VERSION=1.1.5


before_install: before_install:
- sudo apt-get remove -y --purge cassandra - sudo dpkg --purge cassandra
- sudo apt-get install libjna-java
- sudo apt-get install python-support
- sudo rm -rf /var/log/cassandra - sudo rm -rf /var/log/cassandra
- sudo rm -rf /var/lib/cassandra - sudo rm -rf /var/lib/cassandra


Expand Down
11 changes: 10 additions & 1 deletion History.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -167,4 +167,13 @@
0.5.7 / 2012-08-26 0.5.7 / 2012-08-26
================== ==================


* Fixed issue with deserialization of ReversedType in CQL [ @devdazed #67 ] * Fixed issue with deserialization of ReversedType in CQL [ @devdazed #67 ]

0.5.8 / 2012-9-27
==================

* Exposed Consistency Levels [ @calvinfo #73 ]
* Adding callback on nodes unavailable exception [ @calvinfo #72 ]
* Added hostPoolSize on ConnectionPool [ @hpainter #70 ]
* Fixed issue with interpolating array parameters [ @devdazed #68 ]

2 changes: 1 addition & 1 deletion lib/connection.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function escapeCQL(val) {


if (Array.isArray(val)) { if (Array.isArray(val)) {
var sanitized = val.map( function( v ) { return escapeCQL( v ); } ); var sanitized = val.map( function( v ) { return escapeCQL( v ); } );
return "'" + sanitized.join( "','" ) + "'"; return sanitized.join(',');
} }


if (typeof val === 'object') { if (typeof val === 'object') {
Expand Down
41 changes: 22 additions & 19 deletions lib/pool.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ var replyNotAvailable = function (callback) {
* user : 'mary', * user : 'mary',
* pass : 'qwerty', * pass : 'qwerty',
* timeout : 30000, * timeout : 30000,
* cqlVersion : '3.0.0' * cqlVersion : '3.0.0',
* hostPoolSize : 1
* }); * });
* *
* @constructor * @constructor
Expand All @@ -45,11 +46,12 @@ var Pool = function(options){
this.password = options.password; this.password = options.password;
this.timeout = options.timeout; this.timeout = options.timeout;
this.cqlVersion = options.cqlVersion; this.cqlVersion = options.cqlVersion;
this.hostPoolSize = options.hostPoolSize ? options.hostPoolSize : 1;
this.retryInterval = null; this.retryInterval = null;
this.closing = false; this.closing = false;


if(!options.hosts && options.host){ if(!options.hosts && options.host){
this.hosts = [options.hosts]; this.hosts = [options.host];
} else { } else {
this.hosts = options.hosts; this.hosts = options.hosts;
} }
Expand All @@ -67,8 +69,9 @@ util.inherits(Pool, process.EventEmitter);
* @param {Function} callback The callback to invoke when all connections have been made * @param {Function} callback The callback to invoke when all connections have been made
*/ */
Pool.prototype.connect = function(callback){ Pool.prototype.connect = function(callback){
var i = 0, finished = 0, client, self = this, len = this.hosts.length, var i = 0, finished = 0, self = this,
connected = 0, errored; len = this.hosts.length * this.hostPoolSize,
connected = 0;


function onConnect(err, connection, keyspace, host){ function onConnect(err, connection, keyspace, host){
finished += 1; finished += 1;
Expand All @@ -78,24 +81,22 @@ Pool.prototype.connect = function(callback){
} else { } else {
connected += 1; connected += 1;
self.clients.push(connection); self.clients.push(connection);

//we only want to callback once, after we get a valid connection
if(connected === 1){
//set the keyspaces connection to be the pool
if(keyspace){
keyspace.connection = self;
}
callback(null, keyspace);

//now that we have a connection, lets start monitoring
self.monitorConnections();
}
} }

if(finished === len){ if(finished === len){
if(self.clients.length === 0){ if(self.clients.length === 0){
replyNotAvailable(callback); replyNotAvailable(callback);
} }

//set the keyspaces connection to be the pool
if(keyspace){
keyspace.connection = self;
}
//we only want to callback once, after we get the final connection
callback(null, keyspace);

//now that we have a connection, lets start monitoring
self.monitorConnections();
} }
} }


Expand All @@ -118,8 +119,10 @@ Pool.prototype.connect = function(callback){
}); });
} }


for(; i < len; i += 1){ for(; i < this.hosts.length; i += 1){
connect(this.hosts[i]); for(var j=0; j < this.hostPoolSize; j +=1){
connect(this.hosts[i]);
}
} }
}; };


Expand Down
13 changes: 13 additions & 0 deletions test/thriftHostPool.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Runs tests defined in thrift.js, but with ConnectionPool
* option hostPoolSize set to 5.
*/
var config = require('./helpers/thrift'),
system = require('./helpers/connection'),
thriftTest = require('./thrift'),
Helenus, conn, ks, cf_standard, row_standard, cf_composite, cf_counter;

system.hostPoolSize = 5;

module.exports = thriftTest;

0 comments on commit 2646b35

Please sign in to comment.