Commit bfc58c8f authored by unknown's avatar unknown

WL#1034

updated sources


sql/event.cc:
  update
  put some error calls to the places they occur
sql/event.h:
  - change the default (does not work in STRICT mode)
sql/event_executor.cc:
  move mutex initialization to evex_init_mutexes so init_events() can be reused when the
  main thread does not work and set global event_scheduler=1; (this will start the thread)
  The main thread is now visible with show processlist and can be killed.
sql/event_priv.h:
  don't use anymore SP for opening table
sql/event_timed.cc:
  don't use anymore SP routines for opening mysql.event
sql/mysqld.cc:
  shutdown_events() should be maximal at the end of the server because
  it destroys mutexes of EVEX. The call should not be in the main thread.
sql/set_var.cc:
  make sys_var_event_executor subclass sys_var_bool_ptr
  to overload ::update() method - needed to start a
  killed (non-running) evex main thread
sql/set_var.h:
  declare class sys_var_event_executor
sql/share/errmsg.txt:
  2 new messages
parent 9d08edd2
This diff is collapsed.
......@@ -214,8 +214,8 @@ CREATE TABLE `event` (
`execute_at` datetime default NULL,
`transient_expression` int(11) default NULL,
`interval_type` enum('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') default NULL,
`created` timestamp NOT NULL default '0000-00-00 00:00:00',
`modified` timestamp NOT NULL default '0000-00-00 00:00:00',
`created` timestamp NOT NULL,
`modified` timestamp NOT NULL,
`last_executed` datetime default NULL,
`starts` datetime default NULL,
`ends` datetime default NULL,
......
......@@ -36,6 +36,7 @@ my_bool event_executor_running_global_var= false;
extern ulong thread_created;
static my_bool evex_mutexes_initted= false;
static int
evex_load_events_from_db(THD *thd);
......@@ -50,6 +51,19 @@ evex_load_events_from_db(THD *thd);
pthread_handler_t event_executor_worker(void *arg);
pthread_handler_t event_executor_main(void *arg);
static
void evex_init_mutexes()
{
if (evex_mutexes_initted)
{
evex_mutexes_initted= true;
return;
}
pthread_mutex_init(&LOCK_event_arrays, MY_MUTEX_INIT_FAST);
pthread_mutex_init(&LOCK_workers_count, MY_MUTEX_INIT_FAST);
pthread_mutex_init(&LOCK_evex_running, MY_MUTEX_INIT_FAST);
}
int
init_events()
{
......@@ -59,15 +73,15 @@ init_events()
DBUG_PRINT("info",("Starting events main thread"));
pthread_mutex_init(&LOCK_event_arrays, MY_MUTEX_INIT_FAST);
pthread_mutex_init(&LOCK_workers_count, MY_MUTEX_INIT_FAST);
pthread_mutex_init(&LOCK_evex_running, MY_MUTEX_INIT_FAST);
evex_init_mutexes();
VOID(pthread_mutex_lock(&LOCK_evex_running));
evex_is_running= false;
event_executor_running_global_var= false;
VOID(pthread_mutex_unlock(&LOCK_evex_running));
DBUG_RETURN(0);
/*
#ifndef DBUG_FAULTY_THR
//TODO Andrey: Change the error code returned!
if (pthread_create(&th, NULL, event_executor_main, (void*)NULL))
......@@ -77,6 +91,7 @@ init_events()
#endif
DBUG_RETURN(0);
*/
}
......@@ -94,6 +109,7 @@ shutdown_events()
DBUG_VOID_RETURN;
}
#ifdef ANDREY_0
static int
init_event_thread(THD* thd)
......@@ -165,7 +181,7 @@ pthread_handler_t event_executor_main(void *arg)
goto err;
// make this thread invisible it has no vio -> show processlist won't see
thd->system_thread= 0;
thd->system_thread= 1;
VOID(pthread_mutex_lock(&LOCK_thread_count));
threads.append(thd);
......@@ -350,7 +366,7 @@ pthread_handler_t event_executor_main(void *arg)
free_root(&evex_mem_root, MYF(0));
sql_print_information("Event executor stopped");
shutdown_events();
// shutdown_events();
my_thread_end();
pthread_exit(0);
......@@ -391,7 +407,7 @@ pthread_handler_t event_executor_worker(void *event_void)
thd->init_for_queries();
// make this thread visible it has no vio -> show processlist needs this flag
thd->system_thread= 0;
thd->system_thread= 1;
VOID(pthread_mutex_lock(&LOCK_thread_count));
threads.append(thd);
......@@ -531,3 +547,20 @@ evex_load_events_from_db(THD *thd)
("Events loaded from DB. Status code %d", ret));
DBUG_RETURN(ret);
}
#endif
bool sys_var_event_executor::update(THD *thd, set_var *var)
{
#ifdef ANDREY_0
// here start the thread if not running.
VOID(pthread_mutex_lock(&LOCK_evex_running));
if ((my_bool) var->save_result.ulong_value && !evex_is_running) {
VOID(pthread_mutex_unlock(&LOCK_evex_running));
init_events();
} else
VOID(pthread_mutex_unlock(&LOCK_evex_running));
#endif
return sys_var_bool_ptr::update(thd, var);
}
......@@ -17,9 +17,6 @@
#ifndef _EVENT_PRIV_H_
#define _EVENT_PRIV_H_
#define EVEX_OPEN_TABLE_FOR_UPDATE() \
open_proc_type_table_for_update(thd, "event", &mysql_event_table_exists)
enum
{
......@@ -53,5 +50,7 @@ extern pthread_mutex_t LOCK_event_arrays,
int
my_time_compare(TIME *a, TIME *b);
TABLE *evex_open_event_table(THD *thd, enum thr_lock_type lock_type);
#endif /* _EVENT_PRIV_H_ */
......@@ -719,7 +719,7 @@ event_timed::update_fields(THD *thd)
if (!(m_status_changed || m_last_executed_changed))
goto done;
if (!(table= EVEX_OPEN_TABLE_FOR_UPDATE()))
if (!(table= evex_open_event_table(thd, TL_WRITE)))
DBUG_RETURN(SP_OPEN_TABLE_FAILED);
if ((ret= sp_db_find_routine_aux(thd, 0/*notype*/, m_db, m_name, table)))
......
......@@ -3568,6 +3568,7 @@ we force server id to 2, but this MySQL server will not act as a slave.");
clean_up(1);
wait_for_signal_thread_to_end();
clean_up_mutexes();
shutdown_events();
my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
exit(0);
......
......@@ -207,7 +207,7 @@ sys_var_long_ptr sys_delayed_insert_timeout("delayed_insert_timeout",
&delayed_insert_timeout);
sys_var_long_ptr sys_delayed_queue_size("delayed_queue_size",
&delayed_queue_size);
sys_var_bool_ptr sys_event_executor("event_scheduler",
sys_var_event_executor sys_event_executor("event_scheduler",
&event_executor_running_global_var);
sys_var_long_ptr sys_expire_logs_days("expire_logs_days",
&expire_logs_days);
......@@ -3364,6 +3364,7 @@ bool sys_var_trust_routine_creators::update(THD *thd, set_var *var)
return sys_var_bool_ptr::update(thd, var);
}
/****************************************************************************
Used templates
****************************************************************************/
......
......@@ -782,6 +782,17 @@ class sys_var_trust_routine_creators :public sys_var_bool_ptr
bool update(THD *thd, set_var *var);
};
class sys_var_event_executor :public sys_var_bool_ptr
{
/* We need a derived class only to have a warn_deprecated() */
public:
sys_var_event_executor(const char *name_arg, my_bool *value_arg) :
sys_var_bool_ptr(name_arg, value_arg) {};
bool update(THD *thd, set_var *var);
};
/****************************************************************************
Classes for parsing of the SET command
****************************************************************************/
......
......@@ -5737,3 +5737,7 @@ ER_EVENT_ENDS_BEFORE_STARTS
eng "ENDS must be after STARTS"
ER_EVENT_EXEC_TIME_IN_THE_PAST
eng "Activation (AT) time is in the past"
ER_EVENT_OPEN_TABLE_FAILED
eng "Failed to open mysql.event"
ER_EVENT_NEITHER_M_EXPR_NOR_M_AT
eng "No datetime expression provided"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment