summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2022-04-06 06:11:55 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-13 23:01:32 +0000
commit7818bdcb10d520cb0f6685973c707ed5f292325a (patch)
tree0b9d05b8ce1abfee8fcdae0bb21547a0e1005491
parent8748f6b2a2a67282f48d84c1f69d07fc9616a54a (diff)
downloadmongo-7818bdcb10d520cb0f6685973c707ed5f292325a.tar.gz
SERVER-65137 LookupCollectionForYieldRestore saves collection namespace at construction
(cherry picked from commit 729774b7c096ef0a3a6158c5394245937b883667)
-rw-r--r--src/mongo/db/catalog/collection_catalog.cpp11
-rw-r--r--src/mongo/db/catalog/collection_catalog.h4
-rw-r--r--src/mongo/db/catalog_raii.cpp7
3 files changed, 15 insertions, 7 deletions
diff --git a/src/mongo/db/catalog/collection_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp
index 7901809f2ca..ff0fc056e75 100644
--- a/src/mongo/db/catalog/collection_catalog.cpp
+++ b/src/mongo/db/catalog/collection_catalog.cpp
@@ -346,7 +346,8 @@ CollectionCatalog::iterator::value_type CollectionCatalog::iterator::operator*()
return CollectionPtr();
}
- return {_opCtx, _mapIter->second.get(), LookupCollectionForYieldRestore()};
+ return {
+ _opCtx, _mapIter->second.get(), LookupCollectionForYieldRestore(_mapIter->second->ns())};
}
Collection* CollectionCatalog::iterator::getWritableCollection(OperationContext* opCtx,
@@ -672,12 +673,12 @@ CollectionPtr CollectionCatalog::lookupCollectionByUUID(OperationContext* opCtx,
}
if (auto coll = UncommittedCollections::getForTxn(opCtx, uuid)) {
- return {opCtx, coll.get(), LookupCollectionForYieldRestore()};
+ return {opCtx, coll.get(), LookupCollectionForYieldRestore(coll->ns())};
}
auto coll = _lookupCollectionByUUID(uuid);
return (coll && coll->isCommitted())
- ? CollectionPtr(opCtx, coll.get(), LookupCollectionForYieldRestore())
+ ? CollectionPtr(opCtx, coll.get(), LookupCollectionForYieldRestore(coll->ns()))
: CollectionPtr();
}
@@ -757,7 +758,7 @@ CollectionPtr CollectionCatalog::lookupCollectionByNamespace(OperationContext* o
// If found=true above but we don't have a Collection pointer it is a drop or rename. But first
// check UncommittedCollections in case we find a new collection there.
if (auto coll = UncommittedCollections::getForTxn(opCtx, nss)) {
- return {opCtx, coll.get(), LookupCollectionForYieldRestore()};
+ return {opCtx, coll.get(), LookupCollectionForYieldRestore(coll->ns())};
}
// Report the drop or rename as nothing new was created.
@@ -768,7 +769,7 @@ CollectionPtr CollectionCatalog::lookupCollectionByNamespace(OperationContext* o
auto it = _collections.find(nss);
auto coll = (it == _collections.end() ? nullptr : it->second);
return (coll && coll->isCommitted())
- ? CollectionPtr(opCtx, coll.get(), LookupCollectionForYieldRestore())
+ ? CollectionPtr(opCtx, coll.get(), LookupCollectionForYieldRestore(coll->ns()))
: nullptr;
}
diff --git a/src/mongo/db/catalog/collection_catalog.h b/src/mongo/db/catalog/collection_catalog.h
index f8ec0db2533..1103520bce6 100644
--- a/src/mongo/db/catalog/collection_catalog.h
+++ b/src/mongo/db/catalog/collection_catalog.h
@@ -517,7 +517,11 @@ private:
* restore implementation for CollectionPtr when acquired from the catalog.
*/
struct LookupCollectionForYieldRestore {
+ explicit LookupCollectionForYieldRestore(const NamespaceString& nss) : _nss(nss) {}
const Collection* operator()(OperationContext* opCtx, const UUID& uuid) const;
+
+private:
+ const NamespaceString _nss;
};
/**
diff --git a/src/mongo/db/catalog_raii.cpp b/src/mongo/db/catalog_raii.cpp
index 13635b0a16c..5e523a362f2 100644
--- a/src/mongo/db/catalog_raii.cpp
+++ b/src/mongo/db/catalog_raii.cpp
@@ -325,12 +325,15 @@ Collection* AutoGetCollection::getWritableCollection(OperationContext* opCtx,
// new write unit of work is opened.
opCtx->recoveryUnit()->registerChange(
[this, opCtx](boost::optional<Timestamp> commitTime) {
- _coll = CollectionPtr(opCtx, _coll.get(), LookupCollectionForYieldRestore());
+ _coll = CollectionPtr(
+ opCtx, _coll.get(), LookupCollectionForYieldRestore(_coll->ns()));
_writableColl = nullptr;
},
[this, originalCollection = _coll.get(), opCtx]() {
_coll =
- CollectionPtr(opCtx, originalCollection, LookupCollectionForYieldRestore());
+ CollectionPtr(opCtx,
+ originalCollection,
+ LookupCollectionForYieldRestore(originalCollection->ns()));
_writableColl = nullptr;
});
}