summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands.cpp
diff options
context:
space:
mode:
authorAnthony Roy <anthony.roy@10gen.com>2018-06-19 17:53:48 -0400
committerAnthony Roy <anthony.roy@10gen.com>2018-07-05 17:43:25 -0400
commitf78056a8f1f5ea6af23bd68123659b714233b370 (patch)
treeca9bf843fec69e4ba687bdee55dade490b5ac246 /src/mongo/db/commands.cpp
parent173ac70346990e4cf9b2720f86697785b8795967 (diff)
downloadmongo-f78056a8f1f5ea6af23bd68123659b714233b370.tar.gz
SERVER-35460 Replaced CommandReplyBuilder with direct usage of ReplyBuilderInterface
This is to provide access to DocumentSequence returns.
Diffstat (limited to 'src/mongo/db/commands.cpp')
-rw-r--r--src/mongo/db/commands.cpp34
1 files changed, 9 insertions, 25 deletions
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp
index 87f02341918..b020d29eee0 100644
--- a/src/mongo/db/commands.cpp
+++ b/src/mongo/db/commands.cpp
@@ -50,6 +50,9 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/server_parameters.h"
+#include "mongo/rpc/factory.h"
+#include "mongo/rpc/op_msg_rpc_impls.h"
+#include "mongo/rpc/protocol.h"
#include "mongo/rpc/write_concern_error_detail.h"
#include "mongo/s/stale_exception.h"
#include "mongo/util/invariant.h"
@@ -109,22 +112,21 @@ bool checkAuthorizationImplPreParse(OperationContext* opCtx,
BSONObj CommandHelpers::runCommandDirectly(OperationContext* opCtx, const OpMsgRequest& request) {
auto command = globalCommandRegistry()->findCommand(request.getCommandName());
invariant(command);
- BufBuilder bb;
- CommandReplyBuilder crb(BSONObjBuilder{bb});
+ rpc::OpMsgReplyBuilder replyBuilder;
try {
auto invocation = command->parse(opCtx, request);
- invocation->run(opCtx, &crb);
- auto body = crb.getBodyBuilder();
+ invocation->run(opCtx, &replyBuilder);
+ auto body = replyBuilder.getBodyBuilder();
CommandHelpers::extractOrAppendOk(body);
} catch (const StaleConfigException&) {
// These exceptions are intended to be handled at a higher level.
throw;
} catch (const DBException& ex) {
- auto body = crb.getBodyBuilder();
+ auto body = replyBuilder.getBodyBuilder();
body.resetToEmpty();
appendCommandStatusNoThrow(body, ex.toStatus());
}
- return BSONObj(bb.release());
+ return replyBuilder.releaseBody();
}
void CommandHelpers::auditLogAuthEvent(OperationContext* opCtx,
@@ -380,24 +382,6 @@ bool CommandHelpers::uassertShouldAttemptParse(OperationContext* opCtx,
constexpr StringData CommandHelpers::kHelpFieldName;
//////////////////////////////////////////////////////////////
-// CommandReplyBuilder
-
-CommandReplyBuilder::CommandReplyBuilder(BSONObjBuilder bodyObj)
- : _bodyBuf(&bodyObj.bb()), _bodyOffset(bodyObj.offset()) {
- // CommandReplyBuilder requires that bodyObj build into an externally-owned buffer.
- invariant(!bodyObj.owned());
- bodyObj.doneFast();
-}
-
-BSONObjBuilder CommandReplyBuilder::getBodyBuilder() const {
- return BSONObjBuilder(BSONObjBuilder::ResumeBuildingTag{}, *_bodyBuf, _bodyOffset);
-}
-
-void CommandReplyBuilder::reset() {
- getBodyBuilder().resetToEmpty();
-}
-
-//////////////////////////////////////////////////////////////
// CommandInvocation
CommandInvocation::~CommandInvocation() = default;
@@ -443,7 +427,7 @@ public:
_dbName(_request->getDatabase().toString()) {}
private:
- void run(OperationContext* opCtx, CommandReplyBuilder* result) override {
+ void run(OperationContext* opCtx, rpc::ReplyBuilderInterface* result) override {
try {
BSONObjBuilder bob = result->getBodyBuilder();
bool ok = _command->run(opCtx, _dbName, _request->body, bob);