0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-28 07:59:02 +01:00

SERVER-17615 Return ShardNotFound error if non-existent shard passed to moveChunk/movePrimary

This commit is contained in:
Daniel Alabi 2015-03-16 15:23:03 -04:00
parent 21c4f06e35
commit e12ee3248d
6 changed files with 40 additions and 3 deletions

View File

@ -40,5 +40,12 @@ assert.eq( s.normalize( s.config.databases.findOne( { _id : "test1" } ).primary
assert.eq( 3 , from.getDB( "test1" ).foo.count() , "from doesn't have data after move back" );
assert.eq( 0 , to.getDB( "test1" ).foo.count() , "to has data after move back" );
// attempting to move primary DB to non-existent shard should error out with appropriate code
var res = s.admin.runCommand({ movePrimary: 'test1', to: 'dontexist' });
assert.commandFailed(res,
'attempting to use non-existent shard as primary should error out');
// ErrorCodes::ShardNotFound === 70
assert.eq(res.code, 70, 'ShardNotFound code not used');
s.stop();

View File

@ -132,7 +132,16 @@ namespace {
return false;
}
Shard to = Shard::make(toString);
Shard to = Shard::findIfExists(toString);
if (!to.ok()) {
string msg(str::stream() <<
"Could not move chunk in '" << ns <<
"' to shard '" << toString <<
"' because that shard does not exist");
log() << msg;
return appendCommandStatus(result,
Status(ErrorCodes::ShardNotFound, msg));
}
// so far, chunk size serves test purposes; it may or may not become a supported parameter
long long maxChunkSizeBytes = cmdObj["maxChunkSizeBytes"].numberLong();

View File

@ -123,7 +123,16 @@ namespace {
return false;
}
Shard s = Shard::make(to);
Shard s = Shard::findIfExists(to);
if (!s.ok()) {
string msg(str::stream() <<
"Could not move database '" << dbname <<
"' to shard '" << to <<
"' because that shard does not exist");
log() << msg;
return appendCommandStatus(result,
Status(ErrorCodes::ShardNotFound, msg));
}
if (config->getPrimary() == s.getConnString()) {
errmsg = "it is already the primary";

View File

@ -101,7 +101,7 @@ namespace {
const string target = cmdObj.firstElement().valuestrsafe();
Shard s = Shard::findIfExists(target);
if (s == Shard::EMPTY) {
if (!s.ok()) {
string msg(str::stream() <<
"Could not drop shard '" << target <<
"' because it does not exist");

View File

@ -151,6 +151,8 @@ namespace mongo {
}
ShardPtr findIfExists( const string& shardName ) {
reload();
boost::lock_guard<boost::mutex> lk( _mutex );
ShardMap::iterator i = _lookup.find( shardName );
if ( i != _lookup.end() ) return i->second;

View File

@ -70,12 +70,22 @@ namespace mongo {
_isDraining(other._isDraining) {
}
/**
* Returns a Shard corresponding to 'ident', which can
* either be a shard name or a connection string.
* Assumes that a corresponding shard with name 'ident' already exists.
*/
static Shard make( const std::string& ident ) {
Shard s;
s.reset( ident );
return s;
}
/**
* Returns a Shard corresponding to 'shardName' if such a shard
* exists.
* If not, it returns Shard::EMPTY
*/
static Shard findIfExists( const std::string& shardName );
/**