4#include <condition_variable>
33 std::optional<queued_command>
pop();
56 bool commit(std::unique_ptr<Transaction> t)
override;
58 bool abort(std::unique_ptr<Transaction> t)
override;
The Scheduler handles the execution of all incoming queries.
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.