Skip to content

Commit

Permalink
Fixed failures in rpl_parallel2
Browse files Browse the repository at this point in the history
Problem was that we used same condition variable with 2 different mutex.
Fixed by changing to use COND_rpl_thread_stop instead of COND_parallel_entry
for stopping threads.

Patch by Kristian Nielsen
  • Loading branch information
montywi committed Nov 23, 2015
1 parent 72dc30f commit b30a768
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ PSI_cond_key key_RELAYLOG_update_cond, key_COND_wakeup_ready,
PSI_cond_key key_RELAYLOG_COND_queue_busy;
PSI_cond_key key_TC_LOG_MMAP_COND_queue_busy;
PSI_cond_key key_COND_rpl_thread_queue, key_COND_rpl_thread,
key_COND_rpl_thread_pool,
key_COND_rpl_thread_stop, key_COND_rpl_thread_pool,
key_COND_parallel_entry, key_COND_group_commit_orderer,
key_COND_prepare_ordered, key_COND_slave_init;
PSI_cond_key key_COND_wait_gtid, key_COND_gtid_ignore_duplicates;
Expand Down Expand Up @@ -1048,6 +1048,7 @@ static PSI_cond_info all_server_conds[]=
{ &key_COND_flush_thread_cache, "COND_flush_thread_cache", PSI_FLAG_GLOBAL},
{ &key_COND_rpl_thread, "COND_rpl_thread", 0},
{ &key_COND_rpl_thread_queue, "COND_rpl_thread_queue", 0},
{ &key_COND_rpl_thread_stop, "COND_rpl_thread_stop", 0},
{ &key_COND_rpl_thread_pool, "COND_rpl_thread_pool", 0},
{ &key_COND_parallel_entry, "COND_parallel_entry", 0},
{ &key_COND_group_commit_orderer, "COND_group_commit_orderer", 0},
Expand Down
2 changes: 1 addition & 1 deletion sql/mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ extern PSI_cond_key key_RELAYLOG_update_cond, key_COND_wakeup_ready,
extern PSI_cond_key key_RELAYLOG_COND_queue_busy;
extern PSI_cond_key key_TC_LOG_MMAP_COND_queue_busy;
extern PSI_cond_key key_COND_rpl_thread, key_COND_rpl_thread_queue,
key_COND_rpl_thread_pool,
key_COND_rpl_thread_stop, key_COND_rpl_thread_pool,
key_COND_parallel_entry, key_COND_group_commit_orderer;
extern PSI_cond_key key_COND_wait_gtid, key_COND_gtid_ignore_duplicates;

Expand Down
21 changes: 15 additions & 6 deletions sql/rpl_parallel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ do_ftwrl_wait(rpl_group_info *rgi,
THD *thd= rgi->thd;
rpl_parallel_entry *entry= rgi->parallel_entry;
uint64 sub_id= rgi->gtid_sub_id;
DBUG_ENTER("do_ftwrl_wait");

mysql_mutex_assert_owner(&entry->LOCK_parallel_entry);

Expand Down Expand Up @@ -391,6 +392,8 @@ do_ftwrl_wait(rpl_group_info *rgi,

if (sub_id > entry->largest_started_sub_id)
entry->largest_started_sub_id= sub_id;

DBUG_VOID_RETURN;
}


Expand Down Expand Up @@ -454,6 +457,7 @@ rpl_unpause_after_ftwrl(THD *thd)
{
uint32 i;
rpl_parallel_thread_pool *pool= &global_rpl_thread_pool;
DBUG_ENTER("rpl_unpause_after_ftwrl");

DBUG_ASSERT(pool->busy);

Expand All @@ -478,6 +482,7 @@ rpl_unpause_after_ftwrl(THD *thd)
}

pool_mark_not_busy(pool);
DBUG_VOID_RETURN;
}


