summaryrefslogtreecommitdiff
path: root/src/mongo/db/db_raii.cpp
diff options
context:
space:
mode:
authorDianna Hohensee <dianna.hohensee@mongodb.com>2021-01-28 18:25:50 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-03-02 16:51:18 +0000
commit168d5f983a3165d2271569b1fc0dbb671771a87f (patch)
treeaeb2d6a99e5ba3a9c060cca921784d8e450bcc74 /src/mongo/db/db_raii.cpp
parent868785d084ea685f7d0a269d2a87e8a7df338e5d (diff)
downloadmongo-168d5f983a3165d2271569b1fc0dbb671771a87f.tar.gz
SERVER-54024 Use lock-free collection helpers in some auth read lookups and RolesLocks.
Diffstat (limited to 'src/mongo/db/db_raii.cpp')
-rw-r--r--src/mongo/db/db_raii.cpp69
1 files changed, 45 insertions, 24 deletions
diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp
index 27d783e40e2..e6793516fe9 100644
--- a/src/mongo/db/db_raii.cpp
+++ b/src/mongo/db/db_raii.cpp
@@ -68,6 +68,27 @@ bool supportsLockFreeRead(OperationContext* opCtx) {
}
/**
+ * Type that pretends to be a Collection. It implements the minimal interface used by
+ * acquireCollectionAndConsistentSnapshot(). We are tricking acquireCollectionAndConsistentSnapshot
+ * to establish a consistent snapshot with just the catalog and not for a specific Collection.
+ */
+class FakeCollection {
+public:
+ // We just need to return something that would not considered to be the oplog. A default
+ // constructed NamespaceString is fine.
+ const NamespaceString& ns() const {
+ return _ns;
+ };
+ // We just need to return something that compares equal with itself here.
+ boost::optional<Timestamp> getMinimumVisibleSnapshot() const {
+ return boost::none;
+ }
+
+private:
+ NamespaceString _ns;
+};
+
+/**
* Helper function to acquire a collection and consistent snapshot without holding the RSTL or
* collection locks.
*
@@ -153,8 +174,8 @@ auto acquireCollectionAndConsistentSnapshot(
LOGV2_DEBUG(5067701,
3,
- "Retrying acquiring state for lock-free read because collection or replication "
- "state changed.");
+ "Retrying acquiring state for lock-free read because collection, catalog or "
+ "replication state changed.");
reset();
opCtx->recoveryUnit()->abandonSnapshot();
}
@@ -598,6 +619,27 @@ const NamespaceString& AutoGetCollectionForReadCommandMaybeLockFree::getNss() co
}
}
+AutoReadLockFree::AutoReadLockFree(OperationContext* opCtx, Date_t deadline)
+ : _catalogStash(opCtx),
+ _lockFreeReadsBlock(opCtx),
+ _globalLock(
+ opCtx, MODE_IS, deadline, Lock::InterruptBehavior::kThrow, true /* skipRSTLLock */) {
+ // The catalog will be stashed inside the CollectionCatalogStasher.
+ FakeCollection fakeColl;
+ acquireCollectionAndConsistentSnapshot(
+ opCtx,
+ /* isLockFreeReadSubOperation */
+ false,
+ /* CollectionCatalogStasher */
+ _catalogStash,
+ /* GetCollectionAndEstablishReadSourceFunc */
+ [&](OperationContext* opCtx, const CollectionCatalog&) { return &fakeColl; },
+ /* GetCollectionAfterSnapshotFunc */
+ [&](OperationContext* opCtx, const CollectionCatalog& catalog) { return &fakeColl; },
+ /* ResetFunc */
+ []() {});
+}
+
AutoGetDbForReadLockFree::AutoGetDbForReadLockFree(OperationContext* opCtx,
StringData dbName,
Date_t deadline)
@@ -605,28 +647,7 @@ AutoGetDbForReadLockFree::AutoGetDbForReadLockFree(OperationContext* opCtx,
_lockFreeReadsBlock(opCtx),
_globalLock(
opCtx, MODE_IS, deadline, Lock::InterruptBehavior::kThrow, true /* skipRSTLLock */) {
-
- // Type that pretends to be a Collection. It implements the minimal interface used by
- // acquireCollectionAndConsistentSnapshot(). We are tricking
- // acquireCollectionAndConsistentSnapshot to establish a consistent snapshot with just the
- // catalog and not for a specific Collection.
- class FakeCollection {
- public:
- // We just need to return something that would not considered to be the oplog. A default
- // constructed NamespaceString is fine.
- const NamespaceString& ns() const {
- return _ns;
- };
- // We just need to return something that compares equal with itself here.
- boost::optional<Timestamp> getMinimumVisibleSnapshot() const {
- return boost::none;
- }
-
- private:
- NamespaceString _ns;
- };
-
- // The catalog will be stashed inside the CollectionCatalogStasher
+ // The catalog will be stashed inside the CollectionCatalogStasher.
FakeCollection fakeColl;
acquireCollectionAndConsistentSnapshot(
opCtx,