Skip to content

Commit

Permalink
SERVER-27834 FeatureCompatibilityVersion creates the admin.system.ver…
Browse files Browse the repository at this point in the history
…sion collection if missing.

This avoids relying on the implicit collection behavior in IndexBuilder.
  • Loading branch information
benety committed Mar 24, 2017
1 parent f54e89f commit 9bc3083
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/mongo/db/commands/feature_compatibility_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9bc3083

Please sign in to comment.