diff options
author | Kristina Chodorow <k@ubuntu.(none)> | 2010-08-27 12:07:06 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-08-28 12:01:22 -0400 |
commit | 92d5eb42af2e25ac549d7489d90261c7f6a0e767 (patch) | |
tree | 5af659919381ebe10bd4a71d4ec31bf9f082f3fa | |
parent | aaae92dedbd41733fd8043efa2882c0fcebb86f4 (diff) | |
download | mongo-92d5eb42af2e25ac549d7489d90261c7f6a0e767.tar.gz |
use replica set name for shard id SERVER-1665
-rw-r--r-- | s/grid.cpp | 10 | ||||
-rw-r--r-- | s/shard.cpp | 13 |
2 files changed, 23 insertions, 0 deletions
diff --git a/s/grid.cpp b/s/grid.cpp index d206f14ce31..fafccfe607b 100644 --- a/s/grid.cpp +++ b/s/grid.cpp @@ -138,6 +138,16 @@ namespace mongo { return false; } + // if name was not set and this is a replica set, use the rs's name + if ( name->empty() ) { + BSONObj fields; + BSONObj conf = newShardConn->findOne( "local.system.replset", Query(), &fields, 0 ); + if ( !conf.isEmpty() ) { + nameInternal = conf["_id"].String(); + name->assign(nameInternal); + } + } + // get the shard's local db's listing BSONObj res; bool ok = newShardConn->runCommand( "admin" , BSON( "listDatabases" << 1 ) , res ); diff --git a/s/shard.cpp b/s/shard.cpp index 8ef21a0f798..4d73a66824b 100644 --- a/s/shard.cpp +++ b/s/shard.cpp @@ -76,6 +76,12 @@ namespace mongo { Shard s( name , host , maxSize , isDraining ); _lookup[name] = s; _lookup[host] = s; + + // add rs name to lookup (if it exists) + size_t pos; + if ((pos = host.find('/', 0)) != string::npos) { + _lookup[host.substr(0, pos)] = s; + } } } @@ -90,6 +96,13 @@ namespace mongo { { scoped_lock lk( _mutex ); map<string,Shard>::iterator i = _lookup.find( ident ); + + // if normal find didn't find anything, try to find by rs name + size_t pos; + if ( i == _lookup.end() && (pos = ident.find('/', 0)) != string::npos) { + i = _lookup.find( ident.substr(0, pos) ); + } + if ( i != _lookup.end() ) return i->second; } |