diff options
author | Eliot Horowitz <eliot@10gen.com> | 2011-11-30 13:33:16 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2011-12-01 00:07:06 -0500 |
commit | d99fcfeb751c1019abc0654fa5e863aae3c76bcd (patch) | |
tree | a077df2ed876a423faddb19126cbe2e50d5d2db3 | |
parent | bd438596e1f9808663af9c476f0a08940b19df35 (diff) | |
download | mongo-d99fcfeb751c1019abc0654fa5e863aae3c76bcd.tar.gz |
hit config server only once when loading a chunk meta data certain version SERVER-4396
-rw-r--r-- | s/config.cpp | 36 | ||||
-rw-r--r-- | s/config.h | 4 |
2 files changed, 32 insertions, 8 deletions
diff --git a/s/config.cpp b/s/config.cpp index ad617a69d92..645e9236a43 100644 --- a/s/config.cpp +++ b/s/config.cpp @@ -214,10 +214,11 @@ namespace mongo { assert( ! key.isEmpty() ); + BSONObj newest; if ( oldVersion > 0 && ! forceReload ) { ScopedDbConnection conn( configServer.modelServer() , 30.0 ); - BSONObj newest = conn->findOne( ShardNS::chunk , - Query( BSON( "ns" << ns ) ).sort( "lastmod" , -1 ) ); + newest = conn->findOne( ShardNS::chunk , + Query( BSON( "ns" << ns ) ).sort( "lastmod" , -1 ) ); conn.done(); if ( ! newest.isEmpty() ) { @@ -238,11 +239,32 @@ namespace mongo { // we are not locked now, and want to load a new ChunkManager - auto_ptr<ChunkManager> temp( new ChunkManager( ns , key , unique ) ); - if ( temp->numChunks() == 0 ) { - // maybe we're not sharded any more - reload(); // this is a full reload - return getChunkManager( ns , false ); + auto_ptr<ChunkManager> temp; + + { + scoped_lock lll ( _hitConfigServerLock ); + + if ( ! newest.isEmpty() && ! forceReload ) { + // if we have a target we're going for + // see if we've hit already + + scoped_lock lk( _lock ); + CollectionInfo& ci = _collections[ns]; + if ( ci.isSharded() && ci.getCM() ) { + ShardChunkVersion currentVersion = newest["lastmod"]; + if ( currentVersion == ci.getCM()->getVersion() ) { + return ci.getCM(); + } + } + + } + + temp.reset( new ChunkManager( ns , key , unique ) ); + if ( temp->numChunks() == 0 ) { + // maybe we're not sharded any more + reload(); // this is a full reload + return getChunkManager( ns , false ); + } } scoped_lock lk( _lock ); diff --git a/s/config.h b/s/config.h index 3b7eb9570ba..0374bcb52be 100644 --- a/s/config.h +++ b/s/config.h @@ -115,7 +115,8 @@ namespace mongo { : _name( name ) , _primary("config","") , _shardingEnabled(false), - _lock("DBConfig") { + _lock("DBConfig") , + _hitConfigServerLock( "DBConfig::_hitConfigServerLock" ) { assert( name.size() ); } virtual ~DBConfig() {} @@ -195,6 +196,7 @@ namespace mongo { Collections _collections; mutable mongo::mutex _lock; // TODO: change to r/w lock ?? + mutable mongo::mutex _hitConfigServerLock; }; class ConfigServer : public DBConfig { |