summaryrefslogtreecommitdiff
path: root/src/mongo/db/db_raii.h
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2015-08-24 15:53:54 -0400
committerSpencer T Brody <spencer@mongodb.com>2015-08-25 14:58:12 -0400
commitd64c98deed2440ae0f3700dc373bf8b97886030c (patch)
treec676a9a82a56a2191fb5cab3956e515484bc57d1 /src/mongo/db/db_raii.h
parent559be68757f52d0a5f6e2c2622febea8acf80c35 (diff)
downloadmongo-d64c98deed2440ae0f3700dc373bf8b97886030c.tar.gz
SERVER-19855 Do not perform shard version checking where not necessary
This reverts commit 045cd1070cae1e7827255850c2fe35194e48b24e.
Diffstat (limited to 'src/mongo/db/db_raii.h')
-rw-r--r--src/mongo/db/db_raii.h42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/mongo/db/db_raii.h b/src/mongo/db/db_raii.h
index b37112cb267..b6522caad2b 100644
--- a/src/mongo/db/db_raii.h
+++ b/src/mongo/db/db_raii.h
@@ -45,7 +45,7 @@ class Collection;
* RAII-style class, which acquires a lock on the specified database in the requested mode and
* obtains a reference to the database. Used as a shortcut for calls to dbHolder().get().
*
- * It is guaranteed that locks will be released when this object goes out of scope, therefore
+ * It is guaranteed that the lock will be released when this object goes out of scope, therefore
* the database reference returned by this class should not be retained.
*/
class AutoGetDb {
@@ -64,6 +64,33 @@ private:
};
/**
+ * RAII-style class, which acquires a locks on the specified database and collection in the
+ * requested mode and obtains references to both.
+ *
+ * It is guaranteed that locks will be released when this object goes out of scope, therefore
+ * the database and the collection references returned by this class should not be retained.
+ */
+class AutoGetCollection {
+ MONGO_DISALLOW_COPYING(AutoGetCollection);
+
+public:
+ AutoGetCollection(OperationContext* txn, const NamespaceString& nss, LockMode mode);
+
+ Database* getDb() const {
+ return _autoDb.getDb();
+ }
+
+ Collection* getCollection() const {
+ return _coll;
+ }
+
+private:
+ const AutoGetDb _autoDb;
+ const Lock::CollectionLock _collLock;
+ Collection* const _coll;
+};
+
+/**
* 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
@@ -100,7 +127,9 @@ private:
/**
* RAII-style class, which would acquire the appropritate hierarchy of locks for obtaining
- * a particular collection and would retrieve a reference to the collection.
+ * a particular collection and would retrieve a reference to the collection. In addition, this
+ * utility validates the shard version for the specified namespace and sets the current operation's
+ * namespace for the duration while this object is alive.
*
* It is guaranteed that locks will be released when this object goes out of scope, therefore
* database and collection references returned by this class should not be retained.
@@ -114,11 +143,11 @@ public:
~AutoGetCollectionForRead();
Database* getDb() const {
- return _db.getDb();
+ return _autoColl.getDb();
}
Collection* getCollection() const {
- return _coll;
+ return _autoColl.getCollection();
}
private:
@@ -127,10 +156,7 @@ private:
const Timer _timer;
OperationContext* const _txn;
const ScopedTransaction _transaction;
- const AutoGetDb _db;
- const Lock::CollectionLock _collLock;
-
- Collection* _coll;
+ const AutoGetCollection _autoColl;
};
/**