summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/drop_indexes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/commands/drop_indexes.cpp')
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index c7b1af95ef2..04f31e0d99f 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -145,15 +145,16 @@ public:
<< toReIndexNss << "' while replication is active");
}
- AutoGetCollection collection(opCtx, toReIndexNss, MODE_X);
- if (!collection) {
- auto db = collection.getDb();
+ AutoGetCollection autoColl(opCtx, toReIndexNss, MODE_X);
+ if (!autoColl) {
+ auto db = autoColl.getDb();
if (db && ViewCatalog::get(db)->lookup(opCtx, toReIndexNss.ns()))
uasserted(ErrorCodes::CommandNotSupportedOnView, "can't re-index a view");
else
uasserted(ErrorCodes::NamespaceNotFound, "collection does not exist");
}
+ CollectionWriter collection(autoColl, CollectionCatalog::LifetimeMode::kUnmanagedClone);
IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection(
collection->uuid());
@@ -216,21 +217,19 @@ public:
indexer->setIndexBuildMethod(IndexBuildMethod::kForeground);
StatusWith<std::vector<BSONObj>> swIndexesToRebuild(ErrorCodes::UnknownError,
"Uninitialized");
-
writeConflictRetry(opCtx, "dropAllIndexes", toReIndexNss.ns(), [&] {
WriteUnitOfWork wunit(opCtx);
collection.getWritableCollection()->getIndexCatalog()->dropAllIndexes(opCtx, true);
- swIndexesToRebuild = indexer->init(
- opCtx, collection.getWritableCollection(), all, MultiIndexBlock::kNoopOnInitFn);
+ swIndexesToRebuild =
+ indexer->init(opCtx, collection, all, MultiIndexBlock::kNoopOnInitFn);
uassertStatusOK(swIndexesToRebuild.getStatus());
wunit.commit();
});
// The 'indexer' can throw, so ensure build cleanup occurs.
auto abortOnExit = makeGuard([&] {
- indexer->abortIndexBuild(
- opCtx, collection.getWritableCollection(), MultiIndexBlock::kNoopOnCleanUpFn);
+ indexer->abortIndexBuild(opCtx, collection, MultiIndexBlock::kNoopOnCleanUpFn);
});
if (MONGO_unlikely(reIndexCrashAfterDrop.shouldFail())) {
@@ -240,8 +239,7 @@ public:
// The following function performs its own WriteConflict handling, so don't wrap it in a
// writeConflictRetry loop.
- uassertStatusOK(
- indexer->insertAllDocumentsInCollection(opCtx, collection.getWritableCollection()));
+ uassertStatusOK(indexer->insertAllDocumentsInCollection(opCtx, collection.get()));
uassertStatusOK(indexer->checkConstraints(opCtx));
@@ -261,6 +259,7 @@ public:
// snapshot so are unable to be used.
auto clusterTime = LogicalClock::getClusterTimeForReplicaSet(opCtx).asTimestamp();
collection.getWritableCollection()->setMinimumVisibleSnapshot(clusterTime);
+ collection.commitToCatalog();
result.append("nIndexes", static_cast<int>(swIndexesToRebuild.getValue().size()));
result.append("indexes", swIndexesToRebuild.getValue());