mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Scheduler.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <mutable/mutable-config.hpp>
6#include <compare>
7#include <future>
8
9
10namespace m {
11
14struct M_EXPORT Scheduler
15{
16 struct Transaction {
17 private:
19 uint64_t id_;
21 int64_t start_time_ = -1;
22
24 static std::atomic<uint64_t> next_id_;
25
26 public:
27 Transaction() : id_(next_id_.fetch_add(1, std::memory_order_relaxed)) { }
28
30 void start_time(int64_t time) { M_insist(start_time_ == -1 and time >= 0); start_time_ = time; };
31 int64_t start_time() const { return start_time_; };
32
33 auto operator==(const Transaction &other) const { return id_ == other.id_; };
34 auto operator<=>(const Transaction &other) const { return id_ <=> other.id_; };
35 };
36
37 protected:
38 using queued_command = std::tuple<Transaction &, std::unique_ptr<ast::Command>, Diagnostic &, std::promise<bool>>;
39
40 public:
41 Scheduler() = default;
42 virtual ~Scheduler() {}
43
46 virtual std::future<bool> schedule_command(Transaction &t, std::unique_ptr<ast::Command> command, Diagnostic &diag) = 0;
47
49 virtual std::unique_ptr<Transaction> begin_transaction() = 0;
50
53 virtual bool commit(std::unique_ptr<Transaction> t) = 0;
54
57 virtual bool abort(std::unique_ptr<Transaction> t) = 0;
58
61 bool autocommit(std::unique_ptr<ast::Command> command, Diagnostic &diag);
62};
63
64}
and(sizeof(T)==4) U64x1 reinterpret_to_U64(m
Definition: WasmAlgo.cpp:266
#define M_insist(...)
Definition: macro.hpp:129
‍mutable namespace
Definition: Backend.hpp:10
STL namespace.
auto operator==(const Transaction &other) const
Definition: Scheduler.hpp:33
auto operator<=>(const Transaction &other) const
Definition: Scheduler.hpp:34
static std::atomic< uint64_t > next_id_
‍Stores the next available Transaction ID, stored atomically to prevent race conditions
Definition: Scheduler.hpp:24
void start_time(int64_t time)
‍sets the start time of the Transaction. Should only be set once and only to a positive number.
Definition: Scheduler.hpp:30
uint64_t id_
‍the Transaction ID
Definition: Scheduler.hpp:19
int64_t start_time() const
Definition: Scheduler.hpp:31
The Scheduler handles the execution of all incoming queries.
Definition: Scheduler.hpp:15
std::tuple< Transaction &, std::unique_ptr< ast::Command >, Diagnostic &, std::promise< bool > > queued_command
Definition: Scheduler.hpp:38
virtual std::unique_ptr< Transaction > begin_transaction()=0
Returns a new Scheduler::Transaction object that is passed along when scheduling commands.
virtual bool commit(std::unique_ptr< Transaction > t)=0
Closes the given Scheduler::Transaction and commits its changes.
Scheduler()=default
virtual ~Scheduler()
Definition: Scheduler.hpp:42
virtual bool abort(std::unique_ptr< Transaction > t)=0
Closes the given Scheduler::Transaction and discards its changes.
virtual std::future< bool > schedule_command(Transaction &t, std::unique_ptr< ast::Command > command, Diagnostic &diag)=0
Schedule a ast::Command for execution within the given Scheduler::Transaction.