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:
parent
4131dd3679
commit
8b24b1e719
@ -427,10 +427,10 @@ namespace mongo {
|
|||||||
|
|
||||||
assert( toMove );
|
assert( toMove );
|
||||||
|
|
||||||
Shard newLocation = Shard::pick();
|
Shard newLocation = Shard::pick( getShard() );
|
||||||
if ( getShard() == newLocation ){
|
if ( getShard() == newLocation ){
|
||||||
// if this is the best server, then we shouldn't do anything!
|
// if this is the best shard, then we shouldn't do anything (Shard::pick already logged our shard).
|
||||||
log(1) << "not moving chunk: " << toString() << " b/c would move to same place " << newLocation.toString() << " -> " << getShard().toString() << endl;
|
log(1) << "recently split chunk: " << toString() << "already in the best shard" << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
s/shard.cpp
22
s/shard.cpp
@ -219,7 +219,7 @@ namespace mongo {
|
|||||||
staticShardInfo.remove( name );
|
staticShardInfo.remove( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
Shard Shard::pick( const Shard& exclude ){
|
Shard Shard::pick( const Shard& current ){
|
||||||
vector<Shard> all;
|
vector<Shard> all;
|
||||||
staticShardInfo.getAllShards( all );
|
staticShardInfo.getAllShards( all );
|
||||||
if ( all.size() == 0 ){
|
if ( all.size() == 0 ){
|
||||||
@ -229,27 +229,19 @@ namespace mongo {
|
|||||||
return EMPTY;
|
return EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if provided, do not consider the 'exclude' shard as a viable candidate
|
// if current shard was provided, pick a different shard only if it is a better choice
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
ShardStatus best = all[0].getStatus();
|
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();
|
ShardStatus t = all[i].getStatus();
|
||||||
if ( t < best )
|
if ( t < best )
|
||||||
best = t;
|
best = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
log(1) << "picking shard: " << best << endl;
|
log(1) << "best shard for new allocation is " << best << endl;
|
||||||
return best.shard();
|
return best.shard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,10 +131,10 @@ namespace mongo {
|
|||||||
static void printShardInfo( ostream& out );
|
static void printShardInfo( ostream& out );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @parm exclude - disconsiders this shard when selecting one available
|
* @parm current - shard where the chunk/database currently lives in
|
||||||
* @return the currently best known shard to put a chunk/database or EMPTY
|
* @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();
|
static void reloadShardInfo();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user