Commit 0ae219cd authored by Praveenkumar Hulakund's avatar Praveenkumar Hulakund

Bug#16865959 - PLEASE BACKPORT BUG 14749800.

Since log_throttle is not available in 5.5. Logging of
error message for failure of thread to create new connection
in "create_thread_to_handle_connection" is not backported.

Since, function "my_plugin_log_message" is not available in 
5.5 version and since there is incompatibility between
sql_print_XXX function compiled with g++ and alog files with
gcc to use sql_print_error, changes related to audit log
plugin is not backported.
parent 596e9902
...@@ -69,6 +69,7 @@ int pthread_create(pthread_t *thread_id, const pthread_attr_t *attr, ...@@ -69,6 +69,7 @@ int pthread_create(pthread_t *thread_id, const pthread_attr_t *attr,
uintptr_t handle; uintptr_t handle;
struct thread_start_parameter *par; struct thread_start_parameter *par;
unsigned int stack_size; unsigned int stack_size;
int error_no;
DBUG_ENTER("pthread_create"); DBUG_ENTER("pthread_create");
par= (struct thread_start_parameter *)malloc(sizeof(*par)); par= (struct thread_start_parameter *)malloc(sizeof(*par));
...@@ -89,9 +90,10 @@ int pthread_create(pthread_t *thread_id, const pthread_attr_t *attr, ...@@ -89,9 +90,10 @@ int pthread_create(pthread_t *thread_id, const pthread_attr_t *attr,
DBUG_RETURN(0); DBUG_RETURN(0);
error_return: error_return:
error_no= errno;
DBUG_PRINT("error", DBUG_PRINT("error",
("Can't create thread to handle request (error %d)",errno)); ("Can't create thread to handle request (error %d)",error_no));
DBUG_RETURN(-1); DBUG_RETURN(error_no);
} }
......
...@@ -241,6 +241,12 @@ event_scheduler_thread(void *arg) ...@@ -241,6 +241,12 @@ event_scheduler_thread(void *arg)
my_free(arg); my_free(arg);
if (!res) if (!res)
scheduler->run(thd); scheduler->run(thd);
else
{
thd->proc_info= "Clearing";
net_end(&thd->net);
delete thd;
}
DBUG_LEAVE; // Against gcc warnings DBUG_LEAVE; // Against gcc warnings
my_thread_end(); my_thread_end();
...@@ -360,26 +366,26 @@ Event_scheduler::~Event_scheduler() ...@@ -360,26 +366,26 @@ Event_scheduler::~Event_scheduler()
} }
/* /**
Starts the scheduler (again). Creates a new THD and passes it to Starts the scheduler (again). Creates a new THD and passes it to
a forked thread. Does not wait for acknowledgement from the new a forked thread. Does not wait for acknowledgement from the new
thread that it has started. Asynchronous starting. Most of the thread that it has started. Asynchronous starting. Most of the
needed initializations are done in the current thread to minimize needed initializations are done in the current thread to minimize
the chance of failure in the spawned thread. the chance of failure in the spawned thread.
SYNOPSIS @param[out] err_no - errno indicating type of error which caused
Event_scheduler::start() failure to start scheduler thread.
RETURN VALUE @return
FALSE OK @retval false Success.
TRUE Error (not reported) @retval true Error.
*/ */
bool bool
Event_scheduler::start() Event_scheduler::start(int *err_no)
{ {
THD *new_thd= NULL; THD *new_thd= NULL;
bool ret= FALSE; bool ret= false;
pthread_t th; pthread_t th;
struct scheduler_param *scheduler_param_value; struct scheduler_param *scheduler_param_value;
DBUG_ENTER("Event_scheduler::start"); DBUG_ENTER("Event_scheduler::start");
...@@ -389,10 +395,16 @@ Event_scheduler::start() ...@@ -389,10 +395,16 @@ Event_scheduler::start()
if (state > INITIALIZED) if (state > INITIALIZED)
goto end; goto end;
DBUG_EXECUTE_IF("event_scheduler_thread_create_failure", {
*err_no= 11;
Events::opt_event_scheduler= Events::EVENTS_OFF;
ret= true;
goto end; });
if (!(new_thd= new THD)) if (!(new_thd= new THD))
{ {
sql_print_error("Event Scheduler: Cannot initialize the scheduler thread"); sql_print_error("Event Scheduler: Cannot initialize the scheduler thread");
ret= TRUE; ret= true;
goto end; goto end;
} }
pre_init_event_thread(new_thd); pre_init_event_thread(new_thd);
...@@ -415,28 +427,30 @@ Event_scheduler::start() ...@@ -415,28 +427,30 @@ Event_scheduler::start()
DBUG_PRINT("info", ("Setting state go RUNNING")); DBUG_PRINT("info", ("Setting state go RUNNING"));
state= RUNNING; state= RUNNING;
DBUG_PRINT("info", ("Forking new thread for scheduler. THD: 0x%lx", (long) new_thd)); DBUG_PRINT("info", ("Forking new thread for scheduler. THD: 0x%lx", (long) new_thd));
if (mysql_thread_create(key_thread_event_scheduler, if ((*err_no= mysql_thread_create(key_thread_event_scheduler,
&th, &connection_attrib, event_scheduler_thread, &th, &connection_attrib,
(void*)scheduler_param_value)) event_scheduler_thread,
(void*)scheduler_param_value)))
{ {
DBUG_PRINT("error", ("cannot create a new thread")); DBUG_PRINT("error", ("cannot create a new thread"));
state= INITIALIZED; sql_print_error("Event scheduler: Failed to start scheduler,"
scheduler_thd= NULL; " Can not create thread for event scheduler (errno=%d)",
ret= TRUE; *err_no);
new_thd->proc_info= "Clearing"; new_thd->proc_info= "Clearing";
DBUG_ASSERT(new_thd->net.buff != 0); DBUG_ASSERT(new_thd->net.buff != 0);
net_end(&new_thd->net); net_end(&new_thd->net);
mysql_mutex_lock(&LOCK_thread_count);
thread_count--; state= INITIALIZED;
dec_thread_running(); scheduler_thd= NULL;
delete new_thd; delete new_thd;
mysql_cond_broadcast(&COND_thread_count);
mysql_mutex_unlock(&LOCK_thread_count); delete scheduler_param_value;
ret= true;
} }
end: end:
UNLOCK_DATA(); UNLOCK_DATA();
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
...@@ -547,7 +561,20 @@ Event_scheduler::execute_top(Event_queue_element_for_exec *event_name) ...@@ -547,7 +561,20 @@ Event_scheduler::execute_top(Event_queue_element_for_exec *event_name)
if ((res= mysql_thread_create(key_thread_event_worker, if ((res= mysql_thread_create(key_thread_event_worker,
&th, &connection_attrib, event_worker_thread, &th, &connection_attrib, event_worker_thread,
event_name))) 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; goto error;
}
++started_events; ++started_events;
...@@ -557,17 +584,8 @@ Event_scheduler::execute_top(Event_queue_element_for_exec *event_name) ...@@ -557,17 +584,8 @@ Event_scheduler::execute_top(Event_queue_element_for_exec *event_name)
error: error:
DBUG_PRINT("error", ("Event_scheduler::execute_top() res: %d", res)); DBUG_PRINT("error", ("Event_scheduler::execute_top() res: %d", res));
if (new_thd) 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; delete new_thd;
mysql_cond_broadcast(&COND_thread_count);
mysql_mutex_unlock(&LOCK_thread_count);
}
delete event_name; delete event_name;
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
......
...@@ -78,7 +78,7 @@ public: ...@@ -78,7 +78,7 @@ public:
/* State changing methods follow */ /* State changing methods follow */
bool bool
start(); start(int *err_no);
bool bool
stop(); stop();
......
...@@ -798,6 +798,7 @@ Events::init(my_bool opt_noacl_or_bootstrap) ...@@ -798,6 +798,7 @@ Events::init(my_bool opt_noacl_or_bootstrap)
{ {
THD *thd; THD *thd;
int err_no;
bool res= FALSE; bool res= FALSE;
DBUG_ENTER("Events::init"); DBUG_ENTER("Events::init");
...@@ -869,7 +870,7 @@ Events::init(my_bool opt_noacl_or_bootstrap) ...@@ -869,7 +870,7 @@ Events::init(my_bool opt_noacl_or_bootstrap)
} }
if (event_queue->init_queue(thd) || load_events_from_db(thd) || if (event_queue->init_queue(thd) || load_events_from_db(thd) ||
(opt_event_scheduler == EVENTS_ON && scheduler->start())) (opt_event_scheduler == EVENTS_ON && scheduler->start(&err_no)))
{ {
sql_print_error("Event Scheduler: Error while loading from disk."); sql_print_error("Event Scheduler: Error while loading from disk.");
res= TRUE; /* fatal error: request unireg_abort */ res= TRUE; /* fatal error: request unireg_abort */
...@@ -1017,9 +1018,9 @@ Events::dump_internal_status() ...@@ -1017,9 +1018,9 @@ Events::dump_internal_status()
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
bool Events::start() bool Events::start(int *err_no)
{ {
return scheduler->start(); return scheduler->start(err_no);
} }
bool Events::stop() bool Events::stop()
......
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
/* Protected using LOCK_global_system_variables only. */ /* Protected using LOCK_global_system_variables only. */
static ulong opt_event_scheduler; static ulong opt_event_scheduler;
static bool check_if_system_tables_error(); static bool check_if_system_tables_error();
static bool start(); static bool start(int *err_no);
static bool stop(); static bool stop();
public: public:
......
...@@ -1258,11 +1258,12 @@ void kill_mysql(void) ...@@ -1258,11 +1258,12 @@ void kill_mysql(void)
if (!kill_in_progress) if (!kill_in_progress)
{ {
pthread_t tmp; pthread_t tmp;
int error;
abort_loop=1; abort_loop=1;
if (mysql_thread_create(0, /* Not instrumented */ if ((error= mysql_thread_create(0, /* Not instrumented */
&tmp, &connection_attrib, kill_server_thread, &tmp, &connection_attrib,
(void*) 0)) kill_server_thread, (void*) 0)))
sql_print_error("Can't create thread to kill server"); sql_print_error("Can't create thread to kill server (errno= %d).", error);
} }
#endif #endif
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
...@@ -2728,10 +2729,12 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused))) ...@@ -2728,10 +2729,12 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused)))
#endif #endif
#ifdef USE_ONE_SIGNAL_HAND #ifdef USE_ONE_SIGNAL_HAND
pthread_t tmp; pthread_t tmp;
if (mysql_thread_create(0, /* Not instrumented */ if ((error= mysql_thread_create(0, /* Not instrumented */
&tmp, &connection_attrib, kill_server_thread, &tmp, &connection_attrib,
(void*) &sig)) kill_server_thread,
sql_print_error("Can't create thread to kill server"); (void*) &sig)))
sql_print_error("Can't create thread to kill server (errno= %d)",
error);
#else #else
kill_server((void*) sig); // MIT THREAD has a alarm thread kill_server((void*) sig); // MIT THREAD has a alarm thread
#endif #endif
...@@ -4116,9 +4119,12 @@ static void create_shutdown_thread() ...@@ -4116,9 +4119,12 @@ static void create_shutdown_thread()
#ifdef __WIN__ #ifdef __WIN__
hEventShutdown=CreateEvent(0, FALSE, FALSE, shutdown_event_name); hEventShutdown=CreateEvent(0, FALSE, FALSE, shutdown_event_name);
pthread_t hThread; pthread_t hThread;
if (mysql_thread_create(key_thread_handle_shutdown, int error;
&hThread, &connection_attrib, handle_shutdown, 0)) if ((error= mysql_thread_create(key_thread_handle_shutdown,
sql_print_warning("Can't create thread to handle shutdown requests"); &hThread, &connection_attrib,
handle_shutdown, 0)))
sql_print_warning("Can't create thread to handle shutdown requests"
" (errno= %d)", error);
// On "Stop Service" we have to do regular shutdown // On "Stop Service" we have to do regular shutdown
Service.SetShutdownEvent(hEventShutdown); Service.SetShutdownEvent(hEventShutdown);
...@@ -4132,6 +4138,7 @@ static void create_shutdown_thread() ...@@ -4132,6 +4138,7 @@ static void create_shutdown_thread()
static void handle_connections_methods() static void handle_connections_methods()
{ {
pthread_t hThread; pthread_t hThread;
int error;
DBUG_ENTER("handle_connections_methods"); DBUG_ENTER("handle_connections_methods");
if (hPipe == INVALID_HANDLE_VALUE && if (hPipe == INVALID_HANDLE_VALUE &&
(!have_tcpip || opt_disable_networking) && (!have_tcpip || opt_disable_networking) &&
...@@ -4147,22 +4154,24 @@ static void handle_connections_methods() ...@@ -4147,22 +4154,24 @@ static void handle_connections_methods()
if (hPipe != INVALID_HANDLE_VALUE) if (hPipe != INVALID_HANDLE_VALUE)
{ {
handler_count++; handler_count++;
if (mysql_thread_create(key_thread_handle_con_namedpipes, if ((error= mysql_thread_create(key_thread_handle_con_namedpipes,
&hThread, &connection_attrib, &hThread, &connection_attrib,
handle_connections_namedpipes, 0)) handle_connections_namedpipes, 0)))
{ {
sql_print_warning("Can't create thread to handle named pipes"); sql_print_warning("Can't create thread to handle named pipes"
" (errno= %d)", error);
handler_count--; handler_count--;
} }
} }
if (have_tcpip && !opt_disable_networking) if (have_tcpip && !opt_disable_networking)
{ {
handler_count++; handler_count++;
if (mysql_thread_create(key_thread_handle_con_sockets, if ((error= mysql_thread_create(key_thread_handle_con_sockets,
&hThread, &connection_attrib, &hThread, &connection_attrib,
handle_connections_sockets_thread, 0)) handle_connections_sockets_thread, 0)))
{ {
sql_print_warning("Can't create thread to handle TCP/IP"); sql_print_warning("Can't create thread to handle TCP/IP",
" (errno= %d)", error);
handler_count--; handler_count--;
} }
} }
...@@ -4170,11 +4179,12 @@ static void handle_connections_methods() ...@@ -4170,11 +4179,12 @@ static void handle_connections_methods()
if (opt_enable_shared_memory) if (opt_enable_shared_memory)
{ {
handler_count++; handler_count++;
if (mysql_thread_create(key_thread_handle_con_sharedmem, if ((error= mysql_thread_create(key_thread_handle_con_sharedmem,
&hThread, &connection_attrib, &hThread, &connection_attrib,
handle_connections_shared_memory, 0)) handle_connections_shared_memory, 0)))
{ {
sql_print_warning("Can't create thread to handle shared memory"); sql_print_warning("Can't create thread to handle shared memory",
" (errno= %d)", error);
handler_count--; handler_count--;
} }
} }
...@@ -4909,11 +4919,14 @@ static void bootstrap(MYSQL_FILE *file) ...@@ -4909,11 +4919,14 @@ static void bootstrap(MYSQL_FILE *file)
bootstrap_file=file; bootstrap_file=file;
#ifndef EMBEDDED_LIBRARY // TODO: Enable this #ifndef EMBEDDED_LIBRARY // TODO: Enable this
if (mysql_thread_create(key_thread_bootstrap, int error;
&thd->real_id, &connection_attrib, handle_bootstrap, if ((error= mysql_thread_create(key_thread_bootstrap,
(void*) thd)) &thd->real_id, &connection_attrib,
handle_bootstrap,
(void*) thd)))
{ {
sql_print_warning("Can't create thread to handle bootstrap"); sql_print_warning("Can't create thread to handle bootstrap (errno= %d)",
error);
bootstrap_error=-1; bootstrap_error=-1;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -5012,6 +5025,7 @@ void create_thread_to_handle_connection(THD *thd) ...@@ -5012,6 +5025,7 @@ void create_thread_to_handle_connection(THD *thd)
DBUG_PRINT("error", DBUG_PRINT("error",
("Can't create thread to handle request (error %d)", ("Can't create thread to handle request (error %d)",
error)); error));
thread_count--; thread_count--;
thd->killed= THD::KILL_CONNECTION; // Safety thd->killed= THD::KILL_CONNECTION; // Safety
mysql_mutex_unlock(&LOCK_thread_count); mysql_mutex_unlock(&LOCK_thread_count);
......
...@@ -709,6 +709,7 @@ int start_slave_thread( ...@@ -709,6 +709,7 @@ int start_slave_thread(
{ {
pthread_t th; pthread_t th;
ulong start_id; ulong start_id;
int error;
DBUG_ENTER("start_slave_thread"); DBUG_ENTER("start_slave_thread");
DBUG_ASSERT(mi->inited); DBUG_ASSERT(mi->inited);
...@@ -735,9 +736,10 @@ int start_slave_thread( ...@@ -735,9 +736,10 @@ int start_slave_thread(
} }
start_id= *slave_run_id; start_id= *slave_run_id;
DBUG_PRINT("info",("Creating new slave thread")); DBUG_PRINT("info",("Creating new slave thread"));
if (mysql_thread_create(thread_key, if ((error = mysql_thread_create(thread_key,
&th, &connection_attrib, h_func, (void*)mi)) &th, &connection_attrib, h_func, (void*)mi)))
{ {
sql_print_error("Can't create slave thread (errno= %d).", error);
if (start_lock) if (start_lock)
mysql_mutex_unlock(start_lock); mysql_mutex_unlock(start_lock);
DBUG_RETURN(ER_SLAVE_THREAD); DBUG_RETURN(ER_SLAVE_THREAD);
......
...@@ -136,9 +136,12 @@ void start_handle_manager() ...@@ -136,9 +136,12 @@ void start_handle_manager()
if (flush_time && flush_time != ~(ulong) 0L) if (flush_time && flush_time != ~(ulong) 0L)
{ {
pthread_t hThread; pthread_t hThread;
if (mysql_thread_create(key_thread_handle_manager, int error;
&hThread, &connection_attrib, handle_manager, 0)) if ((error= mysql_thread_create(key_thread_handle_manager,
sql_print_warning("Can't create handle_manager thread"); &hThread, &connection_attrib,
handle_manager, 0)))
sql_print_warning("Can't create handle_manager thread (errno= %d)",
error);
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
...@@ -746,6 +746,7 @@ static bool event_scheduler_check(sys_var *self, THD *thd, set_var *var) ...@@ -746,6 +746,7 @@ static bool event_scheduler_check(sys_var *self, THD *thd, set_var *var)
} }
static bool event_scheduler_update(sys_var *self, THD *thd, enum_var_type type) static bool event_scheduler_update(sys_var *self, THD *thd, enum_var_type type)
{ {
int err_no= 0;
uint opt_event_scheduler_value= Events::opt_event_scheduler; uint opt_event_scheduler_value= Events::opt_event_scheduler;
mysql_mutex_unlock(&LOCK_global_system_variables); mysql_mutex_unlock(&LOCK_global_system_variables);
/* /*
...@@ -765,11 +766,14 @@ static bool event_scheduler_update(sys_var *self, THD *thd, enum_var_type type) ...@@ -765,11 +766,14 @@ static bool event_scheduler_update(sys_var *self, THD *thd, enum_var_type type)
for deadlocks. See bug#51160. for deadlocks. See bug#51160.
*/ */
bool ret= opt_event_scheduler_value == Events::EVENTS_ON bool ret= opt_event_scheduler_value == Events::EVENTS_ON
? Events::start() ? Events::start(&err_no)
: Events::stop(); : Events::stop();
mysql_mutex_lock(&LOCK_global_system_variables); mysql_mutex_lock(&LOCK_global_system_variables);
if (ret) if (ret)
my_error(ER_EVENT_SET_VAR_ERROR, MYF(0), 0); {
Events::opt_event_scheduler= Events::EVENTS_OFF;
my_error(ER_EVENT_SET_VAR_ERROR, MYF(0), err_no);
}
return ret; return ret;
} }
......
...@@ -2648,6 +2648,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, ...@@ -2648,6 +2648,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
ulonglong UNINIT_VAR(key_map); ulonglong UNINIT_VAR(key_map);
pthread_attr_t thr_attr; pthread_attr_t thr_attr;
ulong max_pack_reclength; ulong max_pack_reclength;
int error;
DBUG_ENTER("mi_repair_parallel"); DBUG_ENTER("mi_repair_parallel");
start_records=info->state->records; start_records=info->state->records;
...@@ -2942,12 +2943,13 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, ...@@ -2942,12 +2943,13 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
#else #else
param->sort_buffer_length*sort_param[i].key_length/total_key_length; param->sort_buffer_length*sort_param[i].key_length/total_key_length;
#endif #endif
if (mysql_thread_create(mi_key_thread_find_all_keys, if ((error= mysql_thread_create(mi_key_thread_find_all_keys,
&sort_param[i].thr, &thr_attr, &sort_param[i].thr, &thr_attr,
thr_find_all_keys, thr_find_all_keys,
(void *) (sort_param+i))) (void *) (sort_param+i))))
{ {
mi_check_print_error(param,"Cannot start a repair thread"); mi_check_print_error(param,"Cannot start a repair thread (errno= %d)",
error);
/* Cleanup: Detach from the share. Avoid others to be blocked. */ /* Cleanup: Detach from the share. Avoid others to be blocked. */
if (io_share.total_threads) if (io_share.total_threads)
remove_io_thread(&sort_param[i].read_cache); remove_io_thread(&sort_param[i].read_cache);
......
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