diff options
author | Mathias Stearn <mathias@10gen.com> | 2016-06-06 14:08:29 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2016-06-22 16:04:36 -0400 |
commit | e508ddcb51eec941ae50d9c2efb06b601811dc19 (patch) | |
tree | cab51e8665c29d8220b64e7f69a8bbc592ca5339 /src/mongo/db/query/find.cpp | |
parent | 40f20eca105a5e06a72df583ac654f946e9b058e (diff) | |
download | mongo-e508ddcb51eec941ae50d9c2efb06b601811dc19.tar.gz |
SERVER-24418 Make Message and BufBuilder use SharedBuffer for memory management
This makes it possible to get owned BSONObj out of a Message without copying.
Hooked up to the following places:
- Anything using the Fetcher (including oplog fetching on secondaries)
- Anything using DBClientInterface::findOne()
- Anything using CursorResponse (including Sharded queries)
As a simplification, Messages no longer support non-contiguous buffers, or
non-owning buffers. The former wasn't used by anything, and the latter was
only used by mongosniff only for messages that fit in a single packet.
Diffstat (limited to 'src/mongo/db/query/find.cpp')
-rw-r--r-- | src/mongo/db/query/find.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp index 6e501242cee..e5b6646dae6 100644 --- a/src/mongo/db/query/find.cpp +++ b/src/mongo/db/query/find.cpp @@ -223,12 +223,12 @@ void generateBatch(int ntoreturn, /** * Called by db/instance.cpp. This is the getMore entry point. */ -QueryResult::View getMore(OperationContext* txn, - const char* ns, - int ntoreturn, - long long cursorid, - bool* exhaust, - bool* isCursorAuthorized) { +Message getMore(OperationContext* txn, + const char* ns, + int ntoreturn, + long long cursorid, + bool* exhaust, + bool* isCursorAuthorized) { invariant(ntoreturn >= 0); CurOp& curOp = *CurOp::get(txn); @@ -485,9 +485,8 @@ QueryResult::View getMore(OperationContext* txn, qr.setCursorId(cursorid); qr.setStartingFrom(startingResult); qr.setNReturned(numResults); - bb.decouple(); LOG(5) << "getMore returned " << numResults << " results\n"; - return qr; + return Message(bb.release()); } std::string runQuery(OperationContext* txn, @@ -543,7 +542,6 @@ std::string runQuery(OperationContext* txn, // Set query result fields. QueryResult::View qr = bb.buf(); - bb.decouple(); qr.setResultFlagsToOk(); qr.msgdata().setLen(bb.len()); curOp.debug().responseLength = bb.len(); @@ -551,7 +549,7 @@ std::string runQuery(OperationContext* txn, qr.setCursorId(0); qr.setStartingFrom(0); qr.setNReturned(1); - result.setData(qr.view2ptr(), true); + result.setData(bb.release()); return ""; } @@ -686,18 +684,18 @@ std::string runQuery(OperationContext* txn, endQueryOp(txn, collection, *exec, numResults, ccId); } - // Add the results from the query into the output buffer. - result.appendData(bb.buf(), bb.len()); - bb.decouple(); - // Fill out the output buffer's header. - QueryResult::View queryResultView = result.header().view2ptr(); + QueryResult::View queryResultView = bb.buf(); queryResultView.setCursorId(ccId); queryResultView.setResultFlagsToOk(); + queryResultView.msgdata().setLen(bb.len()); queryResultView.msgdata().setOperation(opReply); queryResultView.setStartingFrom(0); queryResultView.setNReturned(numResults); + // Add the results from the query into the output buffer. + result.setData(bb.release()); + // curOp.debug().exhaust is set above. return curOp.debug().exhaust ? nss.ns() : ""; } |