#pragma once #include #include #include #include #include namespace DB { class TransactionLog final : private boost::noncopyable { public: static TransactionLog & instance(); TransactionLog(); Snapshot getLatestSnapshot() const; /// Allocated TID, returns transaction object MergeTreeTransactionPtr beginTransaction(); CSN commitTransaction(const MergeTreeTransactionPtr & txn); void rollbackTransaction(const MergeTreeTransactionPtr & txn) noexcept; CSN getCSN(const TransactionID & tid) const; CSN getCSN(const TIDHash & tid) const; MergeTreeTransactionPtr tryGetRunningTransaction(const TIDHash & tid); private: std::atomic latest_snapshot; std::atomic csn_counter; std::atomic local_tid_counter; /// FIXME Transactions: it's probably a bad idea to use global mutex here mutable std::mutex commit_mutex; std::unordered_map tid_to_csn; mutable std::mutex running_list_mutex; std::unordered_map running_list; }; }