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

Make ChunkManager::_load and _isValid use passed-in maps

This commit is contained in:
Mathias Stearn 2011-05-06 17:12:21 -04:00
parent 0ca8059539
commit 24cd932f3e
2 changed files with 17 additions and 16 deletions

View File

@ -486,12 +486,13 @@ namespace mongo {
{
int tries = 3;
while (tries--) {
_chunkMap.clear();
_chunkRanges.clear();
_shards.clear();
_load();
ChunkMap chunkMap;
set<Shard> shards;
_load(chunkMap, shards);
if (_isValid()) {
if (_isValid(chunkMap)) {
_chunkMap.swap(chunkMap);
_shards.swap(shards);
_chunkRanges.reloadAll(_chunkMap);
// The shard versioning mechanism hinges on keeping track of the number of times we reloaded ChunkManager's.
@ -523,7 +524,7 @@ namespace mongo {
return grid.getDBConfig(getns())->getChunkManager(getns(), force);
}
void ChunkManager::_load() {
void ChunkManager::_load(ChunkMap& chunkMap, set<Shard>& shards) const {
ScopedDbConnection conn( configServer.modelServer() );
// TODO really need the sort?
@ -538,25 +539,25 @@ namespace mongo {
ChunkPtr c( new Chunk( this, d ) );
_chunkMap[c->getMax()] = c;
_shards.insert(c->getShard());
chunkMap[c->getMax()] = c;
shards.insert(c->getShard());
}
conn.done();
}
bool ChunkManager::_isValid() const {
bool ChunkManager::_isValid(const ChunkMap& chunkMap) {
#define ENSURE(x) do { if(!(x)) { log() << "ChunkManager::_isValid failed: " #x << endl; return false; } } while(0)
if (_chunkMap.empty())
if (chunkMap.empty())
return true;
// Check endpoints
ENSURE(allOfType(MinKey, _chunkMap.begin()->second->getMin()));
ENSURE(allOfType(MaxKey, prior(_chunkMap.end())->second->getMax()));
ENSURE(allOfType(MinKey, chunkMap.begin()->second->getMin()));
ENSURE(allOfType(MaxKey, prior(chunkMap.end())->second->getMax()));
// Make sure there are no gaps or overlaps
for (ChunkMap::const_iterator it=boost::next(_chunkMap.begin()), end=_chunkMap.end(); it != end; ++it) {
for (ChunkMap::const_iterator it=boost::next(chunkMap.begin()), end=chunkMap.end(); it != end; ++it) {
ChunkMap::const_iterator last = prior(it);
if (!(it->second->getMin() == last->second->getMax())) {

View File

@ -332,7 +332,9 @@ namespace mongo {
private:
ChunkManagerPtr reload(bool force=true) const; // doesn't modify self!
void _load();
// helpers for constructor
void _load(ChunkMap& chunks, set<Shard>& shards) const;
static bool _isValid(const ChunkMap& chunks);
const string _ns;
const ShardKeyPattern _key;
@ -351,8 +353,6 @@ namespace mongo {
friend class Chunk;
friend class ChunkRangeManager; // only needed for CRM::assertValid()
static AtomicUInt NextSequenceNumber;
bool _isValid() const;
};
// like BSONObjCmp. for use as an STL comparison functor