summaryrefslogtreecommitdiff
path: root/client/connpool.cpp
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-07-01 01:00:21 -0400
committerEliot Horowitz <eliot@10gen.com>2010-07-01 01:00:21 -0400
commit05de6bdacb29823f76162852b2a283f9e95aad93 (patch)
tree985c5ae38839614b7a9580e4373dbd63592bb83b /client/connpool.cpp
parent6d596a5d6488d01f1e416f129f007fc6ad308b5e (diff)
downloadmongo-05de6bdacb29823f76162852b2a283f9e95aad93.tar.gz
more work on ConnectionString SERVER-1319
Diffstat (limited to 'client/connpool.cpp')
-rw-r--r--client/connpool.cpp109
1 files changed, 71 insertions, 38 deletions
diff --git a/client/connpool.cpp b/client/connpool.cpp
index b2d1acae116..e1d0989ff8f 100644
--- a/client/connpool.cpp
+++ b/client/connpool.cpp
@@ -28,50 +28,83 @@ namespace mongo {
DBConnectionPool pool;
- DBClientBase* DBConnectionPool::get(const string& host) {
+ DBClientBase* DBConnectionPool::_get(const string& ident) {
scoped_lock L(_mutex);
- PoolForHost& p = _pools[host];
+ PoolForHost& p = _pools[ident];
+ if ( p.pool.empty() )
+ return 0;
+
+ DBClientBase *c = p.pool.top();
+ p.pool.pop();
+ return c;
+ }
- if ( p.pool.empty() ) {
- int numCommas = DBClientBase::countCommas( host );
- DBClientBase *c;
-
- if( numCommas == 0 ) {
- DBClientConnection *cc = new DBClientConnection(true);
- log(2) << "creating new connection for pool to:" << host << endl;
- string errmsg;
- if ( !cc->connect(host.c_str(), errmsg) ) {
- delete cc;
- uassert( 11002 , (string)"dbconnectionpool: connect failed " + host , false);
- return 0;
- }
- c = cc;
- onCreate( c );
- }
- else if ( numCommas == 1 ) {
- DBClientPaired *p = new DBClientPaired();
- if( !p->connect(host) ) {
- delete p;
- uassert( 11003 , (string)"dbconnectionpool: connect failed [2] " + host , false);
- return 0;
- }
- c = p;
- }
- else if ( numCommas == 2 ) {
- c = new SyncClusterConnection( host );
- }
- else {
- uassert( 13071 , (string)"invalid hostname [" + host + "]" , 0 );
- c = 0; // prevents compiler warning
- }
+ DBClientBase* DBConnectionPool::_finishCreate( const string& host , DBClientBase* conn ){
+ {
+ scoped_lock L(_mutex);
+ PoolForHost& p = _pools[host];
p.created++;
+ }
+
+ onCreate( conn );
+ onHandedOut( conn );
+
+ return conn;
+ }
+
+ DBClientBase* DBConnectionPool::get(const ConnectionString& url) {
+ DBClientBase * c = _get( url.toString() );
+ if ( c ){
+ onHandedOut( c );
return c;
}
- DBClientBase *c = p.pool.top();
- p.pool.pop();
- onHandedOut( c );
- return c;
+
+ string errmsg;
+ c = url.connect( errmsg );
+ uassert( 13328 , (string)"dbconnectionpool: connect failed " + url.toString() + " : " + errmsg , c );
+
+ return _finishCreate( url.toString() , c );
+ }
+
+ DBClientBase* DBConnectionPool::get(const string& host) {
+ DBClientBase * c = _get( host );
+ if ( c ){
+ onHandedOut( c );
+ return c;
+ }
+
+ int numCommas = DBClientBase::countCommas( host );
+
+ if( numCommas == 0 ) {
+ DBClientConnection *cc = new DBClientConnection(true);
+ log(2) << "creating new connection for pool to:" << host << endl;
+ string errmsg;
+ if ( !cc->connect(host.c_str(), errmsg) ) {
+ delete cc;
+ uassert( 11002 , (string)"dbconnectionpool: connect failed " + host , false);
+ return 0;
+ }
+ c = cc;
+ }
+ else if ( numCommas == 1 ) {
+ DBClientPaired *p = new DBClientPaired();
+ if( !p->connect(host) ) {
+ delete p;
+ uassert( 11003 , (string)"dbconnectionpool: connect failed [2] " + host , false);
+ return 0;
+ }
+ c = p;
+ }
+ else if ( numCommas == 2 ) {
+ c = new SyncClusterConnection( host );
+ }
+ else {
+ uassert( 13071 , (string)"invalid hostname [" + host + "]" , 0 );
+ c = 0; // prevents compiler warning
+ }
+
+ return _finishCreate( host , c );
}
DBConnectionPool::~DBConnectionPool(){