mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 00:56:44 +01:00
less thrashing when config changes
This commit is contained in:
parent
dd627743dd
commit
2aa64fb929
45
s/chunk.cpp
45
s/chunk.cpp
@ -504,11 +504,13 @@ namespace mongo {
|
||||
while (tries--) {
|
||||
ChunkMap chunkMap;
|
||||
set<Shard> shards;
|
||||
ShardVersionMap shardVersions;
|
||||
Timer t;
|
||||
_load(chunkMap, shards);
|
||||
_load(chunkMap, shards, shardVersions);
|
||||
{
|
||||
int ms = t.millis();
|
||||
log( ms < 100 ) << "time to load chunks for " << ns << ": " << ms << "ms" << endl;
|
||||
log() << "ChunkManager: time to load chunks for " << ns << ": " << ms << "ms"
|
||||
<< " sequenceNumber: " << _sequenceNumber << endl;
|
||||
}
|
||||
|
||||
if (_isValid(chunkMap)) {
|
||||
@ -517,6 +519,7 @@ namespace mongo {
|
||||
// to worry about that here.
|
||||
const_cast<ChunkMap&>(_chunkMap).swap(chunkMap);
|
||||
const_cast<set<Shard>&>(_shards).swap(shards);
|
||||
const_cast<ShardVersionMap&>(_shardVersions).swap(shardVersions);
|
||||
const_cast<ChunkRangeManager&>(_chunkRanges).reloadAll(_chunkMap);
|
||||
return;
|
||||
}
|
||||
@ -538,7 +541,7 @@ namespace mongo {
|
||||
return grid.getDBConfig(getns())->getChunkManager(getns(), force);
|
||||
}
|
||||
|
||||
void ChunkManager::_load(ChunkMap& chunkMap, set<Shard>& shards) const {
|
||||
void ChunkManager::_load(ChunkMap& chunkMap, set<Shard>& shards, ShardVersionMap& shardVersions) {
|
||||
ScopedDbConnection conn( configServer.modelServer() );
|
||||
|
||||
// TODO really need the sort?
|
||||
@ -555,7 +558,16 @@ namespace mongo {
|
||||
|
||||
chunkMap[c->getMax()] = c;
|
||||
shards.insert(c->getShard());
|
||||
|
||||
|
||||
// set global max
|
||||
if ( c->getLastmod() > _version )
|
||||
_version = c->getLastmod();
|
||||
|
||||
// set shard max
|
||||
ShardChunkVersion& shardMax = shardVersions[c->getShard()];
|
||||
if ( c->getLastmod() > shardMax )
|
||||
shardMax = c->getLastmod();
|
||||
}
|
||||
conn.done();
|
||||
}
|
||||
@ -841,31 +853,14 @@ namespace mongo {
|
||||
}
|
||||
|
||||
ShardChunkVersion ChunkManager::getVersion( const Shard& shard ) const {
|
||||
// TODO: cache or something?
|
||||
|
||||
ShardChunkVersion max = 0;
|
||||
|
||||
for ( ChunkMap::const_iterator i=_chunkMap.begin(); i!=_chunkMap.end(); ++i ) {
|
||||
ChunkPtr c = i->second;
|
||||
DEV assert( c );
|
||||
if ( c->getShard() != shard )
|
||||
continue;
|
||||
if ( c->getLastmod() > max )
|
||||
max = c->getLastmod();
|
||||
}
|
||||
return max;
|
||||
ShardVersionMap::const_iterator i = _shardVersions.find( shard );
|
||||
if ( i == _shardVersions.end() )
|
||||
return 0;
|
||||
return i->second;
|
||||
}
|
||||
|
||||
ShardChunkVersion ChunkManager::getVersion() const {
|
||||
ShardChunkVersion max = 0;
|
||||
|
||||
for ( ChunkMap::const_iterator i=_chunkMap.begin(); i!=_chunkMap.end(); ++i ) {
|
||||
ChunkPtr c = i->second;
|
||||
if ( c->getLastmod() > max )
|
||||
max = c->getLastmod();
|
||||
}
|
||||
|
||||
return max;
|
||||
return _version;
|
||||
}
|
||||
|
||||
string ChunkManager::toString() const {
|
||||
|
@ -283,6 +283,7 @@ namespace mongo {
|
||||
*/
|
||||
class ChunkManager {
|
||||
public:
|
||||
typedef map<Shard,ShardChunkVersion> ShardVersionMap;
|
||||
|
||||
ChunkManager( string ns , ShardKeyPattern pattern , bool unique );
|
||||
|
||||
@ -332,7 +333,7 @@ namespace mongo {
|
||||
ChunkManagerPtr reload(bool force=true) const; // doesn't modify self!
|
||||
|
||||
// helpers for constructor
|
||||
void _load(ChunkMap& chunks, set<Shard>& shards) const;
|
||||
void _load(ChunkMap& chunks, set<Shard>& shards, ShardVersionMap& shardVersions);
|
||||
static bool _isValid(const ChunkMap& chunks);
|
||||
|
||||
// All members should be const for thread-safety
|
||||
@ -345,6 +346,10 @@ namespace mongo {
|
||||
|
||||
const set<Shard> _shards;
|
||||
|
||||
const ShardVersionMap _shardVersions; // max version per shard
|
||||
|
||||
ShardChunkVersion _version; // max version of any chunk
|
||||
|
||||
mutable mutex _mutex; // only used with _nsLock
|
||||
mutable DistributedLock _nsLock;
|
||||
|
||||
|
@ -226,7 +226,12 @@ namespace mongo {
|
||||
CollectionInfo& ci = _collections[ns];
|
||||
massert( 14822 , (string)"state changed in the middle: " + ns , ci.isSharded() || ci.wasDropped() );
|
||||
|
||||
ci.resetCM( temp.release() );
|
||||
if ( temp->getVersion() > ci.getCM()->getVersion() ) {
|
||||
// we only want to reset if we're newer
|
||||
// otherwise we go into a bad cycle
|
||||
ci.resetCM( temp.release() );
|
||||
}
|
||||
|
||||
return ci.getCM();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user