summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <yuchen.pei@mariadb.com>2023-04-28 17:54:41 +1000
committerYuchen Pei <yuchen.pei@mariadb.com>2023-04-28 21:33:14 +1000
commit7d2aea16c804dbb4c2e7f5fbe61203e3c5edb260 (patch)
tree0b8d2962be3ed2f1a4040a3b225c602fb716a5e4
parent27109b7bd80e11390af4879ab91a3d7e78a1cdff (diff)
downloadmariadb-git-7d2aea16c804dbb4c2e7f5fbe61203e3c5edb260.tar.gz
MDEV-22979 wip improving spider init queriesbb-11.0-mdev-22979-init-spider-last
- make spider the last plugin to init (doing it the silly way now, will need refactoring later) - remove procedures in init queries which requires `initialized` to be true which happens later in mysqld_main() during acl_init() - simplification using `if not exists` - move the udf creations to a background thread Result: mdev_27233, mdev_29904, mdev_30370 and their variants pass. mdev-22979 install_db command fails. ALL "NORMAL" tests seem to be hanging...
-rw-r--r--sql/sql_plugin.cc26
-rw-r--r--storage/spider/spd_include.h1
-rw-r--r--storage/spider/spd_init_query.h858
-rw-r--r--storage/spider/spd_table.cc58
4 files changed, 515 insertions, 428 deletions
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 094ff52a4ea..60ede46233c 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -1748,7 +1748,31 @@ int plugin_init(int *argc, char **argv, int flags)
for (uint idx= 0; idx < hash->records; idx++)
{
plugin_ptr= (struct st_plugin_int *) my_hash_element(hash, idx);
- if (plugin_ptr->state == PLUGIN_IS_UNINITIALIZED)
+ if (plugin_ptr->state == PLUGIN_IS_UNINITIALIZED &&
+ strncmp(plugin_ptr->name.str, "SPIDER", plugin_ptr->name.length))
+ {
+ bool plugin_table_engine= lex_string_eq(&plugin_table_engine_name,
+ &plugin_ptr->name);
+ bool opts_only= flags & PLUGIN_INIT_SKIP_INITIALIZATION &&
+ (flags & PLUGIN_INIT_SKIP_PLUGIN_TABLE ||
+ !plugin_table_engine);
+ if (plugin_initialize(&tmp_root, plugin_ptr, argc, argv, opts_only))
+ {
+ plugin_ptr->state= PLUGIN_IS_DYING;
+ *(reap++)= plugin_ptr;
+ }
+ }
+ }
+ }
+
+ for (i=0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
+ {
+ HASH *hash= plugin_hash + plugin_type_initialization_order[i];
+ for (uint idx= 0; idx < hash->records; idx++)
+ {
+ plugin_ptr= (struct st_plugin_int *) my_hash_element(hash, idx);
+ if (plugin_ptr->state == PLUGIN_IS_UNINITIALIZED &&
+ !strncmp(plugin_ptr->name.str, "SPIDER", plugin_ptr->name.length))
{
bool plugin_table_engine= lex_string_eq(&plugin_table_engine_name,
&plugin_ptr->name);
diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h
index ce1107838c2..3c5c3754f4e 100644
--- a/storage/spider/spd_include.h
+++ b/storage/spider/spd_include.h
@@ -199,6 +199,7 @@ typedef struct st_spider_thread
volatile bool killed;
volatile bool thd_wait;
volatile bool first_free_wait;
+ volatile bool init_command;
volatile int error;
pthread_t thread;
pthread_cond_t cond;
diff --git a/storage/spider/spd_init_query.h b/storage/spider/spd_init_query.h
index 1e11e1b70e7..b0003e6ea71 100644
--- a/storage/spider/spd_init_query.h
+++ b/storage/spider/spd_init_query.h
@@ -197,473 +197,481 @@ static LEX_STRING spider_init_queries[] = {
If tables already exist and their definition differ
from the latest ones, we fix them here.
*/
- {C_STRING_WITH_LEN(
- "drop procedure if exists mysql.spider_fix_one_table"
- )},
- {C_STRING_WITH_LEN(
- "drop procedure if exists mysql.spider_fix_system_tables"
- )},
- {C_STRING_WITH_LEN(
- "create procedure mysql.spider_fix_one_table"
- " (tab_name char(255) charset utf8 collate utf8_bin,"
- " test_col_name char(255) charset utf8 collate utf8_bin,"
- " _sql text charset utf8 collate utf8_bin)"
- "begin"
- " set @col_exists := 0;"
- " select 1 into @col_exists from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = tab_name"
- " AND COLUMN_NAME = test_col_name;"
- " if @col_exists = 0 then"
- " select @stmt := _sql;"
- " prepare sp_stmt1 from @stmt;"
- " execute sp_stmt1;"
- " end if;"
- "end;"
- )},
- {C_STRING_WITH_LEN(
- "create procedure mysql.spider_fix_system_tables()"
- "begin"
- " select 'MariaDB' into @server_name;"
- " select substring_index(version(), '.', 1)"
- " into @server_major_version;"
- " select substring_index(substring_index(version(), '.', 2), '.', -1)"
- " into @server_minor_version;"
/*
Fix for 0.5
*/
- " call mysql.spider_fix_one_table('spider_tables', 'server',"
- " 'alter table mysql.spider_tables"
- " add server char(64) default null,"
- " add scheme char(64) default null,"
- " add host char(64) default null,"
- " add port char(5) default null,"
- " add socket char(64) default null,"
- " add username char(64) default null,"
- " add password char(64) default null,"
- " add tgt_db_name char(64) default null,"
- " add tgt_table_name char(64) default null');"
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_tables"
+ " add if not exists server char(64) default null,"
+ " add if not exists scheme char(64) default null,"
+ " add if not exists host char(64) default null,"
+ " add if not exists port char(5) default null,"
+ " add if not exists socket char(64) default null,"
+ " add if not exists username char(64) default null,"
+ " add if not exists password char(64) default null,"
+ " add if not exists tgt_db_name char(64) default null,"
+ " add if not exists tgt_table_name char(64) default null;"
+ )},
/*
Fix for version 0.17
*/
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_xa'"
- " AND COLUMN_NAME = 'data';"
- " if @col_type != 'binary(128)' then"
- " alter table mysql.spider_xa"
- " modify data binary(128) not null default '';"
- " end if;"
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_xa_member'"
- " AND COLUMN_NAME = 'data';"
- " if @col_type != 'binary(128)' then"
- " alter table mysql.spider_xa_member"
- " modify data binary(128) not null default '';"
- " end if;"
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_xa'"
+ " AND COLUMN_NAME = 'data';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type != 'binary(128)' then"
+ " alter table mysql.spider_xa"
+ " modify data binary(128) not null default '';"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_xa_member'"
+ " AND COLUMN_NAME = 'data';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type != 'binary(128)' then"
+ " alter table mysql.spider_xa_member"
+ " modify data binary(128) not null default '';"
+ "end if;"
+ )},
/*
Fix for version 2.7
*/
- " call mysql.spider_fix_one_table('spider_tables', 'link_id',"
- " 'alter table mysql.spider_tables"
- " add column link_id int not null default 0 after table_name,"
- " drop primary key,"
- " add primary key (db_name, table_name, link_id)');"
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_tables"
+ " add column if not exists link_id int not null default 0 after table_name,"
+ " drop primary key,"
+ " add primary key (db_name, table_name, link_id);"
+ )},
/*
Fix for version 2.8
*/
- " call mysql.spider_fix_one_table('spider_tables', 'link_status',"
- " 'alter table mysql.spider_tables"
- " add column link_status tinyint not null default 1');"
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_tables"
+ " add column if not exists link_status tinyint not null default 1;"
+ )},
/*
Fix for version 2.10
*/
- " call mysql.spider_fix_one_table('spider_xa_member', 'ssl_ca',"
- " 'alter table mysql.spider_xa_member"
- " add column ssl_ca char(64) default null after password,"
- " add column ssl_capath char(64) default null after ssl_ca,"
- " add column ssl_cert char(64) default null after ssl_capath,"
- " add column ssl_cipher char(64) default null after ssl_cert,"
- " add column ssl_key char(64) default null after ssl_cipher,"
- " add column ssl_verify_server_cert tinyint not null default 0"
- " after ssl_key,"
- " add column default_file char(64) default null"
- " after ssl_verify_server_cert,"
- " add column default_group char(64) default null after default_file');"
- " call mysql.spider_fix_one_table('spider_tables', 'ssl_ca',"
- " 'alter table mysql.spider_tables"
- " add column ssl_ca char(64) default null after password,"
- " add column ssl_capath char(64) default null after ssl_ca,"
- " add column ssl_cert char(64) default null after ssl_capath,"
- " add column ssl_cipher char(64) default null after ssl_cert,"
- " add column ssl_key char(64) default null after ssl_cipher,"
- " add column ssl_verify_server_cert tinyint not null default 0"
- " after ssl_key,"
- " add column default_file char(64) default null"
- " after ssl_verify_server_cert,"
- " add column default_group char(64) default null after default_file');"
- " call mysql.spider_fix_one_table('spider_link_mon_servers', 'ssl_ca',"
- " 'alter table mysql.spider_link_mon_servers"
- " add column ssl_ca char(64) default null after password,"
- " add column ssl_capath char(64) default null after ssl_ca,"
- " add column ssl_cert char(64) default null after ssl_capath,"
- " add column ssl_cipher char(64) default null after ssl_cert,"
- " add column ssl_key char(64) default null after ssl_cipher,"
- " add column ssl_verify_server_cert tinyint not null default 0"
- " after ssl_key,"
- " add column default_file char(64) default null"
- " after ssl_verify_server_cert,"
- " add column default_group char(64) default null after default_file');"
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_xa_member"
+ " add column if not exists ssl_ca char(64) default null after password,"
+ " add column if not exists ssl_capath char(64) default null after ssl_ca,"
+ " add column if not exists ssl_cert char(64) default null after ssl_capath,"
+ " add column if not exists ssl_cipher char(64) default null after ssl_cert,"
+ " add column if not exists ssl_key char(64) default null after ssl_cipher,"
+ " add column if not exists ssl_verify_server_cert tinyint not null default 0"
+ " after ssl_key,"
+ " add column if not exists default_file char(64) default null"
+ " after ssl_verify_server_cert,"
+ " add column if not exists default_group char(64) default null after default_file;"
+ )},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_tables"
+ " add column if not exists ssl_ca char(64) default null after password,"
+ " add column if not exists ssl_capath char(64) default null after ssl_ca,"
+ " add column if not exists ssl_cert char(64) default null after ssl_capath,"
+ " add column if not exists ssl_cipher char(64) default null after ssl_cert,"
+ " add column if not exists ssl_key char(64) default null after ssl_cipher,"
+ " add column if not exists ssl_verify_server_cert tinyint not null default 0"
+ " after ssl_key,"
+ " add column if not exists default_file char(64) default null"
+ " after ssl_verify_server_cert,"
+ " add column if not exists default_group char(64) default null after default_file;"
+ )},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_link_mon_servers"
+ " add column if not exists ssl_ca char(64) default null after password,"
+ " add column if not exists ssl_capath char(64) default null after ssl_ca,"
+ " add column if not exists ssl_cert char(64) default null after ssl_capath,"
+ " add column if not exists ssl_cipher char(64) default null after ssl_cert,"
+ " add column if not exists ssl_key char(64) default null after ssl_cipher,"
+ " add column if not exists ssl_verify_server_cert tinyint not null default 0"
+ " after ssl_key,"
+ " add column if not exists default_file char(64) default null"
+ " after ssl_verify_server_cert,"
+ " add column if not exists default_group char(64) default null after default_file;"
+ )},
/*
Fix for version 2.28
*/
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_link_mon_servers'"
- " AND COLUMN_NAME = 'sid';"
- " if @col_type != 'int(10) unsigned' then"
- " alter table mysql.spider_link_mon_servers"
- " modify sid int unsigned not null default 0;"
- " end if;"
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_link_mon_servers'"
+ " AND COLUMN_NAME = 'sid';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type != 'int(10) unsigned' then"
+ " alter table mysql.spider_link_mon_servers"
+ " modify sid int unsigned not null default 0;"
+ "end if;"
+ )},
/*
Fix for version 3.1
*/
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_xa_member'"
- " AND COLUMN_NAME = 'socket';"
- " if @col_type = 'char(64)' then"
- " alter table mysql.spider_xa_member"
- " drop primary key,"
- " add index idx1 (data, format_id, gtrid_length, host),"
- " modify socket text not null,"
- " modify ssl_ca text,"
- " modify ssl_capath text,"
- " modify ssl_cert text,"
- " modify ssl_key text,"
- " modify default_file text;"
- " end if;"
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_tables'"
- " AND COLUMN_NAME = 'socket';"
- " if @col_type = 'char(64)' then"
- " alter table mysql.spider_tables"
- " modify socket text,"
- " modify ssl_ca text,"
- " modify ssl_capath text,"
- " modify ssl_cert text,"
- " modify ssl_key text,"
- " modify default_file text;"
- " end if;"
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_link_mon_servers'"
- " AND COLUMN_NAME = 'socket';"
- " if @col_type = 'char(64)' then"
- " alter table mysql.spider_link_mon_servers"
- " modify socket text,"
- " modify ssl_ca text,"
- " modify ssl_capath text,"
- " modify ssl_cert text,"
- " modify ssl_key text,"
- " modify default_file text;"
- " end if;"
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_xa_member'"
+ " AND COLUMN_NAME = 'socket';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type = 'char(64)' then"
+ " alter table mysql.spider_xa_member"
+ " drop primary key,"
+ " add index idx1 (data, format_id, gtrid_length, host),"
+ " modify socket text not null,"
+ " modify ssl_ca text,"
+ " modify ssl_capath text,"
+ " modify ssl_cert text,"
+ " modify ssl_key text,"
+ " modify default_file text;"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_tables'"
+ " AND COLUMN_NAME = 'socket';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type = 'char(64)' then"
+ " alter table mysql.spider_tables"
+ " modify socket text,"
+ " modify ssl_ca text,"
+ " modify ssl_capath text,"
+ " modify ssl_cert text,"
+ " modify ssl_key text,"
+ " modify default_file text;"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_link_mon_servers'"
+ " AND COLUMN_NAME = 'socket';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type = 'char(64)' then"
+ " alter table mysql.spider_link_mon_servers"
+ " modify socket text,"
+ " modify ssl_ca text,"
+ " modify ssl_capath text,"
+ " modify ssl_cert text,"
+ " modify ssl_key text,"
+ " modify default_file text;"
+ "end if;"
+ )},
/*
Fix for version 3.3.0
*/
- " call mysql.spider_fix_one_table('spider_tables',"
- " 'monitoring_binlog_pos_at_failing',"
- " 'alter table mysql.spider_tables"
- " add monitoring_binlog_pos_at_failing tinyint not null default 0"
- " after ssl_verify_server_cert');"
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_tables"
+ " add if not exists monitoring_binlog_pos_at_failing tinyint not null default 0"
+ " after ssl_verify_server_cert;"
+ )},
/*
Fix for version 3.3.6
*/
- " call mysql.spider_fix_one_table('spider_tables', 'block_status',"
- " 'alter table mysql.spider_tables"
- " add column block_status tinyint not null default 0"
- " after link_status');"
- " call mysql.spider_fix_one_table('spider_tables', 'static_link_id',"
- " 'alter table mysql.spider_tables"
- " add column static_link_id char(64) default null after block_status,"
- " add unique index uidx1 (db_name, table_name, static_link_id)');"
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_link_mon_servers'"
- " AND COLUMN_NAME = 'link_id';"
- " if @col_type != 'char(64)' then"
- " alter table mysql.spider_link_mon_servers"
- " modify link_id char(64) not null default '';"
- " end if;"
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_link_failed_log'"
- " AND COLUMN_NAME = 'link_id';"
- " if @col_type != 'char(64)' then"
- " alter table mysql.spider_link_failed_log"
- " modify link_id char(64) not null default '';"
- " end if;"
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_tables"
+ " add column if not exists block_status tinyint not null default 0"
+ " after link_status;"
+ )},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_tables"
+ " add column if not exists static_link_id char(64) default null after block_status,"
+ " add unique index if not exists uidx1 (db_name, table_name, static_link_id);"
+ )},
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_link_mon_servers'"
+ " AND COLUMN_NAME = 'link_id';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type != 'char(64)' then"
+ " alter table mysql.spider_link_mon_servers"
+ " modify link_id char(64) not null default '';"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_link_failed_log'"
+ " AND COLUMN_NAME = 'link_id';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type != 'char(64)' then"
+ " alter table mysql.spider_link_failed_log"
+ " modify link_id char(64) not null default '';"
+ "end if;"
+ )},
/*
Fix for version 3.3.10
*/
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_tables'"
- " AND COLUMN_NAME = 'table_name';"
- " if @col_type != 'char(199)' then"
- " alter table mysql.spider_tables"
- " modify table_name char(199) not null default '';"
- " end if;"
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_link_mon_servers'"
- " AND COLUMN_NAME = 'table_name';"
- " if @col_type != 'char(199)' then"
- " alter table mysql.spider_link_mon_servers"
- " modify table_name char(199) not null default '';"
- " end if;"
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_link_failed_log'"
- " AND COLUMN_NAME = 'table_name';"
- " if @col_type != 'char(199)' then"
- " alter table mysql.spider_link_failed_log"
- " modify table_name char(199) not null default '';"
- " end if;"
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_table_position_for_recovery'"
- " AND COLUMN_NAME = 'table_name';"
- " if @col_type != 'char(199)' then"
- " alter table mysql.spider_table_position_for_recovery"
- " modify table_name char(199) not null default '';"
- " end if;"
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_table_sts'"
- " AND COLUMN_NAME = 'table_name';"
- " if @col_type != 'char(199)' then"
- " alter table mysql.spider_table_sts"
- " modify table_name char(199) not null default '';"
- " end if;"
- " select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_table_crd'"
- " AND COLUMN_NAME = 'table_name';"
- " if @col_type != 'char(199)' then"
- " alter table mysql.spider_table_crd"
- " modify table_name char(199) not null default '';"
- " end if;"
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_tables'"
+ " AND COLUMN_NAME = 'table_name';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type != 'char(199)' then"
+ " alter table mysql.spider_tables"
+ " modify table_name char(199) not null default '';"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_link_mon_servers'"
+ " AND COLUMN_NAME = 'table_name';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type != 'char(199)' then"
+ " alter table mysql.spider_link_mon_servers"
+ " modify table_name char(199) not null default '';"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_link_failed_log'"
+ " AND COLUMN_NAME = 'table_name';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type != 'char(199)' then"
+ " alter table mysql.spider_link_failed_log"
+ " modify table_name char(199) not null default '';"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_table_position_for_recovery'"
+ " AND COLUMN_NAME = 'table_name';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type != 'char(199)' then"
+ " alter table mysql.spider_table_position_for_recovery"
+ " modify table_name char(199) not null default '';"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_table_sts'"
+ " AND COLUMN_NAME = 'table_name';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type != 'char(199)' then"
+ " alter table mysql.spider_table_sts"
+ " modify table_name char(199) not null default '';"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_table_crd'"
+ " AND COLUMN_NAME = 'table_name';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @col_type != 'char(199)' then"
+ " alter table mysql.spider_table_crd"
+ " modify table_name char(199) not null default '';"
+ "end if;"
+ )},
/*
Fix for version 3.3.15
*/
- " call mysql.spider_fix_one_table('spider_table_sts', 'checksum',"
- " 'alter table mysql.spider_table_sts"
- " add column checksum bigint unsigned default null after update_time');"
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_table_sts"
+ " add column if not exists checksum bigint unsigned default null after update_time;"
+ )},
/*
Fix for MariaDB 10.4: Crash-Safe system tables
*/
- " if @server_name = 'MariaDB' and"
- " ("
- " @server_major_version > 10 or"
- " ("
- " @server_major_version = 10 and"
- " @server_minor_version >= 4"
- " )"
- " )"
- " then"
- " select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_link_failed_log';"
- " if @engine_name != 'Aria' then"
- " alter table mysql.spider_link_failed_log"
- " engine=Aria transactional=1;"
- " end if;"
- " select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_link_mon_servers';"
- " if @engine_name != 'Aria' then"
- " alter table mysql.spider_link_mon_servers"
- " engine=Aria transactional=1;"
- " end if;"
- " select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_table_crd';"
- " if @engine_name != 'Aria' then"
- " alter table mysql.spider_table_crd"
- " engine=Aria transactional=1;"
- " end if;"
- " select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_table_position_for_recovery';"
- " if @engine_name != 'Aria' then"
- " alter table mysql.spider_table_position_for_recovery"
- " engine=Aria transactional=1;"
- " end if;"
- " select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_table_sts';"
- " if @engine_name != 'Aria' then"
- " alter table mysql.spider_table_sts"
- " engine=Aria transactional=1;"
- " end if;"
- " select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_tables';"
- " if @engine_name != 'Aria' then"
- " alter table mysql.spider_tables"
- " engine=Aria transactional=1;"
- " end if;"
- " select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_xa';"
- " if @engine_name != 'Aria' then"
- " alter table mysql.spider_xa"
- " engine=Aria transactional=1;"
- " end if;"
- " select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_xa_failed_log';"
- " if @engine_name != 'Aria' then"
- " alter table mysql.spider_xa_failed_log"
- " engine=Aria transactional=1;"
- " end if;"
- " select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
- " where TABLE_SCHEMA = 'mysql'"
- " AND TABLE_NAME = 'spider_xa_member';"
- " if @engine_name != 'Aria' then"
- " alter table mysql.spider_xa_member"
- " engine=Aria transactional=1;"
- " end if;"
- " end if;"
+ {C_STRING_WITH_LEN(
+ "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_link_failed_log';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @engine_name != 'Aria' then"
+ " alter table mysql.spider_link_failed_log"
+ " engine=Aria transactional=1;"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_link_mon_servers';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @engine_name != 'Aria' then"
+ " alter table mysql.spider_link_mon_servers"
+ " engine=Aria transactional=1;"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_table_crd';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @engine_name != 'Aria' then"
+ " alter table mysql.spider_table_crd"
+ " engine=Aria transactional=1;"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_table_position_for_recovery';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @engine_name != 'Aria' then"
+ " alter table mysql.spider_table_position_for_recovery"
+ " engine=Aria transactional=1;"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_table_sts';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @engine_name != 'Aria' then"
+ " alter table mysql.spider_table_sts"
+ " engine=Aria transactional=1;"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_tables';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @engine_name != 'Aria' then"
+ " alter table mysql.spider_tables"
+ " engine=Aria transactional=1;"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_xa';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @engine_name != 'Aria' then"
+ " alter table mysql.spider_xa"
+ " engine=Aria transactional=1;"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_xa_failed_log';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @engine_name != 'Aria' then"
+ " alter table mysql.spider_xa_failed_log"
+ " engine=Aria transactional=1;"
+ "end if;"
+ )},
+ {C_STRING_WITH_LEN(
+ "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES"
+ " where TABLE_SCHEMA = 'mysql'"
+ " AND TABLE_NAME = 'spider_xa_member';"
+ )},
+ {C_STRING_WITH_LEN(
+ "if @engine_name != 'Aria' then"
+ " alter table mysql.spider_xa_member"
+ " engine=Aria transactional=1;"
+ "end if;"
+ )},
/*
Fix for version 3.4
*/
- " call mysql.spider_fix_one_table('spider_link_mon_servers', 'dsn',"
- " 'alter table mysql.spider_link_mon_servers"
- " add column dsn char(64) default null after default_group');"
- " call mysql.spider_fix_one_table('spider_tables', 'dsn',"
- " 'alter table mysql.spider_tables"
- " add column dsn char(64) default null after default_group');"
- " call mysql.spider_fix_one_table('spider_xa_failed_log', 'dsn',"
- " 'alter table mysql.spider_xa_failed_log"
- " add column dsn char(64) default null after default_group');"
- " call mysql.spider_fix_one_table('spider_xa_member', 'dsn',"
- " 'alter table mysql.spider_xa_member"
- " add column dsn char(64) default null after default_group');"
- " call mysql.spider_fix_one_table('spider_link_mon_servers', 'filedsn',"
- " 'alter table mysql.spider_link_mon_servers"
- " add column filedsn text default null after dsn');"
- " call mysql.spider_fix_one_table('spider_tables', 'filedsn',"
- " 'alter table mysql.spider_tables"
- " add column filedsn text default null after dsn');"
- " call mysql.spider_fix_one_table('spider_xa_failed_log', 'filedsn',"
- " 'alter table mysql.spider_xa_failed_log"
- " add column filedsn text default null after dsn');"
- " call mysql.spider_fix_one_table('spider_xa_member', 'filedsn',"
- " 'alter table mysql.spider_xa_member"
- " add column filedsn text default null after dsn');"
- " call mysql.spider_fix_one_table('spider_link_mon_servers', 'driver',"
- " 'alter table mysql.spider_link_mon_servers"
- " add column driver char(64) default null after filedsn');"
- " call mysql.spider_fix_one_table('spider_tables', 'driver',"
- " 'alter table mysql.spider_tables"
- " add column driver char(64) default null after filedsn');"
- " call mysql.spider_fix_one_table('spider_xa_failed_log', 'driver',"
- " 'alter table mysql.spider_xa_failed_log"
- " add column driver char(64) default null after filedsn');"
- " call mysql.spider_fix_one_table('spider_xa_member', 'driver',"
- " 'alter table mysql.spider_xa_member"
- " add column driver char(64) default null after filedsn');"
- "end;"
- )},
- {C_STRING_WITH_LEN(
- "call mysql.spider_fix_system_tables"
- )},
- {C_STRING_WITH_LEN(
- "drop procedure mysql.spider_fix_one_table"
- )},
- {C_STRING_WITH_LEN(
- "drop procedure mysql.spider_fix_system_tables"
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_link_mon_servers"
+ " add column if not exists dsn char(64) default null after default_group;"
+ )},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_tables"
+ " add column if not exists dsn char(64) default null after default_group;"
+ )},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_xa_failed_log"
+ " add column if not exists dsn char(64) default null after default_group;"
+ )},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_xa_member"
+ " add column if not exists dsn char(64) default null after default_group;"
+ )},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_link_mon_servers"
+ " add column if not exists filedsn text default null after dsn;"
+ )},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_tables"
+ " add column if not exists filedsn text default null after dsn;"
+ )},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_xa_failed_log"
+ " add column if not exists filedsn text default null after dsn;"
+ )},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_xa_member"
+ " add column if not exists filedsn text default null after dsn;"
)},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_link_mon_servers"
+ " add column if not exists driver char(64) default null after filedsn;"
+ )},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_tables"
+ " add column if not exists driver char(64) default null after filedsn;"
+ )},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_xa_failed_log"
+ " add column if not exists driver char(64) default null after filedsn;"
+ )},
+ {C_STRING_WITH_LEN(
+ "alter table mysql.spider_xa_member"
+ " add column if not exists driver char(64) default null after filedsn;"
+ )},
+};
+
/*
- Install a plugin and UDFs
+ Install UDFs, requiring init_acl, thus separating out to own thread
*/
+static LEX_STRING spider_bg_init_queries[] = {
+ {C_STRING_WITH_LEN(
+ "create function if not exists spider_direct_sql returns int"
+ " soname 'ha_spider';"
+ )},
+ {C_STRING_WITH_LEN(
+ "create aggregate function if not exists spider_bg_direct_sql returns int"
+ " soname 'ha_spider';"
+ )},
+ {C_STRING_WITH_LEN(
+ "create function if not exists spider_ping_table returns int"
+ " soname 'ha_spider';"
+ )},
+ {C_STRING_WITH_LEN(
+ "create function if not exists spider_copy_tables returns int"
+ " soname 'ha_spider';"
+ )},
{C_STRING_WITH_LEN(
- "drop procedure if exists mysql.spider_plugin_installer"
- )},
- {C_STRING_WITH_LEN(
- "create procedure mysql.spider_plugin_installer()"
- "begin"
- " set @win_plugin := IF(@@version_compile_os like 'Win%', 1, 0);"
- " set @have_spider_direct_sql_udf := 0;"
- " select @have_spider_direct_sql_udf := 1 from mysql.func"
- " where name = 'spider_direct_sql';"
- " if @have_spider_direct_sql_udf = 0 then"
- " if @win_plugin = 0 then "
- " create function spider_direct_sql returns int"
- " soname 'ha_spider.so';"
- " else"
- " create function spider_direct_sql returns int"
- " soname 'ha_spider.dll';"
- " end if;"
- " end if;"
- " set @have_spider_bg_direct_sql_udf := 0;"
- " select @have_spider_bg_direct_sql_udf := 1 from mysql.func"
- " where name = 'spider_bg_direct_sql';"
- " if @have_spider_bg_direct_sql_udf = 0 then"
- " if @win_plugin = 0 then "
- " create aggregate function spider_bg_direct_sql returns int"
- " soname 'ha_spider.so';"
- " else"
- " create aggregate function spider_bg_direct_sql returns int"
- " soname 'ha_spider.dll';"
- " end if;"
- " end if;"
- " set @have_spider_ping_table_udf := 0;"
- " select @have_spider_ping_table_udf := 1 from mysql.func"
- " where name = 'spider_ping_table';"
- " if @have_spider_ping_table_udf = 0 then"
- " if @win_plugin = 0 then "
- " create function spider_ping_table returns int"
- " soname 'ha_spider.so';"
- " else"
- " create function spider_ping_table returns int"
- " soname 'ha_spider.dll';"
- " end if;"
- " end if;"
- " set @have_spider_copy_tables_udf := 0;"
- " select @have_spider_copy_tables_udf := 1 from mysql.func"
- " where name = 'spider_copy_tables';"
- " if @have_spider_copy_tables_udf = 0 then"
- " if @win_plugin = 0 then "
- " create function spider_copy_tables returns int"
- " soname 'ha_spider.so';"
- " else"
- " create function spider_copy_tables returns int"
- " soname 'ha_spider.dll';"
- " end if;"
- " end if;"
- " set @have_spider_flush_table_mon_cache_udf := 0;"
- " select @have_spider_flush_table_mon_cache_udf := 1 from mysql.func"
- " where name = 'spider_flush_table_mon_cache';"
- " if @have_spider_flush_table_mon_cache_udf = 0 then"
- " if @win_plugin = 0 then "
- " create function spider_flush_table_mon_cache returns int"
- " soname 'ha_spider.so';"
- " else"
- " create function spider_flush_table_mon_cache returns int"
- " soname 'ha_spider.dll';"
- " end if;"
- " end if;"
- "end;"
- )},
- {C_STRING_WITH_LEN(
- "call mysql.spider_plugin_installer"
- )},
- {C_STRING_WITH_LEN(
- "drop procedure mysql.spider_plugin_installer"
+ "create function if not exists spider_flush_table_mon_cache returns int"
+ " soname 'ha_spider';"
)}
};
diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc
index 793916e0552..39047497f18 100644
--- a/storage/spider/spd_table.cc
+++ b/storage/spider/spd_table.cc
@@ -117,6 +117,9 @@ const char **spd_mysqld_unix_port;
uint *spd_mysqld_port;
bool volatile *spd_abort_loop;
Time_zone *spd_tz_system;
+static int *spd_mysqld_server_started;
+static pthread_mutex_t *spd_LOCK_server_started;
+static pthread_cond_t *spd_COND_server_started;
extern long spider_conn_mutex_id;
handlerton *spider_hton_ptr;
/** All `SPIDER_DBTON`s */
@@ -6298,6 +6301,9 @@ int spider_db_init(
spd_mysqld_port = &mysqld_port;
spd_abort_loop = &abort_loop;
spd_tz_system = my_tz_SYSTEM;
+ spd_mysqld_server_started = &mysqld_server_started;
+ spd_LOCK_server_started = &LOCK_server_started;
+ spd_COND_server_started = &COND_server_started;
#ifdef HAVE_PSI_INTERFACE
init_spider_psi_keys();
@@ -6489,6 +6495,7 @@ int spider_db_init(
NullS))
)
goto error_alloc_mon_mutxes;
+ spider_table_sts_threads[0].init_command = TRUE;
for (roop_count = 0;
roop_count < (int) spider_param_table_sts_thread_count();
@@ -8625,6 +8632,7 @@ void spider_free_sts_threads(
) {
bool thread_killed;
DBUG_ENTER("spider_free_sts_threads");
+ spider_thread->init_command = FALSE;
pthread_mutex_lock(&spider_thread->mutex);
thread_killed = spider_thread->killed;
spider_thread->killed = TRUE;
@@ -8756,9 +8764,55 @@ void *spider_table_bg_sts_action(
trx->thd = thd;
/* init end */
- if (thd->killed)
+ if (thread->init_command)
{
- thread->killed = TRUE;
+ tmp_disable_binlog(thd);
+ thd->security_ctx->skip_grants();
+ thd->client_capabilities |= CLIENT_MULTI_RESULTS;
+ if (!(*spd_mysqld_server_started) && !thd->killed && !thread->killed)
+ {
+ pthread_mutex_lock(spd_LOCK_server_started);
+ thd->mysys_var->current_cond = spd_COND_server_started;
+ thd->mysys_var->current_mutex = spd_LOCK_server_started;
+ if (!(*spd_mysqld_server_started) && !thd->killed && !thread->killed &&
+ thread->init_command)
+ {
+ do
+ {
+ struct timespec abstime;
+ // set_timespec_nsec(abstime, 5000000000);
+ set_timespec_nsec(abstime, 1000);
+ error_num = pthread_cond_timedwait(spd_COND_server_started,
+ spd_LOCK_server_started, &abstime);
+ // abort();
+ } while (
+ (error_num == ETIMEDOUT || error_num == ETIME) &&
+ !(*spd_mysqld_server_started) && !thd->killed && !thread->killed &&
+ thread->init_command
+ );
+ }
+ pthread_mutex_unlock(spd_LOCK_server_started);
+ thd->mysys_var->current_cond = &thread->cond;
+ thd->mysys_var->current_mutex = &thread->mutex;
+ }
+ const int size= sizeof(spider_bg_init_queries) / sizeof(spider_bg_init_queries[0]);
+ for (int i= 0; i < size && !thd->killed && !thread->killed && thread->init_command; i++)
+ {
+ dispatch_command(COM_QUERY, thd, spider_bg_init_queries[i].str,
+ (uint) spider_bg_init_queries[i].length);
+ if (unlikely(thd->is_error()))
+ {
+ fprintf(stderr, "[ERROR] %s\n", spider_stmt_da_message(thd));
+ thd->clear_error();
+ break;
+ }
+ }
+ thd->mysys_var->current_cond = &thread->cond;
+ thd->mysys_var->current_mutex = &thread->mutex;
+ thd->client_capabilities -= CLIENT_MULTI_RESULTS;
+ reenable_binlog(thd);
+ thread->init_command = FALSE;
+ pthread_cond_broadcast(&thread->sync_cond);
}
if (thd->killed)
{