mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
WL#3337 (Event scheduler new architecture)
This patch makes the relationship between Event_scheduler and Event_queue unidirectional from the former to the latter. The change is that the conditional on which the scheduler sleeped has been moved to the Event_queue and the latter does not call anymore Event_scheduler::queue_changed(), which in turn has be removed. sql/event_queue.cc: Remove dependency of Event_queue on Event_scheduler but not vice versa. Event_scheduler polls whether there is time to execute an event. Removed notify_observers() as the way of calling has changed. Added Event_queue::cond_wait() similar to Event_scheduler::cond_wait(). sql/event_queue.h: init_queue() does not need anymore Event_scheduler object because the relationship is now one-way. Event_scheduler knows about Event_queue but not vice versa. get_top_execution_if_time() does by itself the waiting instead of returning abstime. This simplifies the code in Event_scheduler::run() get_top_execution_if_time() returns only if job_data != NULL or if the scheduler thread was killed. notify_observers() is no more used and therefore removed. Added Event_queue::cond_wait() because now there is waiting on a conditional variable in Event_queue too (like in Event_scheduler for ::stop()). sql/event_scheduler.cc: Change the relationship between Event_scheduler & Event_queue. Event_queue does not know anymore about Event_scheduler. When the scheduler calls get_top_element_if_time() it may fall asleep on a conditional of Event_queue, if either the queue is empty or it's still not time for activation. When the method returns it will return a non-null address, namely an object to be executed. If the return value is NULL, the thread was killed by a call to Event_scheduler::stop() (we assert this). sql/event_scheduler.h: Remove queue_changed() as it is obsoleted by making the relationship between Event_scheduler and Event_queue one-way, from the former to the latter. Event_queue now does not know about Event_scheduler. get_state() is changed to is_running(). The state enum should be private, as it is not needed to be seen from outside anymore. sql/events.cc: Event_queue does not need anymore a pointer to Event_scheduler.
This commit is contained in:
@@ -36,7 +36,7 @@ public:
|
||||
deinit_mutexes();
|
||||
|
||||
bool
|
||||
init_queue(THD *thd, Event_db_repository *db_repo, Event_scheduler *sched);
|
||||
init_queue(THD *thd, Event_db_repository *db_repo);
|
||||
|
||||
void
|
||||
deinit_queue();
|
||||
@@ -60,8 +60,7 @@ public:
|
||||
recalculate_activation_times(THD *thd);
|
||||
|
||||
bool
|
||||
get_top_for_execution_if_time(THD *thd, time_t now, Event_job_data **job_data,
|
||||
struct timespec *abstime);
|
||||
get_top_for_execution_if_time(THD *thd, Event_job_data **job_data);
|
||||
bool
|
||||
dump_internal_status(THD *thd);
|
||||
|
||||
@@ -80,14 +79,12 @@ protected:
|
||||
void
|
||||
empty_queue();
|
||||
|
||||
void
|
||||
notify_observers();
|
||||
|
||||
void
|
||||
dbug_dump_queue(time_t now);
|
||||
|
||||
/* LOCK_event_queue is the mutex which protects the access to the queue. */
|
||||
pthread_mutex_t LOCK_event_queue;
|
||||
pthread_cond_t COND_queue_state;
|
||||
|
||||
Event_db_repository *db_repository;
|
||||
|
||||
@@ -96,6 +93,8 @@ protected:
|
||||
/* The sorted queue with the Event_job_data objects */
|
||||
QUEUE queue;
|
||||
|
||||
TIME next_activation_at;
|
||||
|
||||
uint mutex_last_locked_at_line;
|
||||
uint mutex_last_unlocked_at_line;
|
||||
uint mutex_last_attempted_lock_at_line;
|
||||
@@ -104,6 +103,7 @@ protected:
|
||||
const char* mutex_last_attempted_lock_in_func;
|
||||
bool mutex_queue_data_locked;
|
||||
bool mutex_queue_data_attempting_lock;
|
||||
bool waiting_on_cond;
|
||||
|
||||
/* helper functions for working with mutexes & conditionals */
|
||||
void
|
||||
@@ -111,6 +111,10 @@ protected:
|
||||
|
||||
void
|
||||
unlock_data(const char *func, uint line);
|
||||
|
||||
void
|
||||
cond_wait(THD *thd, struct timespec *abstime, const char* msg,
|
||||
const char *func, uint line);
|
||||
};
|
||||
|
||||
#endif /* _EVENT_QUEUE_H_ */
|
||||
|
Reference in New Issue
Block a user