1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-28 20:02:00 +03:00

Refactoring dbms simulator. Intermediate commit.

This commit is contained in:
Teemu Ollakka
2018-06-15 12:58:36 +03:00
parent cb3b2fbf9e
commit 4fbf1d0cf8
17 changed files with 771 additions and 68 deletions

View File

@ -0,0 +1,53 @@
//
// Copyright (C) 2018 Codership Oy <info@codership.com>
//
#include "db_storage_engine.hpp"
#include "db_client.hpp"
void db::storage_engine::transaction::start(client* cc)
{
wsrep::unique_lock<wsrep::mutex> lock(se_.mutex_);
if (se_.transactions_.insert(cc).second == false)
{
::abort();
}
cc_ = cc;
}
void db::storage_engine::transaction::commit()
{
if (cc_)
{
wsrep::unique_lock<wsrep::mutex> lock(se_.mutex_);
se_.transactions_.erase(cc_);
}
cc_ = nullptr;
}
void db::storage_engine::transaction::rollback()
{
if (cc_)
{
wsrep::unique_lock<wsrep::mutex> lock(se_.mutex_);
se_.transactions_.erase(cc_);
}
cc_ = nullptr;
}
void db::storage_engine::bf_abort_some(const wsrep::transaction_context& txc)
{
wsrep::unique_lock<wsrep::mutex> lock(mutex_);
if (alg_freq_ && (std::rand() % alg_freq_) == 0)
{
if (transactions_.empty() == false)
{
auto* victim_txc(*transactions_.begin());
if (victim_txc->bf_abort(txc.seqno()))
{
++bf_aborts_;
}
}
}
}