summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristina Chodorow <k@ubuntu.(none)>2010-08-27 12:07:06 -0400
committerEliot Horowitz <eliot@10gen.com>2010-08-28 12:01:22 -0400
commit92d5eb42af2e25ac549d7489d90261c7f6a0e767 (patch)
tree5af659919381ebe10bd4a71d4ec31bf9f082f3fa
parentaaae92dedbd41733fd8043efa2882c0fcebb86f4 (diff)
downloadmongo-92d5eb42af2e25ac549d7489d90261c7f6a0e767.tar.gz
use replica set name for shard id SERVER-1665
-rw-r--r--s/grid.cpp10
-rw-r--r--s/shard.cpp13
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;
}