diff options
Diffstat (limited to 'src/mongo/s/catalog/legacy/catalog_manager_legacy.h')
-rw-r--r-- | src/mongo/s/catalog/legacy/catalog_manager_legacy.h | 245 |
1 files changed, 121 insertions, 124 deletions
diff --git a/src/mongo/s/catalog/legacy/catalog_manager_legacy.h b/src/mongo/s/catalog/legacy/catalog_manager_legacy.h index aff0ce6d185..5a762a1aebc 100644 --- a/src/mongo/s/catalog/legacy/catalog_manager_legacy.h +++ b/src/mongo/s/catalog/legacy/catalog_manager_legacy.h @@ -39,173 +39,170 @@ namespace mongo { +/** + * Implements the catalog manager using the legacy 3-config server protocol. + */ +class CatalogManagerLegacy final : public CatalogManager { +public: + CatalogManagerLegacy(); + ~CatalogManagerLegacy(); + /** - * Implements the catalog manager using the legacy 3-config server protocol. + * Initializes the catalog manager with the hosts, which will be used as a configuration + * server. Can only be called once for the lifetime. */ - class CatalogManagerLegacy final : public CatalogManager { - public: - CatalogManagerLegacy(); - ~CatalogManagerLegacy(); + Status init(const ConnectionString& configCS); - /** - * Initializes the catalog manager with the hosts, which will be used as a configuration - * server. Can only be called once for the lifetime. - */ - Status init(const ConnectionString& configCS); + Status startup(bool upgrade) override; - Status startup(bool upgrade) override; + ConnectionString connectionString() const override; - ConnectionString connectionString() const override; + void shutDown() override; - void shutDown() override; + Status enableSharding(const std::string& dbName) override; - Status enableSharding(const std::string& dbName) override; + Status shardCollection(const std::string& ns, + const ShardKeyPattern& fieldsAndOrder, + bool unique, + std::vector<BSONObj>* initPoints, + std::set<ShardId>* initShardIds) override; - Status shardCollection(const std::string& ns, - const ShardKeyPattern& fieldsAndOrder, - bool unique, - std::vector<BSONObj>* initPoints, - std::set<ShardId>* initShardIds) override; + StatusWith<std::string> addShard(const std::string& name, + const ConnectionString& shardConnectionString, + const long long maxSize) override; - StatusWith<std::string> addShard(const std::string& name, - const ConnectionString& shardConnectionString, - const long long maxSize) override; + StatusWith<ShardDrainingStatus> removeShard(OperationContext* txn, + const std::string& name) override; - StatusWith<ShardDrainingStatus> removeShard(OperationContext* txn, - const std::string& name) override; + Status createDatabase(const std::string& dbName) override; - Status createDatabase(const std::string& dbName) override; + Status updateDatabase(const std::string& dbName, const DatabaseType& db) override; - Status updateDatabase(const std::string& dbName, const DatabaseType& db) override; + StatusWith<DatabaseType> getDatabase(const std::string& dbName) override; - StatusWith<DatabaseType> getDatabase(const std::string& dbName) override; + Status updateCollection(const std::string& collNs, const CollectionType& coll) override; - Status updateCollection(const std::string& collNs, const CollectionType& coll) override; + StatusWith<CollectionType> getCollection(const std::string& collNs) override; - StatusWith<CollectionType> getCollection(const std::string& collNs) override; + Status getCollections(const std::string* dbName, std::vector<CollectionType>* collections); - Status getCollections(const std::string* dbName, std::vector<CollectionType>* collections); + Status dropCollection(const std::string& collectionNs); - Status dropCollection(const std::string& collectionNs); + Status getDatabasesForShard(const std::string& shardName, + std::vector<std::string>* dbs) override; - Status getDatabasesForShard(const std::string& shardName, - std::vector<std::string>* dbs) override; + Status getChunks(const Query& query, int nToReturn, std::vector<ChunkType>* chunks) override; - Status getChunks(const Query& query, - int nToReturn, - std::vector<ChunkType>* chunks) override; + Status getTagsForCollection(const std::string& collectionNs, + std::vector<TagsType>* tags) override; - Status getTagsForCollection(const std::string& collectionNs, - std::vector<TagsType>* tags) override; + StatusWith<std::string> getTagForChunk(const std::string& collectionNs, + const ChunkType& chunk) override; - StatusWith<std::string> getTagForChunk(const std::string& collectionNs, - const ChunkType& chunk) override; + Status getAllShards(std::vector<ShardType>* shards) override; - Status getAllShards(std::vector<ShardType>* shards) override; + bool isShardHost(const ConnectionString& shardConnectionString) override; - bool isShardHost(const ConnectionString& shardConnectionString) override; - - /** - * Grabs a distributed lock and runs the command on all config servers. - */ - bool runUserManagementWriteCommand(const std::string& commandName, - const std::string& dbname, - const BSONObj& cmdObj, - BSONObjBuilder* result) override; + /** + * Grabs a distributed lock and runs the command on all config servers. + */ + bool runUserManagementWriteCommand(const std::string& commandName, + const std::string& dbname, + const BSONObj& cmdObj, + BSONObjBuilder* result) override; - bool runUserManagementReadCommand(const std::string& dbname, - const BSONObj& cmdObj, - BSONObjBuilder* result) override; + bool runUserManagementReadCommand(const std::string& dbname, + const BSONObj& cmdObj, + BSONObjBuilder* result) override; - Status applyChunkOpsDeprecated(const BSONArray& updateOps, - const BSONArray& preCondition) override; + Status applyChunkOpsDeprecated(const BSONArray& updateOps, + const BSONArray& preCondition) override; - void logAction(const ActionLogType& actionLog); + void logAction(const ActionLogType& actionLog); - void logChange(OperationContext* txn, - const std::string& what, - const std::string& ns, - const BSONObj& detail) override; + void logChange(OperationContext* txn, + const std::string& what, + const std::string& ns, + const BSONObj& detail) override; - StatusWith<SettingsType> getGlobalSettings(const std::string& key) override; + StatusWith<SettingsType> getGlobalSettings(const std::string& key) override; - void writeConfigServerDirect(const BatchedCommandRequest& request, - BatchedCommandResponse* response) override; + void writeConfigServerDirect(const BatchedCommandRequest& request, + BatchedCommandResponse* response) override; - DistLockManager* getDistLockManager() override; + DistLockManager* getDistLockManager() override; - private: +private: + /** + * Updates the config server's metadata to the current version. + */ + Status _checkAndUpgradeConfigMetadata(bool doUpgrade); - /** - * Updates the config server's metadata to the current version. - */ - Status _checkAndUpgradeConfigMetadata(bool doUpgrade); + /** + * Starts the thread that periodically checks data consistency amongst the config servers. + * Note: this is not thread safe and can only be called once for the lifetime. + */ + Status _startConfigServerChecker(); - /** - * Starts the thread that periodically checks data consistency amongst the config servers. - * Note: this is not thread safe and can only be called once for the lifetime. - */ - Status _startConfigServerChecker(); + /** + * Direct network check to see if a particular database does not already exist with the + * same name or different case. + */ + Status _checkDbDoesNotExist(const std::string& dbName) const; - /** - * Direct network check to see if a particular database does not already exist with the - * same name or different case. - */ - Status _checkDbDoesNotExist(const std::string& dbName) const; + /** + * Generates a new shard name "shard<xxxx>" + * where <xxxx> is an autoincrementing value and <xxxx> < 10000 + */ + StatusWith<std::string> _getNewShardName() const; - /** - * Generates a new shard name "shard<xxxx>" - * where <xxxx> is an autoincrementing value and <xxxx> < 10000 - */ - StatusWith<std::string> _getNewShardName() const; + /** + * Returns the number of shards recognized by the config servers + * in this sharded cluster. + * Optional: use query parameter to filter shard count. + */ + size_t _getShardCount(const BSONObj& query = {}) const; - /** - * Returns the number of shards recognized by the config servers - * in this sharded cluster. - * Optional: use query parameter to filter shard count. - */ - size_t _getShardCount(const BSONObj& query = {}) const; + /** + * Returns true if all config servers have the same state. + * If inconsistency detected on first attempt, checks at most 3 more times. + */ + bool _checkConfigServersConsistent(const unsigned tries = 4) const; - /** - * Returns true if all config servers have the same state. - * If inconsistency detected on first attempt, checks at most 3 more times. - */ - bool _checkConfigServersConsistent(const unsigned tries = 4) const; + /** + * Checks data consistency amongst config servers every 60 seconds. + */ + void _consistencyChecker(); - /** - * Checks data consistency amongst config servers every 60 seconds. - */ - void _consistencyChecker(); + /** + * Returns true if the config servers have the same contents since the last + * check was performed. + */ + bool _isConsistentFromLastCheck(); - /** - * Returns true if the config servers have the same contents since the last - * check was performed. - */ - bool _isConsistentFromLastCheck(); + // Parsed config server hosts, as specified on the command line. + ConnectionString _configServerConnectionString; + std::vector<ConnectionString> _configServers; - // Parsed config server hosts, as specified on the command line. - ConnectionString _configServerConnectionString; - std::vector<ConnectionString> _configServers; + // Distribted lock manager singleton. + std::unique_ptr<DistLockManager> _distLockManager; - // Distribted lock manager singleton. - std::unique_ptr<DistLockManager> _distLockManager; + // protects _inShutdown, _consistentFromLastCheck; used by _consistencyCheckerCV + stdx::mutex _mutex; - // protects _inShutdown, _consistentFromLastCheck; used by _consistencyCheckerCV - stdx::mutex _mutex; + // True if CatalogManagerLegacy::shutDown has been called. False, otherwise. + bool _inShutdown = false; - // True if CatalogManagerLegacy::shutDown has been called. False, otherwise. - bool _inShutdown = false; + // used by consistency checker thread to check if config + // servers are consistent + bool _consistentFromLastCheck = false; - // used by consistency checker thread to check if config - // servers are consistent - bool _consistentFromLastCheck = false; + // Thread that runs dbHash on config servers for checking data consistency. + stdx::thread _consistencyCheckerThread; - // Thread that runs dbHash on config servers for checking data consistency. - stdx::thread _consistencyCheckerThread; + // condition variable used by the consistency checker thread to wait + // for <= 60s, on every iteration, until shutDown is called + stdx::condition_variable _consistencyCheckerCV; +}; - // condition variable used by the consistency checker thread to wait - // for <= 60s, on every iteration, until shutDown is called - stdx::condition_variable _consistencyCheckerCV; - }; - -} // namespace mongo +} // namespace mongo |