Commit bdfd93d3 authored by Yuchen Pei's avatar Yuchen Pei

MDEV-28739 MDEV-29421 Remove spider persistent table stats

We remove the call to update spider persistent table stats (sts/crd)
in spider_free_share(). This prevents spider from opening and closing
further tables during close(), which fixes the following issues:

MDEV-28739: ha_spider::close() is called during tdc_start_shutdown(),
which is called after query_cache_destroy(). Closing the sts/crd Aria
tables will trigger a call to Query_cache::invalidate_table(), which
will attempt to use the query cache mutex structure_guard_mutex
destroyed previously.

MDEV-29421: during ha_spider::close(), spider_free_share() could
trigger another spider_free_share() through updating sts/crd table,
because open_table() calls tc_add_table(), which could trigger another
ha_spider::close()...

Since spider sts/crd system tables are only updated here, there's no
use for these tables any more, and we remove all uses of these tables
too.

The removal should not cause any performance issue, as in memory
spider table stats are only updated based on a time
interval (spider_sts_interval and spider_crd_interval), which defaults
to 10 seconds. It should not affect accuracy either, due to the
infrequency of server restart. And inaccurate stats are not a problem
for optimizer anyway.

To be on the safe side, we defer the removal of the spider sts/crd
tables themselves to future.
parent 1a76d751
......@@ -11965,12 +11965,6 @@ int ha_spider::delete_table(
)
need_lock = TRUE;
if ((error_num = spider_sys_delete_table_sts(
current_thd, name, name_len, need_lock)))
goto error;
if ((error_num = spider_sys_delete_table_crd(
current_thd, name, name_len, need_lock)))
goto error;
if (
!(table_tables = spider_open_sys_table(
current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
......
--connection master_1
alter table mysql.spider_table_sts add column checksum bigint unsigned default null after update_time;
DROP DATABASE IF EXISTS auto_test_local;
--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP
--disable_warnings
--disable_query_log
--disable_result_log
--source ../t/test_deinit.inc
--enable_result_log
--enable_query_log
--enable_warnings
--disable_warnings
--disable_query_log
--disable_result_log
--source ../t/test_init.inc
--enable_result_log
--enable_query_log
--enable_warnings
--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1
let $MASTER_1_COMMENT_2_1=
COMMENT='table "tbl_a", host "127.0.0.1", port "$MASTER_1_MYPORT", user "root"';
--connection master_1
alter table mysql.spider_table_sts drop column checksum;
insert into mysql.spider_table_sts values ('auto_test_local', 'tbl_a', 0, 0, 0, 0, 0, '2019-01-01 00:00:00', '2019-01-01 00:00:00', '2019-01-01 00:00:00');
......@@ -4,15 +4,11 @@
for master_1
for child2
for child3
call mtr.add_suppression("\\[ERROR\\] Table 'mysql.spider_table_sts' doesn't exist");
call mtr.add_suppression("\\[ERROR\\] Server shutdown in progress");
SET GLOBAL default_tmp_storage_engine=spider;
SELECT SLEEP(1);
SLEEP(1)
0
# restart
SET GLOBAL default_storage_engine=Spider;
SELECT SLEEP(1);
SLEEP(1)
0
# restart
for master_1
for child2
......
#
# 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
# restart
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
for master_1
for child2
for child3
set @old_table_open_cache=@@global.table_open_cache;
set global table_open_cache=10;
CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
CREATE TABLE t (c INT) ENGINE=InnoDB;
CREATE TABLE t_s (c INT) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv", TABLE "t"';
CREATE TABLE t1 (a INT) ENGINE=Spider;
SELECT * FROM t1;
ERROR HY000: Unable to connect to foreign data source: localhost
SELECT * FROM information_schema.tables;
DROP TABLE t, t_s, t1;
drop server srv;
set global table_open_cache=@old_table_open_cache;
for master_1
for child2
for child3
for master_1
for child2
for child3
connection master_1;
alter table mysql.spider_table_sts drop column checksum;
insert into mysql.spider_table_sts values ('auto_test_local', 'tbl_a', 0, 0, 0, 0, 0, '2019-01-01 00:00:00', '2019-01-01 00:00:00', '2019-01-01 00:00:00');
this test is for MDEV-19842
drop and create databases
connection master_1;
CREATE DATABASE auto_test_local;
USE auto_test_local;
create table
connection master_1;
CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1
select test 1
connection master_1;
SELECT pkey FROM tbl_a;
ERROR HY000: System table spider_table_sts is different version
deinit
connection master_1;
DROP DATABASE IF EXISTS auto_test_local;
ERROR HY000: System table spider_table_sts is different version
connection master_1;
alter table mysql.spider_table_sts add column checksum bigint unsigned default null after update_time;
DROP DATABASE IF EXISTS auto_test_local;
for master_1
for child2
for child3
end of test
......@@ -7,12 +7,14 @@
--enable_result_log
--enable_query_log
# These suppressions are a workaround and should not be needed once
# MDEV-29870 is done.
call mtr.add_suppression("\\[ERROR\\] Table 'mysql.spider_table_sts' doesn't exist");
call mtr.add_suppression("\\[ERROR\\] Server shutdown in progress");
SET GLOBAL default_tmp_storage_engine=spider;
SELECT SLEEP(1);
--source include/restart_mysqld.inc
SET GLOBAL default_storage_engine=Spider;
SELECT SLEEP(1);
--source include/restart_mysqld.inc
--disable_query_log
......
--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;
--source include/restart_mysqld.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
--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
# set @@global.debug_dbug="+d,xid_thd_trace,enter,exit,info,error:o,/tmp/trace2.out:i:F:L";
#set @@global.debug_dbug="d:t:i:o,mysqld.trace";
set global query_cache_type= on;
evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
create table t2 (c int);
create table t1 (c int) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
SELECT * FROM t1;
#shutdown;
--source include/restart_mysqld.inc
drop table t1, t2;
drop server srv;
--disable_query_log
--disable_result_log
--source ../t/test_deinit.inc
--enable_query_log
--enable_result_log
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
set @old_table_open_cache=@@global.table_open_cache;
set global table_open_cache=10;
evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
CREATE TABLE t (c INT) ENGINE=InnoDB;
CREATE TABLE t_s (c INT) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv", TABLE "t"';
CREATE TABLE t1 (a INT) ENGINE=Spider;
--error 1429
SELECT * FROM t1;
--disable_result_log
SELECT * FROM information_schema.tables;
--enable_result_log
DROP TABLE t, t_s, t1;
drop server srv;
set global table_open_cache=@old_table_open_cache;
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
--source ../include/spider_table_sts_init.inc
--echo
--echo this test is for MDEV-19842
--echo
--echo drop and create databases
--connection master_1
--disable_warnings
CREATE DATABASE auto_test_local;
USE auto_test_local;
--enable_warnings
--echo
--echo create table
--connection master_1
--disable_query_log
echo CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1;
eval CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1;
--enable_query_log
--echo
--echo select test 1
--connection master_1
--error 12609
SELECT pkey FROM tbl_a;
--echo
--echo deinit
--disable_warnings
--connection master_1
--error 12609
DROP DATABASE IF EXISTS auto_test_local;
--enable_warnings
--source ../include/spider_table_sts_deinit.inc
--echo
--echo end of test
This diff is collapsed.
......@@ -28,10 +28,6 @@
#define SPIDER_SYS_XA_FAILED_TABLE_NAME_LEN 20
#define SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR "spider_table_position_for_recovery"
#define SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_LEN 34
#define SPIDER_SYS_TABLE_STS_TABLE_NAME_STR "spider_table_sts"
#define SPIDER_SYS_TABLE_STS_TABLE_NAME_LEN 16
#define SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR "spider_table_crd"
#define SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN 16
#define SPIDER_SYS_XA_PREPARED_STR "PREPARED"
#define SPIDER_SYS_XA_NOT_YET_STR "NOT YET"
......@@ -322,21 +318,6 @@ int spider_insert_sys_table(
TABLE *table
);
int spider_insert_or_update_table_sts(
TABLE *table,
const char *name,
uint name_length,
ha_statistics *stat
);
int spider_insert_or_update_table_crd(
TABLE *table,
const char *name,
uint name_length,
longlong *cardinality,
uint number_of_keys
);
int spider_log_tables_link_failed(
TABLE *table,
char *name,
......@@ -480,17 +461,6 @@ int spider_get_sys_tables_static_link_id(
MEM_ROOT *mem_root
);
void spider_get_sys_table_sts_info(
TABLE *table,
ha_statistics *stat
);
void spider_get_sys_table_crd_info(
TABLE *table,
longlong *cardinality,
uint number_of_keys
);
int spider_sys_update_tables_link_status(
THD *thd,
char *name,
......@@ -542,54 +512,6 @@ int spider_get_link_statuses(
MEM_ROOT *mem_root
);
int spider_sys_insert_or_update_table_sts(
THD *thd,
const char *name,
uint name_length,
ha_statistics *stat,
bool need_lock
);
int spider_sys_insert_or_update_table_crd(
THD *thd,
const char *name,
uint name_length,
longlong *cardinality,
uint number_of_keys,
bool need_lock
);
int spider_sys_delete_table_sts(
THD *thd,
const char *name,
uint name_length,
bool need_lock
);
int spider_sys_delete_table_crd(
THD *thd,
const char *name,
uint name_length,
bool need_lock
);
int spider_sys_get_table_sts(
THD *thd,
const char *name,
uint name_length,
ha_statistics *stat,
bool need_lock
);
int spider_sys_get_table_crd(
THD *thd,
const char *name,
uint name_length,
longlong *cardinality,
uint number_of_keys,
bool need_lock
);
int spider_sys_replace(
TABLE *table,
bool *modified_non_trans_table
......
......@@ -5595,8 +5595,6 @@ 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
......@@ -5614,47 +5612,6 @@ int spider_free_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->stat,
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,
......@@ -5669,8 +5626,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);
}
......@@ -7450,7 +7405,6 @@ int spider_get_sts(
) {
int get_type __attribute__ ((unused));
int error_num = 0;
bool need_to_get = TRUE;
DBUG_ENTER("spider_get_sts");
#ifdef WITH_PARTITION_STORAGE_ENGINE
......@@ -7488,37 +7442,16 @@ int spider_get_sts(
get_type = 0;
}
#endif
if (
!share->sts_init &&
spider_param_load_sts_at_startup(share->load_sts_at_startup) &&
(!share->init || share->init_error)
) {
error_num = spider_sys_get_table_sts(
current_thd,
share->lgtm_tblhnd_share->table_name,
share->lgtm_tblhnd_share->table_name_length,
&share->stat,
FALSE
);
if (
!error_num ||
(error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
)
need_to_get = FALSE;
}
if (need_to_get)
{
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (get_type == 0)
if (get_type == 0)
spider_copy_sts_to_share(share, share->partition_share);
else {
else {
#endif
error_num = spider_db_show_table_status(spider, link_idx, sts_mode, flag);
#ifdef WITH_PARTITION_STORAGE_ENGINE
}
#endif
}
#endif
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (get_type >= 2)
pthread_mutex_unlock(&share->partition_share->sts_mutex);
......@@ -7598,7 +7531,6 @@ int spider_get_crd(
) {
int get_type __attribute__ ((unused));
int error_num = 0;
bool need_to_get = TRUE;
DBUG_ENTER("spider_get_crd");
#ifdef WITH_PARTITION_STORAGE_ENGINE
......@@ -7636,38 +7568,16 @@ int spider_get_crd(
get_type = 0;
}
#endif
if (
!share->crd_init &&
spider_param_load_sts_at_startup(share->load_crd_at_startup)
) {
error_num = spider_sys_get_table_crd(
current_thd,
share->lgtm_tblhnd_share->table_name,
share->lgtm_tblhnd_share->table_name_length,
share->cardinality,
table->s->fields,
FALSE
);
if (
!error_num ||
(error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
)
need_to_get = FALSE;
}
if (need_to_get)
{
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (get_type == 0)
if (get_type == 0)
spider_copy_crd_to_share(share, share->partition_share,
table->s->fields);
else {
table->s->fields);
else {
#endif
error_num = spider_db_show_index(spider, link_idx, table, crd_mode);
#ifdef WITH_PARTITION_STORAGE_ENGINE
}
#endif
}
#endif
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (get_type >= 2)
pthread_mutex_unlock(&share->partition_share->crd_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment