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

better error handling in split client side (still needs work)

This commit is contained in:
Alberto Lerner 2010-12-29 09:58:38 -05:00
parent 1490910fff
commit 70cf11916e
3 changed files with 32 additions and 19 deletions

View File

@ -172,7 +172,7 @@ namespace mongo {
conn.done();
}
ChunkPtr Chunk::singleSplit( bool force ){
ChunkPtr Chunk::singleSplit( bool force , BSONObj& res ){
vector<BSONObj> splitPoint;
// if splitting is not obligatory we may return early if there are not enough data
@ -227,10 +227,10 @@ namespace mongo {
return ChunkPtr();
}
return multiSplit( splitPoint );
return multiSplit( splitPoint , res );
}
ChunkPtr Chunk::multiSplit( const vector<BSONObj>& m ) {
ChunkPtr Chunk::multiSplit( const vector<BSONObj>& m , BSONObj& res ) {
const size_t maxSplitPoints = 256;
uassert( 10165 , "can't split as shard doesn't have a manager" , _manager );
@ -239,7 +239,7 @@ namespace mongo {
uassert( 13003 , "can't split a chunk with only one distinct value" , _min.woCompare(_max) );
ScopedDbConnection conn( getShard().getConnString() );
BSONObj result;
BSONObjBuilder cmd;
cmd.append( "splitChunk" , _manager->getns() );
cmd.append( "keyPattern" , _manager->getShardKey().key() );
@ -250,13 +250,9 @@ namespace mongo {
cmd.append( "configdb" , configServer.modelServer() );
BSONObj cmdObj = cmd.obj();
if ( ! conn->runCommand( "admin" , cmdObj , result )) {
if ( ! conn->runCommand( "admin" , cmdObj , res )) {
conn.done();
// TODO decide if push up the error instead of asserting
ostringstream os;
os << "split chunk command failed: " << result;
uassert( 13504 , os.str() , 0 );
return ChunkPtr();
}
conn.done();
@ -326,7 +322,8 @@ namespace mongo {
_dataWritten = 0; // reset so we check often enough
ChunkPtr newShard = singleSplit( false /* does not force a split if not enough data */ );
BSONObj res;
ChunkPtr newShard = singleSplit( false /* does not force a split if not enough data */ , res );
if ( newShard.get() == NULL ){
// singleSplit would have issued a message if we got here
return false;
@ -874,7 +871,13 @@ namespace mongo {
return;
}
soleChunk->multiSplit( splitPoints );
BSONObj res;
ChunkPtr p;
p = soleChunk->multiSplit( splitPoints , res );
if ( p.get() == NULL ) {
log( LL_WARNING ) << "could not split '" << getns() << "': " << res << endl;
return;
}
}
ShardChunkVersion ChunkManager::getVersion( const Shard& shard ) const{

View File

@ -106,17 +106,19 @@ namespace mongo {
*
* @param force if set to true, will split the chunk regardless if the split is really necessary size wise
* if set to false, will only split if the chunk has reached the currently desired maximum size
* @param res the object containing details about the split execution
* @return if found a key, return a pointer to the first chunk, otherwise return a null pointer
*/
ChunkPtr singleSplit( bool force );
ChunkPtr singleSplit( bool force , BSONObj& res );
/**
* Splits this chunk at the given key (or keys)
*
* @param splitPoints the vector of keys that should be used to divide this chunk
* @return shared pointer to the first new Chunk
* @param res the object containing details about the split execution
* @return shared pointer to the first new Chunk or null pointer if failed
*/
ChunkPtr multiSplit( const vector<BSONObj>& splitPoints );
ChunkPtr multiSplit( const vector<BSONObj>& splitPoints , BSONObj& res );
/**
* Asks the mongod holding this chunk to find a key that approximately divides this chunk in two

View File

@ -493,10 +493,12 @@ namespace mongo {
assert( chunk.get() );
log() << "splitting: " << ns << " shard: " << chunk << endl;
if ( middle.isEmpty() )
chunk->singleSplit( true /* force a split even if not enough data */ );
BSONObj res;
ChunkPtr p;
if ( middle.isEmpty() ) {
p = chunk->singleSplit( true /* force a split even if not enough data */ , res );
else {
} 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";
@ -505,7 +507,13 @@ namespace mongo {
vector<BSONObj> splitPoints;
splitPoints.push_back( middle );
chunk->multiSplit( splitPoints );
p = chunk->multiSplit( splitPoints , res );
}
if ( p.get() == NULL ) {
errmsg = "split failed";
result.append( "cause" , res );
return false;
}
return true;