diff options
author | Jan Lindström <jan.lindstrom@mariadb.com> | 2022-10-06 11:08:09 +0300 |
---|---|---|
committer | Jan Lindström <jan.lindstrom@mariadb.com> | 2022-10-09 10:09:47 +0300 |
commit | 0908a049f80f4024d7e2c8cd9082ca4cfca47b93 (patch) | |
tree | 5272a708b0dc2585bb0222785c9b09ba634e9643 | |
parent | e8acec89741777ebaf46b499fdfe191ad88c3a95 (diff) | |
download | mariadb-git-0908a049f80f4024d7e2c8cd9082ca4cfca47b93.tar.gz |
MDEV-25389 : Assertion `!is_thread_specific || (mysqld_server_initialized && thd)' failed in void my_malloc_size_cb_func(long long int, my_bool)
If wsrep slave thread creation fails for some reason we need to handle
this error correctly and set actual running slave threads accordingly.
-rw-r--r-- | mysql-test/suite/galera/r/MDEV-25389.result | 15 | ||||
-rw-r--r-- | mysql-test/suite/galera/t/MDEV-25389.test | 13 | ||||
-rw-r--r-- | sql/wsrep_mysqld.cc | 5 | ||||
-rw-r--r-- | sql/wsrep_mysqld.h | 3 | ||||
-rw-r--r-- | sql/wsrep_thd.cc | 2 | ||||
-rw-r--r-- | sql/wsrep_var.cc | 24 |
6 files changed, 56 insertions, 6 deletions
diff --git a/mysql-test/suite/galera/r/MDEV-25389.result b/mysql-test/suite/galera/r/MDEV-25389.result new file mode 100644 index 00000000000..9a142676d92 --- /dev/null +++ b/mysql-test/suite/galera/r/MDEV-25389.result @@ -0,0 +1,15 @@ +connection node_2; +connection node_1; +connection node_2; +call mtr.add_suppression("WSREP: Failed to create/initialize system thread"); +SET GLOBAL debug_dbug='+d,simulate_failed_connection_1'; +SET GLOBAL wsrep_slave_threads=2; +ERROR HY000: Incorrect arguments to SET +SELECT @@wsrep_slave_threads; +@@wsrep_slave_threads +1 +SET GLOBAL debug_dbug=''; +SET GLOBAL wsrep_slave_threads=1; +SELECT @@wsrep_slave_threads; +@@wsrep_slave_threads +1 diff --git a/mysql-test/suite/galera/t/MDEV-25389.test b/mysql-test/suite/galera/t/MDEV-25389.test new file mode 100644 index 00000000000..dcb21ee6136 --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-25389.test @@ -0,0 +1,13 @@ +--source include/galera_cluster.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc + +--connection node_2 +call mtr.add_suppression("WSREP: Failed to create/initialize system thread"); +SET GLOBAL debug_dbug='+d,simulate_failed_connection_1'; +--error ER_WRONG_ARGUMENTS +SET GLOBAL wsrep_slave_threads=2; +SELECT @@wsrep_slave_threads; +SET GLOBAL debug_dbug=''; +SET GLOBAL wsrep_slave_threads=1; +SELECT @@wsrep_slave_threads; diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index d7cbc545161..f4efaeee42e 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -126,6 +126,7 @@ ulong wsrep_trx_fragment_unit= WSREP_FRAG_BYTES; ulong wsrep_SR_store_type= WSREP_SR_STORE_TABLE; uint wsrep_ignore_apply_errors= 0; +std::atomic <bool> wsrep_thread_create_failed; /* * End configuration options @@ -2940,7 +2941,9 @@ void* start_wsrep_THD(void *arg) { close_connection(thd, ER_OUT_OF_RESOURCES); statistic_increment(aborted_connects,&LOCK_status); - MYSQL_CALLBACK(thread_scheduler, end_thread, (thd, 0)); + // This will signal error to wsrep_slave_threads_update + wsrep_thread_create_failed.store(true, std::memory_order_relaxed); + WSREP_DEBUG("start_wsrep_THD: init_new_connection_thread failed"); goto error; } diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h index 3fc0e397514..201e3e1a44a 100644 --- a/sql/wsrep_mysqld.h +++ b/sql/wsrep_mysqld.h @@ -1,4 +1,4 @@ -/* Copyright 2008-2021 Codership Oy <http://www.codership.com> +/* Copyright 2008-2022 Codership Oy <http://www.codership.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -88,6 +88,7 @@ extern ulong wsrep_running_rollbacker_threads; extern bool wsrep_new_cluster; extern bool wsrep_gtid_mode; extern uint32 wsrep_gtid_domain_id; +extern std::atomic <bool > wsrep_thread_create_failed; enum enum_wsrep_reject_types { WSREP_REJECT_NONE, /* nothing rejected */ diff --git a/sql/wsrep_thd.cc b/sql/wsrep_thd.cc index 8853ea6a499..5922b39e718 100644 --- a/sql/wsrep_thd.cc +++ b/sql/wsrep_thd.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2013-2021 Codership Oy <info@codership.com> +/* Copyright (C) 2013-2022 Codership Oy <info@codership.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/sql/wsrep_var.cc b/sql/wsrep_var.cc index 8919715b188..dcca0ed08c2 100644 --- a/sql/wsrep_var.cc +++ b/sql/wsrep_var.cc @@ -1,4 +1,4 @@ -/* Copyright 2008-2021 Codership Oy <http://www.codership.com> +/* Copyright 2008-2022 Codership Oy <http://www.codership.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -753,12 +753,30 @@ bool wsrep_slave_threads_update (sys_var *self, THD* thd, enum_var_type type) if (wsrep_slave_count_change > 0) { WSREP_DEBUG("Creating %d applier threads, total %ld", wsrep_slave_count_change, wsrep_slave_threads); + wsrep_thread_create_failed.store(false, std::memory_order_relaxed); res= wsrep_create_appliers(wsrep_slave_count_change, true); + mysql_mutex_unlock(&LOCK_global_system_variables); + mysql_mutex_unlock(&LOCK_wsrep_slave_threads); + // Thread creation and execution is asyncronous, therefore we need + // wait them to be started or error produced + while (wsrep_running_applier_threads != (ulong)wsrep_slave_threads && + !wsrep_thread_create_failed.load(std::memory_order_relaxed)) + { + my_sleep(1000); + } + + mysql_mutex_lock(&LOCK_global_system_variables); + + if (wsrep_thread_create_failed.load(std::memory_order_relaxed)) { + wsrep_slave_threads= wsrep_running_applier_threads; + return true; + } + WSREP_DEBUG("Running %lu applier threads", wsrep_running_applier_threads); wsrep_slave_count_change = 0; } - - mysql_mutex_unlock(&LOCK_wsrep_slave_threads); + else + mysql_mutex_unlock(&LOCK_wsrep_slave_threads); return res; } |