summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPavi Vetriselvan <pvselvan@umich.edu>2019-01-11 10:09:32 -0500
committerPavi Vetriselvan <pvselvan@umich.edu>2019-01-11 10:09:32 -0500
commit38985804d5bef88e1962f1aebfced5d80c058369 (patch)
tree7df437360fbaa308aad0d5c63a6659c2b9c8931f /src
parentdf09162ac73affa30dc03077ae6812e8f99d257f (diff)
downloadmongo-38985804d5bef88e1962f1aebfced5d80c058369.tar.gz
Revert "SERVER-38302 update prepared commit/abort metrics before call to opObserver"
This reverts commit 011d0d1a5d1517f7e8f6df0ce35412e1bf256afe.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/transaction_participant.cpp48
-rw-r--r--src/mongo/db/transaction_participant.h5
2 files changed, 17 insertions, 36 deletions
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp
index 83361ba3be8..f05749b197d 100644
--- a/src/mongo/db/transaction_participant.cpp
+++ b/src/mongo/db/transaction_participant.cpp
@@ -883,9 +883,13 @@ Timestamp TransactionParticipant::prepareTransaction(OperationContext* opCtx,
opCtx->recoveryUnit()->setPrepareTimestamp(prepareOplogSlot.opTime.getTimestamp());
opCtx->getWriteUnitOfWork()->prepare();
- // For prepared transactions, we must update ServerTransactionMetrics with the prepare optime
- // before the prepare oplog entry is written so that we don't incorrectly advance the stable
- // timestamp.
+ // We need to unlock the session to run the opObserver onTransactionPrepare, which calls back
+ // into the session.
+ lk.unlock();
+ opCtx->getServiceContext()->getOpObserver()->onTransactionPrepare(opCtx, prepareOplogSlot);
+
+ abortGuard.Dismiss();
+
invariant(!_oldestOplogEntryOpTime,
str::stream() << "This transaction's oldest oplog entry Timestamp has already "
<< "been set to: "
@@ -904,13 +908,6 @@ Timestamp TransactionParticipant::prepareTransaction(OperationContext* opCtx,
tickSource->getTicks());
}
- // We need to unlock the session to run the opObserver onTransactionPrepare, which calls back
- // into the session.
- lk.unlock();
- opCtx->getServiceContext()->getOpObserver()->onTransactionPrepare(opCtx, prepareOplogSlot);
-
- abortGuard.Dismiss();
-
if (MONGO_FAIL_POINT(hangAfterSettingPrepareStartTime)) {
log() << "transaction - hangAfterSettingPrepareStartTime fail point enabled. Blocking "
"until fail point is disabled.";
@@ -1006,7 +1003,6 @@ void TransactionParticipant::commitUnpreparedTransaction(OperationContext* opCtx
invariant(_txnState.isCommittingWithoutPrepare(lk),
str::stream() << "Current State: " << _txnState);
- _updateTxnMetricsOnCommit(lk, opCtx, false);
_finishCommitTransaction(lk, opCtx);
}
@@ -1057,17 +1053,6 @@ void TransactionParticipant::commitPreparedTransaction(OperationContext* opCtx,
<< commitOplogSlot.opTime.toBSON());
}
- // Prepared transactions must have a valid oldestOplogEntryOpTime.
- invariant(_oldestOplogEntryOpTime);
- _finishOpTime = commitOplogSlot.opTime;
-
- // For prepared transactions, we must update ServerTransactionMetrics with the finish optime
- // before the commit oplog entry is written. This is because the commit point can advance to
- // include the commit's opTime, triggering a recalculation of the stable timestamp. If the
- // metrics are not updated, then the replication coordinator will not know that it can
- // advance the stable timestamp.
- _updateTxnMetricsOnCommit(lk, opCtx, true);
-
// We need to unlock the session to run the opObserver onTransactionCommit, which calls back
// into the session. We also do not want to write to storage with the mutex locked.
lk.unlock();
@@ -1080,6 +1065,11 @@ void TransactionParticipant::commitPreparedTransaction(OperationContext* opCtx,
lk.lock();
_checkIsActiveTransaction(lk, *opCtx->getTxnNumber(), true);
+ // If we are committing a prepared transaction, then we must have already recorded this
+ // transaction's oldest oplog entry optime.
+ invariant(_oldestOplogEntryOpTime);
+ _finishOpTime = repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp();
+
_finishCommitTransaction(lk, opCtx);
} catch (...) {
// It is illegal for committing a prepared transaction to fail for any reason, other than an
@@ -1121,15 +1111,7 @@ void TransactionParticipant::_finishCommitTransaction(WithLock lk, OperationCont
if (_speculativeTransactionReadOpTime > clientInfo.getLastOp()) {
clientInfo.setLastOp(_speculativeTransactionReadOpTime);
}
-
- // We must clear the recovery unit and locker so any post-transaction writes can run without
- // transactional settings such as a read timestamp.
- _cleanUpTxnResourceOnOpCtx(lk, opCtx, TerminationCause::kCommitted);
-}
-
-void TransactionParticipant::_updateTxnMetricsOnCommit(WithLock lk,
- OperationContext* opCtx,
- bool isCommittingWithPrepare) {
+ const bool isCommittingWithPrepare = _txnState.isCommittingWithPrepare(lk);
_txnState.transitionTo(lk, TransactionState::kCommitted);
{
@@ -1146,6 +1128,10 @@ void TransactionParticipant::_updateTxnMetricsOnCommit(WithLock lk,
CurOp::get(opCtx)->debug().additiveMetrics,
CurOp::get(opCtx)->debug().storageStats);
}
+
+ // We must clear the recovery unit and locker so any post-transaction writes can run without
+ // transactional settings such as a read timestamp.
+ _cleanUpTxnResourceOnOpCtx(lk, opCtx, TransactionState::kCommitted);
}
void TransactionParticipant::shutdown() {
diff --git a/src/mongo/db/transaction_participant.h b/src/mongo/db/transaction_participant.h
index c488cd1dc2f..57c4b22a40f 100644
--- a/src/mongo/db/transaction_participant.h
+++ b/src/mongo/db/transaction_participant.h
@@ -768,11 +768,6 @@ private:
// invalidating a transaction, or starting a new transaction.
void _resetTransactionState(WithLock wl, TransactionState::StateFlag state);
- // Helper that updates ServerTransactionsMetrics once a transaction commits.
- void _updateTxnMetricsOnCommit(WithLock lk,
- OperationContext* opCtx,
- bool isCommittingWithPrepare);
-
// Protects the member variables below.
mutable stdx::mutex _mutex;