Commit fcafcff1 authored by andrey@lmy004's avatar andrey@lmy004

WL#1034

updated sources
parent 7120d43c
This diff is collapsed.
...@@ -214,8 +214,8 @@ CREATE TABLE `event` ( ...@@ -214,8 +214,8 @@ CREATE TABLE `event` (
`execute_at` datetime default NULL, `execute_at` datetime default NULL,
`transient_expression` int(11) 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, `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', `created` timestamp NOT NULL,
`modified` timestamp NOT NULL default '0000-00-00 00:00:00', `modified` timestamp NOT NULL,
`last_executed` datetime default NULL, `last_executed` datetime default NULL,
`starts` datetime default NULL, `starts` datetime default NULL,
`ends` datetime default NULL, `ends` datetime default NULL,
......
...@@ -36,6 +36,7 @@ my_bool event_executor_running_global_var= false; ...@@ -36,6 +36,7 @@ my_bool event_executor_running_global_var= false;
extern ulong thread_created; extern ulong thread_created;
static my_bool evex_mutexes_initted= false;
static int static int
evex_load_events_from_db(THD *thd); evex_load_events_from_db(THD *thd);
...@@ -50,6 +51,19 @@ 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_worker(void *arg);
pthread_handler_t event_executor_main(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 int
init_events() init_events()
{ {
...@@ -59,15 +73,15 @@ init_events() ...@@ -59,15 +73,15 @@ init_events()
DBUG_PRINT("info",("Starting events main thread")); DBUG_PRINT("info",("Starting events main thread"));
pthread_mutex_init(&LOCK_event_arrays, MY_MUTEX_INIT_FAST); evex_init_mutexes();
pthread_mutex_init(&LOCK_workers_count, MY_MUTEX_INIT_FAST);
pthread_mutex_init(&LOCK_evex_running, MY_MUTEX_INIT_FAST);
VOID(pthread_mutex_lock(&LOCK_evex_running)); VOID(pthread_mutex_lock(&LOCK_evex_running));
evex_is_running= false; evex_is_running= false;
event_executor_running_global_var= false; event_executor_running_global_var= false;
VOID(pthread_mutex_unlock(&LOCK_evex_running)); VOID(pthread_mutex_unlock(&LOCK_evex_running));
DBUG_RETURN(0);
/*
#ifndef DBUG_FAULTY_THR #ifndef DBUG_FAULTY_THR
//TODO Andrey: Change the error code returned! //TODO Andrey: Change the error code returned!
if (pthread_create(&th, NULL, event_executor_main, (void*)NULL)) if (pthread_create(&th, NULL, event_executor_main, (void*)NULL))
...@@ -77,6 +91,7 @@ init_events() ...@@ -77,6 +91,7 @@ init_events()
#endif #endif
DBUG_RETURN(0); DBUG_RETURN(0);
*/
} }
...@@ -94,6 +109,7 @@ shutdown_events() ...@@ -94,6 +109,7 @@ shutdown_events()
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
#ifdef ANDREY_0
static int static int
init_event_thread(THD* thd) init_event_thread(THD* thd)
...@@ -165,7 +181,7 @@ pthread_handler_t event_executor_main(void *arg) ...@@ -165,7 +181,7 @@ pthread_handler_t event_executor_main(void *arg)
goto err; goto err;
// make this thread invisible it has no vio -> show processlist won't see // 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)); VOID(pthread_mutex_lock(&LOCK_thread_count));
threads.append(thd); threads.append(thd);
...@@ -350,7 +366,7 @@ err_no_thd: ...@@ -350,7 +366,7 @@ err_no_thd:
free_root(&evex_mem_root, MYF(0)); free_root(&evex_mem_root, MYF(0));
sql_print_information("Event executor stopped"); sql_print_information("Event executor stopped");
shutdown_events(); // shutdown_events();
my_thread_end(); my_thread_end();
pthread_exit(0); pthread_exit(0);
...@@ -391,7 +407,7 @@ pthread_handler_t event_executor_worker(void *event_void) ...@@ -391,7 +407,7 @@ pthread_handler_t event_executor_worker(void *event_void)
thd->init_for_queries(); thd->init_for_queries();
// make this thread visible it has no vio -> show processlist needs this flag // 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)); VOID(pthread_mutex_lock(&LOCK_thread_count));
threads.append(thd); threads.append(thd);
...@@ -531,3 +547,20 @@ end: ...@@ -531,3 +547,20 @@ end:
("Events loaded from DB. Status code %d", ret)); ("Events loaded from DB. Status code %d", ret));
DBUG_RETURN(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 @@ ...@@ -17,9 +17,6 @@
#ifndef _EVENT_PRIV_H_ #ifndef _EVENT_PRIV_H_
#define _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 enum
{ {
...@@ -53,5 +50,7 @@ extern pthread_mutex_t LOCK_event_arrays, ...@@ -53,5 +50,7 @@ extern pthread_mutex_t LOCK_event_arrays,
int int
my_time_compare(TIME *a, TIME *b); my_time_compare(TIME *a, TIME *b);
TABLE *evex_open_event_table(THD *thd, enum thr_lock_type lock_type);
#endif /* _EVENT_PRIV_H_ */ #endif /* _EVENT_PRIV_H_ */
...@@ -719,7 +719,7 @@ event_timed::update_fields(THD *thd) ...@@ -719,7 +719,7 @@ event_timed::update_fields(THD *thd)
if (!(m_status_changed || m_last_executed_changed)) if (!(m_status_changed || m_last_executed_changed))
goto done; goto done;
if (!(table= EVEX_OPEN_TABLE_FOR_UPDATE())) if (!(table= evex_open_event_table(thd, TL_WRITE)))
DBUG_RETURN(SP_OPEN_TABLE_FAILED); DBUG_RETURN(SP_OPEN_TABLE_FAILED);
if ((ret= sp_db_find_routine_aux(thd, 0/*notype*/, m_db, m_name, table))) 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."); ...@@ -3568,6 +3568,7 @@ we force server id to 2, but this MySQL server will not act as a slave.");
clean_up(1); clean_up(1);
wait_for_signal_thread_to_end(); wait_for_signal_thread_to_end();
clean_up_mutexes(); clean_up_mutexes();
shutdown_events();
my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
exit(0); exit(0);
......
...@@ -207,7 +207,7 @@ sys_var_long_ptr sys_delayed_insert_timeout("delayed_insert_timeout", ...@@ -207,7 +207,7 @@ sys_var_long_ptr sys_delayed_insert_timeout("delayed_insert_timeout",
&delayed_insert_timeout); &delayed_insert_timeout);
sys_var_long_ptr sys_delayed_queue_size("delayed_queue_size", sys_var_long_ptr sys_delayed_queue_size("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); &event_executor_running_global_var);
sys_var_long_ptr sys_expire_logs_days("expire_logs_days", sys_var_long_ptr sys_expire_logs_days("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) ...@@ -3364,6 +3364,7 @@ bool sys_var_trust_routine_creators::update(THD *thd, set_var *var)
return sys_var_bool_ptr::update(thd, var); return sys_var_bool_ptr::update(thd, var);
} }
/**************************************************************************** /****************************************************************************
Used templates Used templates
****************************************************************************/ ****************************************************************************/
......
...@@ -782,6 +782,17 @@ public: ...@@ -782,6 +782,17 @@ public:
bool update(THD *thd, set_var *var); 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 Classes for parsing of the SET command
****************************************************************************/ ****************************************************************************/
......
...@@ -5737,3 +5737,7 @@ ER_EVENT_ENDS_BEFORE_STARTS ...@@ -5737,3 +5737,7 @@ ER_EVENT_ENDS_BEFORE_STARTS
eng "ENDS must be after STARTS" eng "ENDS must be after STARTS"
ER_EVENT_EXEC_TIME_IN_THE_PAST ER_EVENT_EXEC_TIME_IN_THE_PAST
eng "Activation (AT) time is 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