Skip to content

Commit

Permalink
fix moveChunk on new mongos SERVER-2828
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed May 19, 2011
1 parent ea1a8f4 commit 096e570
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
17 changes: 13 additions & 4 deletions jstests/sharding/multi_mongos2.js
Expand Up @@ -20,10 +20,7 @@ assert.eq(1, s2.getDB('test').existing.count({_id:1}));
s2.adminCommand( { shardcollection : "test.existing" , key : { _id : 1 } } );
s2.adminCommand( { split : "test.existing" , find : { _id : 5 } } )

if (0) // This should work but doesn't due to SERVER-2828
res = s1.getDB( "admin" ).runCommand( { moveChunk: "test.existing" , find : { _id : 1 } , to : s1.getOther( s1.getServer( "test" ) ).name } );
else
res = s2.getDB( "admin" ).runCommand( { moveChunk: "test.existing" , find : { _id : 1 } , to : s1.getOther( s1.getServer( "test" ) ).name } );
res = s2.getDB( "admin" ).runCommand( { moveChunk: "test.existing" , find : { _id : 1 } , to : s1.getOther( s1.getServer( "test" ) ).name } );

assert.eq(1 , res.ok, tojson(res));

Expand All @@ -47,6 +44,18 @@ printjson( res )
assert.eq(true, res.sharded); //SERVER-2828
assert.eq(true, s2.getDB('test').existing2.stats().sharded);

// test admin commands

s1.getDB('test').existing3.insert({_id:1})
assert.eq(1, s1.getDB('test').existing3.count({_id:1}));
assert.eq(1, s2.getDB('test').existing3.count({_id:1}));

s2.adminCommand( { shardcollection : "test.existing3" , key : { _id : 1 } } );
s2.adminCommand( { split : "test.existing3" , find : { _id : 5 } } )

res = s1.getDB( "admin" ).runCommand( { moveChunk: "test.existing3" , find : { _id : 1 } , to : s1.getOther( s1.getServer( "test" ) ).name } );
assert.eq(1 , res.ok, tojson(res));



s1.stop();
14 changes: 10 additions & 4 deletions s/commands_admin.cpp
Expand Up @@ -569,8 +569,11 @@ namespace mongo {

DBConfigPtr config = grid.getDBConfig( ns );
if ( ! config->isSharded( ns ) ) {
errmsg = "ns not sharded. have to shard before can split";
return false;
config->reload();
if ( ! config->isSharded( ns ) ) {
errmsg = "ns not sharded. have to shard before can split";
return false;
}
}

BSONObj find = cmdObj.getObjectField( "find" );
Expand Down Expand Up @@ -640,8 +643,11 @@ namespace mongo {

DBConfigPtr config = grid.getDBConfig( ns );
if ( ! config->isSharded( ns ) ) {
errmsg = "ns not sharded. have to shard before can move a chunk";
return false;
config->reload();
if ( ! config->isSharded( ns ) ) {
errmsg = "ns not sharded. have to shard before can move a chunk";
return false;
}
}

BSONObj find = cmdObj.getObjectField( "find" );
Expand Down

0 comments on commit 096e570

Please sign in to comment.