diff options
author | Tommaso Tocci <tommaso.tocci@mongodb.com> | 2020-08-24 12:52:45 +0200 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-26 07:39:37 +0000 |
commit | 4dc5ad1c019849f2084bb9d30419d303679e6afe (patch) | |
tree | d6145dc37b9b112d34a32f2bedf9775bcaf40df3 /src/mongo | |
parent | 9143e670375cbb8bf95e1018ea0afa4adf831607 (diff) | |
download | mongo-4dc5ad1c019849f2084bb9d30419d303679e6afe.tar.gz |
SERVER-50054 Advance logicalClock on transactionParticipant to commitTimestamp upon receiving commitTransaction
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/transaction_participant.cpp | 12 | ||||
-rw-r--r-- | src/mongo/dbtests/storage_timestamp_tests.cpp | 12 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp index 5a63291993d..d90a57692eb 100644 --- a/src/mongo/db/transaction_participant.cpp +++ b/src/mongo/db/transaction_participant.cpp @@ -64,6 +64,7 @@ #include "mongo/db/storage/flow_control.h" #include "mongo/db/transaction_history_iterator.h" #include "mongo/db/transaction_participant_gen.h" +#include "mongo/db/vector_clock_mutable.h" #include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/log_with_sampling.h" @@ -1392,11 +1393,16 @@ void TransactionParticipant::Participant::commitPreparedTransaction( OplogSlot commitOplogSlot; boost::optional<OplogSlotReserver> oplogSlotReserver; - // On primary, we reserve an oplog slot before committing the transaction so that no - // writes that are causally related to the transaction commit enter the oplog at a - // timestamp earlier than the commit oplog entry. if (opCtx->writesAreReplicated()) { invariant(!commitOplogEntryOpTime); + // When this receiving node is not in a readable state, the cluster time gossiping + // protocol is not enabled, thus it is necessary to advance it explicitely, + // so that causal consistency is maintained in these situations. + VectorClockMutable::get(opCtx)->tickClusterTimeTo(LogicalTime(commitTimestamp)); + + // On primary, we reserve an oplog slot before committing the transaction so that no + // writes that are causally related to the transaction commit enter the oplog at a + // timestamp earlier than the commit oplog entry. oplogSlotReserver.emplace(opCtx); commitOplogSlot = oplogSlotReserver->getLastSlot(); invariant(commitOplogSlot.getTimestamp() >= commitTimestamp, diff --git a/src/mongo/dbtests/storage_timestamp_tests.cpp b/src/mongo/dbtests/storage_timestamp_tests.cpp index a43b1c31058..288f5399808 100644 --- a/src/mongo/dbtests/storage_timestamp_tests.cpp +++ b/src/mongo/dbtests/storage_timestamp_tests.cpp @@ -3475,7 +3475,8 @@ public: const auto clusterTime = currentTime.clusterTime(); firstOplogEntryTs = clusterTime.addTicks(1).asTimestamp(); prepareEntryTs = clusterTime.addTicks(2).asTimestamp(); - commitEntryTs = clusterTime.addTicks(3).asTimestamp(); + commitTs = clusterTime.addTicks(3).asTimestamp(); + commitEntryTs = clusterTime.addTicks(4).asTimestamp(); } void run() { @@ -3570,7 +3571,7 @@ public: { FailPointEnableBlock failPointBlock("skipCommitTxnCheckPrepareMajorityCommitted"); - txnParticipant.commitPreparedTransaction(_opCtx, commitEntryTs, {}); + txnParticipant.commitPreparedTransaction(_opCtx, commitTs, {}); } txnParticipant.stashTransactionResources(_opCtx); @@ -3657,7 +3658,7 @@ public: } protected: - Timestamp firstOplogEntryTs, secondOplogEntryTs, prepareEntryTs; + Timestamp firstOplogEntryTs, secondOplogEntryTs, prepareEntryTs, commitTs; private: MultiOplogScopedSettings multiOplogSettings; @@ -3780,7 +3781,8 @@ public: const auto currentTime = _clock->getTime(); const auto clusterTime = currentTime.clusterTime(); const auto prepareTs = clusterTime.addTicks(1).asTimestamp(); - commitEntryTs = clusterTime.addTicks(2).asTimestamp(); + const auto commitTs = clusterTime.addTicks(2).asTimestamp(); + commitEntryTs = clusterTime.addTicks(3).asTimestamp(); LOGV2(22514, "Prepare TS: {prepareTs}", "prepareTs"_attr = prepareTs); logTimestamps(); @@ -3832,7 +3834,7 @@ public: { FailPointEnableBlock failPointBlock("skipCommitTxnCheckPrepareMajorityCommitted"); - txnParticipant.commitPreparedTransaction(_opCtx, commitEntryTs, {}); + txnParticipant.commitPreparedTransaction(_opCtx, commitTs, {}); } assertNoStartOpTime(); |