Skip to content

Commit

Permalink
Merge revision 3882 from lp:maria/maria-10.0-galera
Browse files Browse the repository at this point in the history
  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.
  • Loading branch information
Jan Lindström committed Aug 29, 2014
1 parent 5a684f8 commit e44751b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 53 deletions.
3 changes: 0 additions & 3 deletions mysql-test/suite/wsrep/r/variables.result
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ SET GLOBAL wsrep_slave_threads= 10;
SHOW STATUS LIKE 'threads_connected';
Variable_name Value
Threads_connected 1
SHOW STATUS LIKE 'wsrep_thread_count';
Variable_name Value
wsrep_thread_count 11
SET GLOBAL wsrep_slave_threads= @wsrep_slave_threads_saved;
SET GLOBAL wsrep_provider= none;
SET GLOBAL wsrep_cluster_address= '';
Expand Down
3 changes: 1 addition & 2 deletions mysql-test/suite/wsrep/t/variables.test
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ SHOW STATUS LIKE 'wsrep_thread_count';
SET @wsrep_slave_threads_saved= @@global.wsrep_slave_threads;
SET GLOBAL wsrep_slave_threads= 10;
--echo # Wait for applier threads to get created.
sleep 3;
sleep 5;
SHOW STATUS LIKE 'threads_connected';
SHOW STATUS LIKE 'wsrep_thread_count';

# reset (for mtr internal checks)
SET GLOBAL wsrep_slave_threads= @wsrep_slave_threads_saved;
Expand Down
53 changes: 5 additions & 48 deletions sql/wsrep_mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,7 @@ static bool abort_replicated(THD *thd)
bool ret_code= false;
if (thd->wsrep_query_state== QUERY_COMMITTING)
{
if (wsrep_debug) WSREP_INFO("aborting replicated trx: %lu", thd->real_id);
WSREP_DEBUG("aborting replicated trx: %lu", thd->real_id);

(void)wsrep_abort_thd(thd, thd, TRUE);
ret_code= true;
Expand Down Expand Up @@ -1769,24 +1769,6 @@ static bool have_client_connections()
return false;
}

/*
returns the number of wsrep appliers running.
However, the caller (thd parameter) is not taken in account
*/
static int have_wsrep_appliers(THD *thd)
{
int ret= 0;
THD *tmp;

I_List_iterator<THD> it(threads);
while ((tmp=it++))
{
ret+= (tmp != thd && tmp->wsrep_applier);
}
return ret;
}


static void wsrep_close_thread(THD *thd)
{
thd->killed= KILL_CONNECTION;
Expand Down Expand Up @@ -1894,7 +1876,7 @@ void wsrep_close_client_connections(my_bool wait_to_end)
while ((tmp=it2++))
{
#ifndef __bsdi__ // Bug in BSDI kernel
if (is_client_connection(tmp) &&
if (is_client_connection(tmp) &&
!abort_replicated(tmp) &&
!is_replaying_connection(tmp))
{
Expand All @@ -1905,8 +1887,7 @@ void wsrep_close_client_connections(my_bool wait_to_end)
}

DBUG_PRINT("quit",("Waiting for threads to die (count=%u)",thread_count));
if (wsrep_debug)
WSREP_INFO("waiting for client connections to close: %u", thread_count);
WSREP_DEBUG("waiting for client connections to close: %u", thread_count);

while (wait_to_end && have_client_connections())
{
Expand Down Expand Up @@ -1950,35 +1931,11 @@ void wsrep_close_threads(THD *thd)
mysql_mutex_unlock(&LOCK_thread_count);
}


void wsrep_close_applier_threads(int count)
{
THD *tmp;
mysql_mutex_lock(&LOCK_thread_count); // For unlink from list

I_List_iterator<THD> it(threads);
while ((tmp=it++) && count)
{
DBUG_PRINT("quit",("Informing thread %ld that it's time to die",
tmp->thread_id));
/* We skip slave threads & scheduler on this first loop through. */
if (tmp->wsrep_applier)
{
WSREP_DEBUG("closing wsrep applier thread %ld", tmp->thread_id);
tmp->wsrep_applier_closing= TRUE;
count--;
}
}

mysql_mutex_unlock(&LOCK_thread_count);
}


void wsrep_wait_appliers_close(THD *thd)
{
/* Wait for wsrep appliers to gracefully exit */
mysql_mutex_lock(&LOCK_thread_count);
while (have_wsrep_appliers(thd) > 1)
while (wsrep_running_threads > 1)
// 1 is for rollbacker thread which needs to be killed explicitly.
// This gotta be fixed in a more elegant manner if we gonna have arbitrary
// number of non-applier wsrep threads.
Expand All @@ -1998,7 +1955,7 @@ void wsrep_wait_appliers_close(THD *thd)
wsrep_close_threads (thd);
/* and wait for them to die */
mysql_mutex_lock(&LOCK_thread_count);
while (have_wsrep_appliers(thd) > 0)
while (wsrep_running_threads > 0)
{
if (thread_handling > SCHEDULER_ONE_THREAD_PER_CONNECTION)
{
Expand Down

0 comments on commit e44751b

Please sign in to comment.