diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-04-09 17:05:00 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-04-10 16:29:38 -0400 |
commit | 8e6804d268895c01678a1a3d2feb57a82cafec62 (patch) | |
tree | ae85091e56240546aae3c92160fef1f8d64fcc6b /src/mongo/s/version_manager.cpp | |
parent | cb236301e4016469c9b5c2802050e7bda08c33b9 (diff) | |
download | mongo-8e6804d268895c01678a1a3d2feb57a82cafec62.tar.gz |
SERVER-17723 Sharding catalog cache
This change builds a sharding catalog cache on top of the CatalogManager
abstraction and use this in place of the direct network calls to the
config server.
Diffstat (limited to 'src/mongo/s/version_manager.cpp')
-rw-r--r-- | src/mongo/s/version_manager.cpp | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/src/mongo/s/version_manager.cpp b/src/mongo/s/version_manager.cpp index 959efa92aeb..96f56dcad93 100644 --- a/src/mongo/s/version_manager.cpp +++ b/src/mongo/s/version_manager.cpp @@ -34,16 +34,21 @@ #include "mongo/s/version_manager.h" +#include <boost/shared_ptr.hpp> + +#include "mongo/db/namespace_string.h" +#include "mongo/s/catalog/catalog_cache.h" #include "mongo/s/chunk_manager.h" #include "mongo/s/chunk_version.h" #include "mongo/s/client/shard_connection.h" #include "mongo/s/config.h" #include "mongo/s/grid.h" -#include "mongo/s/stale_exception.h" // for SendStaleConfigException +#include "mongo/s/stale_exception.h" #include "mongo/util/log.h" namespace mongo { + using boost::shared_ptr; using std::endl; using std::map; using std::string; @@ -137,17 +142,28 @@ namespace mongo { return NULL; } - bool VersionManager::forceRemoteCheckShardVersionCB( const string& ns ){ + bool VersionManager::forceRemoteCheckShardVersionCB(const string& ns) { + const NamespaceString nss(ns); + + // This will force the database catalog entry to be reloaded + grid.catalogCache()->invalidate(nss.db().toString()); + + auto status = grid.catalogCache()->getDatabase(nss.db().toString()); + if (!status.isOK()) { + return false; + } - DBConfigPtr conf = grid.getDBConfig( ns ); - if ( ! conf ) return false; - conf->reload(); + shared_ptr<DBConfig> conf = status.getValue(); // If we don't have a collection, don't refresh the chunk manager - if( nsGetCollection( ns ).size() == 0 ) return false; + if (nsGetCollection(ns).size() == 0) { + return false; + } - ChunkManagerPtr manager = conf->getChunkManagerIfExists( ns, true, true ); - if( ! manager ) return false; + ChunkManagerPtr manager = conf->getChunkManagerIfExists(ns, true, true); + if (!manager) { + return false; + } return true; @@ -247,7 +263,12 @@ namespace mongo { * * @return true if we contacted the remote host */ - bool checkShardVersion( DBClientBase * conn_in , const string& ns , ChunkManagerPtr refManager, bool authoritative , int tryNumber ) { + bool checkShardVersion(DBClientBase* conn_in, + const string& ns, + ChunkManagerPtr refManager, + bool authoritative, + int tryNumber) { + // TODO: cache, optimize, etc... // Empty namespaces are special - we require initialization but not versioning @@ -255,9 +276,13 @@ namespace mongo { return initShardVersionEmptyNS(conn_in); } - DBConfigPtr conf = grid.getDBConfig( ns ); - if ( ! conf ) + const NamespaceString nss(ns); + auto status = grid.catalogCache()->getDatabase(nss.db().toString()); + if (!status.isOK()) { return false; + } + + shared_ptr<DBConfig> conf = status.getValue(); DBClientBase* conn = getVersionable( conn_in ); verify(conn); // errors thrown above |