summaryrefslogtreecommitdiff
path: root/src/mongo/s/write_ops/batch_write_exec_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/write_ops/batch_write_exec_test.cpp')
-rw-r--r--src/mongo/s/write_ops/batch_write_exec_test.cpp508
1 files changed, 42 insertions, 466 deletions
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 3e90e5b65d3..3b4079b4c84 100644
--- a/src/mongo/s/write_ops/batch_write_exec_test.cpp
+++ b/src/mongo/s/write_ops/batch_write_exec_test.cpp
@@ -33,14 +33,12 @@
#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/concurrency/write_conflict_exception.h"
#include "mongo/db/logical_session_id.h"
#include "mongo/db/vector_clock.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/mock_ns_targeter.h"
#include "mongo/s/session_catalog_router.h"
-#include "mongo/s/shard_cannot_refresh_due_to_locks_held_exception.h"
#include "mongo/s/sharding_router_test_fixture.h"
#include "mongo/s/stale_exception.h"
#include "mongo/s/transaction_router.h"
@@ -202,40 +200,6 @@ BSONObj expectInsertsReturnTenantMigrationAbortedErrorsBase(
return tenantMigrationAbortedResponse.obj();
}
-BSONObj expectInsertsReturnCannotRefreshErrorsBase(const NamespaceString& nss,
- const std::vector<BSONObj>& expected,
- const executor::RemoteCommandRequest& request) {
- 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& inserted = actualBatchedInsert.getInsertRequest().getDocuments();
- ASSERT_EQUALS(expected.size(), inserted.size());
-
- auto itInserted = inserted.begin();
- auto itExpected = expected.begin();
-
- for (; itInserted != inserted.end(); itInserted++, itExpected++) {
- ASSERT_BSONOBJ_EQ(*itExpected, *itInserted);
- }
-
- BatchedCommandResponse cannotRefreshResponse;
- cannotRefreshResponse.setStatus(Status::OK());
- cannotRefreshResponse.setN(0);
-
- // Report a ShardCannotRefreshDueToLocksHeld error for each write in the batch.
- int i = 0;
- for (itInserted = inserted.begin(); itInserted != inserted.end(); ++itInserted) {
- cannotRefreshResponse.addToErrDetails(write_ops::WriteError(
- i, Status(ShardCannotRefreshDueToLocksHeldInfo(nss), "Catalog cache busy in refresh")));
- ++i;
- }
-
- return cannotRefreshResponse.toBSON();
-}
-
/**
* Mimics a single shard backend for a particular collection which can be initialized with a
* set of write command results to return.
@@ -335,12 +299,6 @@ public:
});
}
- void expectInsertsReturnCannotRefreshErrors(const std::vector<BSONObj>& expected) {
- onCommandForPoolExecutor([&](const executor::RemoteCommandRequest& request) {
- return expectInsertsReturnCannotRefreshErrorsBase(nss, expected, request);
- });
- }
-
void expectInsertsReturnError(const std::vector<BSONObj>& expected,
const BatchedCommandResponse& errResponse) {
onCommandForPoolExecutor([&](const executor::RemoteCommandRequest& request) {
@@ -397,6 +355,7 @@ TEST_F(BatchWriteExecTest, SingleOpUnordered) {
insertOp.setDocuments({BSON("x" << 1)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
// Do single-target, single doc batch write op
auto future = launchAsync([&] {
@@ -435,6 +394,7 @@ TEST_F(BatchWriteExecTest, SingleUpdateTargetsShardWithLet) {
<< "100")))});
return updateOp;
}());
+ updateRequest.setWriteConcern(BSONObj());
const static auto epoch = OID::gen();
const static Timestamp timestamp(2);
@@ -520,6 +480,7 @@ TEST_F(BatchWriteExecTest, SingleDeleteTargetsShardWithLet) {
deleteOp.setDeletes(std::vector{write_ops::DeleteOpEntry(q, false)});
return deleteOp;
}());
+ deleteRequest.setWriteConcern(BSONObj());
const static auto epoch = OID::gen();
@@ -605,6 +566,7 @@ TEST_F(BatchWriteExecTest, MultiOpLargeOrdered) {
insertOp.setDocuments(docsToInsert);
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
auto future = launchAsync([&] {
BatchedCommandResponse response;
@@ -637,6 +599,7 @@ TEST_F(BatchWriteExecTest, SingleOpUnorderedError) {
insertOp.setDocuments({BSON("x" << 1)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
auto future = launchAsync([&] {
BatchedCommandResponse response;
@@ -677,6 +640,7 @@ TEST_F(BatchWriteExecTest, MultiOpLargeUnorderedWithStaleShardVersionError) {
insertOp.setDocuments(docsToInsert);
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
auto future = launchAsync([&] {
BatchedCommandResponse response;
@@ -708,6 +672,7 @@ TEST_F(BatchWriteExecTest, StaleShardVersionReturnedFromBatchWithSingleMultiWrit
write_ops::UpdateModification::parseFromClassicUpdate(BSON("Key" << 100)))});
return updateOp;
}());
+ request.setWriteConcern(BSONObj());
const static auto epoch = OID::gen();
const static Timestamp timestamp(2);
@@ -785,43 +750,6 @@ TEST_F(BatchWriteExecTest, StaleShardVersionReturnedFromBatchWithSingleMultiWrit
ASSERT_EQ(3, response.getNModified());
}
-TEST_F(BatchWriteExecTest, MultiOpLargeUnorderedWithCannotRefreshError) {
- const int kNumDocsToInsert = 100'000;
-
- std::vector<BSONObj> docsToInsert;
- docsToInsert.reserve(kNumDocsToInsert);
- for (int i = 0; i < kNumDocsToInsert; i++) {
- docsToInsert.push_back(BSON("_id" << i));
- }
-
- BatchedCommandRequest request([&] {
- write_ops::InsertCommandRequest insertOp(nss);
- insertOp.setWriteCommandRequestBase([] {
- write_ops::WriteCommandRequestBase writeCommandBase;
- writeCommandBase.setOrdered(false);
- return writeCommandBase;
- }());
- insertOp.setDocuments(docsToInsert);
- return insertOp;
- }());
-
- auto future = launchAsync([&] {
- BatchedCommandResponse response;
- BatchWriteExecStats stats;
- BatchWriteExec::executeBatch(
- operationContext(), singleShardNSTargeter, request, &response, &stats);
-
- ASSERT(response.getOk());
- ASSERT_EQ(kNumDocsToInsert, response.getN());
- });
-
- expectInsertsReturnCannotRefreshErrors({docsToInsert.begin(), docsToInsert.begin() + 60133});
- expectInsertsReturnSuccess({docsToInsert.begin(), docsToInsert.begin() + 60133});
- expectInsertsReturnSuccess({docsToInsert.begin() + 60133, docsToInsert.end()});
-
- future.default_timed_get();
-}
-
TEST_F(BatchWriteExecTest,
RetryableErrorReturnedFromMultiWriteWithShard1AllOKShard2AllStaleShardVersion) {
BatchedCommandRequest request([&] {
@@ -840,6 +768,7 @@ TEST_F(BatchWriteExecTest,
write_ops::UpdateModification::parseFromClassicUpdate(BSON("y" << 2)))});
return updateOp;
}());
+ request.setWriteConcern(BSONObj());
const static auto epoch = OID::gen();
const static Timestamp timestamp(2);
@@ -943,6 +872,7 @@ TEST_F(BatchWriteExecTest, RetryableErrorReturnedFromMultiWriteWithShard1Firs) {
write_ops::UpdateModification::parseFromClassicUpdate(BSON("y" << 2)))});
return updateOp;
}());
+ request.setWriteConcern(BSONObj());
const static auto epoch = OID::gen();
const static Timestamp timestamp(2);
@@ -1056,6 +986,7 @@ TEST_F(BatchWriteExecTest, RetryableErrorReturnedFromMultiWriteWithShard1FirstOK
write_ops::UpdateModification::parseFromClassicUpdate(BSON("y" << 2)))});
return updateOp;
}());
+ request.setWriteConcern(BSONObj());
const static auto epoch = OID::gen();
const static Timestamp timestamp(2);
@@ -1165,6 +1096,7 @@ TEST_F(BatchWriteExecTest, RetryableErrorReturnedFromWriteWithShard1SSVShard2OK)
write_ops::UpdateModification::parseFromClassicUpdate(BSON("x" << 1)))});
return updateOp;
}());
+ request.setWriteConcern(BSONObj());
const static auto epoch = OID::gen();
const static Timestamp timestamp(2);
@@ -1264,6 +1196,7 @@ TEST_F(BatchWriteExecTest, StaleShardOp) {
insertOp.setDocuments({BSON("x" << 1)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
// Execute request
auto future = launchAsync([&] {
@@ -1295,6 +1228,7 @@ TEST_F(BatchWriteExecTest, MultiStaleShardOp) {
insertOp.setDocuments({BSON("x" << 1)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
auto future = launchAsync([&] {
BatchedCommandResponse response;
@@ -1332,6 +1266,7 @@ TEST_F(BatchWriteExecTest, TooManyStaleShardOp) {
insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
auto future = launchAsync([&] {
BatchedCommandResponse response;
@@ -1366,6 +1301,7 @@ TEST_F(BatchWriteExecTest, StaleDbOp) {
insertOp.setDocuments({BSON("x" << 1)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
// Execute request
auto future = launchAsync([&] {
@@ -1397,6 +1333,7 @@ TEST_F(BatchWriteExecTest, MultiStaleDbOp) {
insertOp.setDocuments({BSON("x" << 1)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
auto future = launchAsync([&] {
BatchedCommandResponse response;
@@ -1434,6 +1371,7 @@ TEST_F(BatchWriteExecTest, TooManyStaleDbOp) {
insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
auto future = launchAsync([&] {
BatchedCommandResponse response;
@@ -1457,73 +1395,6 @@ TEST_F(BatchWriteExecTest, TooManyStaleDbOp) {
future.default_timed_get();
}
-TEST_F(BatchWriteExecTest, MultiCannotRefreshShardOp) {
- BatchedCommandRequest request([&] {
- write_ops::InsertCommandRequest insertOp(nss);
- insertOp.setWriteCommandRequestBase([] {
- write_ops::WriteCommandRequestBase writeCommandBase;
- writeCommandBase.setOrdered(false);
- return writeCommandBase;
- }());
- insertOp.setDocuments({BSON("x" << 1)});
- return insertOp;
- }());
-
- auto future = launchAsync([&] {
- BatchedCommandResponse response;
- BatchWriteExecStats stats;
- BatchWriteExec::executeBatch(
- operationContext(), singleShardNSTargeter, request, &response, &stats);
- ASSERT(response.getOk());
- });
-
- const std::vector<BSONObj> expected{BSON("x" << 1)};
-
- // Return multiple ShardCannotRefreshDueToLocksHeld errors, but less than the give-up number
- for (int i = 0; i < 3; i++) {
- expectInsertsReturnCannotRefreshErrors(expected);
- }
-
- expectInsertsReturnSuccess(expected);
-
- future.default_timed_get();
-}
-
-TEST_F(BatchWriteExecTest, TooManyCannotRefreshShardOp) {
- // Retry op in exec too many times b/c of busy catalog cache (the error is not expected to
- // trigger a refresh on any implementation of NSTargeter). We should report a no progress error
- // for everything in the batch.
- BatchedCommandRequest request([&] {
- write_ops::InsertCommandRequest insertOp(nss);
- insertOp.setWriteCommandRequestBase([] {
- write_ops::WriteCommandRequestBase writeCommandBase;
- writeCommandBase.setOrdered(false);
- return writeCommandBase;
- }());
- insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
- return insertOp;
- }());
-
- auto future = launchAsync([&] {
- BatchedCommandResponse response;
- BatchWriteExecStats stats;
- BatchWriteExec::executeBatch(
- operationContext(), singleShardNSTargeter, request, &response, &stats);
- ASSERT(response.getOk());
- ASSERT_EQ(0, response.getN());
- ASSERT(response.isErrDetailsSet());
- ASSERT_EQUALS(response.getErrDetailsAt(0).getStatus().code(), ErrorCodes::NoProgressMade);
- ASSERT_EQUALS(response.getErrDetailsAt(1).getStatus().code(), ErrorCodes::NoProgressMade);
- });
-
- // Return multiple StaleShardVersion errors
- for (int i = 0; i < (1 + kMaxRoundsWithoutProgress); i++) {
- expectInsertsReturnCannotRefreshErrors({BSON("x" << 1), BSON("x" << 2)});
- }
-
- future.default_timed_get();
-}
-
TEST_F(BatchWriteExecTest, RetryableWritesLargeBatch) {
// A retryable error without a txnNumber is not retried.
@@ -1546,6 +1417,7 @@ TEST_F(BatchWriteExecTest, RetryableWritesLargeBatch) {
insertOp.setDocuments(docsToInsert);
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
operationContext()->setLogicalSessionId(makeLogicalSessionIdForTest());
operationContext()->setTxnNumber(5);
@@ -1580,6 +1452,7 @@ TEST_F(BatchWriteExecTest, RetryableErrorNoTxnNumber) {
insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
BatchedCommandResponse retryableErrResponse;
retryableErrResponse.setStatus({ErrorCodes::NotWritablePrimary, "mock retryable error"});
@@ -1618,6 +1491,7 @@ TEST_F(BatchWriteExecTest, RetryableErrorTxnNumber) {
insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
operationContext()->setLogicalSessionId(makeLogicalSessionIdForTest());
operationContext()->setTxnNumber(5);
@@ -1655,6 +1529,7 @@ TEST_F(BatchWriteExecTest, NonRetryableErrorTxnNumber) {
insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
operationContext()->setLogicalSessionId(makeLogicalSessionIdForTest());
operationContext()->setTxnNumber(5);
@@ -1696,6 +1571,7 @@ TEST_F(BatchWriteExecTest, StaleEpochIsNotRetryable) {
insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
operationContext()->setLogicalSessionId(makeLogicalSessionIdForTest());
operationContext()->setTxnNumber(5);
@@ -1723,249 +1599,6 @@ TEST_F(BatchWriteExecTest, StaleEpochIsNotRetryable) {
future.default_timed_get();
}
-TEST_F(BatchWriteExecTest, FireAndForgetBatchInsertGetsReplyWithOnlyOkStatus) {
- const int kNumDocsToInsert = 5;
- const std::string kDocValue("sample");
-
- std::vector<BSONObj> docsToInsert;
- docsToInsert.reserve(kNumDocsToInsert);
- for (int i = 0; i < kNumDocsToInsert; i++) {
- docsToInsert.push_back(BSON("_id" << i << "otherField" << kDocValue));
- }
-
- BatchedCommandRequest request([&] {
- write_ops::InsertCommandRequest insertOp(nss);
- insertOp.setWriteCommandRequestBase([] {
- write_ops::WriteCommandRequestBase writeCommandBase;
- writeCommandBase.setOrdered(true);
- return writeCommandBase;
- }());
- insertOp.setDocuments(docsToInsert);
- return insertOp;
- }());
-
- auto future = launchAsync([&] {
- BatchedCommandResponse response;
- BatchWriteExecStats stats;
- // Set Unacknowledged WC for a "fire & forget" request
- auto opCtx = operationContext();
- opCtx->setWriteConcern(
- WriteConcernOptions::parse(WriteConcernOptions::Unacknowledged).getValue());
- BatchWriteExec::executeBatch(opCtx, singleShardNSTargeter, request, &response, &stats);
-
- // The reply should only contain an OK status, without any further detail on
- // the ops actually executed across the cluster.
- BatchedCommandResponse expectedReplyToFireAndForgetRequest;
- expectedReplyToFireAndForgetRequest.setStatus(Status::OK());
- ASSERT_EQUALS(response.toBSON().woCompare(expectedReplyToFireAndForgetRequest.toBSON()), 0);
- });
-
- expectInsertsReturnSuccess(docsToInsert.begin(), docsToInsert.end());
-
- future.default_timed_get();
-}
-
-TEST_F(BatchWriteExecTest, FireAndForgetBatchUpdateGetsReplyWithOnlyOkStatus) {
- BatchedCommandRequest request([&] {
- write_ops::UpdateCommandRequest updateOp(nss);
- updateOp.setWriteCommandRequestBase([] {
- write_ops::WriteCommandRequestBase writeCommandBase;
- writeCommandBase.setOrdered(false);
- return writeCommandBase;
- }());
- updateOp.setUpdates(std::vector{write_ops::UpdateOpEntry(
- BSON("_id" << 100),
- write_ops::UpdateModification::parseFromClassicUpdate(BSON("Key" << 100)))});
- return updateOp;
- }());
-
- const static auto epoch = OID::gen();
- const static Timestamp timestamp(2);
-
- // This allows the batch to target each write operation to perform this test
- class MultiShardTargeter : public MockNSTargeter {
- public:
- using MockNSTargeter::MockNSTargeter;
-
- std::vector<ShardEndpoint> targetUpdate(OperationContext* opCtx,
- const BatchItemRef& itemRef) const override {
- if (targetAll) {
- return std::vector{
- ShardEndpoint(
- kShardName1, ChunkVersion(100, 200, epoch, timestamp), boost::none),
- ShardEndpoint(
- kShardName2, ChunkVersion(101, 200, epoch, timestamp), boost::none)};
- } else {
- return std::vector{ShardEndpoint(
- kShardName2, ChunkVersion(101, 200, epoch, timestamp), boost::none)};
- }
- }
-
- bool targetAll = true;
- };
-
- MultiShardTargeter multiShardNSTargeter(
- nss,
- {MockRange(
- ShardEndpoint(kShardName1, ChunkVersion(100, 200, epoch, timestamp), boost::none),
- BSON("sk" << MINKEY),
- BSON("sk" << 10)),
- MockRange(
- ShardEndpoint(kShardName2, ChunkVersion(101, 200, epoch, timestamp), boost::none),
- BSON("sk" << 10),
- BSON("sk" << MAXKEY))});
- auto future = launchAsync([&] {
- // Set Unacknowledged WC for a "fire & forget" request
- auto opCtx = operationContext();
- opCtx->setWriteConcern(
- WriteConcernOptions::parse(WriteConcernOptions::Unacknowledged).getValue());
-
- BatchedCommandResponse response;
- BatchWriteExecStats stats;
- BatchWriteExec::executeBatch(opCtx, multiShardNSTargeter, request, &response, &stats);
- return response;
- });
-
- onCommandForPoolExecutor([&](const RemoteCommandRequest& request) {
- ASSERT_EQ(kTestShardHost1, request.target);
-
- BatchedCommandResponse response;
- response.setStatus(Status::OK());
- response.setNModified(1);
-
- return response.toBSON();
- });
-
- onCommandForPoolExecutor([&](const RemoteCommandRequest& request) {
- ASSERT_EQ(kTestShardHost2, request.target);
-
- BatchedCommandResponse response;
- response.setStatus(Status::OK());
- response.setNModified(0);
- response.addToErrDetails(
- write_ops::WriteError(0,
- Status(StaleConfigInfo(nss,
- ChunkVersion(101, 200, epoch, timestamp),
- ChunkVersion(105, 200, epoch, timestamp),
- ShardId(kShardName2)),
- "Stale error")));
- return response.toBSON();
- });
-
- onCommandForPoolExecutor([&](const RemoteCommandRequest& request) {
- ASSERT_EQ(kTestShardHost2, request.target);
-
- BatchedCommandResponse response;
- response.setStatus(Status::OK());
- response.setNModified(2);
-
- return response.toBSON();
- });
-
- // The reply should only contain an OK status, without any further detail on
- // the ops actually executed across the cluster.
- // (Despite of a "fire and forget" request, child batches still need to be internally processed
- // before returning a reply).
- auto response = future.default_timed_get();
- BatchedCommandResponse expectedReplyToFireAndForgetRequest;
- expectedReplyToFireAndForgetRequest.setStatus(Status::OK());
- ASSERT_EQUALS(response.toBSON().woCompare(expectedReplyToFireAndForgetRequest.toBSON()), 0);
-}
-
-TEST_F(BatchWriteExecTest, FireAndForgetBatchDeleteGetsReplyWithOnlyOkStatus) {
- // Try to update the single doc where a let param is used in the shard key.
- const auto let = BSON("y" << 100);
- const auto rtc = LegacyRuntimeConstants{Date_t::now(), Timestamp(1, 1)};
- const auto q = BSON("x"
- << "$$y");
- BatchedCommandRequest deleteRequest([&] {
- write_ops::DeleteCommandRequest deleteOp(nss);
- deleteOp.setWriteCommandRequestBase([] {
- write_ops::WriteCommandRequestBase writeCommandBase;
- writeCommandBase.setOrdered(false);
- return writeCommandBase;
- }());
- deleteOp.setLet(let);
- deleteOp.setLegacyRuntimeConstants(rtc);
- deleteOp.setDeletes(std::vector{write_ops::DeleteOpEntry(q, false)});
- return deleteOp;
- }());
-
- const static auto epoch = OID::gen();
-
- class MultiShardTargeter : public MockNSTargeter {
- public:
- using MockNSTargeter::MockNSTargeter;
-
- protected:
- std::vector<ShardEndpoint> targetDelete(OperationContext* opCtx,
- const BatchItemRef& itemRef) const override {
- return std::vector{ShardEndpoint(
- kShardName2, ChunkVersion(101, 200, epoch, Timestamp(1, 1)), boost::none)};
- }
- };
-
- MultiShardTargeter multiShardNSTargeter(
- nss,
- {MockRange(ShardEndpoint(
- kShardName1, ChunkVersion(100, 200, epoch, Timestamp(1, 1)), boost::none),
- BSON("x" << MINKEY),
- BSON("x" << 0)),
- MockRange(ShardEndpoint(
- kShardName2, ChunkVersion(101, 200, epoch, Timestamp(1, 1)), boost::none),
- BSON("x" << 0),
- BSON("x" << MAXKEY))});
-
- auto future = launchAsync([&] {
- BatchedCommandResponse response;
- BatchWriteExecStats stats;
-
- // Set Unacknowledged WC for a "fire & forget" request
- auto opCtx = operationContext();
- opCtx->setWriteConcern(
- WriteConcernOptions::parse(WriteConcernOptions::Unacknowledged).getValue());
-
- BatchWriteExec::executeBatch(opCtx, multiShardNSTargeter, deleteRequest, &response, &stats);
-
- return response;
- });
-
- // The update will hit the first shard.
- onCommandForPoolExecutor(
- [&](const RemoteCommandRequest& request) {
- ASSERT_EQ(kTestShardHost2, request.target);
-
- BatchedCommandResponse response;
- response.setStatus(Status::OK());
-
- // Check that let params are propagated to shards.
- const auto opMsgRequest(OpMsgRequest::fromDBAndBody(request.dbname, request.cmdObj));
- const auto actualBatchedUpdate(BatchedCommandRequest::parseDelete(opMsgRequest));
- ASSERT_BSONOBJ_EQ(let, actualBatchedUpdate.getLet().value_or(BSONObj()));
- ASSERT_EQUALS(actualBatchedUpdate.getLegacyRuntimeConstants()->getLocalNow(),
- rtc.getLocalNow());
- ASSERT_EQUALS(actualBatchedUpdate.getLegacyRuntimeConstants()->getClusterTime(),
- rtc.getClusterTime());
-
- // Check that let params are only forwarded and not evaluated.
- auto expectedQ = BSON("x"
- << "$$y");
- for (auto&& u : actualBatchedUpdate.getDeleteRequest().getDeletes())
- ASSERT_BSONOBJ_EQ(expectedQ, u.getQ());
-
- return response.toBSON();
- });
-
- // The reply should only contain an OK status, without any further detail on
- // the ops actually executed across the cluster.
- // (Despite of a "fire and forget" request, child batches still need to be internally processed
- // before returning a reply).
- auto response = future.default_timed_get();
- BatchedCommandResponse expectedReplyToFireAndForgetRequest;
- expectedReplyToFireAndForgetRequest.setStatus(Status::OK());
- ASSERT_EQUALS(response.toBSON().woCompare(expectedReplyToFireAndForgetRequest.toBSON()), 0);
-}
-
TEST_F(BatchWriteExecTest, TenantMigrationAbortedErrorOrderedOp) {
const std::vector<BSONObj> expected{BSON("x" << 1), BSON("x" << 2), BSON("x" << 3)};
BatchedCommandRequest request([&] {
@@ -1978,6 +1611,7 @@ TEST_F(BatchWriteExecTest, TenantMigrationAbortedErrorOrderedOp) {
insertOp.setDocuments(expected);
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
// Execute request
auto future = launchAsync([&] {
@@ -2008,6 +1642,7 @@ TEST_F(BatchWriteExecTest, TenantMigrationAbortedErrorUnorderedOp) {
insertOp.setDocuments(expected);
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
// Execute request
auto future = launchAsync([&] {
@@ -2038,6 +1673,7 @@ TEST_F(BatchWriteExecTest, MultipleTenantMigrationAbortedErrorUnorderedOp) {
insertOp.setDocuments(expected);
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
const int numTenantMigrationAbortedErrors = 3;
@@ -2072,6 +1708,7 @@ TEST_F(BatchWriteExecTest, MultipleTenantMigrationAbortedErrorOrderedOp) {
insertOp.setDocuments(expected);
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
const int numTenantMigrationAbortedErrors = 3;
@@ -2106,6 +1743,7 @@ TEST_F(BatchWriteExecTest, PartialTenantMigrationAbortedErrorOrderedOp) {
insertOp.setDocuments(expected);
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
// Execute request
auto future = launchAsync([&] {
@@ -2138,6 +1776,7 @@ TEST_F(BatchWriteExecTest, PartialTenantMigrationErrorUnorderedOp) {
insertOp.setDocuments(expected);
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
// Execute request
auto future = launchAsync([&] {
@@ -2222,6 +1861,7 @@ TEST_F(BatchWriteExecTargeterErrorTest, TargetedFailedAndErrorResponse) {
write_ops::UpdateModification::parseFromClassicUpdate(BSON("Key" << 100)))});
return updateOp;
}());
+ request.setWriteConcern(BSONObj());
const static auto epoch = OID::gen();
const static Timestamp timestamp(2);
@@ -2357,6 +1997,7 @@ TEST_F(BatchWriteExecTransactionTargeterErrorTest, TargetedFailedAndErrorRespons
write_ops::UpdateModification::parseFromClassicUpdate(BSON("Key" << 100)))});
return updateOp;
}());
+ request.setWriteConcern(BSONObj());
const static auto epoch = OID::gen();
const static Timestamp timestamp(2);
@@ -2500,6 +2141,7 @@ TEST_F(BatchWriteExecTransactionMultiShardTest, TargetedSucceededAndErrorRespons
write_ops::UpdateModification::parseFromClassicUpdate(BSON("Key" << 100)))});
return updateOp;
}());
+ request.setWriteConcern(BSONObj());
const static auto epoch = OID::gen();
const static Timestamp timestamp(2);
@@ -2625,22 +2267,6 @@ public:
});
}
- void expectInsertsReturnCannotRefreshErrors(const std::vector<BSONObj>& expected) {
- onCommandForPoolExecutor([&](const executor::RemoteCommandRequest& request) {
- BSONObjBuilder bob;
-
- bob.appendElementsUnique(
- expectInsertsReturnCannotRefreshErrorsBase(nss, expected, request));
-
- // Because this is the transaction-specific fixture, return transaction metadata in
- // the response.
- TxnResponseMetadata txnResponseMetadata(false /* readOnly */);
- txnResponseMetadata.serialize(&bob);
-
- return bob.obj();
- });
- }
-
void expectInsertsReturnTransientTxnErrors(const std::vector<BSONObj>& expected) {
onCommandForPoolExecutor([&](const executor::RemoteCommandRequest& request) {
ASSERT_EQUALS(nss.db(), request.dbname);
@@ -2690,6 +2316,7 @@ TEST_F(BatchWriteExecTransactionTest, ErrorInBatchThrows_CommandError) {
insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
auto future = launchAsync([&] {
BatchedCommandResponse response;
@@ -2721,6 +2348,7 @@ TEST_F(BatchWriteExecTransactionTest, ErrorInBatchSets_WriteError) {
insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
auto future = launchAsync([&] {
BatchedCommandResponse response;
@@ -2750,6 +2378,7 @@ TEST_F(BatchWriteExecTransactionTest, ErrorInBatchSets_WriteErrorOrdered) {
insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
auto future = launchAsync([&] {
BatchedCommandResponse response;
@@ -2768,64 +2397,6 @@ TEST_F(BatchWriteExecTransactionTest, ErrorInBatchSets_WriteErrorOrdered) {
future.default_timed_get();
}
-TEST_F(BatchWriteExecTransactionTest, ErrorInBatchSets_WriteErrorFromBusyCache) {
- BatchedCommandRequest request([&] {
- write_ops::InsertCommandRequest insertOp(nss);
- insertOp.setWriteCommandRequestBase([] {
- write_ops::WriteCommandRequestBase writeCommandBase;
- writeCommandBase.setOrdered(false);
- return writeCommandBase;
- }());
- insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
- return insertOp;
- }());
-
- auto future = launchAsync([&] {
- BatchedCommandResponse response;
- BatchWriteExecStats stats;
- BatchWriteExec::executeBatch(
- operationContext(), singleShardNSTargeter, request, &response, &stats);
-
- ASSERT(response.isErrDetailsSet());
- ASSERT_GT(response.sizeErrDetails(), 0u);
- ASSERT_EQ(ErrorCodes::ShardCannotRefreshDueToLocksHeld,
- response.getErrDetailsAt(0).getStatus().code());
- });
-
- expectInsertsReturnCannotRefreshErrors({BSON("x" << 1), BSON("x" << 2)});
-
- future.default_timed_get();
-}
-
-TEST_F(BatchWriteExecTransactionTest, ErrorInBatchSets_WriteErrorOrderedFromBusyCache) {
- BatchedCommandRequest request([&] {
- write_ops::InsertCommandRequest insertOp(nss);
- insertOp.setWriteCommandRequestBase([] {
- write_ops::WriteCommandRequestBase writeCommandBase;
- writeCommandBase.setOrdered(true);
- return writeCommandBase;
- }());
- insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
- return insertOp;
- }());
-
- auto future = launchAsync([&] {
- BatchedCommandResponse response;
- BatchWriteExecStats stats;
- BatchWriteExec::executeBatch(
- operationContext(), singleShardNSTargeter, request, &response, &stats);
-
- ASSERT(response.isErrDetailsSet());
- ASSERT_GT(response.sizeErrDetails(), 0u);
- ASSERT_EQ(ErrorCodes::ShardCannotRefreshDueToLocksHeld,
- response.getErrDetailsAt(0).getStatus().code());
- });
-
- expectInsertsReturnCannotRefreshErrors({BSON("x" << 1), BSON("x" << 2)});
-
- future.default_timed_get();
-}
-
TEST_F(BatchWriteExecTransactionTest, ErrorInBatchSets_TransientTxnError) {
BatchedCommandRequest request([&] {
write_ops::InsertCommandRequest insertOp(nss);
@@ -2837,13 +2408,16 @@ TEST_F(BatchWriteExecTransactionTest, ErrorInBatchSets_TransientTxnError) {
insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
auto future = launchAsync([&] {
BatchedCommandResponse response;
BatchWriteExecStats stats;
- ASSERT_THROWS(BatchWriteExec::executeBatch(
- operationContext(), singleShardNSTargeter, request, &response, &stats),
- WriteConflictException);
+ ASSERT_THROWS_CODE(
+ BatchWriteExec::executeBatch(
+ operationContext(), singleShardNSTargeter, request, &response, &stats),
+ AssertionException,
+ ErrorCodes::WriteConflict);
});
expectInsertsReturnTransientTxnErrors({BSON("x" << 1), BSON("x" << 2)});
@@ -2862,6 +2436,7 @@ TEST_F(BatchWriteExecTransactionTest, ErrorInBatchSets_DispatchError) {
insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
auto future = launchAsync([&] {
BatchedCommandResponse response;
@@ -2893,6 +2468,7 @@ TEST_F(BatchWriteExecTransactionTest, ErrorInBatchSets_TransientDispatchError) {
insertOp.setDocuments({BSON("x" << 1), BSON("x" << 2)});
return insertOp;
}());
+ request.setWriteConcern(BSONObj());
auto future = launchAsync([&] {
BatchedCommandResponse response;