diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-08-04 13:28:11 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-08-04 13:28:11 -0400 |
commit | c8f11dff74ca5f9dc02c142ab31be84bf48566e9 (patch) | |
tree | 774e22c612eb3b6702e80babb5008501f0936047 | |
parent | b7462314c472a16d11684084144b05ddff313146 (diff) | |
download | mongo-c8f11dff74ca5f9dc02c142ab31be84bf48566e9.tar.gz |
clean up chunk version handling - prep for SERVER-1473
-rw-r--r-- | s/chunk.cpp | 16 | ||||
-rw-r--r-- | s/chunk.h | 4 | ||||
-rw-r--r-- | s/d_migrate.cpp | 5 | ||||
-rw-r--r-- | s/util.h | 17 |
4 files changed, 27 insertions, 15 deletions
diff --git a/s/chunk.cpp b/s/chunk.cpp index 5df3b6903ba..50d4e7647a3 100644 --- a/s/chunk.cpp +++ b/s/chunk.cpp @@ -265,7 +265,7 @@ namespace mongo { } // Save the new key boundaries in the configDB. - _manager->save(); + _manager->save( false ); // Log all these changes in the configDB's log. We log a simple split differently than a multi-split. if ( newChunks.size() == 1) { @@ -584,7 +584,7 @@ namespace mongo { _shards.insert(c->getShard()); - save_inlock(); + save_inlock( true ); log() << "no chunks for:" << ns << " so creating first: " << c->toString() << endl; } } @@ -880,16 +880,18 @@ namespace mongo { configServer.logChange( "dropCollection" , _ns , BSONObj() ); } - void ChunkManager::save(){ + void ChunkManager::save( bool major ){ rwlock lk( _lock , true ); - save_inlock(); + save_inlock( major ); } - void ChunkManager::save_inlock(){ + void ChunkManager::save_inlock( bool major ){ ShardChunkVersion a = getVersion_inlock(); assert( a > 0 || _chunkMap.size() <= 1 ); - ShardChunkVersion nextChunkVersion = a.incMajor(); + ShardChunkVersion nextChunkVersion = a; + nextChunkVersion.inc( major ); + vector<ChunkPtr> toFix; vector<ShardChunkVersion> newVersions; @@ -907,7 +909,7 @@ namespace mongo { _sequenceNumber = ++NextSequenceNumber; ShardChunkVersion myVersion = nextChunkVersion; - ++nextChunkVersion; + nextChunkVersion.incMinor(); toFix.push_back( c ); newVersions.push_back( myVersion ); diff --git a/s/chunk.h b/s/chunk.h index 2ec43a647b9..b81b7887543 100644 --- a/s/chunk.h +++ b/s/chunk.h @@ -269,7 +269,7 @@ namespace mongo { void getAllShards( set<Shard>& all ); void getShardsForRange(set<Shard>& shards, const BSONObj& min, const BSONObj& max); // [min, max) - void save(); + void save( bool major ); string toString() const; @@ -307,7 +307,7 @@ namespace mongo { void _reload_inlock(); void _load(); - void save_inlock(); + void save_inlock( bool major ); ShardChunkVersion getVersion_inlock() const; void ensureIndex_inlock(); diff --git a/s/d_migrate.cpp b/s/d_migrate.cpp index 84d70c57675..cad127b22cb 100644 --- a/s/d_migrate.cpp +++ b/s/d_migrate.cpp @@ -544,7 +544,7 @@ namespace mongo { // 5.a migrateFromStatus._inCriticalSection = true; ShardChunkVersion myVersion = maxVersion; - ++myVersion; + myVersion.incMajor(); { dblock lk; @@ -587,7 +587,8 @@ namespace mongo { if ( ! x.isEmpty() ){ BSONObjBuilder temp2; - ++myVersion; + myVersion.incMinor(); + temp2.appendTimestamp( "lastmod" , myVersion ); shardingState.setVersion( ns , myVersion ); @@ -58,11 +58,19 @@ namespace mongo { } } - ShardChunkVersion incMajor() const { - return ShardChunkVersion( _major + 1 , 0 ); + void inc( bool major ){ + if ( major ) + incMajor(); + else + incMinor(); } - void operator++(){ + void incMajor() { + _major++; + _minor = 0; + } + + void incMinor() { _minor++; } @@ -79,8 +87,9 @@ namespace mongo { ss << _major << "|" << _minor; return ss.str(); } + operator unsigned long long() const { return _combined; } - + ShardChunkVersion& operator=( const BSONElement& elem ){ switch ( elem.type() ){ case Timestamp: |