mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
SERVER-1353 removeShard takes shard name as well
This commit is contained in:
parent
86c01b838c
commit
2ea2bb00d6
@ -44,8 +44,7 @@ assert.soon( function(){
|
||||
} , "balance didn't happen" , 1000 * 60 * 3 , 5000 );
|
||||
|
||||
var chunkCount = sum();
|
||||
host = s.config.shards.findOne({_id : "shard0" }).host;
|
||||
s.adminCommand( { removeshard: host } );
|
||||
s.adminCommand( { removeshard: "shard0" } );
|
||||
|
||||
assert.soon( function(){
|
||||
printjson(s.chunkCounts( "foo" ));
|
||||
|
@ -708,8 +708,9 @@ namespace mongo {
|
||||
help << "remove a shard to the system.";
|
||||
}
|
||||
bool run(const string& , BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
|
||||
string shard = cmdObj.firstElement().valuestrsafe();
|
||||
if ( ! grid.knowAboutShard( shard ) ){
|
||||
string target = cmdObj.firstElement().valuestrsafe();
|
||||
Shard s = Shard::make( target );
|
||||
if ( ! grid.knowAboutShard( s.getConnString() ) ){
|
||||
errmsg = "unknown shard";
|
||||
return false;
|
||||
}
|
||||
@ -717,20 +718,20 @@ namespace mongo {
|
||||
ScopedDbConnection conn( configServer.getPrimary() );
|
||||
|
||||
// If the server is not yet draining chunks, put it in draining mode.
|
||||
BSONObj searchDoc = BSON( "host" << shard );
|
||||
BSONObj drainingDoc = BSON( "host" << shard << ShardFields::draining(true) );
|
||||
BSONObj searchDoc = BSON( "_id" << s.getName() );
|
||||
BSONObj drainingDoc = BSON( "_id" << s.getName() << ShardFields::draining(true) );
|
||||
BSONObj shardDoc = conn->findOne( "config.shards", drainingDoc );
|
||||
if ( shardDoc.isEmpty() ){
|
||||
|
||||
// TODO prevent move chunks to this shard.
|
||||
|
||||
log() << "going to start draining shard: " << shard << endl;
|
||||
log() << "going to start draining shard: " << s.getName() << endl;
|
||||
BSONObj newStatus = BSON( "$set" << BSON( ShardFields::draining(true) ) );
|
||||
conn->update( "config.shards" , searchDoc , newStatus, false /* do no upsert */);
|
||||
|
||||
errmsg = conn->getLastError();
|
||||
if ( errmsg.size() ){
|
||||
log() << "error starting remove shard: " << shard << " err: " << errmsg << endl;
|
||||
log() << "error starting remove shard: " << s.getName() << " err: " << errmsg << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -738,7 +739,7 @@ namespace mongo {
|
||||
|
||||
result.append( "msg" , "draining started successfully" );
|
||||
result.append( "state" , "started" );
|
||||
result.append( "shard" , shard );
|
||||
result.append( "shard" , s.getName() );
|
||||
conn.done();
|
||||
return true;
|
||||
}
|
||||
@ -750,12 +751,12 @@ namespace mongo {
|
||||
BSONObj primaryDoc = BSON( "primary" << shardDoc[ "_id" ].str() );
|
||||
long long dbCount = conn->count( "config.databases" , primaryDoc );
|
||||
if ( ( chunkCount == 0 ) && ( dbCount == 0 ) ){
|
||||
log() << "going to remove shard: " << shard << endl;
|
||||
log() << "going to remove shard: " << s.getName() << endl;
|
||||
conn->remove( "config.shards" , searchDoc );
|
||||
|
||||
errmsg = conn->getLastError();
|
||||
if ( errmsg.size() ){
|
||||
log() << "error concluding remove shard: " << shard << " err: " << errmsg << endl;
|
||||
log() << "error concluding remove shard: " << s.getName() << " err: " << errmsg << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -764,7 +765,7 @@ namespace mongo {
|
||||
|
||||
result.append( "msg" , "removeshard completed successfully" );
|
||||
result.append( "state" , "completed" );
|
||||
result.append( "shard" , shard );
|
||||
result.append( "shard" , s.getName() );
|
||||
conn.done();
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user