summaryrefslogtreecommitdiff
path: root/src/mongo/db/repair.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/repair.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/repair.cpp')
-rw-r--r--src/mongo/db/repair.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/mongo/db/repair.cpp b/src/mongo/db/repair.cpp
index 0c06a70d3f9..1ef573f0b45 100644
--- a/src/mongo/db/repair.cpp
+++ b/src/mongo/db/repair.cpp
@@ -87,7 +87,7 @@ Status rebuildIndexesForNamespace(OperationContext* opCtx,
}
namespace {
-Status dropUnfinishedIndexes(OperationContext* opCtx, Collection* collection) {
+Status dropUnfinishedIndexes(OperationContext* opCtx, const Collection* collection) {
std::vector<std::string> indexNames;
auto durableCatalog = DurableCatalog::get(opCtx);
durableCatalog->getAllIndexes(opCtx, collection->getCatalogId(), &indexNames);
@@ -173,7 +173,8 @@ Status repairDatabase(OperationContext* opCtx, StorageEngine* engine, const std:
auto clusterTime = LogicalClock::getClusterTimeForReplicaSet(opCtx).asTimestamp();
for (auto collIt = db->begin(opCtx); collIt != db->end(opCtx); ++collIt) {
- auto collection = *collIt;
+ auto collection =
+ collIt.getWritableCollection(opCtx, CollectionCatalog::LifetimeMode::kInplace);
if (collection) {
collection->setMinimumVisibleSnapshot(clusterTime);
}
@@ -201,14 +202,17 @@ Status repairCollection(OperationContext* opCtx,
LOGV2(21027, "Repairing collection", "namespace"_attr = nss);
- auto collection =
- CollectionCatalog::get(opCtx).lookupCollectionByNamespaceForMetadataWrite(opCtx, nss);
- Status status = engine->repairRecordStore(opCtx, collection->getCatalogId(), nss);
+ Status status = Status::OK();
+ {
+ auto collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, nss);
+ status = engine->repairRecordStore(opCtx, collection->getCatalogId(), nss);
+ }
+
// Need to lookup from catalog again because the old collection object was invalidated by
// repairRecordStore.
- collection =
- CollectionCatalog::get(opCtx).lookupCollectionByNamespaceForMetadataWrite(opCtx, nss);
+ auto collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespaceForMetadataWrite(
+ opCtx, CollectionCatalog::LifetimeMode::kInplace, nss);
// If data was modified during repairRecordStore, we know to rebuild indexes without needing
// to run an expensive collection validation.