mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
SerialScheduler.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <condition_variable>
5#include <list>
6#include <future>
7#include <thread>
8
9
10namespace m {
11
16{
17 private:
20 {
21 private:
22 std::list<queued_command> command_list_;
24 std::mutex mutex_;
25 std::condition_variable has_element_;
26 bool closed_ = false;
27
28 public:
29 CommandQueue() = default;
30 ~CommandQueue() = default;
31
33 std::optional<queued_command> pop();
37 void push(Transaction &t, std::unique_ptr<ast::Command> command, Diagnostic &diag, std::promise<bool> promise);
38 void close();
39 bool is_closed();
41 };
42
44 std::thread schedule_thread_;
45
46 static std::atomic<int64_t> next_start_time;
47
48 public:
49 SerialScheduler() = default;
51
52 std::future<bool> schedule_command(Transaction &t, std::unique_ptr<ast::Command> command, Diagnostic &diag) override;
53
54 std::unique_ptr<Transaction> begin_transaction() override;
55
56 bool commit(std::unique_ptr<Transaction> t) override;
57
58 bool abort(std::unique_ptr<Transaction> t) override;
59
60 private:
64 static void schedule_thread();
65};
66
67}
‍mutable namespace
Definition: Backend.hpp:10
The Scheduler handles the execution of all incoming queries.
Definition: Scheduler.hpp:15
A thread-safe query plan queue.
std::condition_variable has_element_
std::optional< queued_command > pop()
‍returns the next queued ast::Command. Returns std::nullopt if the queue is closed.
void stop_transaction(Transaction &t)
Marks t as no longer running.
bool is_closed()
signals waiting threads that no more elements will be pushed
void close()
empties and closes the queue without executing the remaining ast::Commands.
std::list< queued_command > command_list_
void push(Transaction &t, std::unique_ptr< ast::Command > command, Diagnostic &diag, std::promise< bool > promise)
Inserts the command into the queue.
Transaction * running_transaction_
the currently running transaction. Only commands by this transaction are returned.
This class implements a Scheduler that executes all incoming DatabaseCommands serially.
bool commit(std::unique_ptr< Transaction > t) override
Closes the given Scheduler::Transaction and commits its changes.
std::future< bool > schedule_command(Transaction &t, std::unique_ptr< ast::Command > command, Diagnostic &diag) override
Schedule a ast::Command for execution within the given Scheduler::Transaction.
std::unique_ptr< Transaction > begin_transaction() override
Returns a new Scheduler::Transaction object that is passed along when scheduling commands.
static std::atomic< int64_t > next_start_time
stores the next transaction start time
static void schedule_thread()
The method run by the worker thread schedule_thread_.
bool abort(std::unique_ptr< Transaction > t) override
Closes the given Scheduler::Transaction and discards its changes.
SerialScheduler()=default
std::thread schedule_thread_
the worker thread that executes all incoming queries.
static CommandQueue query_queue_
instance of our thread-safe query queue that stores all incoming plans.