diff options
author | Mathias Stearn <mathias@10gen.com> | 2015-07-23 13:51:16 -0400 |
---|---|---|
committer | Ramon Fernandez <ramon.fernandez@mongodb.com> | 2015-08-07 18:27:39 -0400 |
commit | ade79fbb0f2e8843177c9ee2c75c2ef7cdf82db6 (patch) | |
tree | d3f5401dab4ce2a5cb6d57992cbae3015f119f48 | |
parent | 810e4041ee13a1cc31e0090bab903849c5fbbdf6 (diff) | |
download | mongo-ade79fbb0f2e8843177c9ee2c75c2ef7cdf82db6.tar.gz |
SERVER-19464 Add a way to explicitly kill a DBClientCursor before destruction
(cherry picked from commit 0476dec3ae310f768ae7fd31418a4c8aa7c24506)
Conflicts:
src/mongo/client/dbclientcursor.h
-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 d3ec7160ca3..33fccef8945 100644 --- a/src/mongo/client/dbclientcursor.cpp +++ b/src/mongo/client/dbclientcursor.cpp @@ -365,6 +365,10 @@ void DBClientCursor::attach(AScopedConnection* conn) { } DBClientCursor::~DBClientCursor() { + kill(); +} + +void DBClientCursor::kill() { DESTRUCTOR_GUARD( if (cursorId && _ownCursor && !inShutdown()) { @@ -397,6 +401,9 @@ DBClientCursor::~DBClientCursor() { } ); + + // 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 a1c903d157e..b076106489d 100644 --- a/src/mongo/client/dbclientcursor.h +++ b/src/mongo/client/dbclientcursor.h @@ -249,6 +249,18 @@ public: Batch() : m(new Message()), nReturned(), pos(), data() {} }; + /** + * 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(); + private: friend class DBClientBase; friend class DBClientConnection; |