diff --git a/storage/spider/mysql-test/spider/bugfix/include/wait_timeout_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/wait_timeout_deinit.inc new file mode 100644 index 00000000000..e66247c89c5 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/wait_timeout_deinit.inc @@ -0,0 +1,18 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--connection child2_1 +set global wait_timeout= @old_wait_timeout; +--connection child2_2 +set global wait_timeout= @old_wait_timeout; +--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/wait_timeout_init.inc b/storage/spider/mysql-test/spider/bugfix/include/wait_timeout_init.inc new file mode 100644 index 00000000000..d56d7a20940 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/wait_timeout_init.inc @@ -0,0 +1,56 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +if (!$HAVE_PARTITION) +{ + --source wait_timeout_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} +--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"' + PARTITION BY KEY(pkey) ( + PARTITION pt1 COMMENT='srv "s_2_1"', + PARTITION pt2 COMMENT='srv "s_2_2"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; +--connection child2_1 +set @old_wait_timeout= @@wait_timeout; +set global wait_timeout= 1; +--connection child2_2 +set @old_wait_timeout= @@wait_timeout; +set global wait_timeout= 1; diff --git a/storage/spider/mysql-test/spider/bugfix/r/slave_trx_isolation.result b/storage/spider/mysql-test/spider/bugfix/r/slave_trx_isolation.result index 06581a604a2..e93eb78417f 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/slave_trx_isolation.result +++ b/storage/spider/mysql-test/spider/bugfix/r/slave_trx_isolation.result @@ -50,7 +50,7 @@ SELECT argument FROM mysql.general_log WHERE argument LIKE '%set %'; argument set session time_zone = '+00:00' SET NAMES utf8 -set session transaction isolation level read committed;set session autocommit = 1;start transaction +set session transaction isolation level read committed;set session autocommit = 1;set session wait_timeout = 604800;start transaction SELECT argument FROM mysql.general_log WHERE argument LIKE '%set %' SELECT pkey FROM tbl_a ORDER BY pkey; pkey diff --git a/storage/spider/mysql-test/spider/bugfix/r/wait_timeout.result b/storage/spider/mysql-test/spider/bugfix/r/wait_timeout.result new file mode 100644 index 00000000000..ec9534f7592 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/wait_timeout.result @@ -0,0 +1,130 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +set @old_wait_timeout= @@wait_timeout; +set global wait_timeout= 1; +connection child2_2; +set @old_wait_timeout= @@wait_timeout; +set global wait_timeout= 1; + +this test is for MDEV-16530 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_1_2; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +connection child2_2_2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +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 +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +LOCK TABLE tbl_a READ; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +INSERT INTO tbl_a SELECT pkey + 30 FROM tbl_a ORDER BY pkey; +connection child2_1_2; +SELECT SLEEP(2); +SLEEP(2) +0 +SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; +argument +insert into `auto_test_remote`.`tbl_a`(`pkey`)values(31),(33),(35),(37),(39),(41),(43),(45),(47),(49),(51),(53),(55),(57),(59) +SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %' +connection child2_2_2; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; +argument +SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %' +connection child2_1; +UNLOCK TABLES; +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +1 +3 +5 +7 +9 +11 +13 +15 +17 +19 +21 +23 +25 +27 +29 +connection child2_2; +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +2 +4 +6 +8 +10 +12 +14 +16 +18 +20 +22 +24 +26 +28 +connection master_1; + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection child2_1; +set global wait_timeout= @old_wait_timeout; +connection child2_2; +set global wait_timeout= @old_wait_timeout; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/wait_timeout.cnf b/storage/spider/mysql-test/spider/bugfix/t/wait_timeout.cnf new file mode 100644 index 00000000000..e0ffb99c38e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/wait_timeout.cnf @@ -0,0 +1,4 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf +!include ../my_2_2.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/wait_timeout.test b/storage/spider/mysql-test/spider/bugfix/t/wait_timeout.test new file mode 100644 index 00000000000..8da6e8fe314 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/wait_timeout.test @@ -0,0 +1,109 @@ +--source ../include/wait_timeout_init.inc +--echo +--echo this test is for MDEV-16530 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--connection child2_1_2 +USE auto_test_remote; + +--connection child2_2 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +--connection child2_2_2 +USE auto_test_remote2; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +--disable_query_log +echo CHILD2_2_CREATE_TABLES; +eval $CHILD2_2_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--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 +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; +LOCK TABLE tbl_a READ; + +--connection child2_2 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +send_eval INSERT INTO tbl_a SELECT pkey + 30 FROM tbl_a ORDER BY pkey; + +--connection child2_1_2 +SELECT SLEEP(2); +eval $CHILD2_1_SELECT_ARGUMENT1; + +--connection child2_2_2 +eval $CHILD2_2_SELECT_ARGUMENT1; + +--connection child2_1 +UNLOCK TABLES; +eval $CHILD2_1_SELECT_TABLES; + +--connection child2_2 +eval $CHILD2_2_SELECT_TABLES; + +--connection master_1 +reap; + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--connection child2_2 +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/wait_timeout_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/r/slave_trx_isolation.result b/storage/spider/mysql-test/spider/r/slave_trx_isolation.result index 7d9ba40cab3..4fd2e71d3f2 100644 --- a/storage/spider/mysql-test/spider/r/slave_trx_isolation.result +++ b/storage/spider/mysql-test/spider/r/slave_trx_isolation.result @@ -53,7 +53,7 @@ SELECT argument FROM mysql.general_log WHERE argument LIKE '%set %'; argument set session time_zone = '+00:00' SET NAMES utf8 -set session transaction isolation level read committed;set session autocommit = 1;start transaction +set session transaction isolation level read committed;set session autocommit = 1;set session wait_timeout = 604800;start transaction SELECT argument FROM mysql.general_log WHERE argument LIKE '%set %' SELECT pkey FROM tbl_a ORDER BY pkey; pkey diff --git a/storage/spider/mysql-test/spider/t/connect_child2_1.inc b/storage/spider/mysql-test/spider/t/connect_child2_1.inc index cd9b0c9ca9b..15e26031527 100644 --- a/storage/spider/mysql-test/spider/t/connect_child2_1.inc +++ b/storage/spider/mysql-test/spider/t/connect_child2_1.inc @@ -1 +1,2 @@ --connect (child2_1, localhost, root, , , $CHILD2_1_MYPORT, $CHILD2_1_MYSOCK) +--connect (child2_1_2, localhost, root, , , $CHILD2_1_MYPORT, $CHILD2_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/t/connect_child2_2.inc b/storage/spider/mysql-test/spider/t/connect_child2_2.inc index e145f66b630..75a50821ea7 100644 --- a/storage/spider/mysql-test/spider/t/connect_child2_2.inc +++ b/storage/spider/mysql-test/spider/t/connect_child2_2.inc @@ -1 +1,2 @@ --connect (child2_2, localhost, root, , , $CHILD2_2_MYPORT, $CHILD2_2_MYSOCK) +--connect (child2_2_2, localhost, root, , , $CHILD2_2_MYPORT, $CHILD2_2_MYSOCK) diff --git a/storage/spider/mysql-test/spider/t/test_deinit.inc b/storage/spider/mysql-test/spider/t/test_deinit.inc index 989bde26d3c..5a82b43ce0f 100644 --- a/storage/spider/mysql-test/spider/t/test_deinit.inc +++ b/storage/spider/mysql-test/spider/t/test_deinit.inc @@ -10,10 +10,12 @@ if ($USE_CHILD_GROUP2) --connection child2_1 --source ../include/deinit_child2_1.inc --disconnect child2_1 + --disconnect child2_1_2 --echo child2_2 --connection child2_2 --source ../include/deinit_child2_2.inc --disconnect child2_2 + --disconnect child2_2_2 --echo child2_3 --connection child2_3 --source ../include/deinit_child2_3.inc diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index ba59acd64bc..aac4edd072c 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.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 @@ -148,6 +149,7 @@ int spider_reset_conn_setted_parameter( DBUG_ENTER("spider_reset_conn_setted_parameter"); conn->autocommit = spider_param_remote_autocommit(); conn->sql_log_off = spider_param_remote_sql_log_off(); + conn->wait_timeout = spider_param_remote_wait_timeout(thd); if (thd && spider_param_remote_time_zone()) { int tz_length = strlen(spider_param_remote_time_zone()); @@ -1428,6 +1430,20 @@ void spider_conn_queue_sql_log_off( DBUG_VOID_RETURN; } +void spider_conn_queue_wait_timeout( + SPIDER_CONN *conn, + int wait_timeout +) { + DBUG_ENTER("spider_conn_queue_wait_timeout"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + if (wait_timeout > 0) + { + conn->queued_wait_timeout = TRUE; + conn->queued_wait_timeout_val = wait_timeout; + } + DBUG_VOID_RETURN; +} + void spider_conn_queue_time_zone( SPIDER_CONN *conn, Time_zone *time_zone @@ -1483,6 +1499,7 @@ void spider_conn_clear_queue( conn->queued_semi_trx_isolation = FALSE; conn->queued_autocommit = FALSE; conn->queued_sql_log_off = FALSE; + conn->queued_wait_timeout = FALSE; conn->queued_time_zone = FALSE; conn->queued_trx_start = FALSE; conn->queued_xa_start = FALSE; diff --git a/storage/spider/spd_conn.h b/storage/spider/spd_conn.h index 0a9f99a1853..97dc4ac7bf0 100644 --- a/storage/spider/spd_conn.h +++ b/storage/spider/spd_conn.h @@ -132,6 +132,11 @@ void spider_conn_queue_sql_log_off( bool sql_log_off ); +void spider_conn_queue_wait_timeout( + SPIDER_CONN *conn, + int wait_timeout +); + void spider_conn_queue_time_zone( SPIDER_CONN *conn, Time_zone *time_zone diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index c2cd4beccdb..bc2c62387dd 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.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 @@ -380,6 +381,13 @@ int spider_db_conn_queue_action( (error_num = spider_dbton[conn->dbton_id].db_util-> append_sql_log_off(&sql_str, conn->queued_sql_log_off_val)) ) || + ( + conn->queued_wait_timeout && + conn->queued_wait_timeout_val != conn->wait_timeout && + conn->db_conn->set_wait_timeout_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_wait_timeout(&sql_str, conn->queued_wait_timeout_val)) + ) || ( conn->queued_time_zone && conn->queued_time_zone_val != conn->time_zone && @@ -452,6 +460,15 @@ int spider_db_conn_queue_action( ) { DBUG_RETURN(error_num); } + if ( + conn->queued_wait_timeout && + conn->queued_wait_timeout_val != conn->wait_timeout && + !conn->db_conn->set_wait_timeout_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_wait_timeout(&sql_str, conn->queued_wait_timeout_val)) + ) { + DBUG_RETURN(error_num); + } if ( conn->queued_time_zone && conn->queued_time_zone_val != conn->time_zone && @@ -519,6 +536,13 @@ int spider_db_conn_queue_action( conn->trx_isolation)); } + if ( + conn->queued_wait_timeout && + conn->queued_wait_timeout_val != conn->wait_timeout + ) { + conn->wait_timeout = conn->queued_wait_timeout_val; + } + if (conn->queued_autocommit) { if (conn->queued_autocommit_val && conn->autocommit != 1) diff --git a/storage/spider/spd_db_handlersocket.cc b/storage/spider/spd_db_handlersocket.cc index 8eae39ffc5f..c4f403b8728 100644 --- a/storage/spider/spd_db_handlersocket.cc +++ b/storage/spider/spd_db_handlersocket.cc @@ -1839,6 +1839,23 @@ int spider_db_handlersocket::set_sql_log_off( DBUG_RETURN(0); } +bool spider_db_handlersocket::set_wait_timeout_in_bulk_sql() +{ + DBUG_ENTER("spider_db_handlersocket::set_wait_timeout_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_handlersocket::set_wait_timeout( + int wait_timeout, + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::set_wait_timeout"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + bool spider_db_handlersocket::set_time_zone_in_bulk_sql() { DBUG_ENTER("spider_db_handlersocket::set_time_zone_in_bulk_sql"); @@ -2675,6 +2692,16 @@ int spider_db_handlersocket_util::append_sql_log_off( DBUG_RETURN(0); } +int spider_db_handlersocket_util::append_wait_timeout( + spider_string *str, + int wait_timeout +) { + DBUG_ENTER("spider_db_handlersocket_util::append_wait_timeout"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + int spider_db_handlersocket_util::append_time_zone( spider_string *str, Time_zone *time_zone diff --git a/storage/spider/spd_db_handlersocket.h b/storage/spider/spd_db_handlersocket.h index 075f8720abf..4cf6fce6c61 100644 --- a/storage/spider/spd_db_handlersocket.h +++ b/storage/spider/spd_db_handlersocket.h @@ -59,6 +59,10 @@ public: spider_string *str, bool sql_log_off ); + int append_wait_timeout( + spider_string *str, + int wait_timeout + ); int append_time_zone( spider_string *str, Time_zone *time_zone @@ -380,6 +384,11 @@ public: bool sql_log_off, int *need_mon ); + bool set_wait_timeout_in_bulk_sql(); + int set_wait_timeout( + int wait_timeout, + int *need_mon + ); bool set_time_zone_in_bulk_sql(); int set_time_zone( Time_zone *time_zone, diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h index 64cee006c65..3c66b5db77d 100644 --- a/storage/spider/spd_db_include.h +++ b/storage/spider/spd_db_include.h @@ -835,6 +835,10 @@ public: spider_string *str, bool sql_log_off ) = 0; + virtual int append_wait_timeout( + spider_string *str, + int wait_timeout + ) = 0; virtual int append_time_zone( spider_string *str, Time_zone *time_zone @@ -1134,6 +1138,11 @@ public: bool sql_log_off, int *need_mon ) = 0; + virtual bool set_wait_timeout_in_bulk_sql() = 0; + virtual int set_wait_timeout( + int wait_timeout, + int *need_mon + ) = 0; virtual bool set_time_zone_in_bulk_sql() = 0; virtual int set_time_zone( Time_zone *time_zone, diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 18b66d33fbf..b5ce958b927 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -88,6 +88,9 @@ static const char *name_quote_str = SPIDER_SQL_NAME_QUOTE_STR; #define SPIDER_SQL_SQL_LOG_ON_STR "set session sql_log_off = 1" #define SPIDER_SQL_SQL_LOG_ON_LEN sizeof(SPIDER_SQL_SQL_LOG_ON_STR) - 1 +#define SPIDER_SQL_WAIT_TIMEOUT_STR "set session wait_timeout = " +#define SPIDER_SQL_WAIT_TIMEOUT_LEN sizeof(SPIDER_SQL_WAIT_TIMEOUT_STR) - 1 + #define SPIDER_SQL_TIME_ZONE_STR "set session time_zone = '" #define SPIDER_SQL_TIME_ZONE_LEN sizeof(SPIDER_SQL_TIME_ZONE_STR) - 1 @@ -2741,6 +2744,44 @@ int spider_db_mbase::set_sql_log_off( DBUG_RETURN(0); } +bool spider_db_mbase::set_wait_timeout_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mbase::set_wait_timeout_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mbase::set_wait_timeout( + int wait_timeout, + int *need_mon +) { + char sql_buf[MAX_FIELD_WIDTH]; + char timeout_str[SPIDER_SQL_INT_LEN]; + int timeout_str_length; + spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin); + DBUG_ENTER("spider_db_mbase::set_wait_timeout"); + DBUG_PRINT("info",("spider this=%p", this)); + sql_str.init_calc_mem(264); + sql_str.length(0); + timeout_str_length = + my_sprintf(timeout_str, (timeout_str, "%d", wait_timeout)); + if (sql_str.reserve(SPIDER_SQL_WAIT_TIMEOUT_LEN + timeout_str_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_str.q_append(SPIDER_SQL_WAIT_TIMEOUT_STR, SPIDER_SQL_WAIT_TIMEOUT_LEN); + sql_str.q_append(timeout_str, timeout_str_length); + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + bool spider_db_mbase::set_time_zone_in_bulk_sql() { DBUG_ENTER("spider_db_mbase::set_time_zone_in_bulk_sql"); @@ -3710,6 +3751,30 @@ int spider_db_mbase_util::append_sql_log_off( DBUG_RETURN(0); } +int spider_db_mbase_util::append_wait_timeout( + spider_string *str, + int wait_timeout +) { + char timeout_str[SPIDER_SQL_INT_LEN]; + int timeout_str_length; + DBUG_ENTER("spider_db_mbase_util::append_wait_timeout"); + DBUG_PRINT("info",("spider this=%p", this)); + timeout_str_length = + my_sprintf(timeout_str, (timeout_str, "%d", wait_timeout)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + SPIDER_SQL_WAIT_TIMEOUT_LEN + + timeout_str_length)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str->length()) + { + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + str->q_append(SPIDER_SQL_WAIT_TIMEOUT_STR, SPIDER_SQL_WAIT_TIMEOUT_LEN); + str->q_append(timeout_str, timeout_str_length); + DBUG_RETURN(0); +} + int spider_db_mbase_util::append_time_zone( spider_string *str, Time_zone *time_zone diff --git a/storage/spider/spd_db_mysql.h b/storage/spider/spd_db_mysql.h index 3448cea06cc..f9246bf2721 100644 --- a/storage/spider/spd_db_mysql.h +++ b/storage/spider/spd_db_mysql.h @@ -64,6 +64,10 @@ public: spider_string *str, bool sql_log_off ); + int append_wait_timeout( + spider_string *str, + int wait_timeout + ); int append_time_zone( spider_string *str, Time_zone *time_zone @@ -466,6 +470,11 @@ public: bool sql_log_off, int *need_mon ); + bool set_wait_timeout_in_bulk_sql(); + int set_wait_timeout( + int wait_timeout, + int *need_mon + ); bool set_time_zone_in_bulk_sql(); int set_time_zone( Time_zone *time_zone, diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc index eae749f6867..439556af481 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -2104,6 +2104,23 @@ int spider_db_oracle::set_sql_log_off( DBUG_RETURN(0); } +bool spider_db_oracle::set_wait_timeout_in_bulk_sql() +{ + DBUG_ENTER("spider_db_oracle::set_wait_timeout_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_oracle::set_wait_timeout( + int wait_timeout, + int *need_mon +) { + DBUG_ENTER("spider_db_oracle::set_wait_timeout"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + bool spider_db_oracle::set_time_zone_in_bulk_sql() { DBUG_ENTER("spider_db_oracle::set_time_zone_in_bulk_sql"); @@ -2810,6 +2827,16 @@ int spider_db_oracle_util::append_sql_log_off( DBUG_RETURN(0); } +int spider_db_oracle_util::append_wait_timeout( + spider_string *str, + int wait_timeout +) { + DBUG_ENTER("spider_db_oracle_util::append_wait_timeout"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + int spider_db_oracle_util::append_time_zone( spider_string *str, Time_zone *time_zone diff --git a/storage/spider/spd_db_oracle.h b/storage/spider/spd_db_oracle.h index d0bd1757418..1ad79085ef8 100644 --- a/storage/spider/spd_db_oracle.h +++ b/storage/spider/spd_db_oracle.h @@ -67,6 +67,10 @@ public: spider_string *str, bool sql_log_off ); + int append_wait_timeout( + spider_string *str, + int wait_timeout + ); int append_time_zone( spider_string *str, Time_zone *time_zone @@ -430,6 +434,11 @@ public: bool sql_log_off, int *need_mon ); + bool set_wait_timeout_in_bulk_sql(); + int set_wait_timeout( + int wait_timeout, + int *need_mon + ); bool set_time_zone_in_bulk_sql(); int set_time_zone( Time_zone *time_zone, diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index 37ec2d8c608..ead33853957 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -260,7 +260,7 @@ const char SPIDER_empty_string = ""; #define SPIDER_TMP_SHARE_LONG_COUNT 19 #define SPIDER_TMP_SHARE_LONGLONG_COUNT 3 -#define SPIDER_MEM_CALC_LIST_NUM 257 +#define SPIDER_MEM_CALC_LIST_NUM 265 #define SPIDER_CONN_META_BUF_LEN 64 #define SPIDER_BACKUP_DASTATUS \ @@ -449,6 +449,7 @@ typedef struct st_spider_conn bool disable_reconnect; int autocommit; int sql_log_off; + int wait_timeout; THD *thd; void *another_ha_first; void *another_ha_last; @@ -555,6 +556,7 @@ typedef struct st_spider_conn bool queued_ping; bool queued_trx_isolation; bool queued_semi_trx_isolation; + bool queued_wait_timeout; bool queued_autocommit; bool queued_sql_log_off; bool queued_time_zone; @@ -567,6 +569,7 @@ typedef struct st_spider_conn int queued_ping_link_idx; int queued_trx_isolation_val; int queued_semi_trx_isolation_val; + int queued_wait_timeout_val; bool queued_autocommit_val; bool queued_sql_log_off_val; Time_zone *queued_time_zone_val; diff --git a/storage/spider/spd_param.cc b/storage/spider/spd_param.cc index 6b237bbfff8..ba207d360a2 100644 --- a/storage/spider/spd_param.cc +++ b/storage/spider/spd_param.cc @@ -3355,6 +3355,56 @@ int spider_param_slave_trx_isolation() DBUG_RETURN(spider_slave_trx_isolation); } +/* + -1 :not set + 0-:seconds of timeout + */ +static MYSQL_THDVAR_INT( + remote_wait_timeout, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Wait timeout on remote server", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +int spider_param_remote_wait_timeout( + THD *thd +) { + DBUG_ENTER("spider_param_remote_wait_timeout"); + if (likely(thd)) + DBUG_RETURN(THDVAR(thd, remote_wait_timeout)); + DBUG_RETURN(-1); +} + +/* + -1 :not set + 0-:seconds of timeout + */ +static MYSQL_THDVAR_INT( + wait_timeout, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Wait timeout of setting to remote server", /* comment */ + NULL, /* check */ + NULL, /* update */ + 604800, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +int spider_param_wait_timeout( + THD *thd +) { + DBUG_ENTER("spider_param_wait_timeout"); + if (likely(thd)) + DBUG_RETURN(THDVAR(thd, wait_timeout)); + DBUG_RETURN(604800); +} + static struct st_mysql_storage_engine spider_storage_engine = { MYSQL_HANDLERTON_INTERFACE_VERSION }; @@ -3505,6 +3555,8 @@ static struct st_mysql_sys_var* spider_system_variables[] = { MYSQL_SYSVAR(table_crd_thread_count), #endif MYSQL_SYSVAR(slave_trx_isolation), + MYSQL_SYSVAR(remote_wait_timeout), + MYSQL_SYSVAR(wait_timeout), NULL }; diff --git a/storage/spider/spd_param.h b/storage/spider/spd_param.h index 8fdf2e452b2..d874526f29a 100644 --- a/storage/spider/spd_param.h +++ b/storage/spider/spd_param.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 @@ -421,3 +422,9 @@ uint spider_param_table_sts_thread_count(); uint spider_param_table_crd_thread_count(); #endif int spider_param_slave_trx_isolation(); +int spider_param_remote_wait_timeout( + THD *thd +); +int spider_param_wait_timeout( + THD *thd +); diff --git a/storage/spider/spd_trx.cc b/storage/spider/spd_trx.cc index 78a95c5e38a..7c0efda4a7d 100644 --- a/storage/spider/spd_trx.cc +++ b/storage/spider/spd_trx.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 @@ -1667,6 +1668,22 @@ int spider_check_and_set_sql_log_off( DBUG_RETURN(0); } +int spider_check_and_set_wait_timeout( + THD *thd, + SPIDER_CONN *conn, + int *need_mon +) { + int wait_timeout; + DBUG_ENTER("spider_check_and_set_wait_timeout"); + + wait_timeout = spider_param_wait_timeout(thd); + if (wait_timeout > 0) + { + spider_conn_queue_wait_timeout(conn, wait_timeout); + } + DBUG_RETURN(0); +} + int spider_check_and_set_time_zone( THD *thd, SPIDER_CONN *conn, @@ -1866,6 +1883,8 @@ int spider_internal_start_trx( if ( (error_num = spider_check_and_set_sql_log_off(thd, conn, &spider->need_mons[link_idx])) || + (error_num = spider_check_and_set_wait_timeout(thd, conn, + &spider->need_mons[link_idx])) || (sync_autocommit && (error_num = spider_check_and_set_autocommit(thd, conn, &spider->need_mons[link_idx]))) diff --git a/storage/spider/spd_trx.h b/storage/spider/spd_trx.h index 3f3ca7fabed..e24f93598ed 100644 --- a/storage/spider/spd_trx.h +++ b/storage/spider/spd_trx.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2008-2014 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 @@ -99,6 +100,12 @@ int spider_check_and_set_sql_log_off( int *need_mon ); +int spider_check_and_set_wait_timeout( + THD *thd, + SPIDER_CONN *conn, + int *need_mon +); + int spider_check_and_set_time_zone( THD *thd, SPIDER_CONN *conn,