2015-07-04 17:51:33 +08:00
|
|
|
#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)) {}
|
2015-07-04 17:51:33 +08:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2015-07-04 17:51:33 +08:00
|
|
|
// 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.
|
2015-07-04 17:51:33 +08:00
|
|
|
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-04 17:51:33 +08:00
|
|
|
{
|
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;
|
2015-07-04 17:51:33 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|