2021-04-09 12:53:51 +00:00
|
|
|
#include <Interpreters/MergeTreeTransactionHolder.h>
|
|
|
|
#include <Interpreters/MergeTreeTransaction.h>
|
|
|
|
#include <Interpreters/TransactionLog.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
MergeTreeTransactionHolder::MergeTreeTransactionHolder(const MergeTreeTransactionPtr & txn_, bool autocommit_ = false)
|
|
|
|
: txn(txn_)
|
|
|
|
, autocommit(autocommit_)
|
|
|
|
{
|
|
|
|
assert(!txn || txn->getState() == MergeTreeTransaction::RUNNING);
|
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeTransactionHolder::MergeTreeTransactionHolder(MergeTreeTransactionHolder && rhs) noexcept
|
|
|
|
: txn(std::move(rhs.txn))
|
|
|
|
, autocommit(rhs.autocommit)
|
|
|
|
{
|
|
|
|
rhs.txn = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeTransactionHolder & MergeTreeTransactionHolder::operator=(MergeTreeTransactionHolder && rhs) noexcept
|
|
|
|
{
|
|
|
|
onDestroy();
|
|
|
|
txn = std::move(rhs.txn);
|
|
|
|
rhs.txn = {};
|
2021-05-17 11:14:09 +00:00
|
|
|
autocommit = rhs.autocommit;
|
2021-04-09 12:53:51 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeTransactionHolder::~MergeTreeTransactionHolder()
|
|
|
|
{
|
|
|
|
onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MergeTreeTransactionHolder::onDestroy() noexcept
|
|
|
|
{
|
|
|
|
if (!txn)
|
|
|
|
return;
|
|
|
|
if (txn->getState() != MergeTreeTransaction::RUNNING)
|
|
|
|
return;
|
|
|
|
|
2021-05-17 11:14:09 +00:00
|
|
|
if (autocommit && std::uncaught_exceptions() == 0)
|
2021-04-09 12:53:51 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
TransactionLog::instance().commitTransaction(txn);
|
2021-05-17 11:14:09 +00:00
|
|
|
return;
|
2021-04-09 12:53:51 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
tryLogCurrentException(__PRETTY_FUNCTION__);
|
|
|
|
}
|
|
|
|
}
|
2021-05-17 11:14:09 +00:00
|
|
|
|
|
|
|
TransactionLog::instance().rollbackTransaction(txn);
|
2021-04-09 12:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeTransactionHolder::MergeTreeTransactionHolder(const MergeTreeTransactionHolder &)
|
|
|
|
{
|
|
|
|
txn = nullptr;
|
|
|
|
}
|
|
|
|
|
2021-11-08 18:56:09 +00:00
|
|
|
MergeTreeTransactionHolder & MergeTreeTransactionHolder::operator=(const MergeTreeTransactionHolder &) // NOLINT
|
2021-04-09 12:53:51 +00:00
|
|
|
{
|
2021-06-02 20:03:44 +00:00
|
|
|
assert(txn == nullptr);
|
2021-04-09 12:53:51 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|