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

SERVER-1545 don't switch shards if current is best (FCoJ)

This commit is contained in:
Alberto Lerner 2010-09-03 10:23:31 -04:00
parent 4131dd3679
commit 8b24b1e719
3 changed files with 14 additions and 22 deletions

View File

@ -427,10 +427,10 @@ namespace mongo {
assert( toMove );
Shard newLocation = Shard::pick();
Shard newLocation = Shard::pick( getShard() );
if ( getShard() == newLocation ){
// if this is the best server, then we shouldn't do anything!
log(1) << "not moving chunk: " << toString() << " b/c would move to same place " << newLocation.toString() << " -> " << getShard().toString() << endl;
// if this is the best shard, then we shouldn't do anything (Shard::pick already logged our shard).
log(1) << "recently split chunk: " << toString() << "already in the best shard" << endl;
return 0;
}

View File

@ -219,7 +219,7 @@ namespace mongo {
staticShardInfo.remove( name );
}
Shard Shard::pick( const Shard& exclude ){
Shard Shard::pick( const Shard& current ){
vector<Shard> all;
staticShardInfo.getAllShards( all );
if ( all.size() == 0 ){
@ -229,27 +229,19 @@ namespace mongo {
return EMPTY;
}
// if provided, do not consider the 'exclude' shard as a viable candidate
if ( exclude != EMPTY ){
for ( vector<Shard>::iterator it= all.begin() ; it != all.end() ; ++it ){
if ( exclude == *it ){
all.erase( it );
break;
}
}
if ( all.size() == 0 )
return EMPTY;
}
// if current shard was provided, pick a different shard only if it is a better choice
ShardStatus best = all[0].getStatus();
if ( current != EMPTY ){
best = current.getStatus();
}
for ( size_t i=1; i<all.size(); i++ ){
for ( size_t i=0; i<all.size(); i++ ){
ShardStatus t = all[i].getStatus();
if ( t < best )
best = t;
}
log(1) << "picking shard: " << best << endl;
log(1) << "best shard for new allocation is " << best << endl;
return best.shard();
}

View File

@ -131,10 +131,10 @@ namespace mongo {
static void printShardInfo( ostream& out );
/**
* @parm exclude - disconsiders this shard when selecting one available
* @return the currently best known shard to put a chunk/database or EMPTY
* @parm current - shard where the chunk/database currently lives in
* @return the currently emptiest shard, if best then current, or EMPTY
*/
static Shard pick( const Shard& exclude = EMPTY );
static Shard pick( const Shard& current = EMPTY );
static void reloadShardInfo();