diff options
author | Simon Graetzer <simon.gratzer@mongodb.com> | 2021-05-27 14:29:26 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-05-31 08:50:06 +0000 |
commit | a10eaa3cc0e78d4ab1cd2f57b61a1e5e9568e192 (patch) | |
tree | 590f573ec65f8b442021094ee5903916ffcb6f8c /src/mongo/db/s | |
parent | 41b2fe85d08b49eadbe4b79fcb02a2be0e753e38 (diff) | |
download | mongo-a10eaa3cc0e78d4ab1cd2f57b61a1e5e9568e192.tar.gz |
SERVER-57063 Ensure that config.collections exists upon configsvr startup
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager.cpp | 28 | ||||
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager.h | 5 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/mongo/db/s/config/sharding_catalog_manager.cpp b/src/mongo/db/s/config/sharding_catalog_manager.cpp index a13ddcdcabc..0272b7c82ce 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager.cpp @@ -370,7 +370,12 @@ Status ShardingCatalogManager::initializeConfigDatabaseIfNeeded(OperationContext } } - Status status = _initConfigIndexes(opCtx); + Status status = _initConfigCollections(opCtx); + if (!status.isOK()) { + return status; + } + + status = _initConfigIndexes(opCtx); if (!status.isOK()) { return status; } @@ -516,6 +521,27 @@ Status ShardingCatalogManager::_initConfigIndexes(OperationContext* opCtx) { return Status::OK(); } +/** + * Ensure that config.collections exists upon configsvr startup + */ +Status ShardingCatalogManager::_initConfigCollections(OperationContext* opCtx) { + // Ensure that config.collections exist so that snapshot reads on it don't fail with + // SnapshotUnavailable error when it is implicitly created (when sharding a + // collection for the first time) but not in yet in the committed snapshot). + DBDirectClient client(opCtx); + + BSONObj cmd = BSON("create" << CollectionType::ConfigNS.coll()); + BSONObj result; + const bool ok = client.runCommand(CollectionType::ConfigNS.db().toString(), cmd, result); + if (!ok) { // create returns error NamespaceExists if collection already exists + Status status = getStatusFromCommandResult(result); + if (status != ErrorCodes::NamespaceExists) { + return status.withContext("Could not create config.collections"); + } + } + return Status::OK(); +} + Status ShardingCatalogManager::setFeatureCompatibilityVersionOnShards(OperationContext* opCtx, const BSONObj& cmdObj) { diff --git a/src/mongo/db/s/config/sharding_catalog_manager.h b/src/mongo/db/s/config/sharding_catalog_manager.h index e8a7da2b356..4e7f4f1ef35 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager.h +++ b/src/mongo/db/s/config/sharding_catalog_manager.h @@ -467,6 +467,11 @@ private: Status _initConfigIndexes(OperationContext* opCtx); /** + * Ensure that config.collections exists upon configsvr startup + */ + Status _initConfigCollections(OperationContext* opCtx); + + /** * Used during addShard to determine if there is already an existing shard that matches the * shard that is currently being added. An OK return with boost::none indicates that there * is no conflicting shard, and we can proceed trying to add the new shard. An OK return |