summaryrefslogtreecommitdiff
path: root/sql/event_queue.cc
diff options
context:
space:
mode:
authorkostja@vajra.(none) <>2007-04-05 15:24:34 +0400
committerkostja@vajra.(none) <>2007-04-05 15:24:34 +0400
commit98db2300865004a4bb573caebc82b25fb5b08911 (patch)
tree0b971c23e8972589634666ba0253a19e298ee0bf /sql/event_queue.cc
parentc392623bf9fd24193673737902c9751a0bea3e3b (diff)
downloadmariadb-git-98db2300865004a4bb573caebc82b25fb5b08911.tar.gz
A set of changes aiming to make the Event Scheduler more user-friendly
when there are no up-to-date system tables to support it: - initialize the scheduler before reporting "Ready for connections". This ensures that warnings, if any, are printed before "Ready for connections", and this message is not mangled. - do not abort the scheduler if there are no system tables - check the tables once at start up, remember the status and disable the scheduler if the tables are not up to date. If one attempts to use the scheduler with bad tables, issue an error message. - clean up the behaviour of the module under LOCK TABLES and pre-locking mode - make sure implicit commit of Events DDL works as expected. - add more tests Collateral clean ups in the events code. This patch fixes Bug#23631 Events: SHOW VARIABLES doesn't work when mysql.event is damaged
Diffstat (limited to 'sql/event_queue.cc')
-rw-r--r--sql/event_queue.cc76
1 files changed, 36 insertions, 40 deletions
diff --git a/sql/event_queue.cc b/sql/event_queue.cc
index f110bfdd1bf..2fe6e0b87e0 100644
--- a/sql/event_queue.cc
+++ b/sql/event_queue.cc
@@ -72,39 +72,21 @@ event_queue_element_compare_q(void *vptr, byte* a, byte *b)
Event_queue::Event_queue()
:mutex_last_unlocked_at_line(0), mutex_last_locked_at_line(0),
mutex_last_attempted_lock_at_line(0),
- mutex_queue_data_locked(FALSE), mutex_queue_data_attempting_lock(FALSE)
+ mutex_queue_data_locked(FALSE),
+ mutex_queue_data_attempting_lock(FALSE),
+ next_activation_at(0)
{
mutex_last_unlocked_in_func= mutex_last_locked_in_func=
mutex_last_attempted_lock_in_func= "";
- next_activation_at= 0;
-}
-
-/*
- Inits mutexes.
-
- SYNOPSIS
- Event_queue::init_mutexes()
-*/
-
-void
-Event_queue::init_mutexes()
-{
pthread_mutex_init(&LOCK_event_queue, MY_MUTEX_INIT_FAST);
pthread_cond_init(&COND_queue_state, NULL);
}
-/*
- Destroys mutexes.
-
- SYNOPSIS
- Event_queue::deinit_mutexes()
-*/
-
-void
-Event_queue::deinit_mutexes()
+Event_queue::~Event_queue()
{
+ deinit_queue();
pthread_mutex_destroy(&LOCK_event_queue);
pthread_cond_destroy(&COND_queue_state);
}
@@ -176,33 +158,47 @@ Event_queue::deinit_queue()
/**
Adds an event to the queue.
- SYNOPSIS
- Event_queue::create_event()
- dbname The schema of the new event
- name The name of the new event
+ Compute the next execution time for an event, and if it is still
+ active, add it to the queue. Otherwise delete it.
+ The object is left intact in case of an error. Otherwise
+ the queue container assumes ownership of it.
+
+ @param[in] thd thread handle
+ @param[in] new_element a new element to add to the queue
+ @param[out] created set to TRUE if no error and the element is
+ added to the queue, FALSE otherwise
+
+ @retval TRUE an error occured. The value of created is undefined,
+ the element was not deleted.
+ @retval FALSE success
*/
-void
-Event_queue::create_event(THD *thd, Event_queue_element *new_element)
+bool
+Event_queue::create_event(THD *thd, Event_queue_element *new_element,
+ bool *created)
{
DBUG_ENTER("Event_queue::create_event");
DBUG_PRINT("enter", ("thd: 0x%lx et=%s.%s", (long) thd,
new_element->dbname.str, new_element->name.str));
+ /* Will do nothing if the event is disabled */
+ new_element->compute_next_execution_time();
if (new_element->status == Event_queue_element::DISABLED)
- delete new_element;
- else
{
- new_element->compute_next_execution_time();
- DBUG_PRINT("info", ("new event in the queue: 0x%lx", (long) new_element));
-
- LOCK_QUEUE_DATA();
- queue_insert_safe(&queue, (byte *) new_element);
- dbug_dump_queue(thd->query_start());
- pthread_cond_broadcast(&COND_queue_state);
- UNLOCK_QUEUE_DATA();
+ delete new_element;
+ *created= FALSE;
+ DBUG_RETURN(FALSE);
}
- DBUG_VOID_RETURN;
+
+ DBUG_PRINT("info", ("new event in the queue: 0x%lx", (long) new_element));
+
+ LOCK_QUEUE_DATA();
+ *created= (queue_insert_safe(&queue, (byte *) new_element) == FALSE);
+ dbug_dump_queue(thd->query_start());
+ pthread_cond_broadcast(&COND_queue_state);
+ UNLOCK_QUEUE_DATA();
+
+ DBUG_RETURN(!*created);
}