memgraph/transaction/transaction.hpp

38 lines
1.0 KiB
C++
Raw Normal View History

#ifndef MEMGRAPH_TRANSACTION_TRANSACTION_HPP
#define MEMGRAPH_TRANSACTION_TRANSACTION_HPP
#include <cstdlib>
#include <vector>
template <class id_t>
struct Transaction
{
Transaction(id_t id, std::vector<id_t> active)
2015-07-07 22:18:26 +08:00
: id(id), cid(1), active(std::move(active)) {}
// index of this transaction
id_t id;
2015-07-07 22:18:26 +08:00
// index of the current command in the current transaction;
uint8_t cid;
// the ids of the currently active transactions used by the mvcc
2015-07-07 22:18:26 +08:00
// implementation for snapshot transaction isolation.
// std::vector is much faster than std::set for fewer number of items
// we don't expect the number of active transactions getting too large.
std::vector<id_t> active;
2015-07-07 22:18:26 +08:00
// check weather the transaction with the xid looks committed from the
// database snapshot given to this transaction
bool committed(id_t xid)
{
2015-07-07 22:18:26 +08:00
for(size_t i = 0; i < active.size(); ++i)
if(xid < active[i])
return false;
return true;
}
};
#endif