summaryrefslogtreecommitdiff
path: root/src/mongo/db/cursor_manager.h
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2019-01-17 10:36:29 -0500
committerDavid Storch <david.storch@10gen.com>2019-01-23 21:18:45 -0500
commit84b142d5123c06212ce7a2e495ae8afe48eb65cb (patch)
treee267b75425b6b61c863d73276a7be137f4109fc9 /src/mongo/db/cursor_manager.h
parent869b3b64a898076ff98405fa70403084417cb164 (diff)
downloadmongo-84b142d5123c06212ce7a2e495ae8afe48eb65cb.tar.gz
SERVER-37455 Delete per-collection cursor managers.
Diffstat (limited to 'src/mongo/db/cursor_manager.h')
-rw-r--r--src/mongo/db/cursor_manager.h130
1 files changed, 61 insertions, 69 deletions
diff --git a/src/mongo/db/cursor_manager.h b/src/mongo/db/cursor_manager.h
index b1b8beb1fe6..d0e89e1e6de 100644
--- a/src/mongo/db/cursor_manager.h
+++ b/src/mongo/db/cursor_manager.h
@@ -57,68 +57,92 @@ class PlanExecutor;
* ClientCursors. It is also responsible for allocating the cursor ids that are passed back to
* clients.
*
- * There is a CursorManager per-collection and a global CursorManager. The global CursorManager owns
- * cursors whose lifetime is not tied to that of the collection and which do not need to receive
- * notifications about writes for a particular collection. In contrast, cursors owned by a
- * collection's CursorManager, unless pinned, are destroyed when the collection is destroyed.
- *
- * Callers must hold the collection lock in at least MODE_IS in order to access a collection's
- * CursorManager, which guards against the CursorManager being concurrently deleted due to a
- * catalog-level operation such as a collection drop. No locks are required to access the global
- * cursor manager.
- *
- * The CursorManager is internally synchronized; operations on a given collection may call methods
- * concurrently on that collection's CursorManager.
+ * There is a process-global CursorManager on every mongod which is responsible for managing all
+ * open cursors on the node. No lock manager locks are required to access this global cursor
+ * manager. The CursorManager is internally synchronized, and unless otherwise noted its public
+ * methods are thread-safe. For scalability in circumstances where many threads may be concurrently
+ * accessing the CursorManager (i.e. a workload which runs many concurrent queries), the cursor
+ * manager's underlying data structure is partitioned. Each partition is protected by its own latch.
*
* See clientcursor.h for more information.
*/
class CursorManager {
public:
/**
+ * Returns a pointer to the process-global cursor manager.
+ */
+ static CursorManager* getGlobalCursorManager();
+
+ /**
* Appends the sessions that have open cursors on the global cursor manager and across
* all collection-level cursor managers to the given set of lsids.
*/
static void appendAllActiveSessions(OperationContext* opCtx, LogicalSessionIdSet* lsids);
/**
- * Returns a list of GenericCursors for all idle cursors on the global cursor manager and across
- * all collection-level cursor managers. Does not include currently pinned cursors.
- * 'userMode': If auth is on, calling with userMode as kExcludeOthers will cause this function
- * to only return cursors owned by the caller. If auth is off, this argument does not matter.
+ * Returns a list of GenericCursors for all idle cursors on global cursor manager. Does not
+ * include currently pinned cursors. 'userMode': If auth is on, calling with userMode as
+ * kExcludeOthers will cause this function to only return cursors owned by the caller. If auth
+ * is off, this argument does not matter.
+ *
+ * TODO SERVER-37454: This method should become non-static now that there are no more
+ * per-collection cursor managers.
*/
static std::vector<GenericCursor> getIdleCursors(
OperationContext* opCtx, MongoProcessInterface::CurrentOpUserMode userMode);
/**
- * Kills cursors with matching logical sessions. Returns a pair with the overall
- * Status of the operation and the number of cursors successfully killed.
+ * Kills cursors with matching logical sessions. Returns a pair with the overall Status of the
+ * operation and the number of cursors successfully killed.
*/
static std::pair<Status, int> killCursorsWithMatchingSessions(
OperationContext* opCtx, const SessionKiller::Matcher& matcher);
- CursorManager(NamespaceString nss);
-
/**
- * Destroys the CursorManager. All cursors must be cleaned up via invalidateAll() before
- * destruction.
+ * This method is deprecated. Do not add new call sites.
+ *
+ * TODO SERVER-37452: Delete this method.
*/
- ~CursorManager();
+ static bool isGloballyManagedCursor(CursorId cursorId) {
+ // The first two bits are 01 for globally managed cursors, and 00 for cursors owned by a
+ // collection. The leading bit is always 0 so that CursorIds do not appear as negative.
+ const long long mask = static_cast<long long>(0b11) << 62;
+ return (cursorId & mask) == (static_cast<long long>(0b01) << 62);
+ }
+
+ static int killCursorGlobalIfAuthorized(OperationContext* opCtx, int n, const char* ids);
+
+ static bool killCursorGlobalIfAuthorized(OperationContext* opCtx, CursorId id);
+
+ static bool killCursorGlobal(OperationContext* opCtx, CursorId id);
/**
- * Kills all managed ClientCursors. Callers must have exclusive access to the collection (i.e.
- * must have the collection, database, or global resource locked in MODE_X).
+ * Deletes inactive cursors from the global cursor manager. Returns the number of cursors that
+ * were timed out.
*
- * Must be called before the CursorManger is destroyed.
- *
- * 'collectionGoingAway' indicates whether the Collection instance is being deleted. This could
- * be because the db is being closed, or the collection/db is being dropped.
+ * TODO SERVER-37454: This method can become non-static now that there are no per-collection
+ * cursor managers.
+ */
+ static std::size_t timeoutCursorsGlobal(OperationContext* opCtx, Date_t now);
+
+ /**
+ * This method is deprecated. Do not add new call sites.
*
- * For any cursors that are in use by an active operation, ownership is transferred to the
- * respective cursor pin objects.
+ * TODO SERVER-39065: Delete this method.
+ */
+ static Status withCursorManager(OperationContext* opCtx,
+ CursorId id,
+ const NamespaceString& nss,
+ stdx::function<Status(CursorManager*)> callback);
+
+ CursorManager();
+
+ ~CursorManager();
+
+ /**
+ * This method is deprecated. Do not add new call sites.
*
- * The 'reason' is the motivation for invalidating all cursors. This will be used for error
- * reporting and logging when an operation finds that the cursor it was operating on has been
- * killed.
+ * TODO SERVER-38288: Delete this method.
*/
void invalidateAll(OperationContext* opCtx,
bool collectionGoingAway,
@@ -196,40 +220,6 @@ public:
*/
std::size_t numCursors() const;
- static CursorManager* getGlobalCursorManager();
-
- /**
- * Returns true if this CursorId would be registered with the global CursorManager. Note that if
- * this method returns true it does not imply the cursor exists.
- */
- static bool isGloballyManagedCursor(CursorId cursorId) {
- // The first two bits are 01 for globally managed cursors, and 00 for cursors owned by a
- // collection. The leading bit is always 0 so that CursorIds do not appear as negative.
- const long long mask = static_cast<long long>(0b11) << 62;
- return (cursorId & mask) == (static_cast<long long>(0b01) << 62);
- }
-
- static int killCursorGlobalIfAuthorized(OperationContext* opCtx, int n, const char* ids);
-
- static bool killCursorGlobalIfAuthorized(OperationContext* opCtx, CursorId id);
-
- static bool killCursorGlobal(OperationContext* opCtx, CursorId id);
-
- /**
- * Deletes inactive cursors from the global cursor manager and from all per-collection cursor
- * managers. Returns the number of cursors that were timed out.
- */
- static std::size_t timeoutCursorsGlobal(OperationContext* opCtx, Date_t now);
-
- /**
- * Locate the correct cursor manager for a given cursorId and execute the provided callback.
- * Returns ErrorCodes::CursorNotFound if cursorId does not exist.
- */
- static Status withCursorManager(OperationContext* opCtx,
- CursorId id,
- const NamespaceString& nss,
- stdx::function<Status(CursorManager*)> callback);
-
private:
static constexpr int kNumPartitions = 16;
friend class ClientCursorPin;
@@ -255,8 +245,10 @@ private:
}
// No locks are needed to consult these data members.
+ //
+ // TODO SERVER-37452: Delete these data members.
const NamespaceString _nss;
- const uint32_t _collectionCacheRuntimeId;
+ const uint32_t _collectionCacheRuntimeId = 0;
// A CursorManager holds a pointer to all open ClientCursors. ClientCursors are owned by the
// CursorManager, except when they are in use by a ClientCursorPin. When in use by a pin, an