Skip to content

Commit f99f573

Browse files
author
Jan Lindström
committed
MDEV-6656: Test wsrep.variables hangs
Analysis: wsrep_applier_thread shutdown signaling does not always work correctly causing a timing problem where main thread is waiting in a condition variable a signal that all worker threads to end.
1 parent 4fb45aa commit f99f573

File tree

3 files changed

+5
-49
lines changed

3 files changed

+5
-49
lines changed

mysql-test/suite/wsrep/r/variables.result

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ SET GLOBAL wsrep_slave_threads= 10;
195195
SHOW STATUS LIKE 'threads_connected';
196196
Variable_name Value
197197
Threads_connected 1
198-
SHOW STATUS LIKE 'wsrep_thread_count';
199-
Variable_name Value
200-
wsrep_thread_count 11
201198
SET GLOBAL wsrep_slave_threads= @wsrep_slave_threads_saved;
202199
SET GLOBAL wsrep_provider= none;
203200
SET GLOBAL wsrep_cluster_address= '';

mysql-test/suite/wsrep/t/variables.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ SHOW STATUS LIKE 'wsrep_thread_count';
120120
SET @wsrep_slave_threads_saved= @@global.wsrep_slave_threads;
121121
SET GLOBAL wsrep_slave_threads= 10;
122122
--echo # Wait for applier threads to get created.
123-
sleep 3;
123+
sleep 5;
124124
SHOW STATUS LIKE 'threads_connected';
125-
SHOW STATUS LIKE 'wsrep_thread_count';
126125

127126
# reset (for mtr internal checks)
128127
SET GLOBAL wsrep_slave_threads= @wsrep_slave_threads_saved;

sql/mysqld.cc

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5437,7 +5437,7 @@ static bool abort_replicated(THD *thd)
54375437
bool ret_code= false;
54385438
if (thd->wsrep_query_state== QUERY_COMMITTING)
54395439
{
5440-
if (wsrep_debug) WSREP_INFO("aborting replicated trx: %lu", thd->real_id);
5440+
WSREP_DEBUG("aborting replicated trx: %lu", thd->real_id);
54415441

54425442
(void)wsrep_abort_thd(thd, thd, TRUE);
54435443
ret_code= true;
@@ -5507,23 +5507,6 @@ static bool have_client_connections()
55075507
return false;
55085508
}
55095509

5510-
/*
5511-
returns the number of wsrep appliers running.
5512-
However, the caller (thd parameter) is not taken in account
5513-
*/
5514-
static int have_wsrep_appliers(THD *thd)
5515-
{
5516-
int ret= 0;
5517-
THD *tmp;
5518-
5519-
I_List_iterator<THD> it(threads);
5520-
while ((tmp=it++))
5521-
{
5522-
ret+= (tmp != thd && tmp->wsrep_applier);
5523-
}
5524-
return ret;
5525-
}
5526-
55275510
static void wsrep_close_thread(THD *thd)
55285511
{
55295512
thd->killed= KILL_CONNECTION;
@@ -5639,8 +5622,7 @@ void wsrep_close_client_connections(my_bool wait_to_end)
56395622
}
56405623

56415624
DBUG_PRINT("quit",("Waiting for threads to die (count=%u)",thread_count));
5642-
if (wsrep_debug)
5643-
WSREP_INFO("waiting for client connections to close: %u", thread_count);
5625+
WSREP_DEBUG("waiting for client connections to close: %u", thread_count);
56445626

56455627
while (wait_to_end && have_client_connections())
56465628
{
@@ -5682,33 +5664,11 @@ static void wsrep_close_threads(THD *thd)
56825664
mysql_mutex_unlock(&LOCK_thread_count);
56835665
}
56845666

5685-
void wsrep_close_applier_threads(int count)
5686-
{
5687-
THD *tmp;
5688-
mysql_mutex_lock(&LOCK_thread_count); // For unlink from list
5689-
5690-
I_List_iterator<THD> it(threads);
5691-
while ((tmp=it++) && count)
5692-
{
5693-
DBUG_PRINT("quit",("Informing thread %ld that it's time to die",
5694-
tmp->thread_id));
5695-
/* We skip slave threads & scheduler on this first loop through. */
5696-
if (tmp->wsrep_applier)
5697-
{
5698-
WSREP_DEBUG("closing wsrep applier thread %ld", tmp->thread_id);
5699-
tmp->wsrep_applier_closing= TRUE;
5700-
count--;
5701-
}
5702-
}
5703-
5704-
mysql_mutex_unlock(&LOCK_thread_count);
5705-
}
5706-
57075667
void wsrep_wait_appliers_close(THD *thd)
57085668
{
57095669
/* Wait for wsrep appliers to gracefully exit */
57105670
mysql_mutex_lock(&LOCK_thread_count);
5711-
while (have_wsrep_appliers(thd) > 1)
5671+
while (wsrep_running_threads > 1)
57125672
// 1 is for rollbacker thread which needs to be killed explicitly.
57135673
// This gotta be fixed in a more elegant manner if we gonna have arbitrary
57145674
// number of non-applier wsrep threads.
@@ -5728,7 +5688,7 @@ void wsrep_wait_appliers_close(THD *thd)
57285688
wsrep_close_threads (thd);
57295689
/* and wait for them to die */
57305690
mysql_mutex_lock(&LOCK_thread_count);
5731-
while (have_wsrep_appliers(thd) > 0)
5691+
while (wsrep_running_threads > 0)
57325692
{
57335693
if (thread_handling > SCHEDULER_ONE_THREAD_PER_CONNECTION)
57345694
{

0 commit comments

Comments
 (0)