ClickHouse/src/Interpreters/MergeTreeTransactionHolder.h

39 lines
1.3 KiB
C++
Raw Normal View History

2021-04-09 12:53:51 +00:00
#pragma once
#include <memory>
namespace DB
{
2022-03-09 20:38:18 +00:00
class Context;
2021-04-09 12:53:51 +00:00
class MergeTreeTransaction;
2021-06-08 10:01:49 +00:00
/// TODO maybe replace with raw pointer? It should not be shared, only MergeTreeTransactionHolder can own a transaction object
2021-04-09 12:53:51 +00:00
using MergeTreeTransactionPtr = std::shared_ptr<MergeTreeTransaction>;
class MergeTreeTransactionHolder
{
public:
MergeTreeTransactionHolder() = default;
2022-03-09 20:38:18 +00:00
MergeTreeTransactionHolder(const MergeTreeTransactionPtr & txn_, bool autocommit_, const Context * owned_by_session_context_ = nullptr);
2021-04-09 12:53:51 +00:00
MergeTreeTransactionHolder(MergeTreeTransactionHolder && rhs) noexcept;
MergeTreeTransactionHolder & operator=(MergeTreeTransactionHolder && rhs) noexcept;
~MergeTreeTransactionHolder();
2021-05-17 11:14:09 +00:00
/// NOTE: We cannot make it noncopyable, because we use it as a field of Context.
2021-04-09 12:53:51 +00:00
/// So the following copy constructor and operator does not copy anything,
/// they just leave txn nullptr.
MergeTreeTransactionHolder(const MergeTreeTransactionHolder & rhs);
MergeTreeTransactionHolder & operator=(const MergeTreeTransactionHolder & rhs);
2021-05-17 11:14:09 +00:00
MergeTreeTransactionPtr getTransaction() const { return txn; }
2021-04-09 12:53:51 +00:00
private:
void onDestroy() noexcept;
MergeTreeTransactionPtr txn;
bool autocommit = false;
2022-03-09 20:38:18 +00:00
const Context * owned_by_session_context = nullptr;
2021-04-09 12:53:51 +00:00
};
}