Permalink
Browse files

hit config server only once when loading a chunk meta data certain ve…

…rsion SERVER-4396
  • Loading branch information...
erh committed Nov 30, 2011
1 parent bd43859 commit d99fcfeb751c1019abc0654fa5e863aae3c76bcd
Showing with 32 additions and 8 deletions.
  1. +29 −7 s/config.cpp
  2. +3 −1 s/config.h
View
@@ -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 );
View
@@ -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 {

0 comments on commit d99fcfe

Please sign in to comment.