summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/drop_indexes.cpp
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2020-08-31 15:39:53 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-15 14:28:38 +0000
commitaccc7e7cd7e7a984347361d03ee76514c4a54163 (patch)
treed01b140af8d8609d19ed1b5f5126511bc06377e3 /src/mongo/db/commands/drop_indexes.cpp
parentb3f2165c7cf7d2e4d098f86eaf8bfa3b87b683a1 (diff)
downloadmongo-accc7e7cd7e7a984347361d03ee76514c4a54163.tar.gz
SERVER-50349 Getting a writable collection now requires the caller to be inside a WUOW by default
There are three modes when accessing a writable Collection: * Managed in WUOW (default) * Unmanaged (users need to commit/rollback) * Inplace that provides direct access to the Collection in the catalog. (Users need to ensure there's no concurrent operations going on) Added a helper RAII type CollectionWriter that abstract the three modes above and also provides abstraction on different methods of accessing Collections (AutoGetCollection or manual lookups). Writable Collection is aquired lazily when needed (usually inside a WUOW).
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());