diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-06-15 10:44:14 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-06-16 13:45:57 -0400 |
commit | 34a05c0a54382012b1d41ce64f6256a6933c9004 (patch) | |
tree | 6698f3a9f672f23d75765b1b6c3d33494d6a160a /src/mongo/s/client | |
parent | 8c877b35e44e15fe2ccaf564103571a7bef728bc (diff) | |
download | mongo-34a05c0a54382012b1d41ce64f6256a6933c9004.tar.gz |
SERVER-18947 Add task executor to RS catalog manager tests
This change introduces dependency on the replica set executor and mock
network to the catalog manager replica set tests fixture.
It also implements the CatalogManager::getCollection method.
Diffstat (limited to 'src/mongo/s/client')
-rw-r--r-- | src/mongo/s/client/shard_registry.cpp | 22 | ||||
-rw-r--r-- | src/mongo/s/client/shard_registry.h | 22 |
2 files changed, 28 insertions, 16 deletions
diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp index ccb95f9e65b..4d6b0ebd89e 100644 --- a/src/mongo/s/client/shard_registry.cpp +++ b/src/mongo/s/client/shard_registry.cpp @@ -86,7 +86,7 @@ namespace mongo { LOG(1) << "found " << numShards << " shards listed on config server(s)"; - boost::lock_guard<boost::mutex> lk(_mutex); + std::lock_guard<std::mutex> lk(_mutex); _lookup.clear(); _targeters.clear(); @@ -123,9 +123,9 @@ namespace mongo { return _findUsingLookUp(id); } - shared_ptr<Shard> ShardRegistry::lookupRSName(const string& name) { - boost::lock_guard<boost::mutex> lk(_mutex); - ShardMap::iterator i = _rsLookup.find(name); + shared_ptr<Shard> ShardRegistry::lookupRSName(const string& name) const { + std::lock_guard<std::mutex> lk(_mutex); + ShardMap::const_iterator i = _rsLookup.find(name); return (i == _rsLookup.end()) ? nullptr : i->second; } @@ -133,12 +133,12 @@ namespace mongo { void ShardRegistry::set(const ShardId& id, const Shard& s) { shared_ptr<Shard> ss(std::make_shared<Shard>(s.getId(), s.getConnString())); - boost::lock_guard<boost::mutex> lk(_mutex); + std::lock_guard<std::mutex> lk(_mutex); _lookup[id] = ss; } void ShardRegistry::remove(const ShardId& id) { - boost::lock_guard<boost::mutex> lk(_mutex); + std::lock_guard<std::mutex> lk(_mutex); for (ShardMap::iterator i = _lookup.begin(); i != _lookup.end();) { shared_ptr<Shard> s = i->second; @@ -165,7 +165,7 @@ namespace mongo { std::set<string> seen; { - boost::lock_guard<boost::mutex> lk(_mutex); + std::lock_guard<std::mutex> lk(_mutex); for (ShardMap::const_iterator i = _lookup.begin(); i != _lookup.end(); ++i) { const shared_ptr<Shard>& s = i->second; if (s->getId() == "config") { @@ -182,10 +182,10 @@ namespace mongo { all->assign(seen.begin(), seen.end()); } - void ShardRegistry::toBSON(BSONObjBuilder* result) const { + void ShardRegistry::toBSON(BSONObjBuilder* result) { BSONObjBuilder b(_lookup.size() + 50); - boost::lock_guard<boost::mutex> lk(_mutex); + std::lock_guard<std::mutex> lk(_mutex); for (ShardMap::const_iterator i = _lookup.begin(); i != _lookup.end(); ++i) { b.append(i->first, i->second->getConnString().toString()); @@ -241,7 +241,7 @@ namespace mongo { } shared_ptr<Shard> ShardRegistry::_findUsingLookUp(const ShardId& shardId) { - boost::lock_guard<boost::mutex> lk(_mutex); + std::lock_guard<std::mutex> lk(_mutex); ShardMap::iterator it = _lookup.find(shardId); if (it != _lookup.end()) { return it->second; @@ -251,7 +251,7 @@ namespace mongo { } std::shared_ptr<RemoteCommandTargeter> ShardRegistry::_findTargeter(const string& shardId) { - boost::lock_guard<boost::mutex> lk(_mutex); + std::lock_guard<std::mutex> lk(_mutex); TargeterMap::iterator it = _targeters.find(shardId); if (it != _targeters.end()) { diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h index 9eeca1e972c..ab7aa7578e6 100644 --- a/src/mongo/s/client/shard_registry.h +++ b/src/mongo/s/client/shard_registry.h @@ -28,7 +28,8 @@ #pragma once -#include <boost/thread/mutex.hpp> +#include <memory> +#include <mutex> #include <string> #include <vector> @@ -45,14 +46,25 @@ namespace mongo { class ShardType; namespace executor { + class TaskExecutor; + } // namespace executor /** - * Maintains the set of all shards known to the MongoS instance. + * Maintains the set of all shards known to the instance and their connections. Manages polling + * the respective replica sets for membership changes. */ class ShardRegistry { public: + /** + * Instantiates a new shard registry. + * + * @param targeterFactory Produces targeters for each shard's individual connection string + * @param commandRunner Command runner for executing commands against hosts + * @param executor Asynchronous task executor to use for making calls to shards. + * @param catalogManager Used to retrieve the list of registered shard. TODO: remove. + */ ShardRegistry(std::unique_ptr<RemoteCommandTargeterFactory> targeterFactory, std::unique_ptr<RemoteCommandRunner> commandRunner, std::unique_ptr<executor::TaskExecutor> executor, @@ -75,7 +87,7 @@ namespace executor { * Note: this doesn't refresh the table if the name isn't found, so it's possible that a * newly added shard/Replica Set may not be found. */ - ShardPtr lookupRSName(const std::string& name); + std::shared_ptr<Shard> lookupRSName(const std::string& name) const; void set(const ShardId& id, const Shard& s); @@ -83,7 +95,7 @@ namespace executor { void getAllShardIds(std::vector<ShardId>* all) const; - void toBSON(BSONObjBuilder* result) const; + void toBSON(BSONObjBuilder* result); private: typedef std::map<ShardId, std::shared_ptr<Shard>> ShardMap; @@ -113,7 +125,7 @@ namespace executor { CatalogManager* const _catalogManager; // Protects the maps below - mutable boost::mutex _mutex; + mutable std::mutex _mutex; // Map of both shardName -> Shard and hostName -> Shard ShardMap _lookup; |