Skip to content

Commit 0ae219c

Browse files
committed
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.
1 parent 596e990 commit 0ae219c

File tree

10 files changed

+123
-77
lines changed

10 files changed

+123
-77
lines changed

mysys/my_winthread.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ int pthread_create(pthread_t *thread_id, const pthread_attr_t *attr,
6969
uintptr_t handle;
7070
struct thread_start_parameter *par;
7171
unsigned int stack_size;
72+
int error_no;
7273
DBUG_ENTER("pthread_create");
7374

7475
par= (struct thread_start_parameter *)malloc(sizeof(*par));
@@ -89,9 +90,10 @@ int pthread_create(pthread_t *thread_id, const pthread_attr_t *attr,
8990
DBUG_RETURN(0);
9091

9192
error_return:
93+
error_no= errno;
9294
DBUG_PRINT("error",
93-
("Can't create thread to handle request (error %d)",errno));
94-
DBUG_RETURN(-1);
95+
("Can't create thread to handle request (error %d)",error_no));
96+
DBUG_RETURN(error_no);
9597
}
9698

9799

sql/event_scheduler.cc

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ event_scheduler_thread(void *arg)
241241
my_free(arg);
242242
if (!res)
243243
scheduler->run(thd);
244+
else
245+
{
246+
thd->proc_info= "Clearing";
247+
net_end(&thd->net);
248+
delete thd;
249+
}
244250

245251
DBUG_LEAVE; // Against gcc warnings
246252
my_thread_end();
@@ -360,26 +366,26 @@ Event_scheduler::~Event_scheduler()
360366
}
361367

362368

363-
/*
369+
/**
364370
Starts the scheduler (again). Creates a new THD and passes it to
365371
a forked thread. Does not wait for acknowledgement from the new
366372
thread that it has started. Asynchronous starting. Most of the
367373
needed initializations are done in the current thread to minimize
368374
the chance of failure in the spawned thread.
369375
370-
SYNOPSIS
371-
Event_scheduler::start()
376+
@param[out] err_no - errno indicating type of error which caused
377+
failure to start scheduler thread.
372378
373-
RETURN VALUE
374-
FALSE OK
375-
TRUE Error (not reported)
379+
@return
380+
@retval false Success.
381+
@retval true Error.
376382
*/
377383

378384
bool
379-
Event_scheduler::start()
385+
Event_scheduler::start(int *err_no)
380386
{
381387
THD *new_thd= NULL;
382-
bool ret= FALSE;
388+
bool ret= false;
383389
pthread_t th;
384390
struct scheduler_param *scheduler_param_value;
385391
DBUG_ENTER("Event_scheduler::start");
@@ -389,10 +395,16 @@ Event_scheduler::start()
389395
if (state > INITIALIZED)
390396
goto end;
391397

398+
DBUG_EXECUTE_IF("event_scheduler_thread_create_failure", {
399+
*err_no= 11;
400+
Events::opt_event_scheduler= Events::EVENTS_OFF;
401+
ret= true;
402+
goto end; });
403+
392404
if (!(new_thd= new THD))
393405
{
394406
sql_print_error("Event Scheduler: Cannot initialize the scheduler thread");
395-
ret= TRUE;
407+
ret= true;
396408
goto end;
397409
}
398410
pre_init_event_thread(new_thd);
@@ -415,28 +427,30 @@ Event_scheduler::start()
415427
DBUG_PRINT("info", ("Setting state go RUNNING"));
416428
state= RUNNING;
417429
DBUG_PRINT("info", ("Forking new thread for scheduler. THD: 0x%lx", (long) new_thd));
418-
if (mysql_thread_create(key_thread_event_scheduler,
419-
&th, &connection_attrib, event_scheduler_thread,
420-
(void*)scheduler_param_value))
430+
if ((*err_no= mysql_thread_create(key_thread_event_scheduler,
431+
&th, &connection_attrib,
432+
event_scheduler_thread,
433+
(void*)scheduler_param_value)))
421434
{
422435
DBUG_PRINT("error", ("cannot create a new thread"));
423-
state= INITIALIZED;
424-
scheduler_thd= NULL;
425-
ret= TRUE;
436+
sql_print_error("Event scheduler: Failed to start scheduler,"
437+
" Can not create thread for event scheduler (errno=%d)",
438+
*err_no);
426439

427440
new_thd->proc_info= "Clearing";
428441
DBUG_ASSERT(new_thd->net.buff != 0);
429442
net_end(&new_thd->net);
430-
mysql_mutex_lock(&LOCK_thread_count);
431-
thread_count--;
432-
dec_thread_running();
443+
444+
state= INITIALIZED;
445+
scheduler_thd= NULL;
433446
delete new_thd;
434-
mysql_cond_broadcast(&COND_thread_count);
435-
mysql_mutex_unlock(&LOCK_thread_count);
447+
448+
delete scheduler_param_value;
449+
ret= true;
436450
}
451+
437452
end:
438453
UNLOCK_DATA();
439-
440454
DBUG_RETURN(ret);
441455
}
442456

