diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-08-21 10:59:45 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-08-21 16:10:25 -0400 |
commit | 31716d2ae526d82d7d36464f6c9fae8b9f38542f (patch) | |
tree | 0e95fcac7ae47450819d51113c86addefaba90ef /src/mongo/db/db_raii.h | |
parent | 0c695aa1e879af482dc3aea4768dbda223ff4592 (diff) | |
download | mongo-31716d2ae526d82d7d36464f6c9fae8b9f38542f.tar.gz |
SERVER-19855 Do not perform shard version checking where not necessary
The code in RangeDeleter and sharding migration and split uses
AutoGetCollectionForRead, which has the side effect of checking for shard
version, based on the context. This causes problems in the cases where we
are transmitting shard version information as part of the context, in
particular during the migration cases.
This change gets rid of these checks and replaces them with plain lock
retrieval.
Diffstat (limited to 'src/mongo/db/db_raii.h')
-rw-r--r-- | src/mongo/db/db_raii.h | 42 |
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; }; /** |