Changed TransactionId to TransactionRead.
This commit is contained in:
parent
16868afb72
commit
443d0e0098
@ -468,7 +468,7 @@ set(memgraph_src_files
|
||||
${src_dir}/storage/garbage/garbage.cpp
|
||||
${src_dir}/storage/vertex_accessor.cpp
|
||||
${src_dir}/transactions/transaction.cpp
|
||||
${src_dir}/transactions/transaction_id.cpp
|
||||
${src_dir}/transactions/transaction_read.cpp
|
||||
${src_dir}/template_engine/engine.cpp
|
||||
${src_dir}/logging/streams/stdout.cpp
|
||||
${src_dir}/logging/levels.cpp
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include "transactions/commit_log.hpp"
|
||||
#include "transactions/engine.hpp"
|
||||
#include "transactions/transaction_id.hpp"
|
||||
#include "transactions/transaction_read.hpp"
|
||||
|
||||
#include "mvcc/cre_exp.hpp"
|
||||
#include "mvcc/hints.hpp"
|
||||
@ -41,7 +41,7 @@ public:
|
||||
RecordLock lock;
|
||||
|
||||
// check if this record is visible to the transaction t
|
||||
bool visible(const tx::TransactionId &t)
|
||||
bool visible(const tx::TransactionRead &t)
|
||||
{
|
||||
// TODO check if the record was created by a transaction that has been
|
||||
// aborted. one might implement this by checking the hints in mvcc
|
||||
@ -70,34 +70,34 @@ public:
|
||||
))));
|
||||
}
|
||||
|
||||
void mark_created(const tx::TransactionId &t)
|
||||
void mark_created(const tx::TransactionRead &t)
|
||||
{
|
||||
tx.cre(t.id);
|
||||
cmd.cre(t.cid);
|
||||
}
|
||||
|
||||
void mark_deleted(const tx::TransactionId &t)
|
||||
void mark_deleted(const tx::TransactionRead &t)
|
||||
{
|
||||
tx.exp(t.id);
|
||||
cmd.exp(t.cid);
|
||||
}
|
||||
|
||||
bool exp_committed(const Id &id, const tx::TransactionId &t)
|
||||
bool exp_committed(const Id &id, const tx::TransactionRead &t)
|
||||
{
|
||||
return committed(hints.exp, id, t);
|
||||
}
|
||||
|
||||
bool exp_committed(const tx::TransactionId &t)
|
||||
bool exp_committed(const tx::TransactionRead &t)
|
||||
{
|
||||
return committed(hints.exp, tx.exp(), t);
|
||||
}
|
||||
|
||||
bool cre_committed(const Id &id, const tx::TransactionId &t)
|
||||
bool cre_committed(const Id &id, const tx::TransactionRead &t)
|
||||
{
|
||||
return committed(hints.cre, id, t);
|
||||
}
|
||||
|
||||
bool cre_committed(const tx::TransactionId &t)
|
||||
bool cre_committed(const tx::TransactionRead &t)
|
||||
{
|
||||
return committed(hints.cre, tx.cre(), t);
|
||||
}
|
||||
@ -110,7 +110,7 @@ public:
|
||||
|
||||
// TODO: Test this
|
||||
// True if this record is visible for write.
|
||||
bool is_visible_write(const tx::TransactionId &t)
|
||||
bool is_visible_write(const tx::TransactionRead &t)
|
||||
{
|
||||
return (tx.cre() == t.id && // inserted by the current transaction
|
||||
cmd.cre() <= t.cid && // before this command, and
|
||||
@ -122,7 +122,7 @@ public:
|
||||
|
||||
protected:
|
||||
template <class U>
|
||||
bool committed(U &hints, const Id &id, const tx::TransactionId &t)
|
||||
bool committed(U &hints, const Id &id, const tx::TransactionRead &t)
|
||||
{
|
||||
// you certainly can't see the transaction with id greater than yours
|
||||
// as that means it started after this transaction and if it committed,
|
||||
|
@ -103,7 +103,7 @@ public:
|
||||
|
||||
void vacuum() {}
|
||||
|
||||
T *find(const tx::TransactionId &t) const
|
||||
T *find(const tx::TransactionRead &t) const
|
||||
{
|
||||
auto r = head.load(std::memory_order_seq_cst);
|
||||
|
||||
|
@ -36,7 +36,7 @@ private:
|
||||
|
||||
// Makes snapshot. It only saves records which have changed since old_trans.
|
||||
void snapshot(DbTransaction const &dt, SnapshotEncoder &snap,
|
||||
tx::TransactionId const &old_trans);
|
||||
tx::TransactionRead const &old_trans);
|
||||
|
||||
// Loads snapshot. True if success
|
||||
bool snapshot_load(DbTransaction const &dt, SnapshotDecoder &snap);
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
|
||||
// True if record visible for current transaction is visible to given
|
||||
// transaction id.
|
||||
bool is_visble_to(tx::TransactionId const &id)
|
||||
bool is_visble_to(tx::TransactionRead const &id)
|
||||
{
|
||||
return record->visible(id);
|
||||
}
|
||||
|
@ -9,12 +9,12 @@
|
||||
#include "storage/locking/record_lock.hpp"
|
||||
#include "transactions/lock_store.hpp"
|
||||
#include "transactions/snapshot.hpp"
|
||||
#include "transactions/transaction_id.hpp"
|
||||
#include "transactions/transaction_read.hpp"
|
||||
|
||||
namespace tx
|
||||
{
|
||||
|
||||
class Transaction : public TransactionId
|
||||
class Transaction : public TransactionRead
|
||||
{
|
||||
|
||||
public:
|
||||
@ -22,8 +22,8 @@ public:
|
||||
Transaction(const Transaction &) = delete;
|
||||
Transaction(Transaction &&) = delete;
|
||||
|
||||
// Returns copy of transaction_id
|
||||
TransactionId transaction_id();
|
||||
// Returns copy of transaction_read
|
||||
TransactionRead transaction_read();
|
||||
|
||||
// Blocks until all transactions from snapshot finish. After this method,
|
||||
// snapshot will be empty.
|
||||
|
@ -13,16 +13,20 @@ namespace tx
|
||||
|
||||
class Engine;
|
||||
|
||||
class TransactionId
|
||||
// Has read only capbilities.
|
||||
// TODO: Not all applicable methods in code have been changed to accept
|
||||
// TransactionRead instead of a Transaction.
|
||||
class TransactionRead
|
||||
{
|
||||
friend class Engine;
|
||||
|
||||
public:
|
||||
TransactionId(Engine &engine);
|
||||
TransactionRead(Engine &engine);
|
||||
|
||||
TransactionId(const Id &&id, const Snapshot<Id> &&snapshot, Engine &engine);
|
||||
TransactionRead(const Id &&id, const Snapshot<Id> &&snapshot,
|
||||
Engine &engine);
|
||||
|
||||
TransactionId(const Id &id, const Snapshot<Id> &snapshot, Engine &engine);
|
||||
TransactionRead(const Id &id, const Snapshot<Id> &snapshot, Engine &engine);
|
||||
|
||||
// Return id of oldest transaction from snapshot.
|
||||
Id oldest_active();
|
@ -38,7 +38,7 @@ bool SnapshotEngine::make_snapshot(std::time_t now, const char *type)
|
||||
|
||||
SnapshotEncoder snap(snapshot_file);
|
||||
|
||||
auto old_trans = tx::TransactionId(db.tx_engine);
|
||||
auto old_trans = tx::TransactionRead(db.tx_engine);
|
||||
snapshot(t, snap, old_trans);
|
||||
|
||||
auto res = sys::flush_file_to_disk(snapshot_file);
|
||||
@ -135,7 +135,7 @@ bool SnapshotEngine::import()
|
||||
}
|
||||
|
||||
void SnapshotEngine::snapshot(DbTransaction const &dt, SnapshotEncoder &snap,
|
||||
tx::TransactionId const &old_trans)
|
||||
tx::TransactionRead const &old_trans)
|
||||
{
|
||||
Db &db = dt.db;
|
||||
DbAccessor t(db, dt.trans);
|
||||
|
@ -11,14 +11,14 @@ namespace tx
|
||||
|
||||
Transaction::Transaction(const Id &id, const Snapshot<Id> &snapshot,
|
||||
Engine &engine)
|
||||
: TransactionId(id, snapshot, engine)
|
||||
: TransactionRead(id, snapshot, engine)
|
||||
{
|
||||
}
|
||||
|
||||
// Returns copy of transaction_id
|
||||
TransactionId Transaction::transaction_id()
|
||||
TransactionRead Transaction::transaction_read()
|
||||
{
|
||||
TransactionId const &t = *this;
|
||||
TransactionRead const &t = *this;
|
||||
return t;
|
||||
}
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
#include "transactions/transaction_id.hpp"
|
||||
|
||||
namespace tx
|
||||
{
|
||||
|
||||
TransactionId::TransactionId(Engine &engine)
|
||||
: TransactionId(Id(), Snapshot<Id>(), engine)
|
||||
{
|
||||
}
|
||||
|
||||
TransactionId::TransactionId(const Id &&id, const Snapshot<Id> &&snapshot,
|
||||
Engine &engine)
|
||||
: id(id), cid(1), snapshot(std::move(snapshot)), engine(engine)
|
||||
{
|
||||
}
|
||||
|
||||
TransactionId::TransactionId(const Id &id, const Snapshot<Id> &snapshot,
|
||||
Engine &engine)
|
||||
: id(id), cid(1), snapshot(snapshot), engine(engine)
|
||||
{
|
||||
}
|
||||
|
||||
bool TransactionId::in_snapshot(const Id &id) const
|
||||
{
|
||||
return snapshot.is_active(id);
|
||||
}
|
||||
|
||||
Id TransactionId::oldest_active()
|
||||
{
|
||||
return snapshot.oldest_active().take_or(Id(id));
|
||||
}
|
||||
}
|
32
src/transactions/transaction_read.cpp
Normal file
32
src/transactions/transaction_read.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "transactions/transaction_read.hpp"
|
||||
|
||||
namespace tx
|
||||
{
|
||||
|
||||
TransactionRead::TransactionRead(Engine &engine)
|
||||
: TransactionRead(Id(), Snapshot<Id>(), engine)
|
||||
{
|
||||
}
|
||||
|
||||
TransactionRead::TransactionRead(const Id &&id, const Snapshot<Id> &&snapshot,
|
||||
Engine &engine)
|
||||
: id(id), cid(1), snapshot(std::move(snapshot)), engine(engine)
|
||||
{
|
||||
}
|
||||
|
||||
TransactionRead::TransactionRead(const Id &id, const Snapshot<Id> &snapshot,
|
||||
Engine &engine)
|
||||
: id(id), cid(1), snapshot(snapshot), engine(engine)
|
||||
{
|
||||
}
|
||||
|
||||
bool TransactionRead::in_snapshot(const Id &id) const
|
||||
{
|
||||
return snapshot.is_active(id);
|
||||
}
|
||||
|
||||
Id TransactionRead::oldest_active()
|
||||
{
|
||||
return snapshot.oldest_active().take_or(Id(id));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user