2021-03-31 17:55:04 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Interpreters/MergeTreeTransaction.h>
|
2021-05-17 11:14:09 +00:00
|
|
|
#include <Interpreters/MergeTreeTransactionHolder.h>
|
2021-03-31 17:55:04 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <mutex>
|
2021-04-08 17:20:45 +00:00
|
|
|
#include <unordered_map>
|
2021-03-31 17:55:04 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2021-04-09 12:53:51 +00:00
|
|
|
void rollbackTransaction(const MergeTreeTransactionPtr & txn) noexcept;
|
2021-03-31 17:55:04 +00:00
|
|
|
|
2021-04-08 17:20:45 +00:00
|
|
|
CSN getCSN(const TransactionID & tid) const;
|
|
|
|
CSN getCSN(const TIDHash & tid) const;
|
|
|
|
|
|
|
|
MergeTreeTransactionPtr tryGetRunningTransaction(const TIDHash & tid);
|
|
|
|
|
2021-03-31 17:55:04 +00:00
|
|
|
private:
|
2021-05-18 17:07:29 +00:00
|
|
|
Poco::Logger * log;
|
|
|
|
|
2021-04-08 17:20:45 +00:00
|
|
|
std::atomic<CSN> latest_snapshot;
|
2021-03-31 17:55:04 +00:00
|
|
|
std::atomic<CSN> csn_counter;
|
|
|
|
std::atomic<LocalTID> local_tid_counter;
|
2021-04-08 17:20:45 +00:00
|
|
|
|
|
|
|
/// FIXME Transactions: it's probably a bad idea to use global mutex here
|
|
|
|
mutable std::mutex commit_mutex;
|
|
|
|
std::unordered_map<TIDHash, CSN> tid_to_csn;
|
|
|
|
|
|
|
|
mutable std::mutex running_list_mutex;
|
|
|
|
std::unordered_map<TIDHash, MergeTreeTransactionPtr> running_list;
|
2021-03-31 17:55:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|