diff options
author | David Storch <david.storch@10gen.com> | 2018-11-28 17:25:24 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2019-01-15 17:54:33 -0500 |
commit | de2a803ca492261cac1d7f43a9f7c847cd0ea24d (patch) | |
tree | 03cb6ea2b304463e7458f557246a95978d1ef96a /src/mongo/db/clientcursor.h | |
parent | af8fa6034f8a989cb47ee890c6a6b3e87e1bcf7b (diff) | |
download | mongo-de2a803ca492261cac1d7f43a9f7c847cd0ea24d.tar.gz |
SERVER-37451 Move all ClientCursor ownership to the global CursorManager.
Deleting the per-collection CursorManagers, and other
related cleanup, is left as future work.
Diffstat (limited to 'src/mongo/db/clientcursor.h')
-rw-r--r-- | src/mongo/db/clientcursor.h | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/mongo/db/clientcursor.h b/src/mongo/db/clientcursor.h index 10fe242abac..8e17f0e0bec 100644 --- a/src/mongo/db/clientcursor.h +++ b/src/mongo/db/clientcursor.h @@ -55,18 +55,40 @@ class RecoveryUnit; * using a CursorManager. See cursor_manager.h for more details. */ struct ClientCursorParams { + // Describes whether callers should acquire locks when using a ClientCursor. Not all cursors + // have the same locking behavior. In particular, find cursors require the caller to lock the + // collection in MODE_IS before calling methods on the underlying plan executor. Aggregate + // cursors, on the other hand, may access multiple collections and acquire their own locks on + // any involved collections while producing query results. Therefore, the caller need not + // explicitly acquire any locks when using a ClientCursor which houses execution machinery for + // an aggregate. + // + // The policy is consulted on getMore in order to determine locking behavior, since during + // getMore we otherwise could not easily know what flavor of cursor we're using. + enum class LockPolicy { + // The caller is responsible for locking the collection over which this ClientCursor + // executes. + kLockExternally, + + // The caller need not hold no locks; this ClientCursor's plan executor acquires any + // necessary locks itself. + kLocksInternally, + }; + ClientCursorParams(std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> planExecutor, NamespaceString nss, UserNameIterator authenticatedUsersIter, repl::ReadConcernArgs readConcernArgs, - BSONObj originatingCommandObj) + BSONObj originatingCommandObj, + LockPolicy lockPolicy) : exec(std::move(planExecutor)), nss(std::move(nss)), readConcernArgs(readConcernArgs), queryOptions(exec->getCanonicalQuery() ? exec->getCanonicalQuery()->getQueryRequest().getOptions() : 0), - originatingCommandObj(originatingCommandObj.getOwned()) { + originatingCommandObj(originatingCommandObj.getOwned()), + lockPolicy(lockPolicy) { while (authenticatedUsersIter.more()) { authenticatedUsers.emplace_back(authenticatedUsersIter.next()); } @@ -92,6 +114,7 @@ struct ClientCursorParams { const repl::ReadConcernArgs readConcernArgs; int queryOptions = 0; BSONObj originatingCommandObj; + const LockPolicy lockPolicy; }; /** @@ -219,6 +242,10 @@ public: return StringData(_planSummary); } + ClientCursorParams::LockPolicy lockPolicy() const { + return _lockPolicy; + } + /** * Returns a generic cursor containing diagnostics about this cursor. * The caller must either have this cursor pinned or hold a mutex from the cursor manager. @@ -348,6 +375,8 @@ private: // See the QueryOptions enum in dbclientinterface.h. const int _queryOptions = 0; + const ClientCursorParams::LockPolicy _lockPolicy; + // Unused maxTime budget for this cursor. Microseconds _leftoverMaxTimeMicros = Microseconds::max(); @@ -467,6 +496,10 @@ public: */ ClientCursor* getCursor() const; + ClientCursor* operator->() { + return _cursor; + } + private: friend class CursorManager; |