summaryrefslogtreecommitdiff
path: root/storage/spider
diff options
context:
space:
mode:
authorKentoku SHIBA <kentokushiba@gmail.com>2019-07-06 23:52:53 +0900
committerGitHub <noreply@github.com>2019-07-06 23:52:53 +0900
commitfa7051c419a653a002282eaca60f8202c1066d61 (patch)
treeb1812a294948f62784b46b9a34ae0a715566a6c2 /storage/spider
parent4a739d7650ebcaad76da87d19b832856d3e81eb3 (diff)
downloadmariadb-git-fa7051c419a653a002282eaca60f8202c1066d61.tar.gz
MDEV-19842 Crash while creating statistics for Spider table (#1355)
Added checks of the number of columns of the system tables. Move install_spider.sql into source code except installing Spider
Diffstat (limited to 'storage/spider')
-rw-r--r--storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_deinit.inc12
-rw-r--r--storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_init.inc13
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/spider_table_sts.result38
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/spider_table_sts.cnf2
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/spider_table_sts.test46
-rw-r--r--storage/spider/mysql-test/spider/include/deinit_spider.inc99
-rw-r--r--storage/spider/mysql-test/spider/include/init_spider.inc542
-rw-r--r--storage/spider/scripts/install_spider.sql549
-rw-r--r--storage/spider/spd_include.h1
-rw-r--r--storage/spider/spd_init_query.h782
-rw-r--r--storage/spider/spd_sys_table.cc335
-rw-r--r--storage/spider/spd_sys_table.h40
-rw-r--r--storage/spider/spd_table.cc194
13 files changed, 1572 insertions, 1081 deletions
diff --git a/storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_deinit.inc
new file mode 100644
index 00000000000..01645e85f32
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_deinit.inc
@@ -0,0 +1,12 @@
+--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
diff --git a/storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_init.inc b/storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_init.inc
new file mode 100644
index 00000000000..1e438812af7
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_init.inc
@@ -0,0 +1,13 @@
+--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');
diff --git a/storage/spider/mysql-test/spider/bugfix/r/spider_table_sts.result b/storage/spider/mysql-test/spider/bugfix/r/spider_table_sts.result
new file mode 100644
index 00000000000..f915cc951b1
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/spider_table_sts.result
@@ -0,0 +1,38 @@
+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
diff --git a/storage/spider/mysql-test/spider/bugfix/t/spider_table_sts.cnf b/storage/spider/mysql-test/spider/bugfix/t/spider_table_sts.cnf
new file mode 100644
index 00000000000..b0853e32654
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/spider_table_sts.cnf
@@ -0,0 +1,2 @@
+!include include/default_mysqld.cnf
+!include ../my_1_1.cnf
diff --git a/storage/spider/mysql-test/spider/bugfix/t/spider_table_sts.test b/storage/spider/mysql-test/spider/bugfix/t/spider_table_sts.test
new file mode 100644
index 00000000000..7213017505b
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/spider_table_sts.test
@@ -0,0 +1,46 @@
+--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
diff --git a/storage/spider/mysql-test/spider/include/deinit_spider.inc b/storage/spider/mysql-test/spider/include/deinit_spider.inc
index 3609551e169..51cc075edaa 100644
--- a/storage/spider/mysql-test/spider/include/deinit_spider.inc
+++ b/storage/spider/mysql-test/spider/include/deinit_spider.inc
@@ -1,8 +1,39 @@
-DROP FUNCTION spider_direct_sql;
-DROP FUNCTION spider_bg_direct_sql;
-DROP FUNCTION spider_ping_table;
-DROP FUNCTION spider_copy_tables;
+let $SERVER_NAME=
+ `SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(version(), '-', 2), '-', -1)`;
+let $SERVER_MAJOR_VERSION=
+ `SELECT SUBSTRING_INDEX(version(), '.', 1)`;
+let $SERVER_MINOR_VERSION=
+ `SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(version(), '.', 2), '.', -1)`;
+let $PLUGIN_VERSION=
+ `SELECT SUBSTRING_INDEX(plugin_version, '.', 1)
+ FROM information_schema.plugins
+ WHERE plugin_name = 'SPIDER'`;
+if (`SELECT IF($PLUGIN_VERSION = 3, 1, 0)`)
+{
+ let $HAS_REWRITE=
+ `SELECT IF (STRCMP('$SERVER_NAME', 'MariaDB') = 0,
+ IF ($SERVER_MAJOR_VERSION = 10,
+ IF ($SERVER_MINOR_VERSION < 4, 0, 1),
+ IF ($SERVER_MAJOR_VERSION < 10, 0, 1)),
+ 0)`;
+ let $HAS_REWRITE= 0;
+ if ($HAS_REWRITE)
+ {
+ DROP FUNCTION spider_flush_rewrite_cache;
+ UNINSTALL PLUGIN spider_rewrite;
+ DROP TABLE IF EXISTS mysql.spider_rewrite_tables;
+ DROP TABLE IF EXISTS mysql.spider_rewrite_table_tables;
+ DROP TABLE IF EXISTS mysql.spider_rewrite_table_partitions;
+ DROP TABLE IF EXISTS mysql.spider_rewrite_table_subpartitions;
+ DROP TABLE IF EXISTS mysql.spider_rewritten_tables;
+ }
+}
DROP FUNCTION spider_flush_table_mon_cache;
+DROP FUNCTION spider_copy_tables;
+DROP FUNCTION spider_ping_table;
+DROP FUNCTION spider_bg_direct_sql;
+DROP FUNCTION spider_direct_sql;
+UNINSTALL PLUGIN spider_alloc_mem;
UNINSTALL PLUGIN spider;
DROP TABLE IF EXISTS mysql.spider_xa;
DROP TABLE IF EXISTS mysql.spider_xa_member;
@@ -13,9 +44,57 @@ DROP TABLE IF EXISTS mysql.spider_link_failed_log;
DROP TABLE IF EXISTS mysql.spider_table_position_for_recovery;
DROP TABLE IF EXISTS mysql.spider_table_sts;
DROP TABLE IF EXISTS mysql.spider_table_crd;
-DROP SERVER s_2_1;
-DROP SERVER s_2_2;
-DROP SERVER s_2_3;
-DROP SERVER s_3_1;
-DROP SERVER s_3_2;
-DROP SERVER s_3_3;
+if ($VERSION_COMPILE_OS_WIN)
+{
+ if ($CHILD2_1_MYPORT)
+ {
+ DROP SERVER s_2_1;
+ }
+ if ($CHILD2_2_MYPORT)
+ {
+ DROP SERVER s_2_2;
+ }
+ if ($CHILD2_3_MYPORT)
+ {
+ DROP SERVER s_2_3;
+ }
+ if ($CHILD3_1_MYPORT)
+ {
+ DROP SERVER s_3_1;
+ }
+ if ($CHILD3_2_MYPORT)
+ {
+ DROP SERVER s_3_2;
+ }
+ if ($CHILD2_3_MYPORT)
+ {
+ DROP SERVER s_3_3;
+ }
+}
+if (!$VERSION_COMPILE_OS_WIN)
+{
+ if ($CHILD2_1_MYSOCK)
+ {
+ DROP SERVER s_2_1;
+ }
+ if ($CHILD2_2_MYSOCK)
+ {
+ DROP SERVER s_2_2;
+ }
+ if ($CHILD2_3_MYSOCK)
+ {
+ DROP SERVER s_2_3;
+ }
+ if ($CHILD3_1_MYSOCK)
+ {
+ DROP SERVER s_3_1;
+ }
+ if ($CHILD3_2_MYSOCK)
+ {
+ DROP SERVER s_3_2;
+ }
+ if ($CHILD3_3_MYSOCK)
+ {
+ DROP SERVER s_3_3;
+ }
+}
diff --git a/storage/spider/mysql-test/spider/include/init_spider.inc b/storage/spider/mysql-test/spider/include/init_spider.inc
index c1167b3c37e..69d1fae425e 100644
--- a/storage/spider/mysql-test/spider/include/init_spider.inc
+++ b/storage/spider/mysql-test/spider/include/init_spider.inc
@@ -3,104 +3,130 @@ let $VERSION_COMPILE_OS_WIN=
if ($VERSION_COMPILE_OS_WIN)
{
INSTALL PLUGIN spider SONAME 'ha_spider.dll';
- CREATE FUNCTION spider_direct_sql RETURNS INT SONAME 'ha_spider.dll';
- CREATE AGGREGATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.dll';
- CREATE FUNCTION spider_ping_table RETURNS INT SONAME 'ha_spider.dll';
- CREATE FUNCTION spider_copy_tables RETURNS INT SONAME 'ha_spider.dll';
- CREATE FUNCTION spider_flush_table_mon_cache RETURNS INT SONAME 'ha_spider.dll';
- eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS (
- HOST 'localhost',
- DATABASE 'auto_test_remote',
- USER 'root',
- PASSWORD '',
- PORT $CHILD2_1_MYPORT
- );
- eval CREATE SERVER s_2_2 FOREIGN DATA WRAPPER mysql OPTIONS (
- HOST 'localhost',
- DATABASE 'auto_test_remote2',
- USER 'root',
- PASSWORD '',
- PORT $CHILD2_2_MYPORT
- );
- eval CREATE SERVER s_2_3 FOREIGN DATA WRAPPER mysql OPTIONS (
- HOST 'localhost',
- DATABASE 'auto_test_remote3',
- USER 'root',
- PASSWORD '',
- PORT $CHILD2_3_MYPORT
- );
- eval CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS (
- HOST 'localhost',
- DATABASE 'auto_test_local',
- USER 'root',
- PASSWORD '',
- PORT $CHILD3_1_MYPORT
- );
- eval CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS (
- HOST 'localhost',
- DATABASE 'auto_test_local',
- USER 'root',
- PASSWORD '',
- PORT $CHILD3_2_MYPORT
- );
- eval CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS (
- HOST 'localhost',
- DATABASE 'auto_test_local',
- USER 'root',
- PASSWORD '',
- PORT $CHILD2_3_MYPORT
- );
+ if ($CHILD2_1_MYPORT)
+ {
+ eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS (
+ HOST 'localhost',
+ DATABASE 'auto_test_remote',
+ USER 'root',
+ PASSWORD '',
+ PORT $CHILD2_1_MYPORT
+ );
+ }
+ if ($CHILD2_2_MYPORT)
+ {
+ eval CREATE SERVER s_2_2 FOREIGN DATA WRAPPER mysql OPTIONS (
+ HOST 'localhost',
+ DATABASE 'auto_test_remote2',
+ USER 'root',
+ PASSWORD '',
+ PORT $CHILD2_2_MYPORT
+ );
+ }
+ if ($CHILD2_3_MYPORT)
+ {
+ eval CREATE SERVER s_2_3 FOREIGN DATA WRAPPER mysql OPTIONS (
+ HOST 'localhost',
+ DATABASE 'auto_test_remote3',
+ USER 'root',
+ PASSWORD '',
+ PORT $CHILD2_3_MYPORT
+ );
+ }
+ if ($CHILD3_1_MYPORT)
+ {
+ eval CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS (
+ HOST 'localhost',
+ DATABASE 'auto_test_local',
+ USER 'root',
+ PASSWORD '',
+ PORT $CHILD3_1_MYPORT
+ );
+ }
+ if ($CHILD3_2_MYPORT)
+ {
+ eval CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS (
+ HOST 'localhost',
+ DATABASE 'auto_test_local',
+ USER 'root',
+ PASSWORD '',
+ PORT $CHILD3_2_MYPORT
+ );
+ }
+ if ($CHILD2_3_MYPORT)
+ {
+ eval CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS (
+ HOST 'localhost',
+ DATABASE 'auto_test_local',
+ USER 'root',
+ PASSWORD '',
+ PORT $CHILD2_3_MYPORT
+ );
+ }
}
if (!$VERSION_COMPILE_OS_WIN)
{
INSTALL PLUGIN spider SONAME 'ha_spider.so';
- CREATE FUNCTION spider_direct_sql RETURNS INT SONAME 'ha_spider.so';
- CREATE AGGREGATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.so';
- CREATE FUNCTION spider_ping_table RETURNS INT SONAME 'ha_spider.so';
- CREATE FUNCTION spider_copy_tables RETURNS INT SONAME 'ha_spider.so';
- CREATE FUNCTION spider_flush_table_mon_cache RETURNS INT SONAME 'ha_spider.so';
- eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS (
- HOST 'localhost',
- DATABASE 'auto_test_remote',
- USER 'root',
- PASSWORD '',
- SOCKET '$CHILD2_1_MYSOCK'
- );
- eval CREATE SERVER s_2_2 FOREIGN DATA WRAPPER mysql OPTIONS (
- HOST 'localhost',
- DATABASE 'auto_test_remote2',
- USER 'root',
- PASSWORD '',
- SOCKET '$CHILD2_2_MYSOCK'
- );
- eval CREATE SERVER s_2_3 FOREIGN DATA WRAPPER mysql OPTIONS (
- HOST 'localhost',
- DATABASE 'auto_test_remote3',
- USER 'root',
- PASSWORD '',
- SOCKET '$CHILD2_3_MYSOCK'
- );
- eval CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS (
- HOST 'localhost',
- DATABASE 'auto_test_local',
- USER 'root',
- PASSWORD '',
- SOCKET '$CHILD3_1_MYSOCK'
- );
- eval CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS (
- HOST 'localhost',
- DATABASE 'auto_test_local',
- USER 'root',
- PASSWORD '',
- SOCKET '$CHILD3_2_MYSOCK'
- );
- eval CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS (
- HOST 'localhost',
- DATABASE 'auto_test_local',
- USER 'root',
- PASSWORD '',
- SOCKET '$CHILD3_3_MYSOCK'
- );
+ if ($CHILD2_1_MYSOCK)
+ {
+ eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS (
+ HOST 'localhost',
+ DATABASE 'auto_test_remote',
+ USER 'root',
+ PASSWORD '',
+ SOCKET '$CHILD2_1_MYSOCK'
+ );
+ }
+ if ($CHILD2_2_MYSOCK)
+ {
+ eval CREATE SERVER s_2_2 FOREIGN DATA WRAPPER mysql OPTIONS (
+ HOST 'localhost',
+ DATABASE 'auto_test_remote2',
+ USER 'root',
+ PASSWORD '',
+ SOCKET '$CHILD2_2_MYSOCK'
+ );
+ }
+ if ($CHILD2_3_MYSOCK)
+ {
+ eval CREATE SERVER s_2_3 FOREIGN DATA WRAPPER mysql OPTIONS (
+ HOST 'localhost',
+ DATABASE 'auto_test_remote3',
+ USER 'root',
+ PASSWORD '',
+ SOCKET '$CHILD2_3_MYSOCK'
+ );
+ }
+ if ($CHILD3_1_MYSOCK)
+ {
+ eval CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS (
+ HOST 'localhost',
+ DATABASE 'auto_test_local',
+ USER 'root',
+ PASSWORD '',
+ SOCKET '$CHILD3_1_MYSOCK'
+ );
+ }
+ if ($CHILD3_2_MYSOCK)
+ {
+ eval CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS (
+ HOST 'localhost',
+ DATABASE 'auto_test_local',
+ USER 'root',
+ PASSWORD '',
+ SOCKET '$CHILD3_2_MYSOCK'
+ );
+ }
+ if ($CHILD3_3_MYSOCK)
+ {
+ eval CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS (
+ HOST 'localhost',
+ DATABASE 'auto_test_local',
+ USER 'root',
+ PASSWORD '',
+ SOCKET '$CHILD3_3_MYSOCK'
+ );
+ }
}
let $SERVER_NAME=
@@ -113,314 +139,34 @@ let $PLUGIN_VERSION=
`SELECT SUBSTRING_INDEX(plugin_version, '.', 1)
FROM information_schema.plugins
WHERE plugin_name = 'SPIDER'`;
-
-if (`SELECT IF($PLUGIN_VERSION = 1, 1, 0)`)
-{
- DROP TABLE IF EXISTS mysql.spider_xa;
- CREATE TABLE mysql.spider_xa(
- format_id int not null default 0,
- gtrid_length int not null default 0,
- bqual_length int not null default 0,
- data char(128) charset binary not null default '',
- status char(8) not null default '',
- PRIMARY KEY (data, format_id, gtrid_length),
- KEY idx1 (status)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_xa_member;
- CREATE TABLE mysql.spider_xa_member(
- format_id int not null default 0,
- gtrid_length int not null default 0,
- bqual_length int not null default 0,
- data char(128) charset binary not null default '',
- scheme char(64) not null default '',
- host char(64) not null default '',
- port char(5) not null default '',
- socket char(64) not null default '',
- username char(64) not null default '',
- password char(64) not null default '',
- PRIMARY KEY (data, format_id, gtrid_length, host, port, socket)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_tables;
- CREATE TABLE mysql.spider_tables(
- db_name char(64) not null default '',
- table_name char(64) not null default '',
- priority bigint not null default 0,
- server char(64) default null,
- scheme char(64) default null,
- host char(64) default null,
- port char(5) default null,
- socket char(64) default null,
- username char(64) default null,
- password char(64) default null,
- tgt_db_name char(64) default null,
- tgt_table_name char(64) default null,
- PRIMARY KEY (db_name, table_name),
- KEY idx1 (priority)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-}
-if (`SELECT IF($PLUGIN_VERSION = 2, 1, 0)`)
-{
- DROP TABLE IF EXISTS mysql.spider_xa;
- CREATE TABLE mysql.spider_xa(
- format_id int not null default 0,
- gtrid_length int not null default 0,
- bqual_length int not null default 0,
- data char(128) charset binary not null default '',
- status char(8) not null default '',
- PRIMARY KEY (data, format_id, gtrid_length),
- KEY idx1 (status)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_xa_member;
- CREATE TABLE mysql.spider_xa_member(
- format_id int not null default 0,
- gtrid_length int not null default 0,
- bqual_length int not null default 0,
- data char(128) charset binary not null default '',
- scheme char(64) not null default '',
- host char(64) not null default '',
- port char(5) not null default '',
- socket char(64) not null default '',
- username char(64) not null default '',
- password char(64) not null default '',
- ssl_ca char(64) default null,
- ssl_capath char(64) default null,
- ssl_cert char(64) default null,
- ssl_cipher char(64) default null,
- ssl_key char(64) default null,
- ssl_verify_server_cert tinyint not null default 0,
- default_file char(64) default null,
- default_group char(64) default null,
- PRIMARY KEY (data, format_id, gtrid_length, host, port, socket)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_tables;
- CREATE TABLE mysql.spider_tables(
- db_name char(64) not null default '',
- table_name char(64) not null default '',
- link_id int not null default 0,
- priority bigint not null default 0,
- server char(64) default null,
- scheme char(64) default null,
- host char(64) default null,
- port char(5) default null,
- socket char(64) default null,
- username char(64) default null,
- password char(64) default null,
- ssl_ca char(64) default null,
- ssl_capath char(64) default null,
- ssl_cert char(64) default null,
- ssl_cipher char(64) default null,
- ssl_key char(64) default null,
- ssl_verify_server_cert tinyint not null default 0,
- default_file char(64) default null,
- default_group char(64) default null,
- tgt_db_name char(64) default null,
- tgt_table_name char(64) default null,
- link_status tinyint not null default 1,
- PRIMARY KEY (db_name, table_name, link_id),
- KEY idx1 (priority)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_link_mon_servers;
- CREATE TABLE mysql.spider_link_mon_servers(
- db_name char(64) not null default '',
- table_name char(64) not null default '',
- link_id char(5) not null default '',
- sid int not null default 0,
- server char(64) default null,
- scheme char(64) default null,
- host char(64) default null,
- port char(5) default null,
- socket char(64) default null,
- username char(64) default null,
- password char(64) default null,
- ssl_ca char(64) default null,
- ssl_capath char(64) default null,
- ssl_cert char(64) default null,
- ssl_cipher char(64) default null,
- ssl_key char(64) default null,
- ssl_verify_server_cert tinyint not null default 0,
- default_file char(64) default null,
- default_group char(64) default null,
- PRIMARY KEY (db_name, table_name, link_id, sid)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_link_failed_log;
- CREATE TABLE mysql.spider_link_failed_log(
- db_name char(64) not null default '',
- table_name char(64) not null default '',
- link_id int not null default 0,
- failed_time timestamp not null default current_timestamp
- ) ENGINE=MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-}
if (`SELECT IF($PLUGIN_VERSION = 3, 1, 0)`)
{
- let $ENGINE_NAME=
+ let $HAS_REWRITE=
`SELECT IF (STRCMP('$SERVER_NAME', 'MariaDB') = 0,
IF ($SERVER_MAJOR_VERSION = 10,
- IF ($SERVER_MINOR_VERSION < 4, 'MyISAM',
- 'Aria transactional=1'),
- IF ($SERVER_MAJOR_VERSION < 10, 'MyISAM',
- 'Aria transactional=1')),
- 'MyISAM')`;
- DROP TABLE IF EXISTS mysql.spider_xa;
- eval
- CREATE TABLE mysql.spider_xa(
- format_id int not null default 0,
- gtrid_length int not null default 0,
- bqual_length int not null default 0,
- data binary(128) not null default '',
- status char(8) not null default '',
- PRIMARY KEY (data, format_id, gtrid_length),
- KEY idx1 (status)
- ) ENGINE=$ENGINE_NAME DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_xa_member;
- eval
- CREATE TABLE mysql.spider_xa_member(
- format_id int not null default 0,
- gtrid_length int not null default 0,
- bqual_length int not null default 0,
- data binary(128) not null default '',
- scheme char(64) not null default '',
- host char(64) not null default '',
- port char(5) not null default '',
- socket text not null default '',
- username char(64) not null default '',
- password char(64) not null default '',
- ssl_ca text default null,
- ssl_capath text default null,
- ssl_cert text default null,
- ssl_cipher char(64) default null,
- ssl_key text default null,
- ssl_verify_server_cert tinyint not null default 0,
- default_file text default null,
- default_group char(64) default null,
- KEY idx1 (data, format_id, gtrid_length, host)
- ) ENGINE=$ENGINE_NAME DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_xa_failed_log;
- eval
- CREATE TABLE mysql.spider_xa_failed_log(
- format_id int not null default 0,
- gtrid_length int not null default 0,
- bqual_length int not null default 0,
- data binary(128) not null default '',
- scheme char(64) not null default '',
- host char(64) not null default '',
- port char(5) not null default '',
- socket text not null,
- username char(64) not null default '',
- password char(64) not null default '',
- ssl_ca text,
- ssl_capath text,
- ssl_cert text,
- ssl_cipher char(64) default null,
- ssl_key text,
- ssl_verify_server_cert tinyint not null default 0,
- default_file text,
- default_group char(64) default null,
- thread_id int default null,
- status char(8) not null default '',
- failed_time timestamp not null default current_timestamp,
- key idx1 (data, format_id, gtrid_length, host)
- ) ENGINE=$ENGINE_NAME DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_tables;
- eval
- CREATE TABLE mysql.spider_tables(
- db_name char(64) not null default '',
- table_name char(199) not null default '',
- link_id int not null default 0,
- priority bigint not null default 0,
- server char(64) default null,
- scheme char(64) default null,
- host char(64) default null,
- port char(5) default null,
- socket text default null,
- username char(64) default null,
- password char(64) default null,
- ssl_ca text default null,
- ssl_capath text default null,
- ssl_cert text default null,
- ssl_cipher char(64) default null,
- ssl_key text default null,
- ssl_verify_server_cert tinyint not null default 0,
- monitoring_binlog_pos_at_failing tinyint not null default 0,
- default_file text default null,
- default_group char(64) default null,
- tgt_db_name char(64) default null,
- tgt_table_name char(64) default null,
- link_status tinyint not null default 1,
- block_status tinyint not null default 0,
- static_link_id char(64) default null,
- PRIMARY KEY (db_name, table_name, link_id),
- KEY idx1 (priority),
- UNIQUE KEY uidx1 (db_name, table_name, static_link_id)
- ) ENGINE=$ENGINE_NAME DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_link_mon_servers;
- eval
- CREATE TABLE mysql.spider_link_mon_servers(
- db_name char(64) not null default '',
- table_name char(199) not null default '',
- link_id char(64) not null default '',
- sid int unsigned not null default 0,
- server char(64) default null,
- scheme char(64) default null,
- host char(64) default null,
- port char(5) default null,
- socket text default null,
- username char(64) default null,
- password char(64) default null,
- ssl_ca text default null,
- ssl_capath text default null,
- ssl_cert text default null,
- ssl_cipher char(64) default null,
- ssl_key text default null,
- ssl_verify_server_cert tinyint not null default 0,
- default_file text default null,
- default_group char(64) default null,
- PRIMARY KEY (db_name, table_name, link_id, sid)
- ) ENGINE=$ENGINE_NAME DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_link_failed_log;
- eval
- CREATE TABLE mysql.spider_link_failed_log(
- db_name char(64) not null default '',
- table_name char(199) not null default '',
- link_id char(64) not null default '',
- failed_time timestamp not null default current_timestamp
- ) ENGINE=$ENGINE_NAME DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_table_position_for_recovery;
- eval
- CREATE TABLE mysql.spider_table_position_for_recovery(
- db_name char(64) not null default '',
- table_name char(199) not null default '',
- failed_link_id int not null default 0,
- source_link_id int not null default 0,
- file text,
- position text,
- gtid text,
- primary key (db_name, table_name, failed_link_id, source_link_id)
- ) ENGINE=$ENGINE_NAME DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_table_sts;
- eval
- CREATE TABLE mysql.spider_table_sts(
- db_name char(64) not null default '',
- table_name char(199) not null default '',
- data_file_length bigint unsigned not null default 0,
- max_data_file_length bigint unsigned not null default 0,
- index_file_length bigint unsigned not null default 0,
- records bigint unsigned not null default 0,
- mean_rec_length bigint unsigned not null default 0,
- check_time datetime not null default '0000-00-00 00:00:00',
- create_time datetime not null default '0000-00-00 00:00:00',
- update_time datetime not null default '0000-00-00 00:00:00',
- checksum bigint unsigned default null,
- primary key (db_name, table_name)
- ) ENGINE=$ENGINE_NAME DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
- DROP TABLE IF EXISTS mysql.spider_table_crd;
- eval
- CREATE TABLE mysql.spider_table_crd(
- db_name char(64) not null default '',
- table_name char(199) not null default '',
- key_seq int unsigned not null default 0,
- cardinality bigint not null default 0,
- primary key (db_name, table_name, key_seq)
- ) ENGINE=$ENGINE_NAME DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+ IF ($SERVER_MINOR_VERSION < 4, 0, 1),
+ IF ($SERVER_MAJOR_VERSION < 10, 0, 1)),
+ 0)`;
+ let $HAS_REWRITE= 0;
+ if ($HAS_REWRITE)
+ {
+ let $PLUGIN_NAME= spider_flush_rewrite_cache;
+ let $PLUGIN_EXIST=
+ `SELECT COUNT(*) FROM mysql.func WHERE name = '$PLUGIN_NAME'`;
+ while (!$PLUGIN_EXIST)
+ {
+ let $PLUGIN_EXIST=
+ `SELECT COUNT(*) FROM mysql.func WHERE name = '$PLUGIN_NAME'`;
+ }
+ }
+}
+let $PLUGIN_NAME= spider_flush_table_mon_cache;
+let $PLUGIN_EXIST=
+ `SELECT COUNT(*) FROM mysql.func WHERE name = '$PLUGIN_NAME'`;
+while (!$PLUGIN_EXIST)
+{
+ let $PLUGIN_EXIST=
+ `SELECT COUNT(*) FROM mysql.func WHERE name = '$PLUGIN_NAME'`;
}
SET spider_internal_sql_log_off= 0;
diff --git a/storage/spider/scripts/install_spider.sql b/storage/spider/scripts/install_spider.sql
index 30c92e6c710..403bd99fd68 100644
--- a/storage/spider/scripts/install_spider.sql
+++ b/storage/spider/scripts/install_spider.sql
@@ -1,4 +1,4 @@
-# Copyright (C) 2010-2018 Kentoku Shiba
+# Copyright (C) 2010-2019 Kentoku Shiba
#
# 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
@@ -13,488 +13,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
-# This SQL script creates system tables for SPIDER
-# or fixes incompatibilities if ones already exist.
-
--- Create system tables if not exist
-create table if not exists mysql.spider_xa(
- format_id int not null default 0,
- gtrid_length int not null default 0,
- bqual_length int not null default 0,
- data char(128) charset binary not null default '',
- status char(8) not null default '',
- primary key (data, format_id, gtrid_length),
- key idx1 (status)
-) engine=MyISAM default charset=utf8 collate=utf8_bin;
-create table if not exists mysql.spider_xa_member(
- format_id int not null default 0,
- gtrid_length int not null default 0,
- bqual_length int not null default 0,
- data char(128) charset binary not null default '',
- scheme char(64) not null default '',
- host char(64) not null default '',
- port char(5) not null default '',
- socket text not null,
- username char(64) not null default '',
- password char(64) not null default '',
- ssl_ca text,
- ssl_capath text,
- ssl_cert text,
- ssl_cipher char(64) default null,
- ssl_key text,
- ssl_verify_server_cert tinyint not null default 0,
- default_file text,
- default_group char(64) default null,
- key idx1 (data, format_id, gtrid_length, host)
-) engine=MyISAM default charset=utf8 collate=utf8_bin;
-create table if not exists mysql.spider_xa_failed_log(
- format_id int not null default 0,
- gtrid_length int not null default 0,
- bqual_length int not null default 0,
- data char(128) charset binary not null default '',
- scheme char(64) not null default '',
- host char(64) not null default '',
- port char(5) not null default '',
- socket text not null,
- username char(64) not null default '',
- password char(64) not null default '',
- ssl_ca text,
- ssl_capath text,
- ssl_cert text,
- ssl_cipher char(64) default null,
- ssl_key text,
- ssl_verify_server_cert tinyint not null default 0,
- default_file text,
- default_group char(64) default null,
- thread_id int default null,
- status char(8) not null default '',
- failed_time timestamp not null default current_timestamp,
- key idx1 (data, format_id, gtrid_length, host)
-) engine=MyISAM default charset=utf8 collate=utf8_bin;
-create table if not exists mysql.spider_tables(
- db_name char(64) not null default '',
- table_name char(199) not null default '',
- link_id int not null default 0,
- priority bigint not null default 0,
- server char(64) default null,
- scheme char(64) default null,
- host char(64) default null,
- port char(5) default null,
- socket text,
- username char(64) default null,
- password char(64) default null,
- ssl_ca text,
- ssl_capath text,
- ssl_cert text,
- ssl_cipher char(64) default null,
- ssl_key text,
- ssl_verify_server_cert tinyint not null default 0,
- monitoring_binlog_pos_at_failing tinyint not null default 0,
- default_file text,
- default_group char(64) default null,
- tgt_db_name char(64) default null,
- tgt_table_name char(64) default null,
- link_status tinyint not null default 1,
- block_status tinyint not null default 0,
- static_link_id char(64) default null,
- primary key (db_name, table_name, link_id),
- key idx1 (priority),
- unique key uidx1 (db_name, table_name, static_link_id)
-) engine=MyISAM default charset=utf8 collate=utf8_bin;
-create table if not exists mysql.spider_link_mon_servers(
- db_name char(64) not null default '',
- table_name char(199) not null default '',
- link_id char(64) not null default '',
- sid int unsigned not null default 0,
- server char(64) default null,
- scheme char(64) default null,
- host char(64) default null,
- port char(5) default null,
- socket text,
- username char(64) default null,
- password char(64) default null,
- ssl_ca text,
- ssl_capath text,
- ssl_cert text,
- ssl_cipher char(64) default null,
- ssl_key text,
- ssl_verify_server_cert tinyint not null default 0,
- default_file text,
- default_group char(64) default null,
- primary key (db_name, table_name, link_id, sid)
-) engine=MyISAM default charset=utf8 collate=utf8_bin;
-create table if not exists mysql.spider_link_failed_log(
- db_name char(64) not null default '',
- table_name char(199) not null default '',
- link_id char(64) not null default '',
- failed_time timestamp not null default current_timestamp
-) engine=MyISAM default charset=utf8 collate=utf8_bin;
-create table if not exists mysql.spider_table_position_for_recovery(
- db_name char(64) not null default '',
- table_name char(199) not null default '',
- failed_link_id int not null default 0,
- source_link_id int not null default 0,
- file text,
- position text,
- gtid text,
- primary key (db_name, table_name, failed_link_id, source_link_id)
-) engine=MyISAM default charset=utf8 collate=utf8_bin;
-create table if not exists mysql.spider_table_sts(
- db_name char(64) not null default '',
- table_name char(199) not null default '',
- data_file_length bigint unsigned not null default 0,
- max_data_file_length bigint unsigned not null default 0,
- index_file_length bigint unsigned not null default 0,
- records bigint unsigned not null default 0,
- mean_rec_length bigint unsigned not null default 0,
- check_time datetime not null default '0000-00-00 00:00:00',
- create_time datetime not null default '0000-00-00 00:00:00',
- update_time datetime not null default '0000-00-00 00:00:00',
- checksum bigint unsigned default null,
- primary key (db_name, table_name)
-) engine=MyISAM default charset=utf8 collate=utf8_bin;
-create table if not exists mysql.spider_table_crd(
- db_name char(64) not null default '',
- table_name char(199) not null default '',
- key_seq int unsigned not null default 0,
- cardinality bigint not null default 0,
- primary key (db_name, table_name, key_seq)
-) engine=MyISAM default charset=utf8 collate=utf8_bin;
-
--- If tables already exist and their definition differ from the latest ones,
--- we fix them here.
-drop procedure if exists mysql.spider_fix_one_table;
-drop procedure if exists mysql.spider_fix_system_tables;
-delimiter //
-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;//
-
-create procedure mysql.spider_fix_system_tables()
-begin
- select substring_index(substring_index(version(), '-', 2), '-', -1)
- 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');
-
- -- 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;
-
- -- 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)');
-
- -- 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');
-
- -- 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');
-
- -- Fix for version 2.25
- -- 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(5)' then
- -- alter table mysql.spider_link_mon_servers
- -- modify link_id char(5) not null default '';
- -- end if;
-
- -- 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;
-
- -- 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;
-
- -- 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');
-
- -- 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;
-
- -- 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;
-
- -- 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');
-
- -- 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;
-end;//
-delimiter ;
-call mysql.spider_fix_system_tables;
-drop procedure mysql.spider_fix_one_table;
-drop procedure mysql.spider_fix_system_tables;
-
--- Install a plugin and UDFs
drop procedure if exists mysql.spider_plugin_installer;
delimiter //
create procedure mysql.spider_plugin_installer()
@@ -518,71 +36,6 @@ begin
install plugin spider soname 'ha_spider.dll';
end if;
end if;
- set @have_spider_i_s_alloc_mem_plugin := 0;
- select @have_spider_i_s_alloc_mem_plugin := 1 from INFORMATION_SCHEMA.plugins where PLUGIN_NAME = 'SPIDER_ALLOC_MEM';
- set @have_spider_alloc_mem_plugin := 0;
- select @have_spider_alloc_mem_plugin := 1 from mysql.plugin where name = 'spider_alloc_mem';
- if @have_spider_i_s_alloc_mem_plugin = 0 then
- if @have_spider_alloc_mem_plugin = 1 then
- -- spider_alloc_mem plugin is present in mysql.plugin but not in
- -- information_schema.plugins. Remove spider_alloc_mem plugin entry
- -- in mysql.plugin first.
- delete from mysql.plugin where name = 'spider_alloc_mem';
- end if;
- -- Install spider_alloc_mem plugin
- if @win_plugin = 0 then
- install plugin spider_alloc_mem soname 'ha_spider.so';
- else
- install plugin spider_alloc_mem soname 'ha_spider.dll';
- end if;
- end if;
- 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;//
delimiter ;
call mysql.spider_plugin_installer;
diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h
index faec3e63804..8b0581b9bd9 100644
--- a/storage/spider/spd_include.h
+++ b/storage/spider/spd_include.h
@@ -292,6 +292,7 @@ typedef struct st_spider_thread
volatile bool killed;
volatile bool thd_wait;
volatile bool first_free_wait;
+ volatile bool init_command;
pthread_t thread;
pthread_cond_t cond;
pthread_mutex_t mutex;
diff --git a/storage/spider/spd_init_query.h b/storage/spider/spd_init_query.h
new file mode 100644
index 00000000000..4c58f8d80a4
--- /dev/null
+++ b/storage/spider/spd_init_query.h
@@ -0,0 +1,782 @@
+/* Copyright (C) 2010-2019 Kentoku Shiba
+ Copyright (C) 2019 MariaDB corp
+
+ 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
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/*
+ This SQL script creates system tables for SPIDER
+ or fixes incompatibilities if ones already exist.
+*/
+
+static LEX_STRING spider_init_queries[] = {
+ {C_STRING_WITH_LEN(
+ "create table if not exists mysql.spider_xa("
+ " format_id int not null default 0,"
+ " gtrid_length int not null default 0,"
+ " bqual_length int not null default 0,"
+ " data char(128) charset binary not null default '',"
+ " status char(8) not null default '',"
+ " primary key (data, format_id, gtrid_length),"
+ " key idx1 (status)"
+ ") engine=MyISAM default charset=utf8 collate=utf8_bin"
+ )},
+ {C_STRING_WITH_LEN(
+ "create table if not exists mysql.spider_xa_member("
+ " format_id int not null default 0,"
+ " gtrid_length int not null default 0,"
+ " bqual_length int not null default 0,"
+ " data char(128) charset binary not null default '',"
+ " scheme char(64) not null default '',"
+ " host char(64) not null default '',"
+ " port char(5) not null default '',"
+ " socket text not null,"
+ " username char(64) not null default '',"
+ " password char(64) not null default '',"
+ " ssl_ca text,"
+ " ssl_capath text,"
+ " ssl_cert text,"
+ " ssl_cipher char(64) default null,"
+ " ssl_key text,"
+ " ssl_verify_server_cert tinyint not null default 0,"
+ " default_file text,"
+ " default_group char(64) default null,"
+ " key idx1 (data, format_id, gtrid_length, host)"
+ ") engine=MyISAM default charset=utf8 collate=utf8_bin"
+ )},
+ {C_STRING_WITH_LEN(
+ "create table if not exists mysql.spider_xa_failed_log("
+ " format_id int not null default 0,"
+ " gtrid_length int not null default 0,"
+ " bqual_length int not null default 0,"
+ " data char(128) charset binary not null default '',"
+ " scheme char(64) not null default '',"
+ " host char(64) not null default '',"
+ " port char(5) not null default '',"
+ " socket text not null,"
+ " username char(64) not null default '',"
+ " password char(64) not null default '',"
+ " ssl_ca text,"
+ " ssl_capath text,"
+ " ssl_cert text,"
+ " ssl_cipher char(64) default null,"
+ " ssl_key text,"
+ " ssl_verify_server_cert tinyint not null default 0,"
+ " default_file text,"
+ " default_group char(64) default null,"
+ " thread_id int default null,"
+ " status char(8) not null default '',"
+ " failed_time timestamp not null default current_timestamp,"
+ " key idx1 (data, format_id, gtrid_length, host)"
+ ") engine=MyISAM default charset=utf8 collate=utf8_bin"
+ )},
+ {C_STRING_WITH_LEN(
+ "create table if not exists mysql.spider_tables("
+ " db_name char(64) not null default '',"
+ " table_name char(199) not null default '',"
+ " link_id int not null default 0,"
+ " priority bigint not null default 0,"
+ " server char(64) default null,"
+ " scheme char(64) default null,"
+ " host char(64) default null,"
+ " port char(5) default null,"
+ " socket text,"
+ " username char(64) default null,"
+ " password char(64) default null,"
+ " ssl_ca text,"
+ " ssl_capath text,"
+ " ssl_cert text,"
+ " ssl_cipher char(64) default null,"
+ " ssl_key text,"
+ " ssl_verify_server_cert tinyint not null default 0,"
+ " monitoring_binlog_pos_at_failing tinyint not null default 0,"
+ " default_file text,"
+ " default_group char(64) default null,"
+ " tgt_db_name char(64) default null,"
+ " tgt_table_name char(64) default null,"
+ " link_status tinyint not null default 1,"
+ " block_status tinyint not null default 0,"
+ " static_link_id char(64) default null,"
+ " primary key (db_name, table_name, link_id),"
+ " key idx1 (priority),"
+ " unique key uidx1 (db_name, table_name, static_link_id)"
+ ") engine=MyISAM default charset=utf8 collate=utf8_bin"
+ )},
+ {C_STRING_WITH_LEN(
+ "create table if not exists mysql.spider_link_mon_servers("
+ " db_name char(64) not null default '',"
+ " table_name char(199) not null default '',"
+ " link_id char(64) not null default '',"
+ " sid int unsigned not null default 0,"
+ " server char(64) default null,"
+ " scheme char(64) default null,"
+ " host char(64) default null,"
+ " port char(5) default null,"
+ " socket text,"
+ " username char(64) default null,"
+ " password char(64) default null,"
+ " ssl_ca text,"
+ " ssl_capath text,"
+ " ssl_cert text,"
+ " ssl_cipher char(64) default null,"
+ " ssl_key text,"
+ " ssl_verify_server_cert tinyint not null default 0,"
+ " default_file text,"
+ " default_group char(64) default null,"
+ " primary key (db_name, table_name, link_id, sid)"
+ ") engine=MyISAM default charset=utf8 collate=utf8_bin"
+ )},
+ {C_STRING_WITH_LEN(
+ "create table if not exists mysql.spider_link_failed_log("
+ " db_name char(64) not null default '',"
+ " table_name char(199) not null default '',"
+ " link_id char(64) not null default '',"
+ " failed_time timestamp not null default current_timestamp"
+ ") engine=MyISAM default charset=utf8 collate=utf8_bin"
+ )},
+ {C_STRING_WITH_LEN(
+ "create table if not exists mysql.spider_table_position_for_recovery("
+ " db_name char(64) not null default '',"
+ " table_name char(199) not null default '',"
+ " failed_link_id int not null default 0,"
+ " source_link_id int not null default 0,"
+ " file text,"
+ " position text,"
+ " gtid text,"
+ " primary key (db_name, table_name, failed_link_id, source_link_id)"
+ ") engine=MyISAM default charset=utf8 collate=utf8_bin"
+ )},
+ {C_STRING_WITH_LEN(
+ "create table if not exists mysql.spider_table_sts("
+ " db_name char(64) not null default '',"
+ " table_name char(199) not null default '',"
+ " data_file_length bigint unsigned not null default 0,"
+ " max_data_file_length bigint unsigned not null default 0,"
+ " index_file_length bigint unsigned not null default 0,"
+ " records bigint unsigned not null default 0,"
+ " mean_rec_length bigint unsigned not null default 0,"
+ " check_time datetime not null default '0000-00-00 00:00:00',"
+ " create_time datetime not null default '0000-00-00 00:00:00',"
+ " update_time datetime not null default '0000-00-00 00:00:00',"
+ " checksum bigint unsigned default null,"
+ " primary key (db_name, table_name)"
+ ") engine=MyISAM default charset=utf8 collate=utf8_bin"
+ )},
+ {C_STRING_WITH_LEN(
+ "create table if not exists mysql.spider_table_crd("
+ " db_name char(64) not null default '',"
+ " table_name char(199) not null default '',"
+ " key_seq int unsigned not null default 0,"
+ " cardinality bigint not null default 0,"
+ " primary key (db_name, table_name, key_seq)"
+ ") engine=MyISAM default charset=utf8 collate=utf8_bin"
+ )},
+/*
+ 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 substring_index(substring_index(version(), '-', 2), '-', -1)"
+ " 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');"
+/*
+ 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;"
+/*
+ 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)');"
+/*
+ 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');"
+/*
+ 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');"
+/*
+ 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;"
+/*
+ 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;"
+/*
+ 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');"
+/*
+ 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;"
+/*
+ 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;"
+/*
+ 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');"
+/*
+ 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;"
+ " if @server_name = 'MariaDB' and"
+ " ("
+ " @server_major_version > 10 or"
+ " ("
+ " @server_major_version = 10 and"
+ " @server_minor_version >= 6"
+ " )"
+ " )"
+ " then"
+ " /* table for ddl pushdown */"
+ " create table if not exists mysql.spider_rewrite_tables("
+ " table_id bigint unsigned not null auto_increment,"
+ " db_name char(64) not null default '',"
+ " table_name char(64) not null default '',"
+ " primary key (table_id),"
+ " unique uk1(db_name, table_name)"
+ " ) engine=Aria transactional=1 default charset=utf8 collate=utf8_bin;"
+ " create table if not exists mysql.spider_rewrite_table_tables("
+ " table_id bigint unsigned not null,"
+ " partition_id bigint unsigned not null auto_increment,"
+ " partition_method varchar(18) default '',"
+ " partition_expression varchar(64) default '',"
+ " subpartition_method varchar(12) default '',"
+ " subpartition_expression varchar(64) default '',"
+ " connection_str text not null default '',"
+ " comment_str text not null default '',"
+ " primary key (table_id, partition_id),"
+ " unique uk1(table_id, partition_method, partition_expression,"
+ " subpartition_method, subpartition_expression)"
+ " ) engine=Aria transactional=1 default charset=utf8 collate=utf8_bin;"
+ " create table if not exists mysql.spider_rewrite_table_partitions("
+ " table_id bigint unsigned not null,"
+ " partition_id bigint unsigned not null,"
+ " partition_ordinal_position bigint unsigned not null auto_increment,"
+ " partition_name varchar(64) not null default '',"
+ " partition_description varchar(64) not null default '',"
+ " connection_str text not null default '',"
+ " comment_str text not null default '',"
+ " primary key (table_id, partition_id, partition_ordinal_position),"
+ " unique key uk1 (table_id, partition_id, partition_name)"
+ " ) engine=Aria transactional=1 default charset=utf8 collate=utf8_bin;"
+ " create table if not exists mysql.spider_rewrite_table_subpartitions("
+ " table_id bigint unsigned not null,"
+ " partition_id bigint unsigned not null,"
+ " partition_ordinal_position bigint unsigned not null,"
+ " subpartition_ordinal_position bigint unsigned not null"
+ " auto_increment,"
+ " subpartition_name varchar(64) not null default '',"
+ " subpartition_description varchar(64) not null default '',"
+ " connection_str text not null default '',"
+ " comment_str text not null default '',"
+ " primary key (table_id, partition_id, partition_ordinal_position,"
+ " subpartition_ordinal_position),"
+ " unique key uk1 (table_id, partition_id, partition_ordinal_position,"
+ " subpartition_name)"
+ " ) engine=Aria transactional=1 default charset=utf8 collate=utf8_bin;"
+ " create table if not exists mysql.spider_rewritten_tables("
+ " db_name char(64) not null,"
+ " table_name char(64) not null,"
+ " table_id bigint unsigned not null,"
+ " partition_id bigint unsigned not null,"
+ " primary key (db_name, table_name, table_id, partition_id)"
+ " ) engine=Aria transactional=1 default charset=utf8 collate=utf8_bin;"
+ " end if;"
+ "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"
+ )},
+/*
+ Install a plugin and UDFs
+*/
+ {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);"
+/*
+ Install spider plugin
+*/
+/*
+ " set @have_spider_i_s_plugin := 0;"
+ " select @have_spider_i_s_plugin := 1 from INFORMATION_SCHEMA.plugins"
+ " where PLUGIN_NAME = 'SPIDER';"
+ " set @have_spider_plugin := 0;"
+ " select @have_spider_plugin := 1 from mysql.plugin"
+ " where name = 'spider';"
+ " if @have_spider_i_s_plugin = 0 then"
+ " if @have_spider_plugin = 1 then"
+ " / *"
+ " spider plugin is present in mysql.plugin but not in"
+ " information_schema.plugins. Remove spider plugin entry"
+ " in mysql.plugin first."
+ " * /"
+ " delete from mysql.plugin where name = 'spider';"
+ " end if;"
+ " if @win_plugin = 0 then "
+ " install plugin spider soname 'ha_spider.so';"
+ " else"
+ " install plugin spider soname 'ha_spider.dll';"
+ " end if;"
+ " end if;"
+*/
+/*
+ Install spider_alloc_mem plugin
+*/
+ " set @have_spider_i_s_alloc_mem_plugin := 0;"
+ " select @have_spider_i_s_alloc_mem_plugin := 1"
+ " from INFORMATION_SCHEMA.plugins"
+ " where PLUGIN_NAME = 'SPIDER_ALLOC_MEM';"
+ " set @have_spider_alloc_mem_plugin := 0;"
+ " select @have_spider_alloc_mem_plugin := 1 from mysql.plugin"
+ " where name = 'spider_alloc_mem';"
+ " if @have_spider_i_s_alloc_mem_plugin = 0 then"
+ " if @have_spider_alloc_mem_plugin = 1 then"
+ " /*"
+ " spider_alloc_mem plugin is present in mysql.plugin but not in"
+ " information_schema.plugins. Remove spider_alloc_mem plugin entry"
+ " in mysql.plugin first."
+ " */"
+ " delete from mysql.plugin where name = 'spider_alloc_mem';"
+ " end if;"
+ " if @win_plugin = 0 then "
+ " install plugin spider_alloc_mem soname 'ha_spider.so';"
+ " else"
+ " install plugin spider_alloc_mem soname 'ha_spider.dll';"
+ " end if;"
+ " end if;"
+ " 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;"
+ " if @server_name = 'MariaDB' and"
+ " ("
+ " @server_major_version > 10 or"
+ " ("
+ " @server_major_version = 10 and"
+ " @server_minor_version >= 6"
+ " )"
+ " )"
+ " then"
+/*
+ Install spider_rewrite plugin
+*/
+ " set @have_spider_i_s_rewrite_plugin := 0;"
+ " select @have_spider_i_s_rewrite_plugin := 1"
+ " from INFORMATION_SCHEMA.plugins"
+ " where PLUGIN_NAME = 'SPIDER_REWRITE';"
+ " set @have_spider_rewrite_plugin := 0;"
+ " select @have_spider_rewrite_plugin := 1 from mysql.plugin"
+ " where name = 'spider_rewrite';"
+ " if @have_spider_i_s_rewrite_plugin = 0 then"
+ " if @have_spider_rewrite_plugin = 1 then"
+ " /*"
+ " spider_rewrite plugin is present in mysql.plugin but not in"
+ " information_schema.plugins. Remove spider_rewrite plugin entry"
+ " in mysql.plugin first."
+ " */"
+ " delete from mysql.plugin where name = 'spider_rewrite';"
+ " end if;"
+ " if @win_plugin = 0 then "
+ " install plugin spider_rewrite soname 'ha_spider.so';"
+ " else"
+ " install plugin spider_rewrite soname 'ha_spider.dll';"
+ " end if;"
+ " end if;"
+ " set @have_spider_flush_rewrite_cache_udf := 0;"
+ " select @have_spider_flush_rewrite_cache_udf := 1 from mysql.func"
+ " where name = 'spider_flush_rewrite_cache';"
+ " if @have_spider_flush_rewrite_cache_udf = 0 then"
+ " if @win_plugin = 0 then "
+ " create function spider_flush_rewrite_cache returns int"
+ " soname 'ha_spider.so';"
+ " else"
+ " create function spider_flush_rewrite_cache returns int"
+ " soname 'ha_spider.dll';"
+ " end if;"
+ " end if;"
+ " end if;"
+ "end;"
+ )},
+ {C_STRING_WITH_LEN(
+ "call mysql.spider_plugin_installer"
+ )},
+ {C_STRING_WITH_LEN(
+ "drop procedure mysql.spider_plugin_installer"
+ )},
+ {C_STRING_WITH_LEN("")}
+};
diff --git a/storage/spider/spd_sys_table.cc b/storage/spider/spd_sys_table.cc
index 07cd6bf1695..ada48c4982d 100644
--- a/storage/spider/spd_sys_table.cc
+++ b/storage/spider/spd_sys_table.cc
@@ -229,85 +229,264 @@ TABLE *spider_open_sys_table(
}
}
#endif
- if (table_name_length == SPIDER_SYS_XA_TABLE_NAME_LEN)
+ switch (table_name_length)
{
- if (
- !memcmp(table_name,
- SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN) &&
- table->s->fields != SPIDER_SYS_XA_COL_CNT
- ) {
- spider_close_sys_table(thd, table, open_tables_backup, need_lock);
- table = NULL;
- my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
- ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
- SPIDER_SYS_XA_TABLE_NAME_STR);
- *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
- goto error_col_num_chk;
- }
- } else if (table_name_length == SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN)
- {
- if (
- !memcmp(table_name,
- SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR,
- SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN) &&
- table->s->fields != SPIDER_SYS_XA_MEMBER_COL_CNT
- ) {
- spider_close_sys_table(thd, table, open_tables_backup, need_lock);
- table = NULL;
- my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
- ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
- SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR);
- *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
- goto error_col_num_chk;
- }
- } else if (table_name_length == SPIDER_SYS_TABLES_TABLE_NAME_LEN)
- {
- if (
- !memcmp(table_name,
- SPIDER_SYS_TABLES_TABLE_NAME_STR,
- SPIDER_SYS_TABLES_TABLE_NAME_LEN) &&
- table->s->fields != SPIDER_SYS_TABLES_COL_CNT
- ) {
- spider_close_sys_table(thd, table, open_tables_backup, need_lock);
- table = NULL;
- my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
- ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
- SPIDER_SYS_TABLES_TABLE_NAME_STR);
- *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
- goto error_col_num_chk;
- }
- } else if (table_name_length == SPIDER_SYS_LINK_MON_TABLE_NAME_LEN)
- {
- if (
- !memcmp(table_name,
- SPIDER_SYS_LINK_MON_TABLE_NAME_STR,
- SPIDER_SYS_LINK_MON_TABLE_NAME_LEN) &&
- table->s->fields != SPIDER_SYS_LINK_MON_TABLE_COL_CNT
- ) {
- spider_close_sys_table(thd, table, open_tables_backup, need_lock);
- table = NULL;
- my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
- ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
- SPIDER_SYS_LINK_MON_TABLE_NAME_STR);
- *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
- goto error_col_num_chk;
- }
- } else if (table_name_length == SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_LEN)
- {
- if (
- !memcmp(table_name,
- SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR,
- SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_LEN) &&
- table->s->fields != SPIDER_SYS_POS_FOR_RECOVERY_TABLE_COL_CNT
- ) {
- spider_close_sys_table(thd, table, open_tables_backup, need_lock);
- table = NULL;
- my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
- ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
- SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR);
- *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
- goto error_col_num_chk;
- }
+ case 9:
+ if (!memcmp(table_name, SPIDER_SYS_XA_TABLE_NAME_STR,
+ SPIDER_SYS_XA_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_XA"));
+ if (table->s->fields != SPIDER_SYS_XA_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_XA_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ break;
+ }
+ DBUG_ASSERT(0);
+ break;
+ case 13:
+ if (!memcmp(table_name, SPIDER_SYS_TABLES_TABLE_NAME_STR,
+ SPIDER_SYS_TABLES_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_TABLES"));
+ if (table->s->fields != SPIDER_SYS_TABLES_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_TABLES_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ break;
+ }
+ DBUG_ASSERT(0);
+ break;
+ case 16:
+ if (!memcmp(table_name, SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR,
+ SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_XA_MEMBER"));
+ if (table->s->fields != SPIDER_SYS_XA_MEMBER_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ break;
+ }
+ if (!memcmp(table_name, SPIDER_SYS_TABLE_STS_TABLE_NAME_STR,
+ SPIDER_SYS_TABLE_STS_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_TABLE_STS"));
+ if (table->s->fields != SPIDER_SYS_TABLE_STS_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_TABLE_STS_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ break;
+ }
+ if (!memcmp(table_name, SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR,
+ SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_TABLE_CRD"));
+ if (table->s->fields != SPIDER_SYS_TABLE_CRD_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ break;
+ }
+ DBUG_ASSERT(0);
+ break;
+ case 20:
+ if (!memcmp(table_name, SPIDER_SYS_XA_FAILED_TABLE_NAME_STR,
+ SPIDER_SYS_XA_FAILED_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_XA_FAILED"));
+ if (table->s->fields != SPIDER_SYS_XA_FAILED_TABLE_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_XA_FAILED_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ break;
+ }
+ DBUG_ASSERT(0);
+ break;
+ case 21:
+ if (!memcmp(table_name, SPIDER_SYS_RW_TBLS_TABLE_NAME_STR,
+ SPIDER_SYS_RW_TBLS_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_RW_TBLS"));
+ if (table->s->fields != SPIDER_SYS_RW_TBLS_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_RW_TBLS_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ }
+ DBUG_ASSERT(0);
+ break;
+ case 22:
+ if (!memcmp(table_name, SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR,
+ SPIDER_SYS_LINK_FAILED_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_LINK_FAILED"));
+ if (table->s->fields != SPIDER_SYS_LINK_FAILED_TABLE_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ break;
+ }
+ DBUG_ASSERT(0);
+ break;
+ case 23:
+ if (!memcmp(table_name, SPIDER_SYS_LINK_MON_TABLE_NAME_STR,
+ SPIDER_SYS_LINK_MON_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_LINK_MON"));
+ if (table->s->fields != SPIDER_SYS_LINK_MON_TABLE_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_LINK_MON_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ break;
+ }
+ if (!memcmp(table_name, SPIDER_SYS_RWN_TBLS_TABLE_NAME_STR,
+ SPIDER_SYS_RWN_TBLS_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_RWN_TBLS"));
+ if (table->s->fields != SPIDER_SYS_RWN_TBLS_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_RWN_TBLS_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ break;
+ }
+ DBUG_ASSERT(0);
+ break;
+ case 27:
+ if (!memcmp(table_name, SPIDER_SYS_RW_TBL_TBLS_TABLE_NAME_STR,
+ SPIDER_SYS_RW_TBL_TBLS_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_RW_TBL_TBLS"));
+ if (table->s->fields != SPIDER_SYS_RW_TBL_TBLS_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_RW_TBL_TBLS_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ break;
+ }
+ DBUG_ASSERT(0);
+ break;
+ case 31:
+ if (!memcmp(table_name, SPIDER_SYS_RW_TBL_PTTS_TABLE_NAME_STR,
+ SPIDER_SYS_RW_TBL_PTTS_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_RW_TBL_PTTS"));
+ if (table->s->fields != SPIDER_SYS_RW_TBL_PTTS_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_RW_TBL_PTTS_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ break;
+ }
+ DBUG_ASSERT(0);
+ break;
+ case 34:
+ if (!memcmp(table_name, SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR,
+ SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_POS_FOR_RECOVERY"));
+ if (table->s->fields != SPIDER_SYS_POS_FOR_RECOVERY_TABLE_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ break;
+ }
+ if (!memcmp(table_name, SPIDER_SYS_RW_TBL_SPTTS_TABLE_NAME_STR,
+ SPIDER_SYS_RW_TBL_SPTTS_TABLE_NAME_LEN))
+ {
+ DBUG_PRINT("info",("spider checking for SYS_RW_TBL_SPTTS"));
+ if (table->s->fields != SPIDER_SYS_RW_TBL_SPTTS_COL_CNT)
+ {
+ spider_close_sys_table(thd, table, open_tables_backup, need_lock);
+ table = NULL;
+ my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
+ ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
+ SPIDER_SYS_RW_TBL_SPTTS_TABLE_NAME_STR);
+ *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
+ goto error_col_num_chk;
+ }
+ break;
+ }
+ DBUG_ASSERT(0);
+ break;
+ default:
+ DBUG_ASSERT(0);
+ break;
}
DBUG_RETURN(table);
diff --git a/storage/spider/spd_sys_table.h b/storage/spider/spd_sys_table.h
index 7a28ea20010..df933ec61b8 100644
--- a/storage/spider/spd_sys_table.h
+++ b/storage/spider/spd_sys_table.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 2008-2018 Kentoku Shiba
+/* Copyright (C) 2008-2019 Kentoku Shiba
+ Copyright (C) 2019 MariaDB corp
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
@@ -14,23 +15,33 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
#define SPIDER_SYS_XA_TABLE_NAME_STR "spider_xa"
-#define SPIDER_SYS_XA_TABLE_NAME_LEN (sizeof(SPIDER_SYS_XA_TABLE_NAME_STR) - 1)
+#define SPIDER_SYS_XA_TABLE_NAME_LEN 9
#define SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR "spider_xa_member"
-#define SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN (sizeof(SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR) - 1)
+#define SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN 16
#define SPIDER_SYS_TABLES_TABLE_NAME_STR "spider_tables"
-#define SPIDER_SYS_TABLES_TABLE_NAME_LEN (sizeof(SPIDER_SYS_TABLES_TABLE_NAME_STR) - 1)
+#define SPIDER_SYS_TABLES_TABLE_NAME_LEN 13
#define SPIDER_SYS_LINK_MON_TABLE_NAME_STR "spider_link_mon_servers"
-#define SPIDER_SYS_LINK_MON_TABLE_NAME_LEN (sizeof(SPIDER_SYS_LINK_MON_TABLE_NAME_STR) - 1)
+#define SPIDER_SYS_LINK_MON_TABLE_NAME_LEN 23
#define SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR "spider_link_failed_log"
-#define SPIDER_SYS_LINK_FAILED_TABLE_NAME_LEN (sizeof(SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR) - 1)
+#define SPIDER_SYS_LINK_FAILED_TABLE_NAME_LEN 22
#define SPIDER_SYS_XA_FAILED_TABLE_NAME_STR "spider_xa_failed_log"
-#define SPIDER_SYS_XA_FAILED_TABLE_NAME_LEN (sizeof(SPIDER_SYS_XA_FAILED_TABLE_NAME_STR) - 1)
+#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 (sizeof(SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR) - 1)
+#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 (sizeof(SPIDER_SYS_TABLE_STS_TABLE_NAME_STR) - 1)
+#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 (sizeof(SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR) - 1)
+#define SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN 16
+#define SPIDER_SYS_RW_TBLS_TABLE_NAME_STR "spider_rewrite_tables"
+#define SPIDER_SYS_RW_TBLS_TABLE_NAME_LEN 21
+#define SPIDER_SYS_RW_TBL_TBLS_TABLE_NAME_STR "spider_rewrite_table_tables"
+#define SPIDER_SYS_RW_TBL_TBLS_TABLE_NAME_LEN 27
+#define SPIDER_SYS_RW_TBL_PTTS_TABLE_NAME_STR "spider_rewrite_table_partitions"
+#define SPIDER_SYS_RW_TBL_PTTS_TABLE_NAME_LEN 31
+#define SPIDER_SYS_RW_TBL_SPTTS_TABLE_NAME_STR "spider_rewrite_table_subpartitions"
+#define SPIDER_SYS_RW_TBL_SPTTS_TABLE_NAME_LEN 34
+#define SPIDER_SYS_RWN_TBLS_TABLE_NAME_STR "spider_rewritten_tables"
+#define SPIDER_SYS_RWN_TBLS_TABLE_NAME_LEN 23
#define SPIDER_SYS_XA_PREPARED_STR "PREPARED"
#define SPIDER_SYS_XA_NOT_YET_STR "NOT YET"
@@ -47,11 +58,18 @@
#define SPIDER_SYS_TABLES_IDX1_COL_CNT 1
#define SPIDER_SYS_TABLES_UIDX1_COL_CNT 3
#define SPIDER_SYS_LINK_MON_TABLE_COL_CNT 19
+#define SPIDER_SYS_LINK_FAILED_TABLE_COL_CNT 4
+#define SPIDER_SYS_XA_FAILED_TABLE_COL_CNT 21
#define SPIDER_SYS_POS_FOR_RECOVERY_TABLE_COL_CNT 7
-#define SPIDER_SYS_TABLE_STS_COL_CNT 10
+#define SPIDER_SYS_TABLE_STS_COL_CNT 11
#define SPIDER_SYS_TABLE_STS_PK_COL_CNT 2
#define SPIDER_SYS_TABLE_CRD_COL_CNT 4
#define SPIDER_SYS_TABLE_CRD_PK_COL_CNT 3
+#define SPIDER_SYS_RW_TBLS_COL_CNT 3
+#define SPIDER_SYS_RW_TBL_TBLS_COL_CNT 8
+#define SPIDER_SYS_RW_TBL_PTTS_COL_CNT 7
+#define SPIDER_SYS_RW_TBL_SPTTS_COL_CNT 8
+#define SPIDER_SYS_RWN_TBLS_COL_CNT 4
#define SPIDER_SYS_LINK_MON_TABLE_DB_NAME_SIZE 64
#define SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE 64
diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc
index 723beb0775e..33573fd7fd3 100644
--- a/storage/spider/spd_table.cc
+++ b/storage/spider/spd_table.cc
@@ -1,4 +1,5 @@
-/* Copyright (C) 2008-2018 Kentoku Shiba
+/* Copyright (C) 2008-2019 Kentoku Shiba
+ Copyright (C) 2019 MariaDB corp
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
@@ -29,6 +30,7 @@
#include "sql_servers.h"
#include "sql_select.h"
#include "tztime.h"
+#include "sql_parse.h"
#endif
#include "spd_err.h"
#include "spd_param.h"
@@ -44,6 +46,7 @@
#include "spd_direct_sql.h"
#include "spd_malloc.h"
#include "spd_group_by_handler.h"
+#include "spd_init_query.h"
/* Background thread management */
#ifdef SPIDER_HAS_NEXT_THREAD_ID
@@ -5024,8 +5027,7 @@ SPIDER_SHARE *spider_get_share(
share->init_error = TRUE;
share->init_error_time = (time_t) time((time_t*) 0);
share->init = TRUE;
- spider_free_share(share);
- goto error_but_no_delete;
+ goto error_after_alloc_conn_keys;
}
if (
@@ -5072,8 +5074,7 @@ SPIDER_SHARE *spider_get_share(
share->init_error = TRUE;
share->init_error_time = (time_t) time((time_t*) 0);
share->init = TRUE;
- spider_free_share(share);
- goto error_but_no_delete;
+ goto error_after_alloc_dbton_handler;
}
spider->conns[roop_count]->error_mode &= spider->error_mode;
}
@@ -5091,8 +5092,7 @@ SPIDER_SHARE *spider_get_share(
share->init_error = TRUE;
share->init_error_time = (time_t) time((time_t*) 0);
share->init = TRUE;
- spider_free_share(share);
- goto error_but_no_delete;
+ goto error_after_alloc_dbton_handler;
}
char *table_name = db + table_share->db.length + 1;
memcpy(db, table_share->db.str, table_share->db.length);
@@ -5107,16 +5107,14 @@ SPIDER_SHARE *spider_get_share(
share->init_error = TRUE;
share->init_error_time = (time_t) time((time_t*) 0);
share->init = TRUE;
- spider_free_share(share);
- goto error_but_no_delete;
+ goto error_after_alloc_dbton_handler;
} else if (search_link_idx == -2)
{
*error_num = HA_ERR_OUT_OF_MEM;
share->init_error = TRUE;
share->init_error_time = (time_t) time((time_t*) 0);
share->init = TRUE;
- spider_free_share(share);
- goto error_but_no_delete;
+ goto error_after_alloc_dbton_handler;
}
spider->search_link_idx = search_link_idx;
@@ -5173,8 +5171,7 @@ SPIDER_SHARE *spider_get_share(
share->init = TRUE;
pthread_mutex_unlock(&share->crd_mutex);
pthread_mutex_unlock(&share->sts_mutex);
- spider_free_share(share);
- goto error_but_no_delete;
+ goto error_after_alloc_dbton_handler;
}
}
@@ -5183,28 +5180,48 @@ SPIDER_SHARE *spider_get_share(
!same_server_link ||
load_sts_at_startup
) &&
- spider_get_sts(share, spider->search_link_idx, tmp_time,
+ (*error_num = spider_get_sts(share, spider->search_link_idx, tmp_time,
spider, sts_interval, sts_mode,
#ifdef WITH_PARTITION_STORAGE_ENGINE
sts_sync,
#endif
- 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO)
+ 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO))
) {
- thd->clear_error();
+ if (*error_num != ER_SPIDER_SYS_TABLE_VERSION_NUM)
+ {
+ thd->clear_error();
+ } else {
+ pthread_mutex_unlock(&share->crd_mutex);
+ pthread_mutex_unlock(&share->sts_mutex);
+ share->init_error = TRUE;
+ share->init_error_time = (time_t) time((time_t*) 0);
+ share->init = TRUE;
+ goto error_after_alloc_dbton_handler;
+ }
}
if (
(
!same_server_link ||
load_crd_at_startup
) &&
- spider_get_crd(share, spider->search_link_idx, tmp_time,
+ (*error_num = spider_get_crd(share, spider->search_link_idx, tmp_time,
spider, table, crd_interval, crd_mode,
#ifdef WITH_PARTITION_STORAGE_ENGINE
crd_sync,
#endif
- 1)
+ 1))
) {
- thd->clear_error();
+ if (*error_num != ER_SPIDER_SYS_TABLE_VERSION_NUM)
+ {
+ thd->clear_error();
+ } else {
+ pthread_mutex_unlock(&share->crd_mutex);
+ pthread_mutex_unlock(&share->sts_mutex);
+ share->init_error = TRUE;
+ share->init_error_time = (time_t) time((time_t*) 0);
+ share->init = TRUE;
+ goto error_after_alloc_dbton_handler;
+ }
}
pthread_mutex_unlock(&share->crd_mutex);
pthread_mutex_unlock(&share->sts_mutex);
@@ -5541,7 +5558,7 @@ SPIDER_SHARE *spider_get_share(
spider->dbton_handler[dbton_id] = NULL;
}
}
- goto error_but_no_delete;
+ goto error_after_alloc_conn_keys;
}
if (
@@ -5585,8 +5602,7 @@ SPIDER_SHARE *spider_get_share(
FALSE
);
}
- spider_free_share(share);
- goto error_but_no_delete;
+ goto error_after_alloc_dbton_handler;
}
spider->conns[roop_count]->error_mode &= spider->error_mode;
}
@@ -5601,8 +5617,7 @@ SPIDER_SHARE *spider_get_share(
if (!db)
{
*error_num = HA_ERR_OUT_OF_MEM;
- spider_free_share(share);
- goto error_but_no_delete;
+ goto error_after_alloc_dbton_handler;
}
char *table_name = db + table_share->db.length + 1;
memcpy(db, table_share->db.str, table_share->db.length);
@@ -5614,13 +5629,11 @@ SPIDER_SHARE *spider_get_share(
ER_SPIDER_ALL_LINKS_FAILED_STR, MYF(0), db, table_name);
my_afree(db);
*error_num = ER_SPIDER_ALL_LINKS_FAILED_NUM;
- spider_free_share(share);
- goto error_but_no_delete;
+ goto error_after_alloc_dbton_handler;
} else if (search_link_idx == -2)
{
*error_num = HA_ERR_OUT_OF_MEM;
- spider_free_share(share);
- goto error_but_no_delete;
+ goto error_after_alloc_dbton_handler;
}
spider->search_link_idx = search_link_idx;
@@ -5679,8 +5692,7 @@ SPIDER_SHARE *spider_get_share(
spider_init_error_table->init_error_msg, MYF(0));
pthread_mutex_unlock(&share->crd_mutex);
pthread_mutex_unlock(&share->sts_mutex);
- spider_free_share(share);
- goto error_but_no_delete;
+ goto error_after_alloc_dbton_handler;
}
}
@@ -5689,28 +5701,42 @@ SPIDER_SHARE *spider_get_share(
!same_server_link ||
load_sts_at_startup
) &&
- spider_get_sts(share, spider->search_link_idx,
+ (*error_num = spider_get_sts(share, spider->search_link_idx,
tmp_time, spider, sts_interval, sts_mode,
#ifdef WITH_PARTITION_STORAGE_ENGINE
sts_sync,
#endif
- 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO)
+ 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO))
) {
- thd->clear_error();
+ if (*error_num != ER_SPIDER_SYS_TABLE_VERSION_NUM)
+ {
+ thd->clear_error();
+ } else {
+ pthread_mutex_unlock(&share->crd_mutex);
+ pthread_mutex_unlock(&share->sts_mutex);
+ goto error_after_alloc_dbton_handler;
+ }
}
if (
(
!same_server_link ||
load_crd_at_startup
) &&
- spider_get_crd(share, spider->search_link_idx,
+ (*error_num = spider_get_crd(share, spider->search_link_idx,
tmp_time, spider, table, crd_interval, crd_mode,
#ifdef WITH_PARTITION_STORAGE_ENGINE
crd_sync,
#endif
- 1)
+ 1))
) {
- thd->clear_error();
+ if (*error_num != ER_SPIDER_SYS_TABLE_VERSION_NUM)
+ {
+ thd->clear_error();
+ } else {
+ pthread_mutex_unlock(&share->crd_mutex);
+ pthread_mutex_unlock(&share->sts_mutex);
+ goto error_after_alloc_dbton_handler;
+ }
}
}
share->init_error = FALSE;
@@ -5723,6 +5749,22 @@ SPIDER_SHARE *spider_get_share(
DBUG_PRINT("info",("spider share=%p", share));
DBUG_RETURN(share);
+error_after_alloc_dbton_handler:
+ for (roop_count = 0; roop_count < (int) share->use_dbton_count; ++roop_count)
+ {
+ uint dbton_id = share->use_dbton_ids[roop_count];
+ if (spider->dbton_handler[dbton_id])
+ {
+ delete spider->dbton_handler[dbton_id];
+ spider->dbton_handler[dbton_id] = NULL;
+ }
+ }
+error_after_alloc_conn_keys:
+ spider_free(spider_current_trx, spider->conn_keys, MYF(0));
+ spider->conn_keys = NULL;
+ spider_free_share(share);
+ goto error_but_no_delete;
+
error_hash_insert:
spider_free_share_resource_only(share);
error_alloc_share:
@@ -6525,6 +6567,14 @@ handler* spider_create_handler(
MEM_ROOT *mem_root
) {
DBUG_ENTER("spider_create_handler");
+#ifndef WITHOUT_SPIDER_BG_SEARCH
+ if (unlikely(spider_table_sts_threads[0].init_command))
+ {
+ /* wait for finishing init_command */
+ pthread_mutex_lock(&spider_table_sts_threads[0].mutex);
+ pthread_mutex_unlock(&spider_table_sts_threads[0].mutex);
+ }
+#endif
DBUG_RETURN(new (mem_root) ha_spider(hton, table));
}
@@ -7255,6 +7305,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();
@@ -7307,6 +7358,29 @@ int spider_db_init(
}
}
+#ifndef WITHOUT_SPIDER_BG_SEARCH
+ DBUG_PRINT("info",("spider before getting mutex"));
+ pthread_mutex_lock(&spider_table_sts_threads[0].mutex);
+ DBUG_PRINT("info",("spider after getting mutex"));
+ if (spider_table_sts_threads[0].init_command)
+ {
+ if (spider_table_sts_threads[0].thd_wait)
+ {
+ pthread_cond_signal(&spider_table_sts_threads[0].cond);
+ }
+ spider_table_sts_threads[0].first_free_wait = TRUE;
+ pthread_cond_wait(&spider_table_sts_threads[0].sync_cond,
+ &spider_table_sts_threads[0].mutex);
+ spider_table_sts_threads[0].first_free_wait = FALSE;
+ if (spider_table_sts_threads[0].thd_wait)
+ {
+ pthread_cond_signal(&spider_table_sts_threads[0].cond);
+ }
+ }
+ DBUG_PRINT("info",("spider before releasing mutex"));
+ pthread_mutex_unlock(&spider_table_sts_threads[0].mutex);
+ DBUG_PRINT("info",("spider after releasing mutex"));
+#endif
DBUG_RETURN(0);
#ifndef WITHOUT_SPIDER_BG_SEARCH
@@ -9947,6 +10021,54 @@ void *spider_table_bg_sts_action(
trx->thd = thd;
/* init end */
+ if (thread->init_command)
+ {
+ uint i = 0;
+ tmp_disable_binlog(thd);
+ thd->security_ctx->skip_grants();
+ thd->client_capabilities |= CLIENT_MULTI_RESULTS;
+ while (spider_init_queries[i + 2].length)
+ {
+ dispatch_command(COM_QUERY, thd, spider_init_queries[i].str,
+ (uint) spider_init_queries[i].length, FALSE, FALSE);
+ if (unlikely(thd->is_error()))
+ {
+ fprintf(stderr, "[ERROR] %s\n", thd->get_stmt_da()->message());
+ thd->clear_error();
+ break;
+ }
+ ++i;
+ }
+ DBUG_PRINT("info",("spider first_free_wait=%s",
+ thread->first_free_wait ? "TRUE" : "FALSE"));
+ if (!thread->first_free_wait)
+ {
+ thread->thd_wait = TRUE;
+ pthread_cond_wait(&thread->cond, &thread->mutex);
+ thread->thd_wait = FALSE;
+ }
+ DBUG_ASSERT(thread->first_free_wait);
+ pthread_cond_signal(&thread->sync_cond);
+ thread->thd_wait = TRUE;
+ pthread_cond_wait(&thread->cond, &thread->mutex);
+ thread->thd_wait = FALSE;
+ while (spider_init_queries[i].length)
+ {
+ dispatch_command(COM_QUERY, thd, spider_init_queries[i].str,
+ (uint) spider_init_queries[i].length, FALSE, FALSE);
+ if (unlikely(thd->is_error()))
+ {
+ fprintf(stderr, "[ERROR] %s\n", thd->get_stmt_da()->message());
+ thd->clear_error();
+ break;
+ }
+ ++i;
+ }
+ thd->client_capabilities -= CLIENT_MULTI_RESULTS;
+ reenable_binlog(thd);
+ thread->init_command = FALSE;
+ }
+
while (TRUE)
{
DBUG_PRINT("info",("spider bg sts loop start"));