2021-03-31 17:55:04 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Common/TransactionMetadata.h>
|
|
|
|
|
|
|
|
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-03-31 17:55:04 +00:00
|
|
|
class MergeTreeTransaction
|
|
|
|
{
|
|
|
|
friend class TransactionLog;
|
|
|
|
public:
|
|
|
|
enum State
|
|
|
|
{
|
|
|
|
RUNNING,
|
|
|
|
COMMITTED,
|
|
|
|
ROLLED_BACK,
|
|
|
|
};
|
|
|
|
|
|
|
|
Snapshot getSnapshot() const { return snapshot; }
|
|
|
|
State getState() const { return state; }
|
|
|
|
|
|
|
|
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-03-31 17:55:04 +00:00
|
|
|
private:
|
2021-04-08 17:20:45 +00:00
|
|
|
void beforeCommit();
|
|
|
|
void afterCommit();
|
|
|
|
void rollback();
|
|
|
|
|
2021-03-31 17:55:04 +00:00
|
|
|
Snapshot snapshot;
|
|
|
|
State state;
|
|
|
|
|
2021-04-08 17:20:45 +00:00
|
|
|
DataPartsVector creating_parts;
|
|
|
|
DataPartsVector removing_parts;
|
|
|
|
|
2021-03-31 17:55:04 +00:00
|
|
|
CSN csn = Tx::UnknownCSN;
|
|
|
|
};
|
|
|
|
|
|
|
|
using MergeTreeTransactionPtr = std::shared_ptr<MergeTreeTransaction>;
|
|
|
|
|
|
|
|
}
|