@@ -547,7 +561,20 @@ Event_scheduler::execute_top(Event_queue_element_for_exec *event_name)
547561
if ((res= mysql_thread_create(key_thread_event_worker,
548562
&th, &connection_attrib, event_worker_thread,
549563
event_name)))
564+
{
565+
mysql_mutex_lock(&LOCK_global_system_variables);
566+
Events::opt_event_scheduler= Events::EVENTS_OFF;
567+
mysql_mutex_unlock(&LOCK_global_system_variables);
568+
569+
sql_print_error("Event_scheduler::execute_top: Can not create event worker"
570+
" thread (errno=%d). Stopping event scheduler", res);
571+
572+
new_thd->proc_info= "Clearing";
573+
DBUG_ASSERT(new_thd->net.buff != 0);
574+
net_end(&new_thd->net);
575+
550576
goto error;
577+
}
551578

552579
++started_events;
553580

@@ -557,17 +584,8 @@ Event_scheduler::execute_top(Event_queue_element_for_exec *event_name)
557584
error:
558585
DBUG_PRINT("error", ("Event_scheduler::execute_top() res: %d", res));
559586
if (new_thd)
560-
{
561-
new_thd->proc_info= "Clearing";
562-
DBUG_ASSERT(new_thd->net.buff != 0);
563-
net_end(&new_thd->net);
564-
mysql_mutex_lock(&LOCK_thread_count);
565-
thread_count--;
566-
dec_thread_running();
567587
delete new_thd;
568-
mysql_cond_broadcast(&COND_thread_count);
569-
mysql_mutex_unlock(&LOCK_thread_count);
570-
}
588+
571589
delete event_name;
572590
DBUG_RETURN(TRUE);
573591
}

sql/event_scheduler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Event_scheduler
7878
/* State changing methods follow */
7979

8080
bool
81-
start();
81+
start(int *err_no);
8282

8383
bool
8484
stop();

sql/events.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ Events::init(my_bool opt_noacl_or_bootstrap)
798798
{
799799

800800
THD *thd;
801+
int err_no;
801802
bool res= FALSE;
802803

803804
DBUG_ENTER("Events::init");
@@ -869,7 +870,7 @@ Events::init(my_bool opt_noacl_or_bootstrap)
869870
}
870871

871872
if (event_queue->init_queue(thd) || load_events_from_db(thd) ||
872-
(opt_event_scheduler == EVENTS_ON && scheduler->start()))
873+
(opt_event_scheduler == EVENTS_ON && scheduler->start(&err_no)))
873874
{
874875
sql_print_error("Event Scheduler: Error while loading from disk.");
875876
res= TRUE; /* fatal error: request unireg_abort */
@@ -1017,9 +1018,9 @@ Events::dump_internal_status()
10171018
DBUG_VOID_RETURN;
10181019
}
10191020

1020-
bool Events::start()
1021+
bool Events::start(int *err_no)
10211022
{
1022-
return scheduler->start();
1023+
return scheduler->start(err_no);
10231024
}
10241025

10251026
bool Events::stop()

sql/events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Events
7979
/* Protected using LOCK_global_system_variables only. */
8080
static ulong opt_event_scheduler;
8181
static bool check_if_system_tables_error();
82-
static bool start();
82+
static bool start(int *err_no);
8383
static bool stop();
8484

