diff options
author | Eliot Horowitz <eliot@10gen.com> | 2011-02-14 14:13:27 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2011-02-14 14:13:27 -0500 |
commit | 36f405d6a76d3940e0d589038edc5a2bd2a76c00 (patch) | |
tree | 835bcef07b223eef62abcbffc217fcf8cd60896d | |
parent | 6dee6f9498d0f5d2d5a5eac8e92fb9ff62124105 (diff) | |
parent | a969a0168cdb23c8cfa0fbcb26a92d0cabebf411 (diff) | |
download | mongo-36f405d6a76d3940e0d589038edc5a2bd2a76c00.tar.gz |
Merge branch 'master' of github.com:mongodb/mongo
-rw-r--r-- | client/dbclient.cpp | 33 | ||||
-rw-r--r-- | client/dbclient.h | 31 | ||||
-rw-r--r-- | db/taskqueue.h | 2 | ||||
-rw-r--r-- | dbtests/clienttests.cpp | 17 |
4 files changed, 60 insertions, 23 deletions
diff --git a/client/dbclient.cpp b/client/dbclient.cpp index 631c6e6ccb5..b4214abbbb2 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -31,6 +31,39 @@ namespace mongo { + void ConnectionString::_fillServers( string s ) { + + { + string::size_type idx = s.find( '/' ); + if ( idx != string::npos ) { + _setName = s.substr( 0 , idx ); + s = s.substr( idx + 1 ); + _type = SET; + } + } + + string::size_type idx; + while ( ( idx = s.find( ',' ) ) != string::npos ) { + _servers.push_back( s.substr( 0 , idx ) ); + s = s.substr( idx + 1 ); + } + _servers.push_back( s ); + + } + + void ConnectionString::_finishInit() { + stringstream ss; + if ( _type == SET ) + ss << _setName << "/"; + for ( unsigned i=0; i<_servers.size(); i++ ) { + if ( i > 0 ) + ss << ","; + ss << _servers[i].toString(); + } + _string = ss.str(); + } + + DBClientBase* ConnectionString::connect( string& errmsg ) const { switch ( _type ) { case MASTER: { diff --git a/client/dbclient.h b/client/dbclient.h index ace3dd4d783..9cb6571ca85 100644 --- a/client/dbclient.h +++ b/client/dbclient.h @@ -154,13 +154,18 @@ namespace mongo { } ConnectionString( const string& s , ConnectionType favoredMultipleType ) { + _type = INVALID; + _fillServers( s ); - if ( _servers.size() == 1 ) { + if ( _type != INVALID ) { + // set already + } + else if ( _servers.size() == 1 ) { _type = MASTER; } else { _type = favoredMultipleType; - assert( _type != MASTER ); + assert( _type == SET || _type == SYNC ); } _finishInit(); } @@ -183,26 +188,8 @@ namespace mongo { private: - void _fillServers( string s ) { - string::size_type idx; - while ( ( idx = s.find( ',' ) ) != string::npos ) { - _servers.push_back( s.substr( 0 , idx ) ); - s = s.substr( idx + 1 ); - } - _servers.push_back( s ); - } - - void _finishInit() { - stringstream ss; - if ( _type == SET ) - ss << _setName << "/"; - for ( unsigned i=0; i<_servers.size(); i++ ) { - if ( i > 0 ) - ss << ","; - ss << _servers[i].toString(); - } - _string = ss.str(); - } + void _fillServers( string s ); + void _finishInit(); ConnectionType _type; vector<HostAndPort> _servers; diff --git a/db/taskqueue.h b/db/taskqueue.h index 0ffe6b4ee42..c6a5667676d 100644 --- a/db/taskqueue.h +++ b/db/taskqueue.h @@ -69,7 +69,7 @@ namespace mongo { */ void invoke() { mutex::scoped_lock lk2(_invokeMutex); - int toDrain; + int toDrain = 0; { // flip queueing to the other queue (we are double buffered) readlocktry lk("", 5); diff --git a/dbtests/clienttests.cpp b/dbtests/clienttests.cpp index 317aad92365..f51b76578a1 100644 --- a/dbtests/clienttests.cpp +++ b/dbtests/clienttests.cpp @@ -161,6 +161,22 @@ namespace ClientTests { ASSERT( db.runCommand( "unittests", BSON( "collstats" << "clienttests.create" ), info ) ); } }; + + class ConnectionStringTests { + public: + void run() { + { + ConnectionString s( "a/b,c,d" , ConnectionString::SET ); + ASSERT_EQUALS( ConnectionString::SET , s.type() ); + ASSERT_EQUALS( "a" , s.getSetName() ); + vector<HostAndPort> v = s.getServers(); + ASSERT_EQUALS( 3U , v.size() ); + ASSERT_EQUALS( "b" , v[0].host() ); + ASSERT_EQUALS( "c" , v[1].host() ); + ASSERT_EQUALS( "d" , v[2].host() ); + } + } + }; class All : public Suite { public: @@ -174,6 +190,7 @@ namespace ClientTests { add<CS_10>(); add<PushBack>(); add<Create>(); + add<ConnectionStringTests>(); } } all; |