summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2022-02-23 19:46:07 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-23 20:51:52 +0000
commit60f8a0134bd837770ee75f85b2f144226529f4f3 (patch)
treeb3cd019234a0f638384bd369074424939f385b73
parent9adbcce9f18b9a40cd3225d4bc1f06c4894eca67 (diff)
downloadmongo-60f8a0134bd837770ee75f85b2f144226529f4f3.tar.gz
SERVER-63875 Move TransactionWithRetries executor futures into Transaction
-rw-r--r--src/mongo/db/transaction_api.cpp23
-rw-r--r--src/mongo/db/transaction_api.h7
2 files changed, 13 insertions, 17 deletions
diff --git a/src/mongo/db/transaction_api.cpp b/src/mongo/db/transaction_api.cpp
index caecdaba75e..060502379aa 100644
--- a/src/mongo/db/transaction_api.cpp
+++ b/src/mongo/db/transaction_api.cpp
@@ -114,10 +114,7 @@ StatusWith<CommitResult> TransactionWithRetries::runSyncNoThrow(OperationContext
_internalTxn->setCallback(std::move(callback));
while (true) {
{
-
- auto bodyStatus = ExecutorFuture<void>(_executor)
- .then([this] { return _internalTxn->runCallback(); })
- .getNoThrow(opCtx);
+ auto bodyStatus = _internalTxn->runCallback().getNoThrow(opCtx);
if (!bodyStatus.isOK()) {
auto nextStep = _internalTxn->handleError(bodyStatus);
@@ -137,9 +134,7 @@ StatusWith<CommitResult> TransactionWithRetries::runSyncNoThrow(OperationContext
}
while (true) {
- auto swResult = ExecutorFuture<void>(_executor)
- .then([this] { return _internalTxn->commit(); })
- .getNoThrow(opCtx);
+ auto swResult = _internalTxn->commit().getNoThrow(opCtx);
if (swResult.isOK() && swResult.getValue().getEffectiveStatus().isOK()) {
// Commit succeeded so return to the caller.
@@ -169,7 +164,7 @@ StatusWith<CommitResult> TransactionWithRetries::runSyncNoThrow(OperationContext
void TransactionWithRetries::_bestEffortAbort(OperationContext* opCtx) {
try {
- ExecutorFuture<void>(_executor).then([this] { return _internalTxn->abort(); }).get(opCtx);
+ _internalTxn->abort().get(opCtx);
} catch (const DBException& e) {
LOGV2(5875900,
"Unable to abort internal transaction",
@@ -299,8 +294,11 @@ SemiFuture<BSONObj> Transaction::_commitOrAbort(StringData dbName, StringData cm
cmdBuilder.append(WriteConcernOptions::kWriteConcernField, _writeConcern);
auto cmdObj = cmdBuilder.obj();
- // Safe to inline because the continuation only holds state.
- return _txnClient->runCommand(dbName, cmdObj)
+ return ExecutorFuture<void>(_executor)
+ .then([this, dbNameCopy = dbName.toString(), cmdObj = std::move(cmdObj)] {
+ return _txnClient->runCommand(dbNameCopy, cmdObj);
+ })
+ // Safe to inline because the continuation only holds state.
.unsafeToInlineFuture()
.tapAll([anchor = shared_from_this()](auto&&) {})
.semi();
@@ -308,8 +306,9 @@ SemiFuture<BSONObj> Transaction::_commitOrAbort(StringData dbName, StringData cm
SemiFuture<void> Transaction::runCallback() {
invariant(_callback);
- // Safe to inline because the continuation only holds state.
- return _callback(*_txnClient, _executor)
+ return ExecutorFuture<void>(_executor)
+ .then([this] { return _callback(*_txnClient, _executor); })
+ // Safe to inline because the continuation only holds state.
.unsafeToInlineFuture()
.tapAll([anchor = shared_from_this()](auto&&) {})
.semi();
diff --git a/src/mongo/db/transaction_api.h b/src/mongo/db/transaction_api.h
index 155c711d8d3..f2fcbc3f349 100644
--- a/src/mongo/db/transaction_api.h
+++ b/src/mongo/db/transaction_api.h
@@ -118,8 +118,7 @@ public:
* Main constructor that constructs an internal transaction with the default options.
*/
TransactionWithRetries(OperationContext* opCtx, ExecutorPtr executor)
- : _executor(executor),
- _internalTxn(std::make_shared<details::Transaction>(opCtx, executor)) {}
+ : _internalTxn(std::make_shared<details::Transaction>(opCtx, executor)) {}
/**
* Alternate constructor that accepts a custom transaction client.
@@ -127,8 +126,7 @@ public:
TransactionWithRetries(OperationContext* opCtx,
ExecutorPtr executor,
std::unique_ptr<TransactionClient> txnClient)
- : _executor(executor),
- _internalTxn(
+ : _internalTxn(
std::make_shared<details::Transaction>(opCtx, executor, std::move(txnClient))) {}
/**
@@ -160,7 +158,6 @@ private:
*/
void _bestEffortAbort(OperationContext* opCtx);
- ExecutorPtr _executor;
std::shared_ptr<details::Transaction> _internalTxn;
};