diff options
author | Pavi Vetriselvan <pvselvan@umich.edu> | 2018-10-30 14:45:38 -0400 |
---|---|---|
committer | Pavi Vetriselvan <pvselvan@umich.edu> | 2018-10-30 14:52:19 -0400 |
commit | 33ac1afd4079e04d12554f9b79d1ab07426caf59 (patch) | |
tree | e18f05ce76cec36901b76ed4cf8f6ba2ba97fb99 /src/mongo/db/server_transactions_metrics.h | |
parent | 6d475fdb5a76acab760ce4b6709b60a4c8c9aec6 (diff) | |
download | mongo-33ac1afd4079e04d12554f9b79d1ab07426caf59.tar.gz |
SERVER-35811 pin stable timestamp behind oldest uncommitted timestamp
Diffstat (limited to 'src/mongo/db/server_transactions_metrics.h')
-rw-r--r-- | src/mongo/db/server_transactions_metrics.h | 69 |
1 files changed, 55 insertions, 14 deletions
diff --git a/src/mongo/db/server_transactions_metrics.h b/src/mongo/db/server_transactions_metrics.h index f82dfb179e6..7dbc208e0c6 100644 --- a/src/mongo/db/server_transactions_metrics.h +++ b/src/mongo/db/server_transactions_metrics.h @@ -32,8 +32,8 @@ #include <set> -#include "mongo/bson/timestamp.h" #include "mongo/db/operation_context.h" +#include "mongo/db/repl/optime.h" #include "mongo/db/service_context.h" #include "mongo/db/transactions_stats_gen.h" @@ -73,26 +73,56 @@ public: void incrementTotalCommitted(); /** - * Returns the Timestamp of the oldest oplog entry written across all open transactions. - * Returns boost::none if there are no transaction oplog entry Timestamps stored. + * Returns the OpTime of the oldest oplog entry written across all open transactions. + * Returns boost::none if there are no transaction oplog entry OpTimes stored. */ - boost::optional<Timestamp> getOldestActiveTS() const; + boost::optional<repl::OpTime> getOldestActiveOpTime() const; /** - * Add the transaction's oplog entry Timestamp to a set of Timestamps. + * Add the transaction's oplog entry OpTime to oldestActiveOplogEntryOpTimes, a set of OpTimes. + * Also creates a pair with this OpTime and OpTime::max() as the corresponding commit/abort + * oplog entry OpTime. Finally, adds this to oldestNonMajorityCommittedOpTimes. */ - void addActiveTS(Timestamp oldestOplogEntryTS); + void addActiveOpTime(repl::OpTime oldestOplogEntryOpTime); /** - * Remove the corresponding transaction oplog entry Timestamp if the transaction commits or - * aborts. + * Remove the corresponding transaction oplog entry OpTime if the transaction commits or + * aborts. Also updates the pair in oldestNonMajorityCommittedOpTimes with the + * oldestOplogEntryOpTime to have a valid finishOpTime instead of OpTime::max(). It's stored in + * the format: < oldestOplogEntryOpTime, finishOpTime >. */ - void removeActiveTS(Timestamp oldestOplogEntryTS); + void removeActiveOpTime(repl::OpTime oldestOplogEntryOpTime, + boost::optional<repl::OpTime> finishOpTime); /** - * Returns the number of transaction oplog entry Timestamps currently stored. + * Returns the number of transaction oplog entry OpTimes currently stored. */ - unsigned int getTotalActiveTS() const; + unsigned int getTotalActiveOpTimes() const; + + /** + * Returns the oldest oplog entry OpTime across transactions whose corresponding commit or + * abort oplog entry has not been majority committed. + */ + boost::optional<repl::OpTime> getOldestNonMajorityCommittedOpTime() const; + + /** + * Remove the corresponding transaction oplog entry OpTime pair from + * oldestNonMajorityCommittedOpTimes if the transaction is majority committed or aborted. + * We determine this by checking if there are any pairs in the set whose + * 'finishOpTime' <= 'committedOpTime'. + */ + void removeOpTimesLessThanOrEqToCommittedOpTime(repl::OpTime committedOpTime); + + /** + * Testing function that adds an OpTime pair to oldestNonMajorityCommittedOpTimes. + */ + void addNonMajCommittedOpTimePair_forTest(std::pair<repl::OpTime, repl::OpTime> OpTimePair); + + /** + * Testing function that returns the oldest non-majority committed OpTime pair in the form: + * < oldestOplogEntryOpTime, finishOpTime >. + */ + boost::optional<repl::OpTime> getFinishOpTimeOfOldestNonMajCommitted_forTest() const; /** * Appends the accumulated stats to a transactions stats object. @@ -118,10 +148,21 @@ private: // The total number of multi-document transaction commits. AtomicUInt64 _totalCommitted{0}; - // Maintain the oldest oplog entry Timestamp across all active transactions. Currently, we only + // Maintain the oldest oplog entry OpTime across all active transactions. Currently, we only // write an oplog entry for an ongoing transaction if it is in the `prepare` state. By - // maintaining an ordered set of timestamps, the timestamp at the beginning will be the oldest. - std::set<Timestamp> _oldestActiveOplogEntryTS; + // maintaining an ordered set of OpTimes, the OpTime at the beginning will be the oldest. + std::set<repl::OpTime> _oldestActiveOplogEntryOpTimes; + + // Maintain the oldest oplog entry OpTime across transactions whose corresponding abort/commit + // oplog entries have not been majority committed. Since this is an ordered set, the first + // pair's oldestOplogEntryOpTime represents the earliest OpTime that we should pin the stable + // timestamp behind. + // Each pair is structured as follows: <oldestOplogEntryOpTime, finishOpTime> + // 'oldestOplogEntryOpTime': The first oplog entry OpTime written by a transaction. + // 'finishOpTime': The commit/abort oplog entry OpTime. + // Once the corresponding abort/commit entry has been majority committed, remove the pair from + // this set. + std::set<std::pair<repl::OpTime, repl::OpTime>> _oldestNonMajorityCommittedOpTimes; }; } // namespace mongo |