summaryrefslogtreecommitdiff
path: root/src/mongo/s
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2018-04-24 16:58:23 -0400
committerMathias Stearn <mathias@10gen.com>2018-05-08 14:57:37 -0400
commit589af3820b00ed0b7ac26a84cfeed6554ab191f3 (patch)
treebb393adad8b1ca4f6f0e23c035141e829e3eeee6 /src/mongo/s
parent98f28d452b9b330d6c1696d6d8207b582a5870fc (diff)
downloadmongo-589af3820b00ed0b7ac26a84cfeed6554ab191f3.tar.gz
SERVER-34628 Prep for removing appendCommandStatus
* Added appendCommandStatusNoThrow matching the current aCS behavior * Make appendCommandStatus call uassertStatusOK then aCS on success * Make the few places that need to not throw call aCSNT A following commit will completely remove appendCommandStatus. It is split out because that commit is fairly huge.
Diffstat (limited to 'src/mongo/s')
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client_impl.cpp14
-rw-r--r--src/mongo/s/catalog/sharding_catalog_log_change_test.cpp4
-rw-r--r--src/mongo/s/catalog/sharding_catalog_test.cpp32
-rw-r--r--src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp15
-rw-r--r--src/mongo/s/commands/cluster_aggregate_test.cpp2
-rw-r--r--src/mongo/s/commands/cluster_commands_helpers.cpp2
-rw-r--r--src/mongo/s/commands/cluster_explain.cpp2
-rw-r--r--src/mongo/s/commands/cluster_get_last_error_cmd.cpp2
-rw-r--r--src/mongo/s/commands/cluster_multicast.cpp2
-rw-r--r--src/mongo/s/commands/cluster_write_cmd.cpp2
-rw-r--r--src/mongo/s/commands/strategy.cpp24
-rw-r--r--src/mongo/s/query/cluster_find_test.cpp2
-rw-r--r--src/mongo/s/sharding_router_test_fixture.cpp2
-rw-r--r--src/mongo/s/write_ops/batch_write_exec_test.cpp32
-rw-r--r--src/mongo/s/write_ops/batched_command_response_test.cpp19
15 files changed, 82 insertions, 74 deletions
diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
index 8987bc20c41..5175e44a1c9 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
@@ -657,12 +657,12 @@ bool ShardingCatalogClientImpl::runUserManagementWriteCommand(OperationContext*
if (initialCmdHadWriteConcern) {
Status status = writeConcern.parse(writeConcernElement.Obj());
if (!status.isOK()) {
- return CommandHelpers::appendCommandStatus(*result, status);
+ return CommandHelpers::appendCommandStatusNoThrow(*result, status);
}
if (!(writeConcern.wNumNodes == 1 ||
writeConcern.wMode == WriteConcernOptions::kMajority)) {
- return CommandHelpers::appendCommandStatus(
+ return CommandHelpers::appendCommandStatusNoThrow(
*result,
{ErrorCodes::InvalidOptions,
str::stream() << "Invalid replication write concern. User management write "
@@ -701,13 +701,15 @@ bool ShardingCatalogClientImpl::runUserManagementWriteCommand(OperationContext*
Shard::RetryPolicy::kNotIdempotent);
if (!response.isOK()) {
- return CommandHelpers::appendCommandStatus(*result, response.getStatus());
+ return CommandHelpers::appendCommandStatusNoThrow(*result, response.getStatus());
}
if (!response.getValue().commandStatus.isOK()) {
- return CommandHelpers::appendCommandStatus(*result, response.getValue().commandStatus);
+ return CommandHelpers::appendCommandStatusNoThrow(*result,
+ response.getValue().commandStatus);
}
if (!response.getValue().writeConcernStatus.isOK()) {
- return CommandHelpers::appendCommandStatus(*result, response.getValue().writeConcernStatus);
+ return CommandHelpers::appendCommandStatusNoThrow(*result,
+ response.getValue().writeConcernStatus);
}
CommandHelpers::filterCommandReplyForPassthrough(response.getValue().response, result);
@@ -731,7 +733,7 @@ bool ShardingCatalogClientImpl::runUserManagementReadCommand(OperationContext* o
return resultStatus.getValue().commandStatus.isOK();
}
- return CommandHelpers::appendCommandStatus(*result, resultStatus.getStatus());
+ return CommandHelpers::appendCommandStatusNoThrow(*result, resultStatus.getStatus()); // XXX
}
Status ShardingCatalogClientImpl::applyChunkOpsDeprecated(OperationContext* opCtx,
diff --git a/src/mongo/s/catalog/sharding_catalog_log_change_test.cpp b/src/mongo/s/catalog/sharding_catalog_log_change_test.cpp
index 429a11ec39b..124b148cde6 100644
--- a/src/mongo/s/catalog/sharding_catalog_log_change_test.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_log_change_test.cpp
@@ -109,7 +109,7 @@ protected:
});
BSONObjBuilder createResponseBuilder;
- CommandHelpers::appendCommandStatus(
+ CommandHelpers::appendCommandStatusNoThrow(
createResponseBuilder, Status(ErrorCodes::NamespaceExists, "coll already exists"));
expectConfigCollectionCreate(
configHost, getConfigCollName(), _cappedSize, createResponseBuilder.obj());
@@ -146,7 +146,7 @@ protected:
});
BSONObjBuilder createResponseBuilder;
- CommandHelpers::appendCommandStatus(
+ CommandHelpers::appendCommandStatusNoThrow(
createResponseBuilder, Status(ErrorCodes::ExceededTimeLimit, "operation timed out"));
expectConfigCollectionCreate(
configHost, getConfigCollName(), _cappedSize, createResponseBuilder.obj());
diff --git a/src/mongo/s/catalog/sharding_catalog_test.cpp b/src/mongo/s/catalog/sharding_catalog_test.cpp
index dd844ddb41d..c8a15fb5c36 100644
--- a/src/mongo/s/catalog/sharding_catalog_test.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_test.cpp
@@ -588,7 +588,7 @@ TEST_F(ShardingCatalogClientTest, RunUserManagementWriteCommandSuccess) {
rpc::TrackingMetadata::removeTrackingData(request.metadata));
BSONObjBuilder responseBuilder;
- CommandHelpers::appendCommandStatus(
+ CommandHelpers::appendCommandStatusNoThrow(
responseBuilder, Status(ErrorCodes::UserNotFound, "User test@test not found"));
return responseBuilder.obj();
});
@@ -661,7 +661,7 @@ TEST_F(ShardingCatalogClientTest, RunUserManagementWriteCommandRewriteWriteConce
rpc::TrackingMetadata::removeTrackingData(request.metadata));
BSONObjBuilder responseBuilder;
- CommandHelpers::appendCommandStatus(
+ CommandHelpers::appendCommandStatusNoThrow(
responseBuilder, Status(ErrorCodes::UserNotFound, "User test@test not found"));
return responseBuilder.obj();
});
@@ -690,8 +690,8 @@ TEST_F(ShardingCatalogClientTest, RunUserManagementWriteCommandNotMaster) {
for (int i = 0; i < 3; ++i) {
onCommand([](const RemoteCommandRequest& request) {
BSONObjBuilder responseBuilder;
- CommandHelpers::appendCommandStatus(responseBuilder,
- Status(ErrorCodes::NotMaster, "not master"));
+ CommandHelpers::appendCommandStatusNoThrow(responseBuilder,
+ Status(ErrorCodes::NotMaster, "not master"));
return responseBuilder.obj();
});
}
@@ -724,8 +724,8 @@ TEST_F(ShardingCatalogClientTest, RunUserManagementWriteCommandNotMasterRetrySuc
ASSERT_EQUALS(host1, request.target);
BSONObjBuilder responseBuilder;
- CommandHelpers::appendCommandStatus(responseBuilder,
- Status(ErrorCodes::NotMaster, "not master"));
+ CommandHelpers::appendCommandStatusNoThrow(responseBuilder,
+ Status(ErrorCodes::NotMaster, "not master"));
// Ensure that when the catalog manager tries to retarget after getting the
// NotMaster response, it will get back a new target.
@@ -1126,12 +1126,18 @@ TEST_F(ShardingCatalogClientTest, UpdateDatabaseExceededTimeLimit) {
});
onCommand([host1](const RemoteCommandRequest& request) {
- ASSERT_EQUALS(host1, request.target);
+ try {
+ ASSERT_EQUALS(host1, request.target);
- BatchedCommandResponse response;
- response.setStatus({ErrorCodes::ExceededTimeLimit, "operation timed out"});
+ BatchedCommandResponse response;
+ response.setStatus({ErrorCodes::ExceededTimeLimit, "operation timed out"});
- return response.toBSON();
+ return response.toBSON();
+ } catch (const DBException& ex) {
+ BSONObjBuilder bb;
+ CommandHelpers::appendCommandStatusNoThrow(bb, ex.toStatus());
+ return bb.obj();
+ }
});
// Now wait for the updateDatabase call to return
@@ -1211,7 +1217,7 @@ TEST_F(ShardingCatalogClientTest, ApplyChunkOpsDeprecatedSuccessfulWithCheck) {
onCommand([&](const RemoteCommandRequest& request) {
BSONObjBuilder responseBuilder;
- CommandHelpers::appendCommandStatus(
+ CommandHelpers::appendCommandStatusNoThrow(
responseBuilder, Status(ErrorCodes::DuplicateKey, "precondition failed"));
return responseBuilder.obj();
});
@@ -1259,8 +1265,8 @@ TEST_F(ShardingCatalogClientTest, ApplyChunkOpsDeprecatedFailedWithCheck) {
onCommand([&](const RemoteCommandRequest& request) {
BSONObjBuilder responseBuilder;
- CommandHelpers::appendCommandStatus(responseBuilder,
- Status(ErrorCodes::NoMatchingDocument, "some error"));
+ CommandHelpers::appendCommandStatusNoThrow(
+ responseBuilder, Status(ErrorCodes::NoMatchingDocument, "some error"));
return responseBuilder.obj();
});
diff --git a/src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp b/src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp
index e15217ade8e..061d3bee333 100644
--- a/src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_write_retry_test.cpp
@@ -368,10 +368,9 @@ TEST_F(UpdateRetryTest, NotMasterErrorReturnedPersistently) {
for (int i = 0; i < 3; ++i) {
onCommand([](const RemoteCommandRequest& request) {
- BatchedCommandResponse response;
- response.setStatus({ErrorCodes::NotMaster, "not master"});
-
- return response.toBSON();
+ BSONObjBuilder bb;
+ CommandHelpers::appendCommandStatusNoThrow(bb, {ErrorCodes::NotMaster, "not master"});
+ return bb.obj();
});
}
@@ -430,13 +429,13 @@ TEST_F(UpdateRetryTest, NotMasterOnceSuccessAfterRetry) {
onCommand([&](const RemoteCommandRequest& request) {
ASSERT_EQUALS(host1, request.target);
- BatchedCommandResponse response;
- response.setStatus({ErrorCodes::NotMaster, "not master"});
-
// Ensure that when the catalog manager tries to retarget after getting the
// NotMaster response, it will get back a new target.
configTargeter()->setFindHostReturnValue(host2);
- return response.toBSON();
+
+ BSONObjBuilder bb;
+ CommandHelpers::appendCommandStatusNoThrow(bb, {ErrorCodes::NotMaster, "not master"});
+ return bb.obj();
});
onCommand([&](const RemoteCommandRequest& request) {
diff --git a/src/mongo/s/commands/cluster_aggregate_test.cpp b/src/mongo/s/commands/cluster_aggregate_test.cpp
index c6b79c7d346..4cd178d7bcb 100644
--- a/src/mongo/s/commands/cluster_aggregate_test.cpp
+++ b/src/mongo/s/commands/cluster_aggregate_test.cpp
@@ -106,7 +106,7 @@ protected:
void expectAggReturnsError(ErrorCodes::Error code) {
onCommandForPoolExecutor([code](const executor::RemoteCommandRequest& request) {
BSONObjBuilder resBob;
- CommandHelpers::appendCommandStatus(resBob, Status(code, "dummy error"));
+ CommandHelpers::appendCommandStatusNoThrow(resBob, Status(code, "dummy error"));
return resBob.obj();
});
}
diff --git a/src/mongo/s/commands/cluster_commands_helpers.cpp b/src/mongo/s/commands/cluster_commands_helpers.cpp
index 9bdab8d5df0..777cbc141b8 100644
--- a/src/mongo/s/commands/cluster_commands_helpers.cpp
+++ b/src/mongo/s/commands/cluster_commands_helpers.cpp
@@ -350,7 +350,7 @@ bool appendRawResponses(OperationContext* opCtx,
// Convert the error status back into the form of a command result and append it as the
// raw response.
BSONObjBuilder statusObjBob;
- CommandHelpers::appendCommandStatus(statusObjBob, sendStatus);
+ CommandHelpers::appendCommandStatusNoThrow(statusObjBob, sendStatus);
subobj.append(shardConnStr, statusObjBob.obj());
errors.push_back(std::make_pair(shardConnStr, sendStatus));
diff --git a/src/mongo/s/commands/cluster_explain.cpp b/src/mongo/s/commands/cluster_explain.cpp
index a45043fe171..5b79d6e1f44 100644
--- a/src/mongo/s/commands/cluster_explain.cpp
+++ b/src/mongo/s/commands/cluster_explain.cpp
@@ -119,7 +119,7 @@ std::vector<Strategy::CommandResult> ClusterExplain::downconvert(
}
// Convert the error status back into the format of a command result.
BSONObjBuilder statusObjBob;
- CommandHelpers::appendCommandStatus(statusObjBob, status);
+ CommandHelpers::appendCommandStatusNoThrow(statusObjBob, status);
// Get the Shard object in order to get the ConnectionString.
auto shard =
diff --git a/src/mongo/s/commands/cluster_get_last_error_cmd.cpp b/src/mongo/s/commands/cluster_get_last_error_cmd.cpp
index f1e00de2930..8eab649a956 100644
--- a/src/mongo/s/commands/cluster_get_last_error_cmd.cpp
+++ b/src/mongo/s/commands/cluster_get_last_error_cmd.cpp
@@ -324,7 +324,7 @@ public:
// Need to always return err
result.appendNull("err");
- return CommandHelpers::appendCommandStatus(
+ return CommandHelpers::appendCommandStatusNoThrow(
result,
Status(ErrorCodes::WriteConcernFailed, "multiple write concern errors occurred"));
}
diff --git a/src/mongo/s/commands/cluster_multicast.cpp b/src/mongo/s/commands/cluster_multicast.cpp
index d80979bf03b..54991980075 100644
--- a/src/mongo/s/commands/cluster_multicast.cpp
+++ b/src/mongo/s/commands/cluster_multicast.cpp
@@ -132,7 +132,7 @@ public:
{
BSONObjBuilder subbob(bob.subobjStart(host.toString()));
- if (CommandHelpers::appendCommandStatus(subbob, response.status)) {
+ if (CommandHelpers::appendCommandStatusNoThrow(subbob, response.status)) {
subbob.append("data", response.data);
subbob.append("metadata", response.metadata);
if (response.elapsedMillis) {
diff --git a/src/mongo/s/commands/cluster_write_cmd.cpp b/src/mongo/s/commands/cluster_write_cmd.cpp
index 2e413ca0c09..84a4036fe1e 100644
--- a/src/mongo/s/commands/cluster_write_cmd.cpp
+++ b/src/mongo/s/commands/cluster_write_cmd.cpp
@@ -306,7 +306,7 @@ private:
try {
BSONObjBuilder bob = result->getBodyBuilder();
bool ok = runImpl(opCtx, *_request, _batchedRequest, bob);
- CommandHelpers::appendCommandStatus(bob, ok);
+ CommandHelpers::appendSimpleCommandStatus(bob, ok);
} catch (const ExceptionFor<ErrorCodes::Unauthorized>&) {
CommandHelpers::logAuthViolation(opCtx, this, *_request, ErrorCodes::Unauthorized);
throw;
diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp
index 612b5b61191..850ff70d14e 100644
--- a/src/mongo/s/commands/strategy.cpp
+++ b/src/mongo/s/commands/strategy.cpp
@@ -172,7 +172,7 @@ void execCommandClient(OperationContext* opCtx,
help << "help for: " << c->getName() << " " << c->help();
auto body = result->getBodyBuilder();
body.append("help", help.str());
- CommandHelpers::appendCommandStatus(body, true, "");
+ CommandHelpers::appendSimpleCommandStatus(body, true, "");
return;
}
@@ -186,7 +186,7 @@ void execCommandClient(OperationContext* opCtx,
invocation->checkAuthorization(opCtx, request);
} catch (const DBException& e) {
auto body = result->getBodyBuilder();
- CommandHelpers::appendCommandStatus(body, e.toStatus());
+ CommandHelpers::appendCommandStatusNoThrow(body, e.toStatus());
return;
}
@@ -200,7 +200,7 @@ void execCommandClient(OperationContext* opCtx,
WriteConcernOptions::extractWCFromCommand(request.body);
if (!wcResult.isOK()) {
auto body = result->getBodyBuilder();
- CommandHelpers::appendCommandStatus(body, wcResult.getStatus());
+ CommandHelpers::appendCommandStatusNoThrow(body, wcResult.getStatus());
return;
}
@@ -210,7 +210,7 @@ void execCommandClient(OperationContext* opCtx,
// 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(
+ CommandHelpers::appendCommandStatusNoThrow(
body, Status(ErrorCodes::InvalidOptions, "Command does not support writeConcern"));
return;
}
@@ -225,7 +225,7 @@ void execCommandClient(OperationContext* opCtx,
// TODO SERVER-33708.
if (!invocation->supportsReadConcern(readConcernArgs.getLevel())) {
auto body = result->getBodyBuilder();
- CommandHelpers::appendCommandStatus(
+ CommandHelpers::appendCommandStatusNoThrow(
body,
Status(ErrorCodes::InvalidOptions,
str::stream()
@@ -236,7 +236,7 @@ void execCommandClient(OperationContext* opCtx,
if (!opCtx->getTxnNumber()) {
auto body = result->getBodyBuilder();
- CommandHelpers::appendCommandStatus(
+ CommandHelpers::appendCommandStatusNoThrow(
body,
Status(ErrorCodes::InvalidOptions,
"read concern snapshot is supported only in a transaction"));
@@ -245,7 +245,7 @@ void execCommandClient(OperationContext* opCtx,
if (readConcernArgs.getArgsAtClusterTime()) {
auto body = result->getBodyBuilder();
- CommandHelpers::appendCommandStatus(
+ CommandHelpers::appendCommandStatusNoThrow(
body,
Status(ErrorCodes::InvalidOptions,
"read concern snapshot is not supported with atClusterTime on mongos"));
@@ -261,7 +261,7 @@ void execCommandClient(OperationContext* opCtx,
auto metadataStatus = processCommandMetadata(opCtx, request.body);
if (!metadataStatus.isOK()) {
auto body = result->getBodyBuilder();
- CommandHelpers::appendCommandStatus(body, metadataStatus);
+ CommandHelpers::appendCommandStatusNoThrow(body, metadataStatus);
return;
}
@@ -292,7 +292,7 @@ void runCommand(OperationContext* opCtx,
auto const command = CommandHelpers::findCommand(commandName);
if (!command) {
ON_BLOCK_EXIT([opCtx, &builder] { appendRequiredFieldsToResponse(opCtx, &builder); });
- CommandHelpers::appendCommandStatus(
+ CommandHelpers::appendCommandStatusNoThrow(
builder,
{ErrorCodes::CommandNotFound, str::stream() << "no such cmd: " << commandName});
globalCommandRegistry()->incrementUnknownCommands();
@@ -338,7 +338,7 @@ void runCommand(OperationContext* opCtx,
auto& readConcernArgs = repl::ReadConcernArgs::get(opCtx);
auto readConcernParseStatus = readConcernArgs.initialize(request.body);
if (!readConcernParseStatus.isOK()) {
- CommandHelpers::appendCommandStatus(builder, readConcernParseStatus);
+ CommandHelpers::appendCommandStatusNoThrow(builder, readConcernParseStatus);
return;
}
@@ -416,7 +416,7 @@ void runCommand(OperationContext* opCtx,
LastError::get(opCtx->getClient()).setLastError(e.code(), e.reason());
crb.reset();
BSONObjBuilder bob = crb.getBodyBuilder();
- CommandHelpers::appendCommandStatus(bob, e.toStatus());
+ CommandHelpers::appendCommandStatusNoThrow(bob, e.toStatus());
appendRequiredFieldsToResponse(opCtx, &bob);
}
}
@@ -565,7 +565,7 @@ DbResponse Strategy::clientCommand(OperationContext* opCtx, const Message& m) {
}
reply->reset();
auto bob = reply->getInPlaceReplyBuilder(0);
- CommandHelpers::appendCommandStatus(bob, ex.toStatus());
+ CommandHelpers::appendCommandStatusNoThrow(bob, ex.toStatus());
appendRequiredFieldsToResponse(opCtx, &bob);
}
diff --git a/src/mongo/s/query/cluster_find_test.cpp b/src/mongo/s/query/cluster_find_test.cpp
index 91c948f536f..e588521c80b 100644
--- a/src/mongo/s/query/cluster_find_test.cpp
+++ b/src/mongo/s/query/cluster_find_test.cpp
@@ -98,7 +98,7 @@ protected:
void expectFindReturnsError(ErrorCodes::Error code) {
onCommandForPoolExecutor([code](const executor::RemoteCommandRequest& request) {
BSONObjBuilder resBob;
- CommandHelpers::appendCommandStatus(resBob, Status(code, "dummy error"));
+ CommandHelpers::appendCommandStatusNoThrow(resBob, Status(code, "dummy error"));
return resBob.obj();
});
}
diff --git a/src/mongo/s/sharding_router_test_fixture.cpp b/src/mongo/s/sharding_router_test_fixture.cpp
index 69cbd4b4ac1..78cda1a545a 100644
--- a/src/mongo/s/sharding_router_test_fixture.cpp
+++ b/src/mongo/s/sharding_router_test_fixture.cpp
@@ -522,7 +522,7 @@ void ShardingTestFixture::expectCount(const HostAndPort& configHost,
checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
BSONObjBuilder responseBuilder;
- CommandHelpers::appendCommandStatus(responseBuilder, response.getStatus());
+ CommandHelpers::appendCommandStatusNoThrow(responseBuilder, response.getStatus());
return responseBuilder.obj();
});
}
diff --git a/src/mongo/s/write_ops/batch_write_exec_test.cpp b/src/mongo/s/write_ops/batch_write_exec_test.cpp
index e39bc0bc930..d563fa8a11f 100644
--- a/src/mongo/s/write_ops/batch_write_exec_test.cpp
+++ b/src/mongo/s/write_ops/batch_write_exec_test.cpp
@@ -30,6 +30,7 @@
#include "mongo/client/remote_command_targeter_factory_mock.h"
#include "mongo/client/remote_command_targeter_mock.h"
+#include "mongo/db/commands.h"
#include "mongo/db/logical_session_id.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/client/shard_registry.h"
@@ -159,23 +160,30 @@ public:
void expectInsertsReturnError(const std::vector<BSONObj>& expected,
const BatchedCommandResponse& errResponse) {
onCommandForPoolExecutor([&](const executor::RemoteCommandRequest& request) {
- ASSERT_EQUALS(nss.db(), request.dbname);
+ try {
+ ASSERT_EQUALS(nss.db(), request.dbname);
- const auto opMsgRequest(OpMsgRequest::fromDBAndBody(request.dbname, request.cmdObj));
- const auto actualBatchedInsert(BatchedCommandRequest::parseInsert(opMsgRequest));
- ASSERT_EQUALS(nss.toString(), actualBatchedInsert.getNS().ns());
+ const auto opMsgRequest(
+ OpMsgRequest::fromDBAndBody(request.dbname, request.cmdObj));
+ const auto actualBatchedInsert(BatchedCommandRequest::parseInsert(opMsgRequest));
+ ASSERT_EQUALS(nss.toString(), actualBatchedInsert.getNS().ns());
- const auto& inserted = actualBatchedInsert.getInsertRequest().getDocuments();
- ASSERT_EQUALS(expected.size(), inserted.size());
+ const auto& inserted = actualBatchedInsert.getInsertRequest().getDocuments();
+ ASSERT_EQUALS(expected.size(), inserted.size());
- auto itInserted = inserted.begin();
- auto itExpected = expected.begin();
+ auto itInserted = inserted.begin();
+ auto itExpected = expected.begin();
- for (; itInserted != inserted.end(); itInserted++, itExpected++) {
- ASSERT_BSONOBJ_EQ(*itExpected, *itInserted);
- }
+ for (; itInserted != inserted.end(); itInserted++, itExpected++) {
+ ASSERT_BSONOBJ_EQ(*itExpected, *itInserted);
+ }
- return errResponse.toBSON();
+ return errResponse.toBSON();
+ } catch (const DBException& ex) {
+ BSONObjBuilder bb;
+ CommandHelpers::appendCommandStatusNoThrow(bb, ex.toStatus());
+ return bb.obj();
+ }
});
}
diff --git a/src/mongo/s/write_ops/batched_command_response_test.cpp b/src/mongo/s/write_ops/batched_command_response_test.cpp
index f4195cff20d..8f37da45cb2 100644
--- a/src/mongo/s/write_ops/batched_command_response_test.cpp
+++ b/src/mongo/s/write_ops/batched_command_response_test.cpp
@@ -60,19 +60,12 @@ TEST(BatchedCommandResponse, Basic) {
<< "errInfo"
<< BSON("a" << 1)));
- BSONObj origResponseObj = BSON("ok" << 0.0 << "errmsg"
- << "this batch didn't work"
- << "code"
- << ErrorCodes::BadValue
- << "codeName"
- << "BadValue"
- << BatchedCommandResponse::n(0)
- << "opTime"
- << mongo::Timestamp(1ULL)
- << BatchedCommandResponse::writeErrors()
- << writeErrorsArray
- << BatchedCommandResponse::writeConcernError()
- << writeConcernError);
+ BSONObj origResponseObj =
+ BSON("ok" << 1.0 << BatchedCommandResponse::n(0) << "opTime" << mongo::Timestamp(1ULL)
+ << BatchedCommandResponse::writeErrors()
+ << writeErrorsArray
+ << BatchedCommandResponse::writeConcernError()
+ << writeConcernError);
string errMsg;
BatchedCommandResponse response;