diff options
author | Matthew Saltz <matthew.saltz@mongodb.com> | 2019-01-04 16:12:46 -0500 |
---|---|---|
committer | Matthew Saltz <matthew.saltz@mongodb.com> | 2019-01-07 11:04:17 -0500 |
commit | 6a0a21214dd96663c899cb8f2562d6121351ed3c (patch) | |
tree | 7eaa947fd31458b4d46c13a4e42429317146f42b /src/mongo/db | |
parent | 3d28a55677f555092d94b2a2908a8a37cdf07db9 (diff) | |
download | mongo-6a0a21214dd96663c899cb8f2562d6121351ed3c.tar.gz |
SERVER-38848 Code cleanup in TransactionCoordinator::continueCommit
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/transaction_coordinator.cpp | 36 |
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() { |