Advertisement
grepwood

/usr/share/mysql/install_spider.sql

Feb 2nd, 2015
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 14.36 KB | None | 0 0
  1. # Copyright (C) 2010-2013 Kentoku Shiba
  2. #
  3. # This program IS free software; you can redistribute it AND/OR MODIFY
  4. # it UNDER the terms OF the GNU General Public License AS published BY
  5. # the Free Software Foundation; version 2 OF the License.
  6. #
  7. # This program IS distributed IN the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; WITHOUT even the implied warranty OF
  9. # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. # GNU General Public License FOR more details.
  11. #
  12. # You should have received a copy OF the GNU General Public License
  13. # along WITH this program; IF NOT, WRITE TO the Free Software
  14. # Foundation, Inc., 51 Franklin St, Fifth FLOOR, Boston, MA  02110-1301  USA
  15.  
  16. # This SQL script creates system TABLES FOR SPIDER
  17. #   OR fixes incompatibilities IF ones already exist.
  18.  
  19. -- Create system tables if not exist
  20. CREATE TABLE IF NOT EXISTS mysql.spider_xa(
  21.   format_id INT NOT NULL DEFAULT 0,
  22.   gtrid_length INT NOT NULL DEFAULT 0,
  23.   bqual_length INT NOT NULL DEFAULT 0,
  24.   DATA CHAR(128) charset BINARY NOT NULL DEFAULT '',
  25.   STATUS CHAR(8) NOT NULL DEFAULT '',
  26.   PRIMARY KEY (DATA, format_id, gtrid_length),
  27.   KEY idx1 (STATUS)
  28. ) engine=MyISAM DEFAULT charset=utf8 COLLATE=utf8_bin;
  29. CREATE TABLE IF NOT EXISTS mysql.spider_xa_member(
  30.   format_id INT NOT NULL DEFAULT 0,
  31.   gtrid_length INT NOT NULL DEFAULT 0,
  32.   bqual_length INT NOT NULL DEFAULT 0,
  33.   DATA CHAR(128) charset BINARY NOT NULL DEFAULT '',
  34.   scheme CHAR(64) NOT NULL DEFAULT '',
  35.   host CHAR(64) NOT NULL DEFAULT '',
  36.   port CHAR(5) NOT NULL DEFAULT '',
  37.   socket text NOT NULL,
  38.   username CHAR(64) NOT NULL DEFAULT '',
  39.   password CHAR(64) NOT NULL DEFAULT '',
  40.   ssl_ca text,
  41.   ssl_capath text,
  42.   ssl_cert text,
  43.   ssl_cipher CHAR(64) DEFAULT NULL,
  44.   ssl_key text,
  45.   ssl_verify_server_cert tinyint NOT NULL DEFAULT 0,
  46.   default_file text,
  47.   default_group CHAR(64) DEFAULT NULL,
  48.   KEY idx1 (DATA, format_id, gtrid_length, host)
  49. ) engine=MyISAM DEFAULT charset=utf8 COLLATE=utf8_bin;
  50. CREATE TABLE IF NOT EXISTS mysql.spider_xa_failed_log(
  51.   format_id INT NOT NULL DEFAULT 0,
  52.   gtrid_length INT NOT NULL DEFAULT 0,
  53.   bqual_length INT NOT NULL DEFAULT 0,
  54.   DATA CHAR(128) charset BINARY NOT NULL DEFAULT '',
  55.   scheme CHAR(64) NOT NULL DEFAULT '',
  56.   host CHAR(64) NOT NULL DEFAULT '',
  57.   port CHAR(5) NOT NULL DEFAULT '',
  58.   socket text NOT NULL,
  59.   username CHAR(64) NOT NULL DEFAULT '',
  60.   password CHAR(64) NOT NULL DEFAULT '',
  61.   ssl_ca text,
  62.   ssl_capath text,
  63.   ssl_cert text,
  64.   ssl_cipher CHAR(64) DEFAULT NULL,
  65.   ssl_key text,
  66.   ssl_verify_server_cert tinyint NOT NULL DEFAULT 0,
  67.   default_file text,
  68.   default_group CHAR(64) DEFAULT NULL,
  69.   thread_id INT DEFAULT NULL,
  70.   STATUS CHAR(8) NOT NULL DEFAULT '',
  71.   failed_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  72.   KEY idx1 (DATA, format_id, gtrid_length, host)
  73. ) engine=MyISAM DEFAULT charset=utf8 COLLATE=utf8_bin;
  74. CREATE TABLE IF NOT EXISTS mysql.spider_tables(
  75.   db_name CHAR(64) NOT NULL DEFAULT '',
  76.   TABLE_NAME CHAR(64) NOT NULL DEFAULT '',
  77.   link_id INT NOT NULL DEFAULT 0,
  78.   priority BIGINT NOT NULL DEFAULT 0,
  79.   server CHAR(64) DEFAULT NULL,
  80.   scheme CHAR(64) DEFAULT NULL,
  81.   host CHAR(64) DEFAULT NULL,
  82.   port CHAR(5) DEFAULT NULL,
  83.   socket text,
  84.   username CHAR(64) DEFAULT NULL,
  85.   password CHAR(64) DEFAULT NULL,
  86.   ssl_ca text,
  87.   ssl_capath text,
  88.   ssl_cert text,
  89.   ssl_cipher CHAR(64) DEFAULT NULL,
  90.   ssl_key text,
  91.   ssl_verify_server_cert tinyint NOT NULL DEFAULT 0,
  92.   default_file text,
  93.   default_group CHAR(64) DEFAULT NULL,
  94.   tgt_db_name CHAR(64) DEFAULT NULL,
  95.   tgt_table_name CHAR(64) DEFAULT NULL,
  96.   link_status tinyint NOT NULL DEFAULT 1,
  97.   PRIMARY KEY (db_name, TABLE_NAME, link_id),
  98.   KEY idx1 (priority)
  99. ) engine=MyISAM DEFAULT charset=utf8 COLLATE=utf8_bin;
  100. CREATE TABLE IF NOT EXISTS mysql.spider_link_mon_servers(
  101.   db_name CHAR(64) NOT NULL DEFAULT '',
  102.   TABLE_NAME CHAR(64) NOT NULL DEFAULT '',
  103.   link_id CHAR(5) NOT NULL DEFAULT '',
  104.   sid INT UNSIGNED NOT NULL DEFAULT 0,
  105.   server CHAR(64) DEFAULT NULL,
  106.   scheme CHAR(64) DEFAULT NULL,
  107.   host CHAR(64) DEFAULT NULL,
  108.   port CHAR(5) DEFAULT NULL,
  109.   socket text,
  110.   username CHAR(64) DEFAULT NULL,
  111.   password CHAR(64) DEFAULT NULL,
  112.   ssl_ca text,
  113.   ssl_capath text,
  114.   ssl_cert text,
  115.   ssl_cipher CHAR(64) DEFAULT NULL,
  116.   ssl_key text,
  117.   ssl_verify_server_cert tinyint NOT NULL DEFAULT 0,
  118.   default_file text,
  119.   default_group CHAR(64) DEFAULT NULL,
  120.   PRIMARY KEY (db_name, TABLE_NAME, link_id, sid)
  121. ) engine=MyISAM DEFAULT charset=utf8 COLLATE=utf8_bin;
  122. CREATE TABLE IF NOT EXISTS mysql.spider_link_failed_log(
  123.   db_name CHAR(64) NOT NULL DEFAULT '',
  124.   TABLE_NAME CHAR(64) NOT NULL DEFAULT '',
  125.   link_id INT NOT NULL DEFAULT 0,
  126.   failed_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
  127. ) engine=MyISAM DEFAULT charset=utf8 COLLATE=utf8_bin;
  128.  
  129. -- If tables already exist and their definition differ from the latest ones,
  130. --   we fix them here.
  131. DROP PROCEDURE IF EXISTS mysql.spider_fix_one_table;
  132. DROP PROCEDURE IF EXISTS mysql.spider_fix_system_tables;
  133. delimiter //
  134. CREATE PROCEDURE mysql.spider_fix_one_table
  135.   (tab_name CHAR(255), test_col_name CHAR(255), _sql text)
  136. BEGIN
  137.   SET @col_exists := 0;
  138.   SELECT 1 INTO @col_exists FROM INFORMATION_SCHEMA.COLUMNS
  139.     WHERE TABLE_SCHEMA = 'mysql'
  140.       AND TABLE_NAME = tab_name
  141.       AND COLUMN_NAME = test_col_name;
  142.   IF @col_exists = 0 THEN
  143.     SELECT @stmt := _sql;
  144.     PREPARE sp_stmt1 FROM @stmt;
  145.     EXECUTE sp_stmt1;
  146.   END IF;
  147. END;//
  148.  
  149. CREATE PROCEDURE mysql.spider_fix_system_tables()
  150. BEGIN
  151.   -- Fix for 0.5
  152.   CALL mysql.spider_fix_one_table('spider_tables', 'server',
  153.    'alter table mysql.spider_tables
  154.    add server char(64) default null,
  155.    add scheme char(64) default null,
  156.    add host char(64) default null,
  157.    add port char(5) default null,
  158.    add socket char(64) default null,
  159.    add username char(64) default null,
  160.    add password char(64) default null,
  161.    add tgt_db_name char(64) default null,
  162.    add tgt_table_name char(64) default null');
  163.  
  164.   -- Fix for version 0.17
  165.   SELECT COLUMN_TYPE INTO @col_type FROM INFORMATION_SCHEMA.COLUMNS
  166.     WHERE TABLE_SCHEMA = 'mysql'
  167.       AND TABLE_NAME = 'spider_xa'
  168.       AND COLUMN_NAME = 'data';
  169.   IF @col_type != 'binary(128)' THEN
  170.     ALTER TABLE mysql.spider_xa MODIFY DATA BINARY(128) NOT NULL DEFAULT '';
  171.   END IF;
  172.   SELECT COLUMN_TYPE INTO @col_type FROM INFORMATION_SCHEMA.COLUMNS
  173.     WHERE TABLE_SCHEMA = 'mysql'
  174.       AND TABLE_NAME = 'spider_xa_member'
  175.       AND COLUMN_NAME = 'data';
  176.   IF @col_type != 'binary(128)' THEN
  177.     ALTER TABLE mysql.spider_xa_member MODIFY DATA BINARY(128) NOT NULL DEFAULT '';
  178.   END IF;
  179.  
  180.   -- Fix for version 2.7
  181.   CALL mysql.spider_fix_one_table('spider_tables', 'link_id',
  182.    'alter table mysql.spider_tables
  183.    add column link_id int not null default 0 after table_name,
  184.    drop primary key,
  185.    add primary key (db_name, table_name, link_id)');
  186.  
  187.   -- Fix for version 2.8
  188.   CALL mysql.spider_fix_one_table('spider_tables', 'link_status',
  189.    'alter table mysql.spider_tables
  190.    add column link_status tinyint not null default 1');
  191.  
  192.   -- Fix for version 2.10
  193.   CALL mysql.spider_fix_one_table('spider_xa_member', 'ssl_ca',
  194.    'alter table mysql.spider_xa_member
  195.    add column ssl_ca char(64) default null after password,
  196.    add column ssl_capath char(64) default null after ssl_ca,
  197.    add column ssl_cert char(64) default null after ssl_capath,
  198.    add column ssl_cipher char(64) default null after ssl_cert,
  199.    add column ssl_key char(64) default null after ssl_cipher,
  200.    add column ssl_verify_server_cert tinyint not null default 0 after ssl_key,
  201.    add column default_file char(64) default null after ssl_verify_server_cert,
  202.    add column default_group char(64) default null after default_file');
  203.   CALL mysql.spider_fix_one_table('spider_tables', 'ssl_ca',
  204.    'alter table mysql.spider_tables
  205.    add column ssl_ca char(64) default null after password,
  206.    add column ssl_capath char(64) default null after ssl_ca,
  207.    add column ssl_cert char(64) default null after ssl_capath,
  208.    add column ssl_cipher char(64) default null after ssl_cert,
  209.    add column ssl_key char(64) default null after ssl_cipher,
  210.    add column ssl_verify_server_cert tinyint not null default 0 after ssl_key,
  211.    add column default_file char(64) default null after ssl_verify_server_cert,
  212.    add column default_group char(64) default null after default_file');
  213.   CALL mysql.spider_fix_one_table('spider_link_mon_servers', 'ssl_ca',
  214.    'alter table mysql.spider_link_mon_servers
  215.    add column ssl_ca char(64) default null after password,
  216.    add column ssl_capath char(64) default null after ssl_ca,
  217.    add column ssl_cert char(64) default null after ssl_capath,
  218.    add column ssl_cipher char(64) default null after ssl_cert,
  219.    add column ssl_key char(64) default null after ssl_cipher,
  220.    add column ssl_verify_server_cert tinyint not null default 0 after ssl_key,
  221.    add column default_file char(64) default null after ssl_verify_server_cert,
  222.    add column default_group char(64) default null after default_file');
  223.  
  224.   -- Fix for version 2.25
  225.   SELECT COLUMN_TYPE INTO @col_type FROM INFORMATION_SCHEMA.COLUMNS
  226.     WHERE TABLE_SCHEMA = 'mysql'
  227.       AND TABLE_NAME = 'spider_link_mon_servers'
  228.       AND COLUMN_NAME = 'link_id';
  229.   IF @col_type != 'char(5)' THEN
  230.     ALTER TABLE mysql.spider_link_mon_servers
  231.     MODIFY link_id CHAR(5) NOT NULL DEFAULT '';
  232.   END IF;
  233.  
  234.   -- Fix for version 2.28
  235.   SELECT COLUMN_TYPE INTO @col_type FROM INFORMATION_SCHEMA.COLUMNS
  236.     WHERE TABLE_SCHEMA = 'mysql'
  237.       AND TABLE_NAME = 'spider_link_mon_servers'
  238.       AND COLUMN_NAME = 'sid';
  239.   IF @col_type != 'int(10) unsigned' THEN
  240.     ALTER TABLE mysql.spider_link_mon_servers
  241.     MODIFY sid INT UNSIGNED NOT NULL DEFAULT 0;
  242.   END IF;
  243.  
  244.   -- Fix for version 3.1
  245.   SELECT COLUMN_TYPE INTO @col_type FROM INFORMATION_SCHEMA.COLUMNS
  246.     WHERE TABLE_SCHEMA = 'mysql'
  247.       AND TABLE_NAME = 'spider_xa_member'
  248.       AND COLUMN_NAME = 'socket';
  249.   IF @col_type = 'char(64)' THEN
  250.     ALTER TABLE mysql.spider_xa_member
  251.       DROP PRIMARY KEY,
  252.       ADD INDEX idx1 (DATA, format_id, gtrid_length, host),
  253.       MODIFY socket text NOT NULL,
  254.       MODIFY ssl_ca text,
  255.       MODIFY ssl_capath text,
  256.       MODIFY ssl_cert text,
  257.       MODIFY ssl_key text,
  258.       MODIFY default_file text;
  259.   END IF;
  260.   SELECT COLUMN_TYPE INTO @col_type FROM INFORMATION_SCHEMA.COLUMNS
  261.     WHERE TABLE_SCHEMA = 'mysql'
  262.       AND TABLE_NAME = 'spider_tables'
  263.       AND COLUMN_NAME = 'socket';
  264.   IF @col_type = 'char(64)' THEN
  265.     ALTER TABLE mysql.spider_tables
  266.       MODIFY socket text,
  267.       MODIFY ssl_ca text,
  268.       MODIFY ssl_capath text,
  269.       MODIFY ssl_cert text,
  270.       MODIFY ssl_key text,
  271.       MODIFY default_file text;
  272.   END IF;
  273.   SELECT COLUMN_TYPE INTO @col_type FROM INFORMATION_SCHEMA.COLUMNS
  274.     WHERE TABLE_SCHEMA = 'mysql'
  275.       AND TABLE_NAME = 'spider_link_mon_servers'
  276.       AND COLUMN_NAME = 'socket';
  277.   IF @col_type = 'char(64)' THEN
  278.     ALTER TABLE mysql.spider_link_mon_servers
  279.       MODIFY socket text,
  280.       MODIFY ssl_ca text,
  281.       MODIFY ssl_capath text,
  282.       MODIFY ssl_cert text,
  283.       MODIFY ssl_key text,
  284.       MODIFY default_file text;
  285.   END IF;
  286. END;//
  287. delimiter ;
  288. CALL mysql.spider_fix_system_tables;
  289. DROP PROCEDURE mysql.spider_fix_one_table;
  290. DROP PROCEDURE mysql.spider_fix_system_tables;
  291.  
  292. -- Install a plugin and UDFs
  293. DROP PROCEDURE IF EXISTS mysql.spider_plugin_installer;
  294. delimiter //
  295. CREATE PROCEDURE mysql.spider_plugin_installer()
  296. BEGIN
  297.   SET @win_plugin := IF(@@version_compile_os LIKE 'Win%', 1, 0);
  298.   SET @have_spider_plugin := 0;
  299.   SELECT @have_spider_plugin := 1 FROM INFORMATION_SCHEMA.plugins WHERE PLUGIN_NAME = 'SPIDER';
  300.   IF @have_spider_plugin = 0 THEN
  301.     IF @win_plugin = 0 THEN
  302.       install plugin spider SONAME 'ha_spider.so';
  303.     ELSE
  304.       install plugin spider SONAME 'ha_spider.dll';
  305.     END IF;
  306.   END IF;
  307.   SET @have_spider_i_s_alloc_mem_plugin := 0;
  308.   SELECT @have_spider_i_s_alloc_mem_plugin := 1 FROM INFORMATION_SCHEMA.plugins WHERE PLUGIN_NAME = 'SPIDER_ALLOC_MEM';
  309.   IF @have_spider_i_s_alloc_mem_plugin = 0 THEN
  310.     IF @win_plugin = 0 THEN
  311.       install plugin spider_alloc_mem SONAME 'ha_spider.so';
  312.     ELSE
  313.       install plugin spider_alloc_mem SONAME 'ha_spider.dll';
  314.     END IF;
  315.   END IF;
  316.   SET @have_spider_direct_sql_udf := 0;
  317.   SELECT @have_spider_direct_sql_udf := 1 FROM mysql.func WHERE name = 'spider_direct_sql';
  318.   IF @have_spider_direct_sql_udf = 0 THEN
  319.     IF @win_plugin = 0 THEN
  320.       CREATE FUNCTION spider_direct_sql RETURNS INT SONAME 'ha_spider.so';
  321.     ELSE
  322.       CREATE FUNCTION spider_direct_sql RETURNS INT SONAME 'ha_spider.dll';
  323.     END IF;
  324.   END IF;
  325.   SET @have_spider_bg_direct_sql_udf := 0;
  326.   SELECT @have_spider_bg_direct_sql_udf := 1 FROM mysql.func WHERE name = 'spider_bg_direct_sql';
  327.   IF @have_spider_bg_direct_sql_udf = 0 THEN
  328.     IF @win_plugin = 0 THEN
  329.       CREATE aggregate FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.so';
  330.     ELSE
  331.       CREATE aggregate FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.dll';
  332.     END IF;
  333.   END IF;
  334.   SET @have_spider_ping_table_udf := 0;
  335.   SELECT @have_spider_ping_table_udf := 1 FROM mysql.func WHERE name = 'spider_ping_table';
  336.   IF @have_spider_ping_table_udf = 0 THEN
  337.     IF @win_plugin = 0 THEN
  338.       CREATE FUNCTION spider_ping_table RETURNS INT SONAME 'ha_spider.so';
  339.     ELSE
  340.       CREATE FUNCTION spider_ping_table RETURNS INT SONAME 'ha_spider.dll';
  341.     END IF;
  342.   END IF;
  343.   SET @have_spider_copy_tables_udf := 0;
  344.   SELECT @have_spider_copy_tables_udf := 1 FROM mysql.func WHERE name = 'spider_copy_tables';
  345.   IF @have_spider_copy_tables_udf = 0 THEN
  346.     IF @win_plugin = 0 THEN
  347.       CREATE FUNCTION spider_copy_tables RETURNS INT SONAME 'ha_spider.so';
  348.     ELSE
  349.       CREATE FUNCTION spider_copy_tables RETURNS INT SONAME 'ha_spider.dll';
  350.     END IF;
  351.   END IF;
  352.  
  353.   SET @have_spider_flush_table_mon_cache_udf := 0;
  354.   SELECT @have_spider_flush_table_mon_cache_udf := 1 FROM mysql.func WHERE name = 'spider_flush_table_mon_cache';
  355.   IF @have_spider_flush_table_mon_cache_udf = 0 THEN
  356.     IF @win_plugin = 0 THEN
  357.       CREATE FUNCTION spider_flush_table_mon_cache RETURNS INT SONAME 'ha_spider.so';
  358.     ELSE
  359.       CREATE FUNCTION spider_flush_table_mon_cache RETURNS INT SONAME 'ha_spider.dll';
  360.     END IF;
  361.   END IF;
  362.  
  363. END;//
  364. delimiter ;
  365. CALL mysql.spider_plugin_installer;
  366. DROP PROCEDURE mysql.spider_plugin_installer;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement