1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

MW-336 Avoid slave threads leaking

This patch fixes two problems that may arise when changing the
value of wsrep_slave_threads:

1) Threads may be leaked if wsrep_slave_threads is changed
   repeatedly. Specifically, when changing the number of slave
   threads, we keep track of wsrep_slave_count_change, the
   number of slaves to start / stop. The problem arises when
   wsrep_slave_count_change is updated before slaves had a
   chance to exit (threads may take some time to exit, as they
   exit only after commiting one more replication event).
   The fix is to update wsrep_slave_count_change such that it
   reflects the number of threads that already exited or are
   scheduled to exit.

2) Attempting to set out of range value for wsrep_slave_threads
   (below 1 / above 512) results in wsrep_slave_count_change to
   be computed based on the out of range value, even though a
   warning is generated and wsrep_slave_threads is set to a
   truncated value. wsrep_slave_count_change is computed in
   wsrep_slave_threads_check(), which is called before mysql
   checks for valid range. Fix is to update wsrep_count_change
   whenever wsrep_slave_threads is updated with a valid value.
This commit is contained in:
Daniele Sciascia
2017-02-08 23:36:34 +01:00
committed by Jan Lindström
parent 7af44d7aa0
commit 364b15c090
4 changed files with 113 additions and 8 deletions

View File

@ -36,6 +36,8 @@ const char* wsrep_node_address = 0;
const char* wsrep_node_incoming_address = 0;
const char* wsrep_start_position = 0;
static long wsrep_prev_slave_threads = wsrep_slave_threads;
int wsrep_init_vars()
{
wsrep_provider = my_strdup(WSREP_NONE, MYF(MY_WME));
@ -497,18 +499,15 @@ void wsrep_node_address_init (const char* value)
wsrep_node_address = (value) ? my_strdup(value, MYF(0)) : NULL;
}
bool wsrep_slave_threads_check (sys_var *self, THD* thd, set_var* var)
static void wsrep_slave_count_change_update ()
{
mysql_mutex_lock(&LOCK_wsrep_slave_threads);
wsrep_slave_count_change += (var->save_result.ulonglong_value -
wsrep_slave_threads);
mysql_mutex_unlock(&LOCK_wsrep_slave_threads);
return 0;
wsrep_slave_count_change += (wsrep_slave_threads - wsrep_prev_slave_threads);
wsrep_prev_slave_threads = wsrep_slave_threads;
}
bool wsrep_slave_threads_update (sys_var *self, THD* thd, enum_var_type type)
{
wsrep_slave_count_change_update();
if (wsrep_slave_count_change > 0)
{
wsrep_create_appliers(wsrep_slave_count_change);