diff options
author | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2018-03-05 09:49:29 -0500 |
---|---|---|
committer | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2018-03-05 12:23:39 -0500 |
commit | 74177edb35b6ce7594e4751051010ceade592484 (patch) | |
tree | 3dad385af5647a24291e8ab26ca3fdcf164e5dfd /src/mongo/s/commands | |
parent | 9a364b4c60a3f249947468a918071e3bf586dabc (diff) | |
download | mongo-74177edb35b6ce7594e4751051010ceade592484.tar.gz |
Revert "SERVER-33065 CommandReplyBuilder and CommandInvocation"
This reverts commit ad94e51e0dd40b0d0c38215a36caf75a4be48415.
Diffstat (limited to 'src/mongo/s/commands')
-rw-r--r-- | src/mongo/s/commands/cluster_count_cmd.cpp | 5 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_distinct_cmd.cpp | 5 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_explain_cmd.cpp | 10 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_find_and_modify_cmd.cpp | 5 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_find_cmd.cpp | 5 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_pipeline_cmd.cpp | 5 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_write_cmd.cpp | 13 | ||||
-rw-r--r-- | src/mongo/s/commands/commands_public.cpp | 5 | ||||
-rw-r--r-- | src/mongo/s/commands/strategy.cpp | 62 |
9 files changed, 52 insertions, 63 deletions
diff --git a/src/mongo/s/commands/cluster_count_cmd.cpp b/src/mongo/s/commands/cluster_count_cmd.cpp index bac5ee5d969..794cf1d9fb3 100644 --- a/src/mongo/s/commands/cluster_count_cmd.cpp +++ b/src/mongo/s/commands/cluster_count_cmd.cpp @@ -218,11 +218,10 @@ public: } Status explain(OperationContext* opCtx, - const OpMsgRequest& request, + const std::string& dbname, + const BSONObj& cmdObj, ExplainOptions::Verbosity verbosity, BSONObjBuilder* out) const override { - std::string dbname = request.getDatabase().toString(); - const BSONObj& cmdObj = request.body; const NamespaceString nss(parseNs(dbname, cmdObj)); uassert(ErrorCodes::InvalidNamespace, str::stream() << "Invalid namespace specified '" << nss.ns() << "'", diff --git a/src/mongo/s/commands/cluster_distinct_cmd.cpp b/src/mongo/s/commands/cluster_distinct_cmd.cpp index 9787476f035..1fb071ea75c 100644 --- a/src/mongo/s/commands/cluster_distinct_cmd.cpp +++ b/src/mongo/s/commands/cluster_distinct_cmd.cpp @@ -78,11 +78,10 @@ public: } Status explain(OperationContext* opCtx, - const OpMsgRequest& opMsgRequest, + const std::string& dbname, + const BSONObj& cmdObj, ExplainOptions::Verbosity verbosity, BSONObjBuilder* out) const override { - std::string dbname = opMsgRequest.getDatabase().toString(); - const BSONObj& cmdObj = opMsgRequest.body; const NamespaceString nss(parseNs(dbname, cmdObj)); auto targetingQuery = extractQuery(cmdObj); diff --git a/src/mongo/s/commands/cluster_explain_cmd.cpp b/src/mongo/s/commands/cluster_explain_cmd.cpp index d6b249e7e36..058beee615c 100644 --- a/src/mongo/s/commands/cluster_explain_cmd.cpp +++ b/src/mongo/s/commands/cluster_explain_cmd.cpp @@ -147,9 +147,13 @@ public: } // Actually call the nested command's explain(...) method. - commToExplain->parse(opCtx, OpMsgRequest{OpMsg{explainObj}}) - ->explain(opCtx, verbosity.getValue(), &result); - return CommandHelpers::extractOrAppendOk(result); + Status explainStatus = + commToExplain->explain(opCtx, dbName, explainObj, verbosity.getValue(), &result); + if (!explainStatus.isOK()) { + return CommandHelpers::appendCommandStatus(result, explainStatus); + } + + return true; } } cmdExplainCluster; diff --git a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp index 744b2e0feb1..8a6799d8264 100644 --- a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp +++ b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp @@ -97,11 +97,10 @@ public: } Status explain(OperationContext* opCtx, - const OpMsgRequest& request, + const std::string& dbName, + const BSONObj& cmdObj, ExplainOptions::Verbosity verbosity, BSONObjBuilder* out) const override { - std::string dbName = request.getDatabase().toString(); - const BSONObj& cmdObj = request.body; const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbName, cmdObj)); auto routingInfo = diff --git a/src/mongo/s/commands/cluster_find_cmd.cpp b/src/mongo/s/commands/cluster_find_cmd.cpp index fca5dedd52c..65e26656b33 100644 --- a/src/mongo/s/commands/cluster_find_cmd.cpp +++ b/src/mongo/s/commands/cluster_find_cmd.cpp @@ -98,11 +98,10 @@ public: } Status explain(OperationContext* opCtx, - const OpMsgRequest& request, + const std::string& dbname, + const BSONObj& cmdObj, ExplainOptions::Verbosity verbosity, BSONObjBuilder* out) const final { - std::string dbname = request.getDatabase().toString(); - const BSONObj& cmdObj = request.body; const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbname, cmdObj)); // Parse the command BSON to a QueryRequest. bool isExplain = true; diff --git a/src/mongo/s/commands/cluster_pipeline_cmd.cpp b/src/mongo/s/commands/cluster_pipeline_cmd.cpp index 816c94ec087..600a0e558c3 100644 --- a/src/mongo/s/commands/cluster_pipeline_cmd.cpp +++ b/src/mongo/s/commands/cluster_pipeline_cmd.cpp @@ -75,11 +75,10 @@ public: } Status explain(OperationContext* opCtx, - const OpMsgRequest& request, + const std::string& dbname, + const BSONObj& cmdObj, ExplainOptions::Verbosity verbosity, BSONObjBuilder* out) const override { - std::string dbname = request.getDatabase().toString(); - const BSONObj& cmdObj = request.body; return _runAggCommand(opCtx, dbname, cmdObj, verbosity, out); } diff --git a/src/mongo/s/commands/cluster_write_cmd.cpp b/src/mongo/s/commands/cluster_write_cmd.cpp index 11130f2d4ec..516cc2d7b82 100644 --- a/src/mongo/s/commands/cluster_write_cmd.cpp +++ b/src/mongo/s/commands/cluster_write_cmd.cpp @@ -160,9 +160,14 @@ public: } Status explain(OperationContext* opCtx, - const OpMsgRequest& request, + const std::string& dbname, + const BSONObj& cmdObj, ExplainOptions::Verbosity verbosity, BSONObjBuilder* out) const final { + OpMsgRequest request; + request.body = cmdObj; + invariant(request.getDatabase() == dbname); // Ensured by explain command's run() method. + const auto batchedRequest(parseRequest(_writeType, request)); // We can only explain write batches of size 1. @@ -170,7 +175,7 @@ public: return Status(ErrorCodes::InvalidLength, "explained write batches must be of size 1"); } - const auto explainCmd = ClusterExplain::wrapAsExplain(request.body, verbosity); + const auto explainCmd = ClusterExplain::wrapAsExplain(cmdObj, verbosity); // We will time how long it takes to run the commands on the shards. Timer timer; @@ -178,8 +183,8 @@ public: // Target the command to the shards based on the singleton batch item. BatchItemRef targetingBatchItem(&batchedRequest, 0); std::vector<Strategy::CommandResult> shardResults; - Status status = _commandOpWrite( - opCtx, request.getDatabase().toString(), explainCmd, targetingBatchItem, &shardResults); + Status status = + _commandOpWrite(opCtx, dbname, explainCmd, targetingBatchItem, &shardResults); if (!status.isOK()) { return status; } diff --git a/src/mongo/s/commands/commands_public.cpp b/src/mongo/s/commands/commands_public.cpp index 0188f00f132..54499f66924 100644 --- a/src/mongo/s/commands/commands_public.cpp +++ b/src/mongo/s/commands/commands_public.cpp @@ -626,11 +626,10 @@ public: } Status explain(OperationContext* opCtx, - const OpMsgRequest& request, + const std::string& dbname, + const BSONObj& cmdObj, ExplainOptions::Verbosity verbosity, BSONObjBuilder* out) const override { - std::string dbname = request.getDatabase().toString(); - const BSONObj& cmdObj = request.body; // We will time how long it takes to run the commands on the shards. Timer timer; BSONObj command = ClusterExplain::wrapAsExplain(cmdObj, verbosity); diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp index c9e9276764d..6a10b1b6856 100644 --- a/src/mongo/s/commands/strategy.cpp +++ b/src/mongo/s/commands/strategy.cpp @@ -145,11 +145,8 @@ void appendRequiredFieldsToResponse(OperationContext* opCtx, BSONObjBuilder* res void execCommandClient(OperationContext* opCtx, Command* c, const OpMsgRequest& request, - CommandReplyBuilder* result) { - ON_BLOCK_EXIT([opCtx, &result] { - auto body = result->getBodyBuilder(); - appendRequiredFieldsToResponse(opCtx, &body); - }); + BSONObjBuilder& result) { + ON_BLOCK_EXIT([opCtx, &result] { appendRequiredFieldsToResponse(opCtx, &result); }); const auto dbname = request.getDatabase(); uassert(ErrorCodes::IllegalOperation, @@ -164,10 +161,10 @@ void execCommandClient(OperationContext* opCtx, StringData fieldName = element.fieldNameStringData(); if (fieldName == "help" && element.type() == Bool && element.Bool()) { std::stringstream help; - help << "help for: " << c->getName() << " " << c->help(); - auto body = result->getBodyBuilder(); - body.append("help", help.str()); - CommandHelpers::appendCommandStatus(body, true, ""); + help << "help for: " << c->getName() << " "; + help << c->help(); + result.append("help", help.str()); + CommandHelpers::appendCommandStatus(result, true, ""); return; } @@ -179,8 +176,7 @@ void execCommandClient(OperationContext* opCtx, Status status = Command::checkAuthorization(c, opCtx, request); if (!status.isOK()) { - auto body = result->getBodyBuilder(); - CommandHelpers::appendCommandStatus(body, status); + CommandHelpers::appendCommandStatus(result, status); return; } @@ -193,35 +189,29 @@ void execCommandClient(OperationContext* opCtx, StatusWith<WriteConcernOptions> wcResult = WriteConcernOptions::extractWCFromCommand(request.body); if (!wcResult.isOK()) { - auto body = result->getBodyBuilder(); - CommandHelpers::appendCommandStatus(body, wcResult.getStatus()); + CommandHelpers::appendCommandStatus(result, wcResult.getStatus()); return; } - auto invocation = c->parse(opCtx, request); - - bool supportsWriteConcern = invocation->supportsWriteConcern(); + bool supportsWriteConcern = c->supportsWriteConcern(request.body); if (!supportsWriteConcern && !wcResult.getValue().usedDefault) { // This command doesn't do writes so it should not be passed a writeConcern. // If we did not use the default writeConcern, one was provided when it shouldn't have // been by the user. - auto body = result->getBodyBuilder(); CommandHelpers::appendCommandStatus( - body, Status(ErrorCodes::InvalidOptions, "Command does not support writeConcern")); + result, Status(ErrorCodes::InvalidOptions, "Command does not support writeConcern")); return; } repl::ReadConcernArgs readConcernArgs; auto readConcernParseStatus = readConcernArgs.initialize(request.body); if (!readConcernParseStatus.isOK()) { - auto body = result->getBodyBuilder(); - CommandHelpers::appendCommandStatus(body, readConcernParseStatus); + CommandHelpers::appendCommandStatus(result, readConcernParseStatus); return; } if (readConcernArgs.getLevel() == repl::ReadConcernLevel::kSnapshotReadConcern) { - auto body = result->getBodyBuilder(); CommandHelpers::appendCommandStatus( - body, + result, Status(ErrorCodes::InvalidOptions, "read concern snapshot is not supported on mongos")); return; } @@ -233,26 +223,25 @@ void execCommandClient(OperationContext* opCtx, auto metadataStatus = processCommandMetadata(opCtx, request.body); if (!metadataStatus.isOK()) { - auto body = result->getBodyBuilder(); - CommandHelpers::appendCommandStatus(body, metadataStatus); + CommandHelpers::appendCommandStatus(result, metadataStatus); return; } + bool ok = false; if (!supportsWriteConcern) { - invocation->run(opCtx, result); + ok = c->publicRun(opCtx, request, result); } else { // Change the write concern while running the command. const auto oldWC = opCtx->getWriteConcern(); ON_BLOCK_EXIT([&] { opCtx->setWriteConcern(oldWC); }); opCtx->setWriteConcern(wcResult.getValue()); - invocation->run(opCtx, result); + ok = c->publicRun(opCtx, request, result); } - auto body = result->getBodyBuilder(); - bool ok = CommandHelpers::extractOrAppendOk(body); if (!ok) { c->incrementCommandsFailed(); } + CommandHelpers::appendCommandStatus(result, ok); } void runCommand(OperationContext* opCtx, const OpMsgRequest& request, BSONObjBuilder&& builder) { @@ -281,13 +270,12 @@ void runCommand(OperationContext* opCtx, const OpMsgRequest& request, BSONObjBui initializeOperationSessionInfo(opCtx, request.body, command->requiresAuth(), true, true); - CommandReplyBuilder crb(std::move(builder)); - int loops = 5; + while (true) { - crb.reset(); + builder.resetToEmpty(); try { - execCommandClient(opCtx, command, request, &crb); + execCommandClient(opCtx, command, request, builder); return; } catch (const StaleConfigException& e) { if (e->getns().empty()) { @@ -313,11 +301,10 @@ void runCommand(OperationContext* opCtx, const OpMsgRequest& request, BSONObjBui continue; } catch (const DBException& e) { - crb.reset(); - BSONObjBuilder bob = crb.getBodyBuilder(); - ON_BLOCK_EXIT([&] { appendRequiredFieldsToResponse(opCtx, &bob); }); + ON_BLOCK_EXIT([opCtx, &builder] { appendRequiredFieldsToResponse(opCtx, &builder); }); + builder.resetToEmpty(); command->incrementCommandsFailed(); - CommandHelpers::appendCommandStatus(bob, e.toStatus()); + CommandHelpers::appendCommandStatus(builder, e.toStatus()); LastError::get(opCtx->getClient()).setLastError(e.code(), e.reason()); return; } @@ -590,7 +577,6 @@ void Strategy::killCursors(OperationContext* opCtx, DbMessage* dbm) { } void Strategy::writeOp(OperationContext* opCtx, DbMessage* dbm) { - BufBuilder bb; runCommand(opCtx, [&]() { const auto& msg = dbm->msg(); @@ -609,7 +595,7 @@ void Strategy::writeOp(OperationContext* opCtx, DbMessage* dbm) { MONGO_UNREACHABLE; } }(), - BSONObjBuilder{bb}); // built object is ignored + BSONObjBuilder()); } void Strategy::explainFind(OperationContext* opCtx, |