summaryrefslogtreecommitdiff
path: root/sql/rpl_parallel.cc
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2018-10-11 08:16:08 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2018-10-11 08:16:08 +0300
commit07815d9555b099482f8877ec700bbc39d1d553dd (patch)
tree60df9098dabb0a465317135b9a6daabf4152d2e7 /sql/rpl_parallel.cc
parent940f0c78a4c45536ddede5aaeeebcf36bda53251 (diff)
parent3c3c4ae22545d3242a8b7c4f2bec3bf2d245890a (diff)
downloadmariadb-git-07815d9555b099482f8877ec700bbc39d1d553dd.tar.gz
Merge 10.1 into 10.2
Diffstat (limited to 'sql/rpl_parallel.cc')
-rw-r--r--sql/rpl_parallel.cc32
1 files changed, 21 insertions, 11 deletions
diff --git a/sql/rpl_parallel.cc b/sql/rpl_parallel.cc
index 5d1e5418925..6340e4d7cc6 100644
--- a/sql/rpl_parallel.cc
+++ b/sql/rpl_parallel.cc
@@ -1659,21 +1659,31 @@ int rpl_parallel_resize_pool_if_no_slaves(void)
/**
- Resize pool if not active or busy (in which case we may be in
- resize to 0
+ Pool activation is preceeded by taking a "lock" of pool_mark_busy
+ which guarantees the number of running slaves drops to zero atomicly
+ with the number of pool workers.
+ This resolves race between the function caller thread and one
+ that may be attempting to deactivate the pool.
*/
-
int
rpl_parallel_activate_pool(rpl_parallel_thread_pool *pool)
{
- bool resize;
- mysql_mutex_lock(&pool->LOCK_rpl_thread_pool);
- resize= !pool->count || pool->busy;
- mysql_mutex_unlock(&pool->LOCK_rpl_thread_pool);
- if (resize)
- return rpl_parallel_change_thread_count(pool, opt_slave_parallel_threads,
- 0);
- return 0;
+ int rc= 0;
+
+ if ((rc= pool_mark_busy(pool, current_thd)))
+ return rc; // killed
+
+ if (!pool->count)
+ {
+ pool_mark_not_busy(pool);
+ rc= rpl_parallel_change_thread_count(pool, opt_slave_parallel_threads,
+ 0);
+ }
+ else
+ {
+ pool_mark_not_busy(pool);
+ }
+ return rc;
}