diff options
author | David Storch <david.storch@10gen.com> | 2015-11-13 13:28:36 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2015-11-13 16:41:37 -0500 |
commit | 7a99fd808fc4e8960d2981799415617c495a0fda (patch) | |
tree | 89fbd9ea94559b27637e9d3d1a09827981622c19 /src/mongo/s | |
parent | bddbae79b4733dbd392215c38beccab5daa0109c (diff) | |
download | mongo-7a99fd808fc4e8960d2981799415617c495a0fda.tar.gz |
SERVER-20853 eliminate copies in find and getMore path
Diffstat (limited to 'src/mongo/s')
-rw-r--r-- | src/mongo/s/commands/cluster_find_cmd.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/s_only.cpp | 1 | ||||
-rw-r--r-- | src/mongo/s/strategy.cpp | 41 |
3 files changed, 25 insertions, 23 deletions
diff --git a/src/mongo/s/commands/cluster_find_cmd.cpp b/src/mongo/s/commands/cluster_find_cmd.cpp index f49c4ebd3c6..44ec66acb12 100644 --- a/src/mongo/s/commands/cluster_find_cmd.cpp +++ b/src/mongo/s/commands/cluster_find_cmd.cpp @@ -165,11 +165,11 @@ public: } // Build the response document. - BSONArrayBuilder arr; + CursorResponseBuilder firstBatch(/*firstBatch*/ true, &result); for (const auto& obj : batch) { - arr.append(obj); + firstBatch.append(obj); } - appendCursorResponseObject(cursorId.getValue(), nss.ns(), arr.arr(), &result); + firstBatch.done(cursorId.getValue(), nss.ns()); return true; } diff --git a/src/mongo/s/s_only.cpp b/src/mongo/s/s_only.cpp index a718c31c22d..2322aa67d3d 100644 --- a/src/mongo/s/s_only.cpp +++ b/src/mongo/s/s_only.cpp @@ -127,6 +127,7 @@ void Command::execCommandClientBasic(OperationContext* txn, try { ok = c->run(txn, dbname, cmdObj, queryOptions, errmsg, result); } catch (const DBException& e) { + result.resetToEmpty(); const int code = e.getCode(); // Codes for StaleConfigException diff --git a/src/mongo/s/strategy.cpp b/src/mongo/s/strategy.cpp index 04b71efca20..3cd57de4fa2 100644 --- a/src/mongo/s/strategy.cpp +++ b/src/mongo/s/strategy.cpp @@ -165,23 +165,19 @@ void Strategy::queryOp(OperationContext* txn, Request& request) { auto cursorId = ClusterFind::runQuery(txn, *canonicalQuery.getValue(), readPreference, &batch); uassertStatusOK(cursorId.getStatus()); - BufBuilder buffer(FindCommon::kInitReplyBufferSize); - // Fill out the response buffer. int numResults = 0; - for (const auto& obj : batch) { - buffer.appendBuf((void*)obj.objdata(), obj.objsize()); + OpQueryReplyBuilder reply; + for (auto&& obj : batch) { + obj.appendSelfToBufBuilder(reply.bufBuilderForResults()); numResults++; } - - replyToQuery(0, // query result flags - request.p(), - request.m(), - buffer.buf(), - buffer.len(), - numResults, - 0, // startingFrom - cursorId.getValue()); + reply.send(request.p(), + 0, // query result flags + request.m(), + numResults, + 0, // startingFrom + cursorId.getValue()); } void Strategy::clientCommandOp(OperationContext* txn, Request& request) { @@ -207,7 +203,6 @@ void Strategy::clientCommandOp(OperationContext* txn, Request& request) { bool cmChangeAttempted = false; while (true) { - BSONObjBuilder builder; try { BSONObj cmdObj = q.query; { @@ -236,9 +231,12 @@ void Strategy::clientCommandOp(OperationContext* txn, Request& request) { } } - Command::runAgainstRegistered(txn, q.ns, cmdObj, builder, q.queryOptions); - BSONObj x = builder.done(); - replyToQuery(0, request.p(), request.m(), x); + OpQueryReplyBuilder reply; + { + BSONObjBuilder builder(reply.bufBuilderForResults()); + Command::runAgainstRegistered(txn, q.ns, cmdObj, builder, q.queryOptions); + } + reply.sendCommandReply(request.p(), request.m()); return; } catch (const StaleConfigException& e) { if (loops <= 0) @@ -262,9 +260,12 @@ void Strategy::clientCommandOp(OperationContext* txn, Request& request) { grid.forwardingCatalogManager()->waitForCatalogManagerChange(txn); } else { - Command::appendCommandStatus(builder, e.toStatus()); - BSONObj x = builder.done(); - replyToQuery(0, request.p(), request.m(), x); + OpQueryReplyBuilder reply; + { + BSONObjBuilder builder(reply.bufBuilderForResults()); + Command::appendCommandStatus(builder, e.toStatus()); + } + reply.sendCommandReply(request.p(), request.m()); return; } } |