summaryrefslogtreecommitdiff
path: root/src/mongo/db/op_observer_impl.cpp
diff options
context:
space:
mode:
authorBlake Oler <blake.oler@mongodb.com>2019-02-13 12:44:39 -0500
committerBlake Oler <blake.oler@mongodb.com>2019-02-20 15:41:41 -0500
commitbdd0c8ff4cb70b3c14e2dfbe68c0baa3b26a6e82 (patch)
tree9add6eba3de4aebaf6b1e9b6b2be1ef53059598e /src/mongo/db/op_observer_impl.cpp
parent0d79175a88ee958722c0ffb276606949e695d028 (diff)
downloadmongo-bdd0c8ff4cb70b3c14e2dfbe68c0baa3b26a6e82.tar.gz
SERVER-39561 Split OpObserver::onTransactionCommit() into two functions for unprepared and prepared transactions respectively
Diffstat (limited to 'src/mongo/db/op_observer_impl.cpp')
-rw-r--r--src/mongo/db/op_observer_impl.cpp44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp
index 17db14347b9..6996a5e772c 100644
--- a/src/mongo/db/op_observer_impl.cpp
+++ b/src/mongo/db/op_observer_impl.cpp
@@ -1096,36 +1096,40 @@ void logCommitOrAbortForPreparedTransaction(OperationContext* opCtx,
} // namespace
-void OpObserverImpl::onTransactionCommit(OperationContext* opCtx,
- boost::optional<OplogSlot> commitOplogEntryOpTime,
- boost::optional<Timestamp> commitTimestamp,
- std::vector<repl::ReplOperation>& statements) {
+void OpObserverImpl::onUnpreparedTransactionCommit(
+ OperationContext* opCtx, const std::vector<repl::ReplOperation>& statements) {
invariant(opCtx->getTxnNumber());
if (!opCtx->writesAreReplicated()) {
return;
}
- if (commitOplogEntryOpTime) {
- invariant(commitTimestamp);
- invariant(!commitTimestamp->isNull());
+ // It is possible that the transaction resulted in no changes. In that case, we should
+ // not write an empty applyOps entry.
+ if (statements.empty())
+ return;
- CommitTransactionOplogObject cmdObj;
- cmdObj.setCommitTimestamp(*commitTimestamp);
- logCommitOrAbortForPreparedTransaction(
- opCtx, *commitOplogEntryOpTime, cmdObj.toBSON(), DurableTxnStateEnum::kCommitted);
- } else {
- invariant(!commitTimestamp);
+ const auto commitOpTime = logApplyOpsForTransaction(opCtx, statements, OplogSlot()).writeOpTime;
+ invariant(!commitOpTime.isNull());
+}
- // It is possible that the transaction resulted in no changes. In that case, we should
- // not write an empty applyOps entry.
- if (statements.empty())
- return;
+void OpObserverImpl::onPreparedTransactionCommit(
+ OperationContext* opCtx,
+ OplogSlot commitOplogEntryOpTime,
+ Timestamp commitTimestamp,
+ const std::vector<repl::ReplOperation>& statements) noexcept {
+ invariant(opCtx->getTxnNumber());
- const auto commitOpTime =
- logApplyOpsForTransaction(opCtx, statements, OplogSlot()).writeOpTime;
- invariant(!commitOpTime.isNull());
+ if (!opCtx->writesAreReplicated()) {
+ return;
}
+
+ invariant(!commitTimestamp.isNull());
+
+ CommitTransactionOplogObject cmdObj;
+ cmdObj.setCommitTimestamp(commitTimestamp);
+ logCommitOrAbortForPreparedTransaction(
+ opCtx, commitOplogEntryOpTime, cmdObj.toBSON(), DurableTxnStateEnum::kCommitted);
}
void OpObserverImpl::onTransactionPrepare(OperationContext* opCtx,