summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-02-14 14:16:18 -0500
committerEliot Horowitz <eliot@10gen.com>2011-02-14 14:16:18 -0500
commit3f1c76f47a18e4d99d658189aef3dfb058f077a6 (patch)
treedfc4931b5fa167335227f3b277e8d49d35bc45ce
parent36f405d6a76d3940e0d589038edc5a2bd2a76c00 (diff)
downloadmongo-3f1c76f47a18e4d99d658189aef3dfb058f077a6.tar.gz
cleanup replica set handling
-rw-r--r--s/config.cpp2
-rw-r--r--s/shard.cpp38
-rw-r--r--s/shard.h3
3 files changed, 26 insertions, 17 deletions
diff --git a/s/config.cpp b/s/config.cpp
index ace47edc89a..35a3be2d334 100644
--- a/s/config.cpp
+++ b/s/config.cpp
@@ -448,7 +448,7 @@ namespace mongo {
string fullString;
joinStringDelim( configHosts, &fullString, ',' );
- _primary.setAddress( fullString , true );
+ _primary.setAddress( ConnectionString( fullString , ConnectionString::SYNC ) );
log(1) << " config string : " << fullString << endl;
return true;
diff --git a/s/shard.cpp b/s/shard.cpp
index 56f32b96aca..ae6815e1d4a 100644
--- a/s/shard.cpp
+++ b/s/shard.cpp
@@ -114,13 +114,12 @@ namespace mongo {
return i->second;
}
- void set( const string& name , const string& addr , bool setName = true , bool setAddr = true ) {
- Shard s(name,addr);
+ void set( const string& name , const Shard& s , bool setName = true , bool setAddr = true ) {
scoped_lock lk( _mutex );
if ( setName )
_lookup[name] = s;
if ( setAddr )
- _lookup[addr] = s;
+ _lookup[s.getConnString()] = s;
}
void remove( const string& name ) {
@@ -180,27 +179,36 @@ namespace mongo {
_addr = addr;
if ( _addr.size() ) {
_cs = ConnectionString( addr , ConnectionString::SET );
- if ( _cs.type() == ConnectionString::SET ) {
- string x = _cs.getSetName();
- if ( x.size() == 0 )
- x = _name;
- _rs = ReplicaSetMonitor::get( x , _cs.getServers() );
- }
- }
+ _rsInit();
+ }
+ }
+
+ void Shard::_rsInit() {
+ if ( _cs.type() == ConnectionString::SET ) {
+ string x = _cs.getSetName();
+ if ( x.size() == 0 ) {
+ warning() << "no set name for shard: " << _name << " " << _cs.toString() << endl;
+ }
+ assert( x.size() );
+ _rs = ReplicaSetMonitor::get( x , _cs.getServers() );
+ }
}
- void Shard::setAddress( const string& addr , bool authoritative ) {
+ void Shard::setAddress( const ConnectionString& cs) {
assert( _name.size() );
- _setAddr( addr );
- if ( authoritative )
- staticShardInfo.set( _name , _addr , true , false );
+ _addr = cs.toString();
+ _cs = cs;
+ _rsInit();
+ staticShardInfo.set( _name , *this , true , false );
}
void Shard::reset( const string& ident ) {
const Shard& s = staticShardInfo.find( ident );
uassert( 13128 , (string)"can't find shard for: " + ident , s.ok() );
_name = s._name;
- _setAddr( s._addr );
+ _addr = s._addr;
+ _cs = s._cs;
+ _rsInit();
_maxSize = s._maxSize;
_isDraining = s._isDraining;
}
diff --git a/s/shard.h b/s/shard.h
index 5898a6fcca7..b1e15b7850a 100644
--- a/s/shard.h
+++ b/s/shard.h
@@ -67,7 +67,7 @@ namespace mongo {
*/
void reset( const string& ident );
- void setAddress( const string& addr , bool authoritative = false );
+ void setAddress( const ConnectionString& cs );
string getName() const {
assert( _name.size() );
@@ -159,6 +159,7 @@ namespace mongo {
private:
+ void _rsInit();
void _setAddr( const string& addr );
string _name;