diff options
author | Mathias Stearn <mathias@10gen.com> | 2015-07-23 13:51:16 -0400 |
---|---|---|
committer | Mathias Stearn <redbeard0531@gmail.com> | 2015-07-28 14:33:59 -0400 |
commit | bd585fa7ac8fb51df967116e360f5fc0e8b97596 (patch) | |
tree | 10040faaab3004787516dd94cbadb8c43517c5fa /src | |
parent | 0e5875d237ee4f113c63470521a9991dcf0807c7 (diff) | |
download | mongo-bd585fa7ac8fb51df967116e360f5fc0e8b97596.tar.gz |
SERVER-19464 Add a way to explicitly kill a DBClientCursor before destruction
(cherry picked from commit 0476dec3ae310f768ae7fd31418a4c8aa7c24506)
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/client/dbclientcursor.cpp | 7 | ||||
-rw-r--r-- | src/mongo/client/dbclientcursor.h | 12 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/mongo/client/dbclientcursor.cpp b/src/mongo/client/dbclientcursor.cpp index fa8e5c7d14b..2e0b0a0fa4d 100644 --- a/src/mongo/client/dbclientcursor.cpp +++ b/src/mongo/client/dbclientcursor.cpp @@ -325,6 +325,10 @@ namespace mongo { } DBClientCursor::~DBClientCursor() { + kill(); + } + + void DBClientCursor::kill() { if (!this) return; @@ -362,6 +366,9 @@ namespace mongo { } ); + + // Mark this cursor as dead since we can't do any getMores. + cursorId = 0; } diff --git a/src/mongo/client/dbclientcursor.h b/src/mongo/client/dbclientcursor.h index 4ed29b0150a..810822f6a91 100644 --- a/src/mongo/client/dbclientcursor.h +++ b/src/mongo/client/dbclientcursor.h @@ -202,6 +202,18 @@ namespace mongo { void initLazy( bool isRetry = false ); bool initLazyFinish( bool& retry ); + /** + * Marks this object as dead and sends the KillCursors message to the server. + * + * Any errors that result from this are swallowed since this is typically performed as part + * of cleanup and a failure to kill the cursor should not result in a failure of the + * operation using the cursor. + * + * Killing an already killed or exhausted cursor does nothing, so it is safe to always call + * this if you want to ensure that a cursor is killed. + */ + void kill(); + class Batch : boost::noncopyable { friend class DBClientCursor; auto_ptr<Message> m; |