summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorAlex Taskov <alex.taskov@mongodb.com>2019-05-28 16:21:48 -0400
committerAlex Taskov <alex.taskov@mongodb.com>2019-06-04 13:31:58 -0400
commitf75aa0003333eefd1e1c56039bd1d44c44fb3620 (patch)
treee75d6eec866287fa8dd981a398b8d4fb821b79ed /src/mongo
parentf998fc0de986f4cc7b81648374c5b70d298ca2af (diff)
downloadmongo-f75aa0003333eefd1e1c56039bd1d44c44fb3620.tar.gz
SERVER-41137 Propagate WriteConcern in abortTransaction
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/s/transaction_router.cpp3
-rw-r--r--src/mongo/s/transaction_router_test.cpp33
2 files changed, 32 insertions, 4 deletions
diff --git a/src/mongo/s/transaction_router.cpp b/src/mongo/s/transaction_router.cpp
index 47f4728fb54..fd71d7eff4d 100644
--- a/src/mongo/s/transaction_router.cpp
+++ b/src/mongo/s/transaction_router.cpp
@@ -877,7 +877,8 @@ BSONObj TransactionRouter::abortTransaction(OperationContext* opCtx) {
_terminationInitiated = true;
- auto abortCmd = BSON("abortTransaction" << 1);
+ auto abortCmd = BSON("abortTransaction" << 1 << WriteConcernOptions::kWriteConcernField
+ << opCtx->getWriteConcern().toBSON());
std::vector<AsyncRequestsSender::Request> abortRequests;
for (const auto& participantEntry : _participants) {
abortRequests.emplace_back(ShardId(participantEntry.first), abortCmd);
diff --git a/src/mongo/s/transaction_router_test.cpp b/src/mongo/s/transaction_router_test.cpp
index 4fc83724956..1555f11972f 100644
--- a/src/mongo/s/transaction_router_test.cpp
+++ b/src/mongo/s/transaction_router_test.cpp
@@ -937,9 +937,9 @@ void checkSessionDetails(const BSONObj& cmdObj,
}
void checkWriteConcern(const BSONObj& cmdObj, const WriteConcernOptions& expectedWC) {
- auto writeCocernElem = cmdObj["writeConcern"];
- ASSERT_FALSE(writeCocernElem.eoo());
- ASSERT_BSONOBJ_EQ(expectedWC.toBSON(), writeCocernElem.Obj());
+ auto writeConcernElem = cmdObj["writeConcern"];
+ ASSERT_FALSE(writeConcernElem.eoo());
+ ASSERT_BSONOBJ_EQ(expectedWC.toBSON(), writeConcernElem.Obj());
}
TEST_F(TransactionRouterTestWithDefaultSession,
@@ -2266,6 +2266,33 @@ TEST_F(TransactionRouterTest, ImplicitAbortIgnoresErrors) {
future.default_timed_get();
}
+TEST_F(TransactionRouterTestWithDefaultSession, AbortPropagatesWriteConcern) {
+ TxnNumber txnNum{3};
+ auto opCtx = operationContext();
+ auto txnRouter = TransactionRouter::get(opCtx);
+
+ WriteConcernOptions writeConcern(10, WriteConcernOptions::SyncMode::NONE, 0);
+ opCtx->setWriteConcern(writeConcern);
+
+ txnRouter->beginOrContinueTxn(opCtx, txnNum, TransactionRouter::TransactionActions::kStart);
+
+ txnRouter->setDefaultAtClusterTime(opCtx);
+ txnRouter->attachTxnFieldsIfNeeded(opCtx, shard1, {});
+
+ auto future = launchAsync([&] { return txnRouter->abortTransaction(operationContext()); });
+
+ onCommandForPoolExecutor([&](const RemoteCommandRequest& request) {
+ auto cmdName = request.cmdObj.firstElement().fieldNameStringData();
+ ASSERT_EQ(cmdName, "abortTransaction");
+
+ checkWriteConcern(request.cmdObj, writeConcern);
+
+ return kOkReadOnlyFalseResponse;
+ });
+
+ auto response = future.default_timed_get();
+}
+
TEST_F(TransactionRouterTestWithDefaultSession,
CannotContinueOnSnapshotOrStaleVersionErrorsWithoutFailpoint) {
TxnNumber txnNum{3};