ClickHouse/src/Interpreters/MergeTreeTransactionHolder.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.5 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>;
2022-03-18 11:01:26 +00:00
/// Owns a MergeTreeTransactionObject.
/// Rolls back a transaction in dtor if it was not committed.
/// If `autocommit` flag is true, then it commits transaction if dtor is called normally
/// or rolls it back if dtor was called due to an exception.
2021-04-09 12:53:51 +00:00
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
};
}