summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorMatthew Saltz <matthew.saltz@mongodb.com>2019-01-04 16:12:46 -0500
committerMatthew Saltz <matthew.saltz@mongodb.com>2019-01-07 11:04:17 -0500
commit6a0a21214dd96663c899cb8f2562d6121351ed3c (patch)
tree7eaa947fd31458b4d46c13a4e42429317146f42b /src/mongo/db
parent3d28a55677f555092d94b2a2908a8a37cdf07db9 (diff)
downloadmongo-6a0a21214dd96663c899cb8f2562d6121351ed3c.tar.gz
SERVER-38848 Code cleanup in TransactionCoordinator::continueCommit
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/transaction_coordinator.cpp36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/mongo/db/transaction_coordinator.cpp b/src/mongo/db/transaction_coordinator.cpp
index 983ad744d4d..7eab0ada758 100644
--- a/src/mongo/db/transaction_coordinator.cpp
+++ b/src/mongo/db/transaction_coordinator.cpp
@@ -145,27 +145,23 @@ void TransactionCoordinator::continueCommit(const TransactionCoordinatorDocument
_state = CoordinatorState::kPreparing;
const auto participantShards = doc.getParticipants();
- if (!doc.getDecision()) {
- _runPhaseOne(participantShards)
- .then([this, participantShards](CoordinatorCommitDecision decision) {
- return _runPhaseTwo(participantShards, decision);
- })
- .getAsync([this](Status s) { _handleCompletionStatus(s); });
- return;
- }
-
- CoordinatorCommitDecision decision;
-
- if (*doc.getDecision() == "commit") {
- decision =
- CoordinatorCommitDecision{txn::CommitDecision::kCommit, *doc.getCommitTimestamp()};
- } else if (*doc.getDecision() == "abort") {
- decision = CoordinatorCommitDecision{txn::CommitDecision::kAbort, boost::none};
- }
+ // Helper lambda to get the decision either from the document passed in or from the participants
+ // (by performing 'phase one' of two-phase commit).
+ auto getDecision = [&]() -> Future<CoordinatorCommitDecision> {
+ if (!doc.getDecision()) {
+ return _runPhaseOne(participantShards);
+ } else {
+ return (*doc.getDecision() == "commit")
+ ? CoordinatorCommitDecision{txn::CommitDecision::kCommit, *doc.getCommitTimestamp()}
+ : CoordinatorCommitDecision{txn::CommitDecision::kAbort, boost::none};
+ }
+ };
- _runPhaseTwo(participantShards, decision).getAsync([this](Status s) {
- _handleCompletionStatus(s);
- });
+ getDecision()
+ .then([this, participantShards](CoordinatorCommitDecision decision) {
+ return _runPhaseTwo(participantShards, decision);
+ })
+ .getAsync([this](Status s) { _handleCompletionStatus(s); });
}
Future<void> TransactionCoordinator::onCompletion() {