ClickHouse/src/Interpreters/MergeTreeTransaction.h

60 lines
1.5 KiB
C++
Raw Normal View History

2021-03-31 17:55:04 +00:00
#pragma once
#include <Common/TransactionMetadata.h>
2021-04-09 12:53:51 +00:00
#include <boost/noncopyable.hpp>
2021-03-31 17:55:04 +00:00
namespace DB
{
2021-04-08 17:20:45 +00:00
class IMergeTreeDataPart;
using DataPartPtr = std::shared_ptr<const IMergeTreeDataPart>;
using DataPartsVector = std::vector<DataPartPtr>;
2021-04-09 12:53:51 +00:00
class MergeTreeTransaction : public std::enable_shared_from_this<MergeTreeTransaction>, private boost::noncopyable
2021-03-31 17:55:04 +00:00
{
friend class TransactionLog;
public:
enum State
{
RUNNING,
COMMITTED,
ROLLED_BACK,
};
Snapshot getSnapshot() const { return snapshot; }
2021-04-09 12:53:51 +00:00
State getState() const;
2021-03-31 17:55:04 +00:00
const TransactionID tid;
MergeTreeTransaction() = delete;
MergeTreeTransaction(Snapshot snapshot_, LocalTID local_tid_, UUID host_id);
2021-04-08 17:20:45 +00:00
void addNewPart(const DataPartPtr & new_part);
void removeOldPart(const DataPartPtr & part_to_remove);
static void addNewPart(const DataPartPtr & new_part, MergeTreeTransaction * txn);
static void removeOldPart(const DataPartPtr & part_to_remove, MergeTreeTransaction * txn);
static void addNewPartAndRemoveCovered(const DataPartPtr & new_part, const DataPartsVector & covered_parts, MergeTreeTransaction * txn);
bool isReadOnly() const;
2021-04-09 12:53:51 +00:00
void onException();
2021-05-18 17:07:29 +00:00
String dumpDescription() const;
2021-03-31 17:55:04 +00:00
private:
2021-04-08 17:20:45 +00:00
void beforeCommit();
2021-04-09 12:53:51 +00:00
void afterCommit(CSN assigned_csn) noexcept;
void rollback() noexcept;
2021-04-08 17:20:45 +00:00
2021-03-31 17:55:04 +00:00
Snapshot snapshot;
2021-04-08 17:20:45 +00:00
DataPartsVector creating_parts;
DataPartsVector removing_parts;
2021-04-09 12:53:51 +00:00
CSN csn;
2021-03-31 17:55:04 +00:00
};
using MergeTreeTransactionPtr = std::shared_ptr<MergeTreeTransaction>;
}