summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2017-03-23 13:55:22 -0400
committerBenety Goh <benety@mongodb.com>2017-03-24 14:38:53 -0400
commit9bc30836f60a888c44de09c55a45c278b215a02b (patch)
tree4561ff132059ca2c3fde2b1e4917c381c4081ce6
parentf54e89fa124ef679e25ca37b3bcf8e02572f38fd (diff)
downloadmongo-9bc30836f60a888c44de09c55a45c278b215a02b.tar.gz
SERVER-27834 FeatureCompatibilityVersion creates the admin.system.version collection if missing.
This avoids relying on the implicit collection behavior in IndexBuilder.
-rw-r--r--src/mongo/db/commands/feature_compatibility_version.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp
index e636c8f9987..4e9ed583696 100644
--- a/src/mongo/db/commands/feature_compatibility_version.cpp
+++ b/src/mongo/db/commands/feature_compatibility_version.cpp
@@ -220,6 +220,13 @@ void FeatureCompatibilityVersion::set(OperationContext* opCtx, StringData versio
repl::ReplicationCoordinator::get(opCtx->getServiceContext())
->canAcceptWritesFor(opCtx, nss));
+ // If the "admin.system.version" collection has not been created yet, explicitly create
+ // it to hold the v=2 index.
+ if (!autoDB.getDb()->getCollection(nss)) {
+ uassertStatusOK(
+ repl::StorageInterface::get(opCtx)->createCollection(opCtx, nss, {}));
+ }
+
IndexBuilder builder(k32IncompatibleIndexSpec, false);
auto status = builder.buildInForeground(opCtx, autoDB.getDb());
uassertStatusOK(status);
@@ -304,6 +311,12 @@ void FeatureCompatibilityVersion::setIfCleanStartup(OperationContext* opCtx,
{
AutoGetOrCreateDb autoDB(opCtx, nss.db(), MODE_X);
+ // We reached this point because the only database that exists on the server is "local"
+ // and we have just created an empty "admin" database.
+ // Therefore, it is safe to create the "admin.system.version" collection.
+ invariant(autoDB.justCreated());
+ uassertStatusOK(storageInterface->createCollection(opCtx, nss, {}));
+
IndexBuilder builder(k32IncompatibleIndexSpec, false);
auto status = builder.buildInForeground(opCtx, autoDB.getDb());
uassertStatusOK(status);