2015-11-22 02:16:19 +08:00
|
|
|
#pragma once
|
2015-07-04 17:51:33 +08:00
|
|
|
|
2015-07-31 18:36:41 +08:00
|
|
|
#include <cstdint>
|
2016-07-05 11:01:22 +08:00
|
|
|
#include <cstdlib>
|
2015-07-04 17:51:33 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2015-11-22 02:16:19 +08:00
|
|
|
#include "mvcc/id.hpp"
|
2016-01-03 05:20:09 +08:00
|
|
|
#include "storage/locking/record_lock.hpp"
|
2016-07-05 11:01:22 +08:00
|
|
|
#include "transactions/lock_store.hpp"
|
|
|
|
#include "transactions/snapshot.hpp"
|
2015-10-08 06:58:29 +08:00
|
|
|
|
2015-10-04 15:47:15 +08:00
|
|
|
namespace tx
|
|
|
|
{
|
2015-07-31 18:36:41 +08:00
|
|
|
|
2015-12-06 23:42:47 +08:00
|
|
|
class Engine;
|
|
|
|
|
|
|
|
class Transaction
|
2015-07-04 17:51:33 +08:00
|
|
|
{
|
2015-12-06 23:42:47 +08:00
|
|
|
friend class Engine;
|
|
|
|
|
|
|
|
public:
|
2016-07-05 11:01:22 +08:00
|
|
|
Transaction(const Id &id, const Snapshot<Id> &snapshot, Engine &engine);
|
|
|
|
Transaction(const Transaction &) = delete;
|
|
|
|
Transaction(Transaction &&) = delete;
|
2015-07-04 17:51:33 +08:00
|
|
|
|
|
|
|
// index of this transaction
|
2015-12-06 23:42:47 +08:00
|
|
|
const Id id;
|
2015-07-07 22:18:26 +08:00
|
|
|
// index of the current command in the current transaction;
|
|
|
|
uint8_t cid;
|
2015-10-08 06:58:29 +08:00
|
|
|
// a snapshot of currently active transactions
|
2015-12-06 23:42:47 +08:00
|
|
|
const Snapshot<Id> snapshot;
|
|
|
|
|
2016-07-05 11:01:22 +08:00
|
|
|
void take_lock(RecordLock &lock);
|
2015-12-06 23:42:47 +08:00
|
|
|
void commit();
|
|
|
|
void abort();
|
|
|
|
|
2016-07-05 11:01:22 +08:00
|
|
|
Engine &engine;
|
2016-03-12 19:26:56 +08:00
|
|
|
|
|
|
|
private:
|
2015-12-06 23:42:47 +08:00
|
|
|
LockStore<RecordLock> locks;
|
2015-07-04 17:51:33 +08:00
|
|
|
};
|
2015-10-04 15:47:15 +08:00
|
|
|
}
|