From 33b7eb758b5cff2e35ee21e639e3bd7166d94e7b Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Wed, 4 Aug 2010 10:11:49 -0400 Subject: [PATCH] when access namespace for the first time, prep all connections SERVER-1560 --- s/shardconnection.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/s/shardconnection.cpp b/s/shardconnection.cpp index 6c4bb1fe02a..5d89b51729d 100644 --- a/s/shardconnection.cpp +++ b/s/shardconnection.cpp @@ -26,6 +26,7 @@ namespace mongo { /** * holds all the actual db connections for a client to various servers + * 1 pre thread, so don't have to worry about thread safety */ class ClientConnections : boost::noncopyable { public: @@ -70,7 +71,8 @@ namespace mongo { _hosts.clear(); } - DBClientBase * get( const string& addr ){ + DBClientBase * get( const string& addr , const string& ns ){ + _check( ns ); scoped_lock lk( _mutex ); Status* &s = _hosts[addr]; if ( ! s ) @@ -152,9 +154,16 @@ namespace mongo { } } + void _check( const string& ns ){ + if ( ns.size() == 0 || _seenNS.count( ns ) ) + return; + _seenNS.insert( ns ); + checkVersions( ns ); + } + map _hosts; mongo::mutex _mutex; - + set _seenNS; // ----- static thread_specific_ptr _perThread; @@ -188,7 +197,7 @@ namespace mongo { void ShardConnection::_init(){ assert( _addr.size() ); - _conn = ClientConnections::get()->get( _addr ); + _conn = ClientConnections::get()->get( _addr , _ns ); _finishedInit = false; }