summaryrefslogtreecommitdiff
path: root/s
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2011-05-06 17:12:21 -0400
committerMathias Stearn <mathias@10gen.com>2011-05-06 19:01:04 -0400
commit24cd932f3ef29ad38c0c45b9076652e8f707df13 (patch)
tree752821cb9aef1dd629072dd7f0cbd50cc26ab467 /s
parent0ca805953972134c6710f7df1ee8629aa2788e2b (diff)
downloadmongo-24cd932f3ef29ad38c0c45b9076652e8f707df13.tar.gz
Make ChunkManager::_load and _isValid use passed-in maps
Diffstat (limited to 's')
-rw-r--r--s/chunk.cpp27
-rw-r--r--s/chunk.h6
2 files changed, 17 insertions, 16 deletions
diff --git a/s/chunk.cpp b/s/chunk.cpp
index e8352ab3d54..95a1b82f601 100644
--- a/s/chunk.cpp
+++ b/s/chunk.cpp
@@ -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())) {
diff --git a/s/chunk.h b/s/chunk.h
index b9f13f612c9..f16c3c20c36 100644
--- a/s/chunk.h
+++ b/s/chunk.h
@@ -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