8585
public:

sql/mysqld.cc

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,11 +1258,12 @@ void kill_mysql(void)
12581258
if (!kill_in_progress)
12591259
{
12601260
pthread_t tmp;
1261+
int error;
12611262
abort_loop=1;
1262-
if (mysql_thread_create(0, /* Not instrumented */
1263-
&tmp, &connection_attrib, kill_server_thread,
1264-
(void*) 0))
1265-
sql_print_error("Can't create thread to kill server");
1263+
if ((error= mysql_thread_create(0, /* Not instrumented */
1264+
&tmp, &connection_attrib,
1265+
kill_server_thread, (void*) 0)))
1266+
sql_print_error("Can't create thread to kill server (errno= %d).", error);
12661267
}
12671268
#endif
12681269
DBUG_VOID_RETURN;
@@ -2728,10 +2729,12 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused)))
27282729
#endif
27292730
#ifdef USE_ONE_SIGNAL_HAND
27302731
pthread_t tmp;
2731-
if (mysql_thread_create(0, /* Not instrumented */
2732-
&tmp, &connection_attrib, kill_server_thread,
2733-
(void*) &sig))
2734-
sql_print_error("Can't create thread to kill server");
2732+
if ((error= mysql_thread_create(0, /* Not instrumented */
2733+
&tmp, &connection_attrib,
2734+
kill_server_thread,
2735+
(void*) &sig)))
2736+
sql_print_error("Can't create thread to kill server (errno= %d)",
2737+
error);
27352738
#else
27362739
kill_server((void*) sig); // MIT THREAD has a alarm thread
27372740
#endif
@@ -4116,9 +4119,12 @@ static void create_shutdown_thread()
41164119
#ifdef __WIN__
41174120
hEventShutdown=CreateEvent(0, FALSE, FALSE, shutdown_event_name);
41184121
pthread_t hThread;
4119-
if (mysql_thread_create(key_thread_handle_shutdown,
4120-
&hThread, &connection_attrib, handle_shutdown, 0))
4121-
sql_print_warning("Can't create thread to handle shutdown requests");
4122+
int error;
4123+
if ((error= mysql_thread_create(key_thread_handle_shutdown,
4124+
&hThread, &connection_attrib,
4125+
handle_shutdown, 0)))
4126+
sql_print_warning("Can't create thread to handle shutdown requests"
4127+
" (errno= %d)", error);
41224128

