diff options
author | Sergei Golubchik <sergii@pisem.net> | 2013-11-23 00:50:54 +0100 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2013-11-23 00:50:54 +0100 |
commit | c6d30805db3a1a2a098c3009fde8a42efd9fb9de (patch) | |
tree | e55f68e5adf40e1a75e08bda91b712ab6a094643 /sql/event_scheduler.cc | |
parent | 2c032b990e4ec470fad2e9f61cf6267a68b7e937 (diff) | |
parent | eea310e498f3b7ac95a4492d48f04e08d3009412 (diff) | |
download | mariadb-git-c6d30805db3a1a2a098c3009fde8a42efd9fb9de.tar.gz |
5.5 merge
Diffstat (limited to 'sql/event_scheduler.cc')
-rw-r--r-- | sql/event_scheduler.cc | 66 |
1 files changed, 46 insertions, 20 deletions
diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc index 4a4ae5a732f..07f5a520e64 100644 --- a/sql/event_scheduler.cc +++ b/sql/event_scheduler.cc @@ -238,6 +238,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(); @@ -365,26 +371,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"); @@ -397,7 +403,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; } @@ -422,21 +428,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")); + 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); + state= INITIALIZED; scheduler_thd= NULL; - ret= TRUE; + delete new_thd; - new_thd->proc_info= "Clearing"; - delete_running_thd(new_thd); + delete scheduler_param_value; + ret= true; } + end: UNLOCK_DATA(); - DBUG_RETURN(ret); } @@ -548,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 @@ -559,10 +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"; - delete_running_thd(new_thd); - } + delete new_thd; + delete event_name; DBUG_RETURN(TRUE); } |