diff options
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r-- | src/mongo/db/commands/count_cmd.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/commands/current_op.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/commands/distinct.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/commands/explain_cmd.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/commands/find_and_modify.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/commands/find_cmd.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/commands/getmore_cmd.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/commands/pipeline_command.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/commands/run_aggregate.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/commands/run_aggregate.h | 3 | ||||
-rw-r--r-- | src/mongo/db/commands/user_management_commands.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/commands/write_commands/write_commands.cpp | 10 |
12 files changed, 56 insertions, 41 deletions
diff --git a/src/mongo/db/commands/count_cmd.cpp b/src/mongo/db/commands/count_cmd.cpp index 8818ded8b59..ecff6c12986 100644 --- a/src/mongo/db/commands/count_cmd.cpp +++ b/src/mongo/db/commands/count_cmd.cpp @@ -107,7 +107,7 @@ public: Status explain(OperationContext* opCtx, const OpMsgRequest& opMsgRequest, ExplainOptions::Verbosity verbosity, - BSONObjBuilder* out) const override { + rpc::ReplyBuilderInterface* result) const override { std::string dbname = opMsgRequest.getDatabase().toString(); const BSONObj& cmdObj = opMsgRequest.body; // Acquire locks and resolve possible UUID. The RAII object is optional, because in the case @@ -143,7 +143,7 @@ public: viewAggRequest.getValue().getNamespaceString(), viewAggRequest.getValue(), viewAggregation.getValue(), - *out); + result); } Collection* const collection = ctx->getCollection(); @@ -160,7 +160,8 @@ public: auto exec = std::move(statusWithPlanExecutor.getValue()); - Explain::explainStages(exec.get(), collection, verbosity, out); + auto bodyBuilder = result->getBodyBuilder(); + Explain::explainStages(exec.get(), collection, verbosity, &bodyBuilder); return Status::OK(); } diff --git a/src/mongo/db/commands/current_op.cpp b/src/mongo/db/commands/current_op.cpp index 47e22ea8296..3b0d2d1814f 100644 --- a/src/mongo/db/commands/current_op.cpp +++ b/src/mongo/db/commands/current_op.cpp @@ -66,18 +66,20 @@ public: OperationContext* opCtx, const AggregationRequest& request) const final { auto aggCmdObj = request.serializeToCommandObj().toBson(); - BSONObjBuilder responseBuilder; + rpc::OpMsgReplyBuilder replyBuilder; auto status = runAggregate( - opCtx, request.getNamespaceString(), request, std::move(aggCmdObj), responseBuilder); + opCtx, request.getNamespaceString(), request, std::move(aggCmdObj), &replyBuilder); if (!status.isOK()) { return status; } - CommandHelpers::appendSimpleCommandStatus(responseBuilder, true); + auto bodyBuilder = replyBuilder.getBodyBuilder(); + CommandHelpers::appendSimpleCommandStatus(bodyBuilder, true); + bodyBuilder.doneFast(); - return CursorResponse::parseFromBSON(responseBuilder.obj()); + return CursorResponse::parseFromBSON(replyBuilder.releaseBody()); } virtual void appendToResponse(BSONObjBuilder* result) const final { diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp index 8802e4875cb..8b6098f4341 100644 --- a/src/mongo/db/commands/distinct.cpp +++ b/src/mongo/db/commands/distinct.cpp @@ -112,7 +112,7 @@ public: Status explain(OperationContext* opCtx, const OpMsgRequest& request, ExplainOptions::Verbosity verbosity, - BSONObjBuilder* out) const override { + rpc::ReplyBuilderInterface* result) const override { std::string dbname = request.getDatabase().toString(); const BSONObj& cmdObj = request.body; // Acquire locks and resolve possible UUID. The RAII object is optional, because in the case @@ -143,7 +143,7 @@ public: } return runAggregate( - opCtx, nss, viewAggRequest.getValue(), viewAggregation.getValue(), *out); + opCtx, nss, viewAggRequest.getValue(), viewAggregation.getValue(), result); } Collection* const collection = ctx->getCollection(); @@ -151,7 +151,8 @@ public: auto executor = uassertStatusOK(getExecutorDistinct(opCtx, collection, nss.ns(), &parsedDistinct)); - Explain::explainStages(executor.get(), collection, verbosity, out); + auto bodyBuilder = result->getBodyBuilder(); + Explain::explainStages(executor.get(), collection, verbosity, &bodyBuilder); return Status::OK(); } diff --git a/src/mongo/db/commands/explain_cmd.cpp b/src/mongo/db/commands/explain_cmd.cpp index b20a1a7d850..c41022b5550 100644 --- a/src/mongo/db/commands/explain_cmd.cpp +++ b/src/mongo/db/commands/explain_cmd.cpp @@ -97,13 +97,12 @@ public: "Explain's child command cannot run on this node. " "Are you explaining a write command on a secondary?", commandCanRunHere(opCtx, _dbName, _innerInvocation->definition())); - BSONObjBuilder bob = result->getBodyBuilder(); - _innerInvocation->explain(opCtx, _verbosity, &bob); + _innerInvocation->explain(opCtx, _verbosity, result); } void explain(OperationContext* opCtx, ExplainOptions::Verbosity verbosity, - BSONObjBuilder* result) override { + rpc::ReplyBuilderInterface* result) override { uasserted(ErrorCodes::IllegalOperation, "Explain cannot explain itself."); } diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp index 4c70636f928..070557d4f41 100644 --- a/src/mongo/db/commands/find_and_modify.cpp +++ b/src/mongo/db/commands/find_and_modify.cpp @@ -256,7 +256,7 @@ public: Status explain(OperationContext* opCtx, const OpMsgRequest& request, ExplainOptions::Verbosity verbosity, - BSONObjBuilder* out) const override { + rpc::ReplyBuilderInterface* result) const override { std::string dbName = request.getDatabase().toString(); const BSONObj& cmdObj = request.body; const auto args(uassertStatusOK(FindAndModifyRequest::parseFromBSON( @@ -288,7 +288,8 @@ public: const auto exec = uassertStatusOK(getExecutorDelete(opCtx, opDebug, collection, &parsedDelete)); - Explain::explainStages(exec.get(), collection, verbosity, out); + auto bodyBuilder = result->getBodyBuilder(); + Explain::explainStages(exec.get(), collection, verbosity, &bodyBuilder); } else { UpdateRequest request(nsString); UpdateLifecycleImpl updateLifecycle(nsString); @@ -312,7 +313,8 @@ public: const auto exec = uassertStatusOK(getExecutorUpdate(opCtx, opDebug, collection, &parsedUpdate)); - Explain::explainStages(exec.get(), collection, verbosity, out); + auto bodyBuilder = result->getBodyBuilder(); + Explain::explainStages(exec.get(), collection, verbosity, &bodyBuilder); } return Status::OK(); diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp index e16f2473092..7c82c31da29 100644 --- a/src/mongo/db/commands/find_cmd.cpp +++ b/src/mongo/db/commands/find_cmd.cpp @@ -142,7 +142,7 @@ public: void explain(OperationContext* opCtx, ExplainOptions::Verbosity verbosity, - BSONObjBuilder* result) override { + rpc::ReplyBuilderInterface* result) override { // Acquire locks and resolve possible UUID. The RAII object is optional, because in the // case of a view, the locks need to be released. boost::optional<AutoGetCollectionForReadCommand> ctx; @@ -182,7 +182,7 @@ public: try { uassertStatusOK( - runAggregate(opCtx, nss, aggRequest, viewAggregationCommand, *result)); + runAggregate(opCtx, nss, aggRequest, viewAggregationCommand, result)); } catch (DBException& error) { if (error.code() == ErrorCodes::InvalidPipelineOperator) { uasserted(ErrorCodes::InvalidPipelineOperator, @@ -201,8 +201,9 @@ public: // We have a parsed query. Time to get the execution plan for it. auto exec = uassertStatusOK(getExecutorFind(opCtx, collection, nss, std::move(cq))); + auto bodyBuilder = result->getBodyBuilder(); // Got the execution tree. Explain it. - Explain::explainStages(exec.get(), collection, verbosity, result); + Explain::explainStages(exec.get(), collection, verbosity, &bodyBuilder); } /** @@ -320,8 +321,9 @@ public: const QueryRequest& originalQR = exec->getCanonicalQuery()->getQueryRequest(); // Stream query results, adding them to a BSONArray as we go. - auto bodyBuilder = result->getBodyBuilder(); - CursorResponseBuilder firstBatch(/*isInitialResponse*/ true, &bodyBuilder); + CursorResponseBuilder::Options options; + options.isInitialResponse = true; + CursorResponseBuilder firstBatch(result, options); BSONObj obj; PlanExecutor::ExecState state = PlanExecutor::ADVANCED; long long numResults = 0; diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp index e296e4e0c97..a6fa17ab2d6 100644 --- a/src/mongo/db/commands/getmore_cmd.cpp +++ b/src/mongo/db/commands/getmore_cmd.cpp @@ -244,7 +244,6 @@ public: void run(OperationContext* opCtx, rpc::ReplyBuilderInterface* reply) override { // Counted as a getMore, not as a command. globalOpCounters.gotGetMore(); - auto result = reply->getBodyBuilder(); auto curOp = CurOp::get(opCtx); curOp->debug().cursorid = _request.cursorid; @@ -428,7 +427,8 @@ public: } CursorId respondWithId = 0; - CursorResponseBuilder nextBatch(/*isInitialResponse*/ false, &result); + + CursorResponseBuilder nextBatch(reply, CursorResponseBuilder::Options()); BSONObj obj; PlanExecutor::ExecState state = PlanExecutor::ADVANCED; long long numResults = 0; diff --git a/src/mongo/db/commands/pipeline_command.cpp b/src/mongo/db/commands/pipeline_command.cpp index a7096773104..54ecc3df1ab 100644 --- a/src/mongo/db/commands/pipeline_command.cpp +++ b/src/mongo/db/commands/pipeline_command.cpp @@ -79,7 +79,6 @@ public: } void run(OperationContext* opCtx, rpc::ReplyBuilderInterface* reply) override { - auto bob = reply->getBodyBuilder(); const auto aggregationRequest = uassertStatusOK( AggregationRequest::parseFromBSON(_dbName, _request.body, boost::none)); @@ -87,7 +86,7 @@ public: aggregationRequest.getNamespaceString(), aggregationRequest, _request.body, - bob)); + reply)); } NamespaceString ns() const override { @@ -96,7 +95,7 @@ public: void explain(OperationContext* opCtx, ExplainOptions::Verbosity verbosity, - BSONObjBuilder* out) override { + rpc::ReplyBuilderInterface* result) override { const auto aggregationRequest = uassertStatusOK( AggregationRequest::parseFromBSON(_dbName, _request.body, verbosity)); @@ -104,7 +103,7 @@ public: aggregationRequest.getNamespaceString(), aggregationRequest, _request.body, - *out)); + result)); } void doCheckAuthorization(OperationContext* opCtx) const override { diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp index 5e00d3f867c..60efa126c3c 100644 --- a/src/mongo/db/commands/run_aggregate.cpp +++ b/src/mongo/db/commands/run_aggregate.cpp @@ -91,7 +91,7 @@ bool handleCursorCommand(OperationContext* opCtx, const NamespaceString& nsForCursor, std::vector<ClientCursor*> cursors, const AggregationRequest& request, - BSONObjBuilder& result) { + rpc::ReplyBuilderInterface* result) { invariant(!cursors.empty()); long long batchSize = request.getBatchSize(); @@ -121,12 +121,15 @@ bool handleCursorCommand(OperationContext* opCtx, cursors[idx]->getExecutor()->detachFromOperationContext(); } - result.appendArray("cursors", cursorsBuilder.obj()); + auto bodyBuilder = result->getBodyBuilder(); + bodyBuilder.appendArray("cursors", cursorsBuilder.obj()); return true; } - CursorResponseBuilder responseBuilder(true, &result); + CursorResponseBuilder::Options options; + options.isInitialResponse = true; + CursorResponseBuilder responseBuilder(result, options); ClientCursor* cursor = cursors[0]; invariant(cursor); @@ -345,7 +348,7 @@ Status runAggregate(OperationContext* opCtx, const NamespaceString& origNss, const AggregationRequest& request, const BSONObj& cmdObj, - BSONObjBuilder& result) { + rpc::ReplyBuilderInterface* result) { // For operations on views, this will be the underlying namespace. NamespaceString nss = request.getNamespaceString(); @@ -611,8 +614,9 @@ Status runAggregate(OperationContext* opCtx, // If both explain and cursor are specified, explain wins. if (expCtx->explain) { + auto bodyBuilder = result->getBodyBuilder(); Explain::explainPipelineExecutor( - pins[0].getCursor()->getExecutor(), *(expCtx->explain), &result); + pins[0].getCursor()->getExecutor(), *(expCtx->explain), &bodyBuilder); } else { // Cursor must be specified, if explain is not. const bool keepCursor = diff --git a/src/mongo/db/commands/run_aggregate.h b/src/mongo/db/commands/run_aggregate.h index 1412768ddcf..75212efc22c 100644 --- a/src/mongo/db/commands/run_aggregate.h +++ b/src/mongo/db/commands/run_aggregate.h @@ -33,6 +33,7 @@ #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" #include "mongo/db/pipeline/aggregation_request.h" +#include "mongo/rpc/op_msg_rpc_impls.h" namespace mongo { @@ -48,6 +49,6 @@ Status runAggregate(OperationContext* opCtx, const NamespaceString& nss, const AggregationRequest& request, const BSONObj& cmdObj, - BSONObjBuilder& result); + rpc::ReplyBuilderInterface* result); } // namespace mongo diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp index 145cd247301..82823e3cfcc 100644 --- a/src/mongo/db/commands/user_management_commands.cpp +++ b/src/mongo/db/commands/user_management_commands.cpp @@ -1371,16 +1371,18 @@ public: DBDirectClient client(opCtx); - BSONObjBuilder responseBuilder; + rpc::OpMsgReplyBuilder replyBuilder; AggregationRequest aggRequest(AuthorizationManager::usersCollectionNamespace, std::move(pipeline)); uassertStatusOK(runAggregate(opCtx, AuthorizationManager::usersCollectionNamespace, aggRequest, aggRequest.serializeToCommandObj().toBson(), - responseBuilder)); - CommandHelpers::appendSimpleCommandStatus(responseBuilder, true); - auto response = CursorResponse::parseFromBSONThrowing(responseBuilder.obj()); + &replyBuilder)); + auto bodyBuilder = replyBuilder.getBodyBuilder(); + CommandHelpers::appendSimpleCommandStatus(bodyBuilder, true); + bodyBuilder.doneFast(); + auto response = CursorResponse::parseFromBSONThrowing(replyBuilder.releaseBody()); DBClientCursor cursor(&client, response.getNSS().toString(), response.getCursorId(), diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp index 49e90ff0899..35d2e0ec53b 100644 --- a/src/mongo/db/commands/write_commands/write_commands.cpp +++ b/src/mongo/db/commands/write_commands/write_commands.cpp @@ -350,7 +350,7 @@ private: void explain(OperationContext* opCtx, ExplainOptions::Verbosity verbosity, - BSONObjBuilder* out) override { + rpc::ReplyBuilderInterface* result) override { uassert(ErrorCodes::InvalidLength, "explained write batches must be of size 1", _batch.getUpdates().size() == 1); @@ -376,7 +376,8 @@ private: auto exec = uassertStatusOK(getExecutorUpdate( opCtx, &CurOp::get(opCtx)->debug(), collection.getCollection(), &parsedUpdate)); - Explain::explainStages(exec.get(), collection.getCollection(), verbosity, out); + auto bodyBuilder = result->getBodyBuilder(); + Explain::explainStages(exec.get(), collection.getCollection(), verbosity, &bodyBuilder); } write_ops::Update _batch; @@ -426,7 +427,7 @@ private: void explain(OperationContext* opCtx, ExplainOptions::Verbosity verbosity, - BSONObjBuilder* out) override { + rpc::ReplyBuilderInterface* result) override { uassert(ErrorCodes::InvalidLength, "explained write batches must be of size 1", _batch.getDeletes().size() == 1); @@ -448,7 +449,8 @@ private: // Explain the plan tree. auto exec = uassertStatusOK(getExecutorDelete( opCtx, &CurOp::get(opCtx)->debug(), collection.getCollection(), &parsedDelete)); - Explain::explainStages(exec.get(), collection.getCollection(), verbosity, out); + auto bodyBuilder = result->getBodyBuilder(); + Explain::explainStages(exec.get(), collection.getCollection(), verbosity, &bodyBuilder); } write_ops::Delete _batch; |