summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNayuta Yanagisawa <nayuta.yanagisawa@hey.com>2022-06-20 18:02:30 +0900
committerNayuta Yanagisawa <nayuta.yanagisawa@hey.com>2022-06-20 21:18:23 +0900
commit1541ce77661d5e2f3fd10cd99568826546f6c94e (patch)
treeec2149b778c20be5224852597869330c620719b1
parentf299351e1c2aa00dcce3c6f58c58bb5e28469c61 (diff)
downloadmariadb-git-bb-10.3-MDEV-28758.tar.gz
MDEV-28739 Trying to lock uninitialized mutex or hang upon shutdown after using Spider with query_cachebb-10.3-MDEV-28758bb-10.3-MDEV-28739
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_28739.result33
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_28739.cnf3
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_28739.test47
-rw-r--r--storage/spider/spd_table.cc109
4 files changed, 134 insertions, 58 deletions
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28739.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28739.result
new file mode 100644
index 00000000000..ec85170a91d
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28739.result
@@ -0,0 +1,33 @@
+#
+# MDEV-28739 Trying to lock uninitialized mutex or hang upon shutdown after using Spider with query_cache
+#
+for master_1
+for child2
+child2_1
+child2_2
+child2_3
+for child3
+connection child2_1;
+CREATE DATABASE auto_test_remote;
+USE auto_test_remote;
+CREATE TABLE tbl_a (id INT);
+connection master_1;
+CREATE DATABASE auto_test_local;
+USE auto_test_local;
+set global query_cache_type= on;
+set spider_same_server_link = on;
+CREATE TABLE tbl_a (
+id INT
+) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"';
+SELECT * FROM tbl_a;
+id
+connection master_1;
+DROP DATABASE IF EXISTS auto_test_local;
+connection child2_1;
+DROP DATABASE IF EXISTS auto_test_remote;
+for master_1
+for child2
+child2_1
+child2_2
+child2_3
+for child3
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28739.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_28739.cnf
new file mode 100644
index 00000000000..05dfd8a0bce
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28739.cnf
@@ -0,0 +1,3 @@
+!include include/default_mysqld.cnf
+!include ../my_1_1.cnf
+!include ../my_2_1.cnf
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28739.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28739.test
new file mode 100644
index 00000000000..b68d6578305
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28739.test
@@ -0,0 +1,47 @@
+--echo #
+--echo # MDEV-28739 Trying to lock uninitialized mutex or hang upon shutdown after using Spider with query_cache
+--echo #
+
+--disable_query_log
+--disable_result_log
+--source ../../t/test_init.inc
+--enable_result_log
+--enable_query_log
+
+--connection child2_1
+CREATE DATABASE auto_test_remote;
+USE auto_test_remote;
+
+CREATE TABLE tbl_a (id INT);
+
+--connection master_1
+CREATE DATABASE auto_test_local;
+USE auto_test_local;
+
+set global query_cache_type= on;
+set spider_same_server_link = on;
+
+eval CREATE TABLE tbl_a (
+ id INT
+) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"';
+
+SELECT * FROM tbl_a;
+
+# A workaround for MDEV-27912
+--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.1.expect
+--shutdown_server
+--source include/wait_until_disconnected.inc
+--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.1.expect
+--enable_reconnect
+--source include/wait_until_connected_again.inc
+
+--connection master_1
+DROP DATABASE IF EXISTS auto_test_local;
+--connection child2_1
+DROP DATABASE IF EXISTS auto_test_remote;
+
+--disable_query_log
+--disable_result_log
+--source ../t/test_deinit.inc
+--enable_query_log
+--enable_result_log
diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc
index 20347c4ebad..0aec411b357 100644
--- a/storage/spider/spd_table.cc
+++ b/storage/spider/spd_table.cc
@@ -5745,11 +5745,8 @@ int spider_free_share(
) {
DBUG_ENTER("spider_free_share");
pthread_mutex_lock(&spider_tbl_mutex);
- bool do_delete_thd = false;
- THD *thd = current_thd;
if (!--share->use_count)
{
-#ifndef WITHOUT_SPIDER_BG_SEARCH
spider_free_sts_thread(share);
spider_free_crd_thread(share);
spider_free_mon_threads(share);
@@ -5763,55 +5760,6 @@ int spider_free_share(
spider_table_remove_share_from_crd_thread(share);
spider_free_spider_object_for_share(&share->crd_spider);
}
-#endif
- if (
- share->sts_init &&
- spider_param_store_last_sts(share->store_last_sts)
- ) {
- if (!thd)
- {
- /* Create a thread for Spider system table update */
- thd = spider_create_thd();
- if (!thd)
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- do_delete_thd = TRUE;
- }
- spider_sys_insert_or_update_table_sts(
- thd,
- share->lgtm_tblhnd_share->table_name,
- share->lgtm_tblhnd_share->table_name_length,
- &share->data_file_length,
- &share->max_data_file_length,
- &share->index_file_length,
- &share->records,
- &share->mean_rec_length,
- &share->check_time,
- &share->create_time,
- &share->update_time,
- FALSE
- );
- }
- if (
- share->crd_init &&
- spider_param_store_last_crd(share->store_last_crd)
- ) {
- if (!thd)
- {
- /* Create a thread for Spider system table update */
- thd = spider_create_thd();
- if (!thd)
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- do_delete_thd = TRUE;
- }
- spider_sys_insert_or_update_table_crd(
- thd,
- share->lgtm_tblhnd_share->table_name,
- share->lgtm_tblhnd_share->table_name_length,
- share->cardinality,
- share->table_share->fields,
- FALSE
- );
- }
spider_free_share_alloc(share);
#ifdef HASH_UPDATE_WITH_HASH_VALUE
my_hash_delete_with_hash_value(&spider_open_tables,
@@ -5826,8 +5774,6 @@ int spider_free_share(
free_root(&share->mem_root, MYF(0));
spider_free(spider_current_trx, share, MYF(0));
}
- if (do_delete_thd)
- spider_destroy_thd(thd);
pthread_mutex_unlock(&spider_tbl_mutex);
DBUG_RETURN(0);
}
@@ -6860,11 +6806,58 @@ DBUG_ASSERT(0);
DBUG_RETURN(0);
}
-int spider_panic(
- handlerton *hton,
- ha_panic_function type
-) {
+/*
+ Shut down the Spider storage engine.
+*/
+int spider_panic(handlerton *hton, ha_panic_function type)
+{
+ THD *thd= current_thd;
+ SPIDER_SHARE *share;
+ int loop_count= 0;
+
DBUG_ENTER("spider_panic");
+
+ pthread_mutex_lock(&spider_tbl_mutex);
+ while ((share= (SPIDER_SHARE *) my_hash_element(&spider_open_tables,
+ loop_count)))
+ {
+ DBUG_ASSERT(share->use_count == 0);
+ DBUG_ASSERT(0);
+
+ spider_free_sts_thread(share);
+ spider_free_crd_thread(share);
+ spider_free_mon_threads(share);
+ if (share->sts_spider_init)
+ {
+ spider_table_remove_share_from_sts_thread(share);
+ spider_free_spider_object_for_share(&share->sts_spider);
+ }
+ if (share->crd_spider_init)
+ {
+ spider_table_remove_share_from_crd_thread(share);
+ spider_free_spider_object_for_share(&share->crd_spider);
+ }
+
+ if (share->sts_init && spider_param_store_last_sts(share->store_last_sts))
+ {
+ spider_sys_insert_or_update_table_sts(
+ thd, share->lgtm_tblhnd_share->table_name,
+ share->lgtm_tblhnd_share->table_name_length,
+ &share->data_file_length, &share->max_data_file_length,
+ &share->index_file_length, &share->records, &share->mean_rec_length,
+ &share->check_time, &share->create_time, &share->update_time, FALSE);
+ }
+ if (share->crd_init && spider_param_store_last_crd(share->store_last_crd))
+ {
+ spider_sys_insert_or_update_table_crd(
+ thd, share->lgtm_tblhnd_share->table_name,
+ share->lgtm_tblhnd_share->table_name_length, share->cardinality,
+ share->table_share->fields, FALSE);
+ }
+ loop_count++;
+ }
+ pthread_mutex_unlock(&spider_tbl_mutex);
+
DBUG_RETURN(0);
}