diff options
author | Sergei Golubchik <sergii@pisem.net> | 2013-11-19 13:16:25 +0100 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2013-11-19 13:16:25 +0100 |
commit | fa3f8a18b247d5d7d86d60d016681cc188522f80 (patch) | |
tree | 180232f5e13c81e22ae9374b41be168ed9578932 /sql/event_scheduler.cc | |
parent | efab095c7f8f044525ce7d2313fad5f86032baab (diff) | |
parent | 543b6e02246db25d8a61574fc709b28e7720d1a0 (diff) | |
download | mariadb-git-fa3f8a18b247d5d7d86d60d016681cc188522f80.tar.gz |
mysql-5.5.34 merge
(some patches reverted, test case added)
Diffstat (limited to 'sql/event_scheduler.cc')
-rw-r--r-- | sql/event_scheduler.cc | 74 |
1 files changed, 43 insertions, 31 deletions
diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc index b41c9e2cda0..95152778bfd 100644 --- a/sql/event_scheduler.cc +++ b/sql/event_scheduler.cc @@ -241,6 +241,12 @@ event_scheduler_thread(void *arg) my_free(arg); if (!res) scheduler->run(thd); + else + { + thd->proc_info= "Clearing"; + net_end(&thd->net); + delete thd; + } DBUG_LEAVE; // Against gcc warnings my_thread_end(); @@ -368,26 +374,26 @@ Event_scheduler::~Event_scheduler() } -/* +/** Starts the scheduler (again). Creates a new THD and passes it to a forked thread. Does not wait for acknowledgement from the new thread that it has started. Asynchronous starting. Most of the needed initializations are done in the current thread to minimize the chance of failure in the spawned thread. - SYNOPSIS - Event_scheduler::start() + @param[out] err_no - errno indicating type of error which caused + failure to start scheduler thread. - RETURN VALUE - FALSE OK - TRUE Error (not reported) + @return + @retval false Success. + @retval true Error. */ bool -Event_scheduler::start() +Event_scheduler::start(int *err_no) { THD *new_thd= NULL; - bool ret= FALSE; + bool ret= false; pthread_t th; struct scheduler_param *scheduler_param_value; DBUG_ENTER("Event_scheduler::start"); @@ -400,7 +406,7 @@ Event_scheduler::start() if (!(new_thd= new THD)) { sql_print_error("Event Scheduler: Cannot initialize the scheduler thread"); - ret= TRUE; + ret= true; goto end; } pre_init_event_thread(new_thd); @@ -423,28 +429,30 @@ Event_scheduler::start() DBUG_PRINT("info", ("Setting state go RUNNING")); state= RUNNING; DBUG_PRINT("info", ("Forking new thread for scheduler. THD: 0x%lx", (long) new_thd)); - if (mysql_thread_create(key_thread_event_scheduler, - &th, &connection_attrib, event_scheduler_thread, - (void*)scheduler_param_value)) + if ((*err_no= mysql_thread_create(key_thread_event_scheduler, + &th, &connection_attrib, + event_scheduler_thread, + (void*)scheduler_param_value))) { DBUG_PRINT("error", ("cannot create a new thread")); - state= INITIALIZED; - scheduler_thd= NULL; - ret= TRUE; + sql_print_error("Event scheduler: Failed to start scheduler," + " Can not create thread for event scheduler (errno=%d)", + *err_no); new_thd->proc_info= "Clearing"; DBUG_ASSERT(new_thd->net.buff != 0); net_end(&new_thd->net); - mysql_mutex_lock(&LOCK_thread_count); - thread_count--; - dec_thread_running(); + + state= INITIALIZED; + scheduler_thd= NULL; delete new_thd; - mysql_cond_broadcast(&COND_thread_count); - mysql_mutex_unlock(&LOCK_thread_count); + + delete scheduler_param_value; + ret= true; } + end: UNLOCK_DATA(); - DBUG_RETURN(ret); } @@ -555,7 +563,20 @@ Event_scheduler::execute_top(Event_queue_element_for_exec *event_name) if ((res= mysql_thread_create(key_thread_event_worker, &th, &connection_attrib, event_worker_thread, event_name))) + { + mysql_mutex_lock(&LOCK_global_system_variables); + Events::opt_event_scheduler= Events::EVENTS_OFF; + mysql_mutex_unlock(&LOCK_global_system_variables); + + sql_print_error("Event_scheduler::execute_top: Can not create event worker" + " thread (errno=%d). Stopping event scheduler", res); + + new_thd->proc_info= "Clearing"; + DBUG_ASSERT(new_thd->net.buff != 0); + net_end(&new_thd->net); + goto error; + } started_events++; executed_events++; // For SHOW STATUS @@ -566,17 +587,8 @@ Event_scheduler::execute_top(Event_queue_element_for_exec *event_name) error: DBUG_PRINT("error", ("Event_scheduler::execute_top() res: %d", res)); if (new_thd) - { - new_thd->proc_info= "Clearing"; - DBUG_ASSERT(new_thd->net.buff != 0); - net_end(&new_thd->net); - mysql_mutex_lock(&LOCK_thread_count); - thread_count--; - dec_thread_running(); delete new_thd; - mysql_cond_broadcast(&COND_thread_count); - mysql_mutex_unlock(&LOCK_thread_count); - } + delete event_name; DBUG_RETURN(TRUE); } |