void _installHost( const string& host , const ShardPtr& s ) { _lookup[host] = s; const ConnectionString& cs = s->getAddress(); if ( cs.type() == ConnectionString::SET ) { if ( cs.getSetName().size() ) { scoped_lock lk( _rsMutex); _rsLookup[ cs.getSetName() ] = s; } vector<HostAndPort> servers = cs.getServers(); for ( unsigned i=0; i<servers.size(); i++ ) { _lookup[ servers[i].toString() ] = s; } } }
bool run( const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool ) { string ns; if ( !FieldParser::extract( cmdObj, nsField, &ns, &errmsg ) ) { return false; } if ( ns.size() == 0 ) { errmsg = "no namespace specified"; return false; } vector<BSONObj> bounds; if ( !FieldParser::extract( cmdObj, boundsField, &bounds, &errmsg ) ) { return false; } if ( bounds.size() == 0 ) { errmsg = "no bounds were specified"; return false; } if ( bounds.size() != 2 ) { errmsg = "only a min and max bound may be specified"; return false; } BSONObj minKey = bounds[0]; BSONObj maxKey = bounds[1]; if ( minKey.isEmpty() ) { errmsg = "no min key specified"; return false; } if ( maxKey.isEmpty() ) { errmsg = "no max key specified"; return false; } ShardPtr mergeShard = guessMergeShard( NamespaceString( ns ), minKey ); if ( !mergeShard ) { errmsg = (string)"could not find shard for merge range starting at " + minKey.toString(); return false; } BSONObjBuilder remoteCmdObjB; remoteCmdObjB.append( cmdObj[ MergeChunksPassCommand::nsField() ] ); remoteCmdObjB.append( cmdObj[ MergeChunksPassCommand::boundsField() ] ); remoteCmdObjB.append( MergeChunksPassCommand::configField(), configServer.getPrimary().getAddress().toString() ); remoteCmdObjB.append( MergeChunksPassCommand::shardNameField(), mergeShard->getName() ); BSONObj remoteResult; // Throws, but handled at level above. Don't want to rewrap to preserve exception // formatting. ScopedDbConnection conn( mergeShard->getAddress() ); bool ok = conn->runCommand( "admin", remoteCmdObjB.obj(), remoteResult ); conn.done(); // Always refresh our chunks afterwards refreshChunkCache( NamespaceString( ns ) ); result.appendElements( remoteResult ); return ok; }