@@ -2735,11 +2735,7 @@ static void network_init(void)
27352735 @note
27362736 For the connection that is doing shutdown, this is called twice
27372737*/
2738- #ifdef WITH_WSREP
2739- void close_connection (THD *thd, uint sql_errno, bool lock)
2740- #else
27412738void close_connection (THD *thd, uint sql_errno)
2742- #endif
27432739{
27442740 DBUG_ENTER (" close_connection" );
27452741
@@ -2972,7 +2968,11 @@ bool one_thread_per_connection_end(THD *thd, bool put_in_cache)
29722968 unlink_thd (thd);
29732969 /* Mark that current_thd is not valid anymore */
29742970 set_current_thd (0 );
2971+ #ifdef WITH_WSREP
2972+ if (put_in_cache && cache_thread () && !thd->wsrep_applier )
2973+ #else
29752974 if (put_in_cache && cache_thread ())
2975+ #endif /* WITH_WSREP */
29762976 DBUG_RETURN (0 ); // Thread is reused
29772977
29782978 /*
@@ -5248,7 +5248,7 @@ pthread_handler_t start_wsrep_THD(void *arg)
52485248 thd->thr_create_utime = microsecond_interval_timer ();
52495249 if (MYSQL_CALLBACK_ELSE (thread_scheduler, init_new_connection_thread, (), 0 ))
52505250 {
5251- close_connection (thd, ER_OUT_OF_RESOURCES, 1 );
5251+ close_connection (thd, ER_OUT_OF_RESOURCES);
52525252 statistic_increment (aborted_connects,&LOCK_status);
52535253 MYSQL_CALLBACK (thread_scheduler, end_thread, (thd, 0 ));
52545254
@@ -5271,7 +5271,7 @@ pthread_handler_t start_wsrep_THD(void *arg)
52715271 thd->thread_stack = (char *) &thd;
52725272 if (thd->store_globals ())
52735273 {
5274- close_connection (thd, ER_OUT_OF_RESOURCES, 1 );
5274+ close_connection (thd, ER_OUT_OF_RESOURCES);
52755275 statistic_increment (aborted_connects,&LOCK_status);
52765276 MYSQL_CALLBACK (thread_scheduler, end_thread, (thd, 0 ));
52775277 delete thd;
@@ -5300,10 +5300,11 @@ pthread_handler_t start_wsrep_THD(void *arg)
53005300
53015301 processor (thd);
53025302
5303- close_connection (thd, 0 , 1 );
5303+ close_connection (thd, 0 );
53045304
53055305 mysql_mutex_lock (&LOCK_thread_count);
53065306 wsrep_running_threads--;
5307+ WSREP_DEBUG (" wsrep running threads now: %lu" , wsrep_running_threads);
53075308 mysql_cond_signal (&COND_thread_count);
53085309 mysql_mutex_unlock (&LOCK_thread_count);
53095310
@@ -5323,6 +5324,7 @@ pthread_handler_t start_wsrep_THD(void *arg)
53235324 // at server shutdown
53245325 }
53255326
5327+ my_thread_end ();
53265328 if (thread_handling > SCHEDULER_ONE_THREAD_PER_CONNECTION)
53275329 {
53285330 mysql_mutex_lock (&LOCK_thread_count);
@@ -5409,23 +5411,6 @@ static bool have_client_connections()
54095411 return false ;
54105412}
54115413
5412- /*
5413- returns the number of wsrep appliers running.
5414- However, the caller (thd parameter) is not taken in account
5415- */
5416- static int have_wsrep_appliers (THD *thd)
5417- {
5418- int ret= 0 ;
5419- THD *tmp;
5420-
5421- I_List_iterator<THD> it (threads);
5422- while ((tmp=it++))
5423- {
5424- ret+= (tmp != thd && tmp->wsrep_applier );
5425- }
5426- return ret;
5427- }
5428-
54295414static void wsrep_close_thread (THD *thd)
54305415{
54315416 thd->killed = KILL_CONNECTION;
@@ -5536,7 +5521,7 @@ void wsrep_close_client_connections(my_bool wait_to_end)
55365521!is_replaying_connection (tmp))
55375522 {
55385523 WSREP_INFO (" killing local connection: %ld" ,tmp->thread_id );
5539- close_connection (tmp,0 , 0 );
5524+ close_connection (tmp,0 );
55405525 }
55415526#endif
55425527 }
@@ -5611,7 +5596,7 @@ void wsrep_wait_appliers_close(THD *thd)
56115596{
56125597 /* Wait for wsrep appliers to gracefully exit */
56135598 mysql_mutex_lock (&LOCK_thread_count);
5614- while (have_wsrep_appliers (thd) > 1 )
5599+ while (wsrep_running_threads > 1 )
56155600 // 1 is for rollbacker thread which needs to be killed explicitly.
56165601 // This gotta be fixed in a more elegant manner if we gonna have arbitrary
56175602 // number of non-applier wsrep threads.
@@ -5631,7 +5616,7 @@ void wsrep_wait_appliers_close(THD *thd)
56315616 wsrep_close_threads (thd);
56325617 /* and wait for them to die */
56335618 mysql_mutex_lock (&LOCK_thread_count);
5634- while (have_wsrep_appliers (thd) > 0 )
5619+ while (wsrep_running_threads > 0 )
56355620 {
56365621 if (thread_handling > SCHEDULER_ONE_THREAD_PER_CONNECTION)
56375622 {
@@ -6630,11 +6615,7 @@ void create_thread_to_handle_connection(THD *thd)
66306615 my_snprintf (error_message_buff, sizeof (error_message_buff),
66316616 ER_THD (thd, ER_CANT_CREATE_THREAD), error);
66326617 net_send_error (thd, ER_CANT_CREATE_THREAD, error_message_buff, NULL );
6633- #ifdef WITH_WSREP
6634- close_connection (thd, ER_OUT_OF_RESOURCES ,0 );
6635- #else
66366618 close_connection (thd, ER_OUT_OF_RESOURCES);
6637- #endif /* WITH_WSREP */
66386619
66396620 mysql_mutex_lock (&LOCK_thread_count);
66406621 thd->unlink ();
@@ -6680,11 +6661,7 @@ static void create_new_thread(THD *thd)
66806661 mysql_mutex_unlock (&LOCK_connection_count);
66816662
66826663 DBUG_PRINT (" error" ,(" Too many connections" ));
6683- #ifdef WITH_WSREP
6684- close_connection (thd, ER_CON_COUNT_ERROR, 1 );
6685- #else
66866664 close_connection (thd, ER_CON_COUNT_ERROR);
6687- #endif /* WITH_WSREP */
66886665 statistic_increment (denied_connections, &LOCK_status);
66896666 delete thd;
66906667 statistic_increment (connection_errors_max_connection, &LOCK_status);
@@ -7095,11 +7072,7 @@ pthread_handler_t handle_connections_namedpipes(void *arg)
70957072 if (!(thd->net .vio = vio_new_win32pipe (hConnectedPipe)) ||
70967073my_net_init (&thd->net , thd->net .vio , MYF (MY_THREAD_SPECIFIC)))
70977074 {
7098- #ifdef WITH_WSREP
7099- close_connection (thd, ER_OUT_OF_RESOURCES, 1 );
7100- #else
71017075 close_connection (thd, ER_OUT_OF_RESOURCES);
7102- #endif
71037076 delete thd;
71047077 set_current_thd (0 );
71057078 continue ;
@@ -7297,11 +7270,7 @@ pthread_handler_t handle_connections_shared_memory(void *arg)
72977270 event_conn_closed)) ||
72987271 my_net_init (&thd->net , thd->net .vio , MYF (MY_THREAD_SPECIFIC)))
72997272 {
7300- #ifdef WITH_WSREP
7301- close_connection (thd, ER_OUT_OF_RESOURCES, 1 );
7302- #else
73037273 close_connection (thd, ER_OUT_OF_RESOURCES);
7304- #endif
73057274 errmsg= 0 ;
73067275 goto errorconn;
73077276 }
0 commit comments