0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

fix error when key provided is not a valid split key

This commit is contained in:
Alberto Lerner 2010-10-23 10:40:10 -04:00
parent 57507b03ef
commit 18938d62ec
2 changed files with 17 additions and 6 deletions

View File

@ -39,6 +39,11 @@ assert.eq( 6 , db.foo.find().sort( { name : 1 } ).count() , "total count with co
assert.eq( "allan,bob,eliot,joe,mark,sara" , db.foo.find().sort( { name : 1 } ).toArray().map( function(z){ return z.name; } ) , "sort 1" );
assert.eq( "sara,mark,joe,eliot,bob,allan" , db.foo.find().sort( { name : -1 } ).toArray().map( function(z){ return z.name; } ) , "sort 2" );
// make sure we can't foce a split on an extreme key
// [allan->joe)
assert.throws( function(){ s.adminCommand( { split : "test.foo" , middle : { name : "allan" } } ) } );
assert.throws( function(){ s.adminCommand( { split : "test.foo" , middle : { name : "joe" } } ) } );
s.stop();

View File

@ -479,19 +479,25 @@ namespace mongo {
}
ChunkManagerPtr info = config->getChunkManager( ns );
ChunkPtr old = info->findChunk( find );
ChunkPtr chunk = info->findChunk( find );
BSONObj middle = cmdObj.getObjectField( "middle" );
assert( old.get() );
log() << "splitting: " << ns << " shard: " << old << endl;
assert( chunk.get() );
log() << "splitting: " << ns << " shard: " << chunk << endl;
if ( middle.isEmpty() )
old->simpleSplit( true /* force a split even if not enough data */ );
chunk->simpleSplit( true /* force a split even if not enough data */ );
else {
// sanity check if the key provided is a valid split point
if ( ( middle == chunk->getMin() ) || ( middle == chunk->getMax() ) ) {
errmsg = "cannot split on initial or final chunk's key";
return false;
}
vector<BSONObj> splitPoints;
splitPoints.push_back( middle );
old->multiSplit( splitPoints );
chunk->multiSplit( splitPoints );
}
return true;