diff options
Diffstat (limited to 's/commands_admin.cpp')
-rw-r--r-- | s/commands_admin.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/s/commands_admin.cpp b/s/commands_admin.cpp index 685d020..551b8a9 100644 --- a/s/commands_admin.cpp +++ b/s/commands_admin.cpp @@ -616,29 +616,44 @@ namespace mongo { help << "add a new shard to the system"; } bool run(const string& , BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){ - HostAndPort shardAddr( cmdObj.firstElement().valuestrsafe() ); - if ( shardAddr.isLocalHost() != grid.allowLocalHost() ){ - errmsg = "can't use localhost as a shard since all shards need to communicate. " - "either use all shards and configdbs in localhost or all in actual IPs " ; - log() << "addshard request " << cmdObj << " failed: attempt to mix localhosts and IPs" << endl; + errmsg.clear(); + + // get replica set component hosts + ConnectionString servers = ConnectionString::parse( cmdObj.firstElement().valuestrsafe() , errmsg ); + if ( ! errmsg.empty() ){ + log() << "addshard request " << cmdObj << " failed:" << errmsg << endl; return false; } - if ( ! shardAddr.hasPort() ){ - shardAddr.setPort( CmdLine::ShardServerPort ); + // using localhost in server names implies every other process must use locahost addresses too + vector<HostAndPort> serverAddrs = servers.getServers(); + for ( size_t i = 0 ; i < serverAddrs.size() ; i++ ){ + if ( serverAddrs[i].isLocalHost() != grid.allowLocalHost() ){ + errmsg = "can't use localhost as a shard since all shards need to communicate. " + "either use all shards and configdbs in localhost or all in actual IPs " ; + log() << "addshard request " << cmdObj << " failed: attempt to mix localhosts and IPs" << endl; + return false; + } + + // it's fine if mongods of a set all use default port + if ( ! serverAddrs[i].hasPort() ){ + serverAddrs[i].setPort( CmdLine::ShardServerPort ); + } } + // name is optional; addShard will provide one if needed string name = ""; if ( cmdObj["name"].type() == String ) { name = cmdObj["name"].valuestrsafe(); } + // maxSize is the space usage cap in a shard in MBs long long maxSize = 0; if ( cmdObj[ ShardFields::maxSize.name() ].isNumber() ){ maxSize = cmdObj[ ShardFields::maxSize.name() ].numberLong(); } - if ( ! grid.addShard( &name , shardAddr.toString() , maxSize , errmsg ) ){ + if ( ! grid.addShard( &name , servers , maxSize , errmsg ) ){ log() << "addshard request " << cmdObj << " failed: " << errmsg << endl; return false; } |