summaryrefslogtreecommitdiff
path: root/src/mongo/db/db_raii.h
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2017-06-06 13:49:35 -0400
committersamantharitter <samantha.ritter@10gen.com>2017-06-15 13:54:58 -0400
commiteddb3e4535a9bf9198b207bf155889bf4625cdf0 (patch)
treed6b941bb582d5abbfef293503727d5c340410c54 /src/mongo/db/db_raii.h
parent1efbf03521e9c6d85df33ab6786f6c121d8b56c2 (diff)
downloadmongo-eddb3e4535a9bf9198b207bf155889bf4625cdf0.tar.gz
SERVER-29417 Attach logical session ids to cursors
Diffstat (limited to 'src/mongo/db/db_raii.h')
-rw-r--r--src/mongo/db/db_raii.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/mongo/db/db_raii.h b/src/mongo/db/db_raii.h
index 753909e3c6a..641b64e7988 100644
--- a/src/mongo/db/db_raii.h
+++ b/src/mongo/db/db_raii.h
@@ -128,12 +128,55 @@ private:
const Lock::CollectionLock _collLock;
Collection* const _coll;
+ friend class AutoGetCollectionOrView;
friend class AutoGetCollectionForRead;
friend class AutoGetCollectionForReadCommand;
friend class AutoGetCollectionOrViewForReadCommand;
};
/**
+ * RAII-style class which acquires the appropriate hierarchy of locks for a collection or
+ * view. The pointer to a view definition is nullptr if it does not exist.
+ *
+ * Use this when you have not yet determined if the namespace is a view or a collection.
+ * For example, you can use this to access a namespace's CursorManager.
+ *
+ * It is guaranteed that locks will be released when this object goes out of scope, therefore
+ * the view returned by this class should not be retained.
+ */
+class AutoGetCollectionOrView {
+ MONGO_DISALLOW_COPYING(AutoGetCollectionOrView);
+
+public:
+ AutoGetCollectionOrView(OperationContext* opCtx, const NamespaceString& nss, LockMode modeAll);
+
+ /**
+ * Returns nullptr if the database didn't exist.
+ */
+ Database* getDb() const {
+ return _autoColl.getDb();
+ }
+
+ /**
+ * Returns nullptr if the collection didn't exist.
+ */
+ Collection* getCollection() const {
+ return _autoColl.getCollection();
+ }
+
+ /**
+ * Returns nullptr if the view didn't exist.
+ */
+ ViewDefinition* getView() const {
+ return _view.get();
+ }
+
+private:
+ const AutoGetCollection _autoColl;
+ std::shared_ptr<ViewDefinition> _view;
+};
+
+/**
* RAII-style class, which acquires a lock on the specified database in the requested mode and
* obtains a reference to the database, creating it was non-existing. Used as a shortcut for
* calls to dbHolder().openDb(), taking care of locking details. The requested mode must be