diff options
author | dwight <dwight@10gen.com> | 2010-07-16 10:16:45 -0400 |
---|---|---|
committer | dwight <dwight@10gen.com> | 2010-07-16 10:16:45 -0400 |
commit | 493ef0e11f5ff2ec201f02fa2614217da8ac5d42 (patch) | |
tree | 016285507e1397f38f82c938b49e7685c1cdda72 | |
parent | fc03c2290fe74e42aa81c5367329bfa173f7498c (diff) | |
parent | 2d8137ae8e9b9a015eca47d0799291e7835310e4 (diff) | |
download | mongo-493ef0e11f5ff2ec201f02fa2614217da8ac5d42.tar.gz |
Merge branch 'master' of github.com:mongodb/mongo
-rw-r--r-- | client/dbclient.cpp | 2 | ||||
-rw-r--r-- | jstests/slowNightly/sharding_balance4.js | 1 | ||||
-rw-r--r-- | s/chunk.cpp | 53 | ||||
-rw-r--r-- | s/chunk.h | 21 |
4 files changed, 67 insertions, 10 deletions
diff --git a/client/dbclient.cpp b/client/dbclient.cpp index 9acfd47c163..0b684006ac2 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -612,7 +612,7 @@ namespace mongo { queryOptions |= (int)QueryOption_Exhaust; } auto_ptr<DBClientCursor> c( this->query(ns, query, 0, 0, fieldsToReturn, queryOptions) ); - massert( 133082, "socket error for mapping query", c.get() ); + massert( 13386, "socket error for mapping query", c.get() ); if ( !doExhaust ) { while( c->more() ) { diff --git a/jstests/slowNightly/sharding_balance4.js b/jstests/slowNightly/sharding_balance4.js index 69f59de20c5..944ebbb656d 100644 --- a/jstests/slowNightly/sharding_balance4.js +++ b/jstests/slowNightly/sharding_balance4.js @@ -55,6 +55,7 @@ function check(){ for ( var x in counts ){ var e = counts[x]; var z = db.foo.findOne( { _id : parseInt( x ) } ) + assert( z , "couldn't find : " + x ) assert.eq( e , z.x , "count for : " + x ) } } diff --git a/s/chunk.cpp b/s/chunk.cpp index 0734aac74b4..cc0608ca19b 100644 --- a/s/chunk.cpp +++ b/s/chunk.cpp @@ -188,6 +188,18 @@ namespace mongo { dist_lock_try dlk( &lockSetup , string("split-") + toString() ); uassert( 10166 , "locking namespace failed" , dlk.got() ); + { + ShardChunkVersion onServer = getVersionOnConfigServer(); + ShardChunkVersion mine = _lastmod; + if ( onServer > mine ){ + stringstream ss; + ss << "mulitSplit failing because config not up to date" + << " onServer: " << onServer.toString() + << " mine: " << mine.toString(); + uasserted( 13387 , ss.str() ); + } + } + BSONObjBuilder detail; appendShortVersion( "before" , detail ); log(1) << "before split on " << m.size() << " points " << toString() << endl; @@ -298,6 +310,16 @@ namespace mongo { } bool Chunk::splitIfShould( long dataWritten ){ + try { + return _splitIfShould( dataWritten ); + } + catch ( std::exception& e ){ + log( LL_ERROR ) << "splitIfShould failed: " << e.what() << endl; + return false; + } + } + + bool Chunk::_splitIfShould( long dataWritten ){ _dataWritten += dataWritten; int myMax = MaxChunkSize; @@ -348,11 +370,11 @@ namespace mongo { toMove = shared_from_this(); } else { - log(1) << "don't know how to decide if i should move inner shard" << endl; + // moving middle shards is handled by balancer + return false; } - if ( ! toMove ) - return false; + assert( toMove ); Shard newLocation = Shard::pick(); if ( getShard() == newLocation ){ @@ -434,7 +456,7 @@ namespace mongo { to << "shard" << _shard.getName(); } - string Chunk::genID( const string& ns , const BSONObj& o ){ + string Chunk::genID( const string& ns , const BSONObj& o ) { StringBuilder buf( ns.size() + o.objsize() + 16 ); buf << ns << "-"; @@ -474,11 +496,18 @@ namespace mongo { uassert( 10173 , "Chunk needs a max" , ! _max.isEmpty() ); } - string Chunk::modelServer() { + string Chunk::modelServer() const { // TODO: this could move around? return configServer.modelServer(); } + ShardChunkVersion Chunk::getVersionOnConfigServer() const { + ScopedDbConnection conn( modelServer() ); + BSONObj o = conn->findOne( ShardNS::chunk , BSON( "_id" << genID() ) ); + conn.done(); + return o["lastmod"]; + } + void Chunk::_markModified(){ _modified = true; } @@ -893,6 +922,20 @@ namespace mongo { soleChunk->multiSplit( splitPoints ); } + ShardChunkVersion ChunkManager::getVersionOnConfigServer() const { + static Chunk temp(0); + + ScopedDbConnection conn( temp.modelServer() ); + + auto_ptr<DBClientCursor> cursor = conn->query(temp.getNS(), QUERY("ns" << _ns).sort("lastmod",1), 1 ); + BSONObj o; + if ( cursor->more() ) + o = cursor->next(); + conn.done(); + + return o["lastmod"]; + } + ShardChunkVersion ChunkManager::getVersion( const Shard& shard ) const{ rwlock lk( _lock , false ); // TODO: cache or something? diff --git a/s/chunk.h b/s/chunk.h index fba328b67f9..cb4650d8273 100644 --- a/s/chunk.h +++ b/s/chunk.h @@ -61,6 +61,9 @@ namespace mongo { if ( e.type() == Date || e.type() == Timestamp ){ _combined = e._numberLong(); } + else if ( e.eoo() ){ + _combined = 0; + } else { log() << "ShardChunkVersion can't handle type (" << (int)(e.type()) << ") " << e << endl; assert(0); @@ -192,7 +195,7 @@ namespace mongo { const char * getNS(){ return "config.chunks"; } void serialize(BSONObjBuilder& to, ShardChunkVersion myLastMod=0); void unserialize(const BSONObj& from); - string modelServer(); + string modelServer() const; void appendShortVersion( const char * name , BSONObjBuilder& b ); @@ -202,14 +205,18 @@ namespace mongo { static int MaxChunkSize; - string genID(); + string genID() const; static string genID( const string& ns , const BSONObj& min ); const ChunkManager* getManager() const { return _manager; } bool modified(); + + ShardChunkVersion getVersionOnConfigServer() const; private: - + + bool _splitIfShould( long dataWritten ); + // main shard info ChunkManager * _manager; @@ -349,6 +356,12 @@ namespace mongo { ShardChunkVersion getVersion( const Shard& shard ) const; ShardChunkVersion getVersion() const; + /** + * actually does a query on the server + * doesn't look at any local data + */ + ShardChunkVersion getVersionOnConfigServer() const; + /** * this is just an increasing number of how many ChunkManagers we have so we know if something has been updated */ @@ -431,6 +444,6 @@ namespace mongo { Chunk _c; }; */ - inline string Chunk::genID(){ return genID(_manager->getns(), _min); } + inline string Chunk::genID() const { return genID(_manager->getns(), _min); } } // namespace mongo |