Expand All @@ -492,6 +497,7 @@ rpl_pause_for_ftwrl(THD *thd)
uint32 i;
rpl_parallel_thread_pool *pool= &global_rpl_thread_pool;
int err;
DBUG_ENTER("rpl_pause_for_ftwrl");

/*
While the count_pending_pause_for_ftwrl counter is non-zero, the pool
Expand All @@ -502,7 +508,7 @@ rpl_pause_for_ftwrl(THD *thd)
as this can deadlock against release_thread()).
*/
if ((err= pool_mark_busy(pool, thd)))
return err;
DBUG_RETURN(err);

for (i= 0; i < pool->count; ++i)
{
Expand Down Expand Up @@ -549,7 +555,7 @@ rpl_pause_for_ftwrl(THD *thd)

if (err)
rpl_unpause_after_ftwrl(thd);
return err;
DBUG_RETURN(err);
}


Expand Down Expand Up @@ -1271,8 +1277,9 @@ handle_rpl_parallel_thread(void *arg)
*/
mysql_mutex_lock(&rpt->current_entry->LOCK_parallel_entry);
mysql_mutex_unlock(&rpt->LOCK_rpl_thread);
mysql_cond_wait(&rpt->current_entry->COND_parallel_entry,
&rpt->current_entry->LOCK_parallel_entry);
if (rpt->pause_for_ftwrl)
mysql_cond_wait(&rpt->current_entry->COND_parallel_entry,
&rpt->current_entry->LOCK_parallel_entry);
mysql_mutex_unlock(&rpt->current_entry->LOCK_parallel_entry);
mysql_mutex_lock(&rpt->LOCK_rpl_thread);
/*
Expand Down Expand Up @@ -1309,7 +1316,7 @@ handle_rpl_parallel_thread(void *arg)
/* Tell wait_for_done() that we are done, if it is waiting. */
if (likely(rpt->current_entry) &&
unlikely(rpt->current_entry->force_abort))
mysql_cond_broadcast(&rpt->current_entry->COND_parallel_entry);
mysql_cond_broadcast(&rpt->COND_rpl_thread_stop);
rpt->current_entry= NULL;
if (!rpt->stop)
rpt->pool->release_thread(rpt);
Expand Down Expand Up @@ -1389,6 +1396,8 @@ rpl_parallel_change_thread_count(rpl_parallel_thread_pool *pool,
mysql_cond_init(key_COND_rpl_thread, &new_list[i]->COND_rpl_thread, NULL);
mysql_cond_init(key_COND_rpl_thread_queue,
&new_list[i]->COND_rpl_thread_queue, NULL);
mysql_cond_init(key_COND_rpl_thread_stop,
&new_list[i]->COND_rpl_thread_stop, NULL);
new_list[i]->pool= pool;
if (mysql_thread_create(key_rpl_parallel_thread, &th, &connection_attrib,
handle_rpl_parallel_thread, new_list[i]))
Expand Down Expand Up @@ -2099,7 +2108,7 @@ rpl_parallel::wait_for_done(THD *thd, Relay_log_info *rli)
{
mysql_mutex_lock(&rpt->LOCK_rpl_thread);
while (rpt->current_owner == &e->rpl_threads[j])
mysql_cond_wait(&e->COND_parallel_entry, &rpt->LOCK_rpl_thread);
mysql_cond_wait(&rpt->COND_rpl_thread_stop, &rpt->LOCK_rpl_thread);
mysql_mutex_unlock(&rpt->LOCK_rpl_thread);
}
}
Expand Down
1 change: 1 addition & 0 deletions sql/rpl_parallel.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct rpl_parallel_thread {
mysql_mutex_t LOCK_rpl_thread;
mysql_cond_t COND_rpl_thread;
mysql_cond_t COND_rpl_thread_queue;
mysql_cond_t COND_rpl_thread_stop;
struct rpl_parallel_thread *next; /* For free list. */
struct rpl_parallel_thread_pool *pool;
THD *thd;
Expand Down

0 comments on commit b30a768

Please sign in to comment.