41234129
// On "Stop Service" we have to do regular shutdown
41244130
Service.SetShutdownEvent(hEventShutdown);
@@ -4132,6 +4138,7 @@ static void create_shutdown_thread()
41324138
static void handle_connections_methods()
41334139
{
41344140
pthread_t hThread;
4141+
int error;
41354142
DBUG_ENTER("handle_connections_methods");
41364143
if (hPipe == INVALID_HANDLE_VALUE &&
41374144
(!have_tcpip || opt_disable_networking) &&
@@ -4147,34 +4154,37 @@ static void handle_connections_methods()
41474154
if (hPipe != INVALID_HANDLE_VALUE)
41484155
{
41494156
handler_count++;
4150-
if (mysql_thread_create(key_thread_handle_con_namedpipes,
4151-
&hThread, &connection_attrib,
4152-
handle_connections_namedpipes, 0))
4157+
if ((error= mysql_thread_create(key_thread_handle_con_namedpipes,
4158+
&hThread, &connection_attrib,
4159+
handle_connections_namedpipes, 0)))
41534160
{
4154-
sql_print_warning("Can't create thread to handle named pipes");
4161+
sql_print_warning("Can't create thread to handle named pipes"
4162+
" (errno= %d)", error);
41554163
handler_count--;
41564164
}
41574165
}
41584166
if (have_tcpip && !opt_disable_networking)
41594167
{
41604168
handler_count++;
4161-
if (mysql_thread_create(key_thread_handle_con_sockets,
4162-
&hThread, &connection_attrib,
4163-
handle_connections_sockets_thread, 0))
4169+
if ((error= mysql_thread_create(key_thread_handle_con_sockets,
4170+
&hThread, &connection_attrib,
4171+
handle_connections_sockets_thread, 0)))
41644172
{
4165-
sql_print_warning("Can't create thread to handle TCP/IP");
4173+
sql_print_warning("Can't create thread to handle TCP/IP",
4174+
" (errno= %d)", error);
41664175
handler_count--;
41674176
}
41684177
}
41694178
#ifdef HAVE_SMEM
41704179
if (opt_enable_shared_memory)
41714180
{
41724181
handler_count++;
4173-
if (mysql_thread_create(key_thread_handle_con_sharedmem,
4174-
&hThread, &connection_attrib,
4175-
handle_connections_shared_memory, 0))
4182+
if ((error= mysql_thread_create(key_thread_handle_con_sharedmem,
4183+
&hThread, &connection_attrib,
4184+
handle_connections_shared_memory, 0)))
41764185
{
4177-
sql_print_warning("Can't create thread to handle shared memory");
4186+
sql_print_warning("Can't create thread to handle shared memory",
4187+
" (errno= %d)", error);
41784188
handler_count--;
41794189
}
41804190
}
@@ -4909,11 +4919,14 @@ static void bootstrap(MYSQL_FILE *file)
49094919

49104920
bootstrap_file=file;
49114921
#ifndef EMBEDDED_LIBRARY // TODO: Enable this
4912-
if (mysql_thread_create(key_thread_bootstrap,
4913-
&thd->real_id, &connection_attrib, handle_bootstrap,
4914-
(void*) thd))
4922+
int error;
4923+
if ((error= mysql_thread_create(key_thread_bootstrap,
4924+
&thd->real_id, &connection_attrib,
4925+
handle_bootstrap,
4926+
(void*) thd)))
49154927
{
4916-
sql_print_warning("Can't create thread to handle bootstrap");
4928+
sql_print_warning("Can't create thread to handle bootstrap (errno= %d)",
4929+
error);
49174930
bootstrap_error=-1;
49184931
DBUG_VOID_RETURN;
49194932
}
@@ -5012,6 +5025,7 @@ void create_thread_to_handle_connection(THD *thd)
50125025
DBUG_PRINT("error",
50135026
("Can't create thread to handle request (error %d)",
50145027
error));
5028+
50155029
thread_count--;
50165030
thd->killed= THD::KILL_CONNECTION; // Safety
50175031
mysql_mutex_unlock(&LOCK_thread_count);

sql/slave.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ int start_slave_thread(
709709
{
710710
pthread_t th;
711711
ulong start_id;
712+
int error;
712713
DBUG_ENTER("start_slave_thread");
713714

714715
DBUG_ASSERT(mi->inited);
@@ -735,9 +736,10 @@ int start_slave_thread(
735736
}
736737
start_id= *slave_run_id;
737738
DBUG_PRINT("info",("Creating new slave thread"));
738-
if (mysql_thread_create(thread_key,
739-
&th, &connection_attrib, h_func, (void*)mi))
739+
if ((error = mysql_thread_create(thread_key,
740+
&th, &connection_attrib, h_func, (void*)mi)))
740741
{
742+
sql_print_error("Can't create slave thread (errno= %d).", error);
741743
if (start_lock)
742744
mysql_mutex_unlock(start_lock);
743745
DBUG_RETURN(ER_SLAVE_THREAD);

sql/sql_manager.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,12 @@ void start_handle_manager()
136136
if (flush_time && flush_time != ~(ulong) 0L)
137137
{
138138
pthread_t hThread;
139-
if (mysql_thread_create(key_thread_handle_manager,
140-
&hThread, &connection_attrib, handle_manager, 0))
141-
sql_print_warning("Can't create handle_manager thread");
139+
int error;
140+
if ((error= mysql_thread_create(key_thread_handle_manager,
141+
&hThread, &connection_attrib,
142+
handle_manager, 0)))
143+
sql_print_warning("Can't create handle_manager thread (errno= %d)",
144+
error);
142145
}
143146
DBUG_VOID_RETURN;
144147
}

0 commit comments

Comments
 (0)