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,
uintptr_t handle;
struct thread_start_parameter *par;
unsigned int stack_size;
int error_no;
DBUG_ENTER("pthread_create");
par= (struct thread_start_parameter *)malloc(sizeof(*par));
......@@ -89,9 +90,10 @@ int pthread_create(pthread_t *thread_id, const pthread_attr_t *attr,
DBUG_RETURN(0);
error_return:
error_no= errno;
DBUG_PRINT("error",
("Can't create thread to handle request (error %d)",errno));
DBUG_RETURN(-1);
("Can't create thread to handle request (error %d)",error_no));
DBUG_RETURN(error_no);
}
......
......@@ -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();
......@@ -360,26 +366,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");
......@@ -389,10 +395,16 @@ Event_scheduler::start()
if (state > INITIALIZED)
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))
{
sql_print_error("Event Scheduler: Cannot initialize the scheduler thread");
ret= TRUE;
ret= true;
goto end;
}
pre_init_event_thread(new_thd);
......@@ -415,28 +427,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);
}
......@@ -547,7 +561,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;
......@@ -557,17 +584,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);
}
......
......@@ -78,7 +78,7 @@ public:
/* State changing methods follow */
bool
start();
start(int *err_no);
bool
stop();
......
......@@ -798,6 +798,7 @@ Events::init(my_bool opt_noacl_or_bootstrap)
{
THD *thd;
int err_no;
bool res= FALSE;
DBUG_ENTER("Events::init");
......@@ -869,7 +870,7 @@ Events::init(my_bool opt_noacl_or_bootstrap)
}
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.");
res= TRUE; /* fatal error: request unireg_abort */
......@@ -1017,9 +1018,9 @@ Events::dump_internal_status()
DBUG_VOID_RETURN;
}
bool Events::start()
bool Events::start(int *err_no)
{
return scheduler->start();
return scheduler->start(err_no);
}
bool Events::stop()
......
......@@ -79,7 +79,7 @@ public:
/* Protected using LOCK_global_system_variables only. */
static ulong opt_event_scheduler;
static bool check_if_system_tables_error();
static bool start();
static bool start(int *err_no);
static bool stop();
public:
......
......@@ -1258,11 +1258,12 @@ void kill_mysql(void)
if (!kill_in_progress)
{
pthread_t tmp;
int error;
abort_loop=1;
if (mysql_thread_create(0, /* Not instrumented */
&tmp, &connection_attrib, kill_server_thread,
(void*) 0))
sql_print_error("Can't create thread to kill server");
if ((error= mysql_thread_create(0, /* Not instrumented */
&tmp, &connection_attrib,
kill_server_thread, (void*) 0)))
sql_print_error("Can't create thread to kill server (errno= %d).", error);
}
#endif
DBUG_VOID_RETURN;
......@@ -2728,10 +2729,12 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused)))
#endif
#ifdef USE_ONE_SIGNAL_HAND
pthread_t tmp;
if (mysql_thread_create(0, /* Not instrumented */
&tmp, &connection_attrib, kill_server_thread,
(void*) &sig))
sql_print_error("Can't create thread to kill server");
if ((error= mysql_thread_create(0, /* Not instrumented */
&tmp, &connection_attrib,
kill_server_thread,
(void*) &sig)))
sql_print_error("Can't create thread to kill server (errno= %d)",
error);
#else
kill_server((void*) sig); // MIT THREAD has a alarm thread
#endif
......@@ -4116,9 +4119,12 @@ static void create_shutdown_thread()
#ifdef __WIN__
hEventShutdown=CreateEvent(0, FALSE, FALSE, shutdown_event_name);
pthread_t hThread;
if (mysql_thread_create(key_thread_handle_shutdown,
&hThread, &connection_attrib, handle_shutdown, 0))
sql_print_warning("Can't create thread to handle shutdown requests");
int error;
if ((error= mysql_thread_create(key_thread_handle_shutdown,
&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
Service.SetShutdownEvent(hEventShutdown);
......@@ -4132,6 +4138,7 @@ static void create_shutdown_thread()
static void handle_connections_methods()
{
pthread_t hThread;
int error;
DBUG_ENTER("handle_connections_methods");
if (hPipe == INVALID_HANDLE_VALUE &&
(!have_tcpip || opt_disable_networking) &&
......@@ -4147,22 +4154,24 @@ static void handle_connections_methods()
if (hPipe != INVALID_HANDLE_VALUE)
{
handler_count++;
if (mysql_thread_create(key_thread_handle_con_namedpipes,
if ((error= mysql_thread_create(key_thread_handle_con_namedpipes,
&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--;
}
}
if (have_tcpip && !opt_disable_networking)
{
handler_count++;
if (mysql_thread_create(key_thread_handle_con_sockets,
if ((error= mysql_thread_create(key_thread_handle_con_sockets,
&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--;
}
}
......@@ -4170,11 +4179,12 @@ static void handle_connections_methods()
if (opt_enable_shared_memory)
{
handler_count++;
if (mysql_thread_create(key_thread_handle_con_sharedmem,
if ((error= mysql_thread_create(key_thread_handle_con_sharedmem,
&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--;
}
}
......@@ -4909,11 +4919,14 @@ static void bootstrap(MYSQL_FILE *file)
bootstrap_file=file;
#ifndef EMBEDDED_LIBRARY // TODO: Enable this
if (mysql_thread_create(key_thread_bootstrap,
&thd->real_id, &connection_attrib, handle_bootstrap,
(void*) thd))
int error;
if ((error= mysql_thread_create(key_thread_bootstrap,
&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;
DBUG_VOID_RETURN;
}
......@@ -5012,6 +5025,7 @@ void create_thread_to_handle_connection(THD *thd)
DBUG_PRINT("error",
("Can't create thread to handle request (error %d)",
error));
thread_count--;
thd->killed= THD::KILL_CONNECTION; // Safety
mysql_mutex_unlock(&LOCK_thread_count);
......
......@@ -709,6 +709,7 @@ int start_slave_thread(
{
pthread_t th;
ulong start_id;
int error;
DBUG_ENTER("start_slave_thread");
DBUG_ASSERT(mi->inited);
......@@ -735,9 +736,10 @@ int start_slave_thread(
}
start_id= *slave_run_id;
DBUG_PRINT("info",("Creating new slave thread"));
if (mysql_thread_create(thread_key,
&th, &connection_attrib, h_func, (void*)mi))
if ((error = mysql_thread_create(thread_key,
&th, &connection_attrib, h_func, (void*)mi)))
{
sql_print_error("Can't create slave thread (errno= %d).", error);
if (start_lock)
mysql_mutex_unlock(start_lock);
DBUG_RETURN(ER_SLAVE_THREAD);
......
......@@ -136,9 +136,12 @@ void start_handle_manager()
if (flush_time && flush_time != ~(ulong) 0L)
{
pthread_t hThread;
if (mysql_thread_create(key_thread_handle_manager,
&hThread, &connection_attrib, handle_manager, 0))
sql_print_warning("Can't create handle_manager thread");
int error;
if ((error= mysql_thread_create(key_thread_handle_manager,
&hThread, &connection_attrib,
handle_manager, 0)))
sql_print_warning("Can't create handle_manager thread (errno= %d)",
error);
}
DBUG_VOID_RETURN;
}
......
......@@ -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)
{
int err_no= 0;
uint opt_event_scheduler_value= Events::opt_event_scheduler;
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)
for deadlocks. See bug#51160.
*/
bool ret= opt_event_scheduler_value == Events::EVENTS_ON
? Events::start()
? Events::start(&err_no)
: Events::stop();
mysql_mutex_lock(&LOCK_global_system_variables);
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;
}
......
......@@ -2648,6 +2648,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
ulonglong UNINIT_VAR(key_map);
pthread_attr_t thr_attr;
ulong max_pack_reclength;
int error;
DBUG_ENTER("mi_repair_parallel");
start_records=info->state->records;
......@@ -2942,12 +2943,13 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
#else
param->sort_buffer_length*sort_param[i].key_length/total_key_length;
#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,
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. */
if (io_share.total_threads)
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