summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2015-07-23 13:55:45 -0400
committerMathias Stearn <redbeard0531@gmail.com>2015-07-28 14:41:29 -0400
commitaace5734271b3563ca883c39c0ea37f2e111f8cb (patch)
tree45ca1ab1f1a4c9783ec3646bd144e09633b2f4f3
parentbd585fa7ac8fb51df967116e360f5fc0e8b97596 (diff)
downloadmongo-aace5734271b3563ca883c39c0ea37f2e111f8cb.tar.gz
SERVER-19464 Have DSMergeCursors correctly cleanup _cursors in dispose()
This involves killing the cursor and returning the connection to the pool. This commit also ensures that DSSort calls dispose on its source as needed. (cherry picked from commit 5c20356061c19b7343cb9aab7398238581f0b600)
-rw-r--r--src/mongo/db/pipeline/document_source_merge_cursors.cpp7
-rw-r--r--src/mongo/db/pipeline/document_source_sort.cpp11
2 files changed, 16 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/document_source_merge_cursors.cpp b/src/mongo/db/pipeline/document_source_merge_cursors.cpp
index 408475f022b..46a3b6fa73e 100644
--- a/src/mongo/db/pipeline/document_source_merge_cursors.cpp
+++ b/src/mongo/db/pipeline/document_source_merge_cursors.cpp
@@ -167,6 +167,13 @@ namespace mongo {
}
void DocumentSourceMergeCursors::dispose() {
+ // Note it is an error to call done() on a connection before consuming the response from a
+ // request. Therefore it is an error to call dispose() if there are any outstanding
+ // connections which have not received a reply.
+ for (_currentCursor = _cursors.begin(); _currentCursor != _cursors.end(); ++_currentCursor) {
+ (*_currentCursor)->cursor.kill();
+ (*_currentCursor)->connection.done();
+ }
_cursors.clear();
_currentCursor = _cursors.end();
}
diff --git a/src/mongo/db/pipeline/document_source_sort.cpp b/src/mongo/db/pipeline/document_source_sort.cpp
index 697fb5814e6..5b078f21508 100644
--- a/src/mongo/db/pipeline/document_source_sort.cpp
+++ b/src/mongo/db/pipeline/document_source_sort.cpp
@@ -49,8 +49,13 @@ namespace mongo {
if (!populated)
populate();
- if (!_output || !_output->more())
+ if (!_output || !_output->more()) {
+ // Need to be sure connections are marked as done so they can be returned to the
+ // connection pool. This only needs to happen in the _mergingPresorted case, but it
+ // doesn't hurt to always do it.
+ dispose();
return boost::none;
+ }
return _output->next().second;
}
@@ -76,7 +81,9 @@ namespace mongo {
void DocumentSourceSort::dispose() {
_output.reset();
- pSource->dispose();
+ if (pSource) {
+ pSource->dispose();
+ }
}
DocumentSourceSort::DocumentSourceSort(const intrusive_ptr<ExpressionContext> &pExpCtx)