diff options
author | Jason Rassi <rassi@10gen.com> | 2015-01-12 12:39:33 -0500 |
---|---|---|
committer | Jason Rassi <rassi@10gen.com> | 2015-01-12 12:40:46 -0500 |
commit | e7c69c447f63564da9001ff59ce98d2cc82e87b9 (patch) | |
tree | 14de10f6f59e0bf11b9fd18b319013560e4b5095 /src/mongo/db/clientcursor.h | |
parent | 95c60a44f94a2d8f090787a14dbdfbe96fdb97a3 (diff) | |
download | mongo-e7c69c447f63564da9001ff59ce98d2cc82e87b9.tar.gz |
SERVER-16659 Fix CursorManager/ClientCursorPin cosmetic issues
Const-correctness, comments.
Diffstat (limited to 'src/mongo/db/clientcursor.h')
-rw-r--r-- | src/mongo/db/clientcursor.h | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/src/mongo/db/clientcursor.h b/src/mongo/db/clientcursor.h index 462ae1caa4a..3f80c19d824 100644 --- a/src/mongo/db/clientcursor.h +++ b/src/mongo/db/clientcursor.h @@ -286,17 +286,49 @@ namespace mongo { }; /** - * use this to assure we don't in the background time out cursor while it is under use. if you - * are using noTimeout() already, there is no risk anyway. Further, this mechanism guards - * against two getMore requests on the same cursor executing at the same time - which might be - * bad. That should never happen, but if a client driver had a bug, it could (or perhaps some - * sort of attack situation). - * Must have a read lock on the collection already - */ - class ClientCursorPin : boost::noncopyable { + * ClientCursorPin is an RAII class that manages the pinned state of a ClientCursor. + * ClientCursorPin objects pin the given cursor upon construction, and release the pin upon + * destruction. + * + * A pin extends the lifetime of a ClientCursor object until the pin's release. Pinned + * ClientCursor objects cannot not be killed due to inactivity, and cannot be killed by user + * kill requests. When a CursorManager is destroyed (e.g. by a collection drop), ownership of + * any still-pinned ClientCursor objects is transferred to their managing ClientCursorPin + * objects. + * + * Example usage: + * { + * ClientCursorPin pin(cursorManager, cursorid); + * ClientCursor* cursor = pin.c(); + * if (cursor) { + * // Use cursor. + * } + * // Pin automatically released on block exit. + * } + * + * Clients that wish to access ClientCursor objects owned by collection cursor managers must + * hold the collection lock during pin acquisition and pin release. This guards from a + * collection drop (which requires an exclusive lock on the collection) occurring concurrently + * with the pin request or unpin request. + * + * Clients that wish to access ClientCursor objects owned by the global cursor manager need not + * hold any locks; the global cursor manager can only be destroyed by a process exit. + */ + class ClientCursorPin { + MONGO_DISALLOW_COPYING(ClientCursorPin); public: + /** + * Asks "cursorManager" to set a pin on the ClientCursor associated with "cursorid". If no + * such cursor exists, does nothing. If the cursor is already pinned, throws a + * UserException. + */ ClientCursorPin( CursorManager* cursorManager, long long cursorid ); + + /** + * Calls release(). + */ ~ClientCursorPin(); + // This just releases the pin, does not delete the underlying // unless ownership has passed to us after kill void release(); |