From f0a57acb492c4b034213d37c1fb5943850619f5a Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 3 Sep 2020 11:31:06 +0400 Subject: [PATCH 01/48] MDEV-23535 SIGSEGV, SIGABRT and SIGILL in typeinfo for Item_func_set_collation (on optimized builds) This piece of the code in Item_func_or_sum::agg_item_set_converter: if (!conv && ((*arg)->collation.repertoire == MY_REPERTOIRE_ASCII)) conv= new (thd->mem_root) Item_func_conv_charset(thd, *arg, coll.collation, 1); was wrong because: 1. It could change Item_cache to Item_func_conv_charset (with the old Item_cache in args[0]). Such Item type change is not always supported, e.g. the code in Item_singlerow_subselect::reset() expects only Item_cache, to be able to call Item_cache::set_null(). So it erroneously reinterpreted Item_func_conv_charset to Item_cache and called a non-existing method set_null(), which crashed the server. 2. The 1 in the last parameter to Item_func_conv_charset() was also a problem. In MariaDB versions where the reported query did not crash, it erroneously returned "empty set" instead of one row, because the 1 made subselects execute too earlier and return NULL. Fix: 1. Removing the above two lines from Item_func_or_sum::agg_item_set_converter() 2. Adding the repertoire test inside the constructor of Item_func_conv_charset, so it now detects itself as "safe" in more cases than before. This is needed to avoid new "Illegal mix of collations" after removing the wrong code in various scenarios when character set conversion from pure ASCII happens, including the reported scenario. So now this sequence: Item_cache -> Item_func_concat is replaced to this compatible sequence (the top Item is still Item_cache): new Item_cache -> Item_func_conv_charset -> Item_func_concat Before the fix it was replaced to this incompatible sequence: Item_func_conv_charset -> old Item_cache -> Item_func_concat --- mysql-test/r/ctype_utf8.result | 12 ++++++++++++ mysql-test/r/subselect_innodb.result | 14 ++++++++++++++ mysql-test/t/ctype_utf8.test | 12 ++++++++++++ mysql-test/t/subselect_innodb.test | 16 ++++++++++++++++ sql/item.cc | 2 -- sql/item_strfunc.h | 10 +++++++++- 6 files changed, 63 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 8b35305a79b..b614444fd2a 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -10583,5 +10583,17 @@ SELECT CONVERT(1, CHAR) IN ('100', '10', '1'); CONVERT(1, CHAR) IN ('100', '10', '1') 1 # +# MDEV-23535 SIGSEGV, SIGABRT and SIGILL in typeinfo for Item_func_set_collation (on optimized builds) +# +SET NAMES utf8; +CREATE OR REPLACE TABLE t1(a DATETIME) ENGINE=MYISAM; +INSERT INTO t1 VALUES ('2019-03-10 02:55:05'); +CREATE OR REPLACE TABLE t2(a VARCHAR(50) CHARACTER SET latin1) ENGINE=MYISAM; +INSERT INTO t2 VALUES ('2019-03-10 02:55:05'); +SELECT * FROM t1 WHERE (SELECT 1,CONCAT(a) FROM t1) = (SELECT 1,CONCAT(a) FROM t2); +a +2019-03-10 02:55:05 +DROP TABLE t1, t2; +# # End of 10.1 tests # diff --git a/mysql-test/r/subselect_innodb.result b/mysql-test/r/subselect_innodb.result index 240a6ab47e4..bfdf5525cad 100644 --- a/mysql-test/r/subselect_innodb.result +++ b/mysql-test/r/subselect_innodb.result @@ -615,3 +615,17 @@ id select_type table type possible_keys key key_len ref rows filtered Extra Warnings: Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t3`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` semi join (`test`.`t4`) join `test`.`t3` where ((`test`.`t4`.`f4` = 1) and (`test`.`t1`.`f1` >= `test`.`t2`.`f2`)) DROP TABLE t1,t2,t3,t4; +# +# MDEV-23535: SIGSEGV, SIGABRT and SIGILL in typeinfo for Item_func_set_collation (on optimized builds) +# +set @save_character_set_connection=@@character_set_connection; +set character_set_connection='utf8'; +CREATE TABLE t1(a DATETIME, b VARCHAR(50)) ENGINE=INNODB; +INSERT INTO t1 VALUES ('2019-03-10 02:55:05', '2019-03-10 02:55:05'); +CREATE TABLE t2(a VARCHAR(50)) ENGINE=INNODB; +INSERT INTO t2 VALUES ('2019-03-10 02:55:05'); +SELECT * FROM t1 WHERE (SELECT 1,CONCAT(a) FROM t1) = (SELECT 1,CONCAT(a) FROM t2); +a b +2019-03-10 02:55:05 2019-03-10 02:55:05 +DROP TABLE t1,t2; +set character_set_connection=@save_character_set_connection; diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 7abcc693926..90f7b0fb75c 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -2040,6 +2040,18 @@ SELECT CONVERT(1, CHAR) IN ('100', 10, '101'); SELECT CONVERT(1, CHAR) IN ('100', 10, '1'); SELECT CONVERT(1, CHAR) IN ('100', '10', '1'); +--echo # +--echo # MDEV-23535 SIGSEGV, SIGABRT and SIGILL in typeinfo for Item_func_set_collation (on optimized builds) +--echo # + +SET NAMES utf8; +CREATE OR REPLACE TABLE t1(a DATETIME) ENGINE=MYISAM; +INSERT INTO t1 VALUES ('2019-03-10 02:55:05'); +CREATE OR REPLACE TABLE t2(a VARCHAR(50) CHARACTER SET latin1) ENGINE=MYISAM; +INSERT INTO t2 VALUES ('2019-03-10 02:55:05'); +SELECT * FROM t1 WHERE (SELECT 1,CONCAT(a) FROM t1) = (SELECT 1,CONCAT(a) FROM t2); +DROP TABLE t1, t2; + --echo # --echo # End of 10.1 tests diff --git a/mysql-test/t/subselect_innodb.test b/mysql-test/t/subselect_innodb.test index 544bcd994ed..2c117fe00d6 100644 --- a/mysql-test/t/subselect_innodb.test +++ b/mysql-test/t/subselect_innodb.test @@ -611,3 +611,19 @@ FROM t1 DROP TABLE t1,t2,t3,t4; + +--echo # +--echo # MDEV-23535: SIGSEGV, SIGABRT and SIGILL in typeinfo for Item_func_set_collation (on optimized builds) +--echo # + +set @save_character_set_connection=@@character_set_connection; +set character_set_connection='utf8'; + +CREATE TABLE t1(a DATETIME, b VARCHAR(50)) ENGINE=INNODB; +INSERT INTO t1 VALUES ('2019-03-10 02:55:05', '2019-03-10 02:55:05'); +CREATE TABLE t2(a VARCHAR(50)) ENGINE=INNODB; +INSERT INTO t2 VALUES ('2019-03-10 02:55:05'); +SELECT * FROM t1 WHERE (SELECT 1,CONCAT(a) FROM t1) = (SELECT 1,CONCAT(a) FROM t2); +DROP TABLE t1,t2; + +set character_set_connection=@save_character_set_connection; diff --git a/sql/item.cc b/sql/item.cc index 2e12b8d8b64..8792b1c3f32 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2188,8 +2188,6 @@ bool Item_func_or_sum::agg_item_set_converter(const DTCollation &coll, Item* conv= (*arg)->safe_charset_converter(thd, coll.collation); if (conv == *arg) continue; - if (!conv && ((*arg)->collation.repertoire == MY_REPERTOIRE_ASCII)) - conv= new (thd->mem_root) Item_func_conv_charset(thd, *arg, coll.collation, 1); if (!conv) { diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 9ea9ff97016..6989639ae67 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -1053,11 +1053,19 @@ public: /* Conversion from and to "binary" is safe. Conversion to Unicode is safe. + Conversion from an expression with the ASCII repertoire + to any character set that can store characters U+0000..U+007F + is safe: + - All supported multibyte character sets can store U+0000..U+007F + - All supported 7bit character sets can store U+0000..U+007F + except those marked with MY_CS_NONASCII (e.g. swe7). Other kind of conversions are potentially lossy. */ safe= (args[0]->collation.collation == &my_charset_bin || cs == &my_charset_bin || - (cs->state & MY_CS_UNICODE)); + (cs->state & MY_CS_UNICODE) || + (args[0]->collation.repertoire == MY_REPERTOIRE_ASCII && + (cs->mbmaxlen > 1 || !(cs->state & MY_CS_NONASCII)))); } } String *val_str(String *); From 3ee2422624ffb3d7ffefff8db7ef9398816299bc Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Fri, 4 Sep 2020 17:40:51 +0800 Subject: [PATCH 02/48] InnoDB, XtraDB: handle EOPNOTSUPP from posix_fallocate() On some libc (like musl[1]), posix_fallocate() is a fallocate() syscall wrapper, and does not include fallback code like glibc does. In that case, EOPNOTSUPP is returned if underlying filesystem does not support fallocate() with mode = 0. This patch enables falling back to writing zeros when EOPNOTSUPP, fixes some cases like running on filesystem without proper fallocate support on Alpine. [1]: https://git.musl-libc.org/cgit/musl/tree/src/fcntl/posix_fallocate.c?h=v1.2.1 --- storage/innobase/os/os0file.cc | 1 + storage/xtradb/os/os0file.cc | 1 + 2 files changed, 2 insertions(+) diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index 3a403f880c1..9987544c6a1 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -2427,6 +2427,7 @@ os_file_set_size( errno = err; return false; case EINVAL: + case EOPNOTSUPP: /* fall back to the code below */ break; } diff --git a/storage/xtradb/os/os0file.cc b/storage/xtradb/os/os0file.cc index 1e0f28d393f..66af4a39f7c 100644 --- a/storage/xtradb/os/os0file.cc +++ b/storage/xtradb/os/os0file.cc @@ -2716,6 +2716,7 @@ os_file_set_size( errno = err; return false; case EINVAL: + case EOPNOTSUPP: /* fall back to the code below */ break; } From 420c4dcc7e05748ae876707a1afe464134916aa7 Mon Sep 17 00:00:00 2001 From: Kentoku SHIBA Date: Fri, 4 Sep 2020 22:10:57 +0900 Subject: [PATCH 03/48] MDEV-7098 spider/bg.spider_fixes failed in buildbot with safe_mutex: Trying to unlock mutex conn->mta_conn_mutex that wasn't locked at storage/spider/spd_db_conn.cc, line 671 --- storage/spider/ha_spider.cc | 179 ++++++++ storage/spider/spd_conn.cc | 22 + storage/spider/spd_db_conn.cc | 772 +++++++++++++++++++++----------- storage/spider/spd_db_mysql.cc | 597 ++++++++++++++++++++++-- storage/spider/spd_db_oracle.cc | 492 ++++++++++---------- storage/spider/spd_include.h | 4 + storage/spider/spd_table.cc | 7 + 7 files changed, 1534 insertions(+), 539 deletions(-) diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 6b105200c55..851ac35557b 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -2257,6 +2257,7 @@ int ha_spider::index_read_map_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -2264,6 +2265,11 @@ int ha_spider::index_read_map_internal( } if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -2285,11 +2291,15 @@ int ha_spider::index_read_map_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -2324,6 +2334,8 @@ int ha_spider::index_read_map_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -2350,6 +2362,8 @@ int ha_spider::index_read_map_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -2748,6 +2762,7 @@ int ha_spider::index_read_last_map_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -2755,6 +2770,11 @@ int ha_spider::index_read_last_map_internal( } if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -2773,11 +2793,15 @@ int ha_spider::index_read_last_map_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -2812,6 +2836,8 @@ int ha_spider::index_read_last_map_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -2838,6 +2864,8 @@ int ha_spider::index_read_last_map_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -3213,6 +3241,7 @@ int ha_spider::index_first_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -3221,6 +3250,11 @@ int ha_spider::index_first_internal( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -3239,11 +3273,15 @@ int ha_spider::index_first_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -3278,6 +3316,8 @@ int ha_spider::index_first_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -3304,6 +3344,8 @@ int ha_spider::index_first_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -3596,6 +3638,7 @@ int ha_spider::index_last_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -3604,6 +3647,11 @@ int ha_spider::index_last_internal( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -3622,11 +3670,15 @@ int ha_spider::index_last_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -3661,6 +3713,8 @@ int ha_spider::index_last_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -3687,6 +3741,8 @@ int ha_spider::index_last_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -4039,6 +4095,7 @@ int ha_spider::read_range_first_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -4046,6 +4103,11 @@ int ha_spider::read_range_first_internal( } if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -4064,11 +4126,15 @@ int ha_spider::read_range_first_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -4103,6 +4169,8 @@ int ha_spider::read_range_first_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -4129,6 +4197,8 @@ int ha_spider::read_range_first_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -4665,6 +4735,7 @@ int ha_spider::read_multi_range_first_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -4673,6 +4744,11 @@ int ha_spider::read_multi_range_first_internal( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -4697,11 +4773,15 @@ int ha_spider::read_multi_range_first_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -4737,6 +4817,8 @@ int ha_spider::read_multi_range_first_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -4765,6 +4847,8 @@ int ha_spider::read_multi_range_first_internal( if (!error_num) { connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -5458,6 +5542,7 @@ int ha_spider::read_multi_range_first_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -5466,6 +5551,11 @@ int ha_spider::read_multi_range_first_internal( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -5491,11 +5581,15 @@ int ha_spider::read_multi_range_first_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5537,6 +5631,8 @@ int ha_spider::read_multi_range_first_internal( -1, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -5572,6 +5668,8 @@ int ha_spider::read_multi_range_first_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -5598,6 +5696,8 @@ int ha_spider::read_multi_range_first_internal( break; } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -6105,6 +6205,7 @@ int ha_spider::read_multi_range_next( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -6113,6 +6214,11 @@ int ha_spider::read_multi_range_next( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -6137,11 +6243,15 @@ int ha_spider::read_multi_range_next( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6177,6 +6287,8 @@ int ha_spider::read_multi_range_next( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -6205,6 +6317,8 @@ int ha_spider::read_multi_range_next( if (!error_num) { connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -6902,6 +7016,7 @@ int ha_spider::read_multi_range_next( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -6910,6 +7025,11 @@ int ha_spider::read_multi_range_next( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -6935,11 +7055,15 @@ int ha_spider::read_multi_range_next( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6981,6 +7105,8 @@ int ha_spider::read_multi_range_next( -1, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -7016,6 +7142,8 @@ int ha_spider::read_multi_range_next( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -7042,6 +7170,8 @@ int ha_spider::read_multi_range_next( break; } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -7519,6 +7649,7 @@ int ha_spider::rnd_next_internal( sql_type = SPIDER_SQL_TYPE_HANDLER; } spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -7527,6 +7658,11 @@ int ha_spider::rnd_next_internal( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -7536,11 +7672,15 @@ int ha_spider::rnd_next_internal( } DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -7575,6 +7715,8 @@ int ha_spider::rnd_next_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -7601,6 +7743,8 @@ int ha_spider::rnd_next_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -8111,6 +8255,7 @@ int ha_spider::ft_read_internal( uint dbton_id = share->use_sql_dbton_ids[roop_count]; spider_db_handler *dbton_hdl = dbton_handler[dbton_id]; SPIDER_CONN *conn = conns[roop_count]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_SELECT_SQL)) { @@ -8120,6 +8265,12 @@ int ha_spider::ft_read_internal( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_SELECT_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_SELECT_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -8129,10 +8280,14 @@ int ha_spider::ft_read_internal( SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -8166,6 +8321,8 @@ int ha_spider::ft_read_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -8192,6 +8349,8 @@ int ha_spider::ft_read_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -10453,9 +10612,12 @@ void ha_spider::bulk_req_exec() if (conn->bulk_access_requests) { spider_bg_conn_wait(conn); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; /* currently only used for HS */ @@ -10473,6 +10635,8 @@ void ha_spider::bulk_req_exec() conn->bulk_access_sended += conn->bulk_access_requests; */ conn->bulk_access_requests = 0; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -12140,6 +12304,7 @@ int ha_spider::drop_tmp_tables() uint dbton_id = share->use_sql_dbton_ids[roop_count]; spider_db_handler *dbton_hdl = dbton_handler[dbton_id]; SPIDER_CONN *conn = conns[roop_count]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_TMP_SQL)) { @@ -12149,6 +12314,12 @@ int ha_spider::drop_tmp_tables() if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_TMP_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_TMP_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -12158,10 +12329,14 @@ int ha_spider::drop_tmp_tables() SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((tmp_error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -12198,6 +12373,8 @@ int ha_spider::drop_tmp_tables() -1, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; tmp_error_num = spider_db_errorno(conn); @@ -12223,6 +12400,8 @@ int ha_spider::drop_tmp_tables() } error_num = tmp_error_num; } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index 99599bca1be..aef3d1df991 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -2390,6 +2390,7 @@ void *spider_bg_conn_action( sql_type = SPIDER_SQL_TYPE_SELECT_HS; } #endif + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -2419,6 +2420,8 @@ void *spider_bg_conn_action( if (!result_list->bgs_error) { conn->need_mon = &spider->need_mons[conn->link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; #ifdef HA_CAN_BULK_ACCESS @@ -2496,6 +2499,8 @@ void *spider_bg_conn_action( #ifdef HA_CAN_BULK_ACCESS } #endif + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -2506,11 +2511,14 @@ void *spider_bg_conn_action( } } else { spider->connection_ids[conn->link_idx] = conn->connection_id; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_unlock_later = TRUE; result_list->bgs_error = spider_db_store_result(spider, conn->link_idx, result_list->table); if ((result_list->bgs_error_with_message = thd->is_error())) strmov(result_list->bgs_error_msg, spider_stmt_da_message(thd)); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_unlock_later = FALSE; } conn->bg_search = FALSE; @@ -2574,12 +2582,26 @@ void *spider_bg_conn_action( { DBUG_PRINT("info",("spider bg exec sql start")); spider = (ha_spider*) conn->bg_target; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[conn->link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; *conn->bg_error_num = spider_db_query_with_set_names( conn->bg_sql_type, spider, conn, conn->link_idx ); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); conn->bg_exec_sql = FALSE; continue; } diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index efb5e6d8c8c..5e9e53d89ff 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -205,23 +205,14 @@ int spider_db_ping( DBUG_PRINT("info", ("spider thd->query_id is %lld", spider->trx->thd->query_id)); #endif - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &spider->need_mons[link_idx]; - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); if (conn->server_lost || conn->queued_connect) { if ((error_num = spider_db_connect(spider->share, conn, spider->conn_link_idx[link_idx]))) { - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } conn->server_lost = FALSE; @@ -235,11 +226,7 @@ int spider_db_ping( { DBUG_PRINT("info", ("spider conn=%p SERVER_LOST", conn)); conn->server_lost = TRUE; - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } if((error_num = conn->db_conn->ping())) @@ -247,20 +234,12 @@ int spider_db_ping( spider_db_disconnect(conn); DBUG_PRINT("info", ("spider conn=%p SERVER_LOST", conn)); conn->server_lost = TRUE; - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } } conn->ping_time = (time_t) time((time_t*) 0); - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(0); } @@ -300,6 +279,7 @@ int spider_db_conn_queue_action( conn->queued_connect = FALSE; } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) { @@ -548,7 +528,6 @@ int spider_db_before_query( int *need_mon ) { int error_num; - bool tmp_mta_conn_mutex_lock_already; DBUG_ENTER("spider_db_before_query"); DBUG_ASSERT(need_mon); #ifndef WITHOUT_SPIDER_BG_SEARCH @@ -556,25 +535,18 @@ int spider_db_before_query( spider_bg_conn_break(conn, NULL); #endif conn->in_before_query = TRUE; - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = need_mon; - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; - conn->mta_conn_mutex_lock_already = TRUE; if ((error_num = spider_db_conn_queue_action(conn))) { conn->in_before_query = FALSE; - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; if (conn->server_lost) { conn->in_before_query = FALSE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(CR_SERVER_GONE_ERROR); } DBUG_PRINT("info", ("spider conn[%p]->quick_target=%p", @@ -601,6 +573,7 @@ int spider_db_before_query( ) { conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; conn->in_before_query = FALSE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } } @@ -616,6 +589,7 @@ int spider_db_before_query( } } conn->in_before_query = FALSE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(0); } @@ -628,6 +602,7 @@ int spider_db_query( ) { int error_num; DBUG_ENTER("spider_db_query"); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) { @@ -670,6 +645,7 @@ int spider_db_errorno( int error_num; DBUG_ENTER("spider_db_errorno"); DBUG_ASSERT(conn->need_mon); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) { @@ -684,6 +660,7 @@ int spider_db_errorno( } if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -705,6 +682,7 @@ int spider_db_errorno( } if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -717,6 +695,7 @@ int spider_db_errorno( conn->error_length = strlen(conn->error_str); if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -741,6 +720,7 @@ int spider_db_errorno( } if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -761,6 +741,7 @@ int spider_db_errorno( } if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -777,6 +758,7 @@ int spider_db_errorno( conn->server_lost = TRUE; if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -786,6 +768,7 @@ int spider_db_errorno( *conn->need_mon = 0; if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -808,6 +791,7 @@ int spider_db_errorno( *conn->need_mon = ER_SPIDER_HS_NUM; if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -816,6 +800,7 @@ int spider_db_errorno( #endif if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -838,33 +823,25 @@ int spider_db_set_names_internal( int all_link_idx, int *need_mon ) { - bool tmp_mta_conn_mutex_lock_already; DBUG_ENTER("spider_db_set_names_internal"); #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) { #endif - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = need_mon; - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); if ( !conn->access_charset || share->access_charset->cset != conn->access_charset->cset ) { - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; - conn->mta_conn_mutex_lock_already = TRUE; if ( spider_db_before_query(conn, need_mon) || conn->db_conn->set_character_set(share->access_charset->csname) ) { - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; DBUG_RETURN(spider_db_errorno(conn)); } - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; conn->access_charset = share->access_charset; } if ( @@ -879,13 +856,10 @@ int spider_db_set_names_internal( ) { DBUG_PRINT("info",("spider all_link_idx=%d db=%s", all_link_idx, share->tgt_dbs[all_link_idx])); - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; - conn->mta_conn_mutex_lock_already = TRUE; if ( spider_db_before_query(conn, need_mon) || conn->db_conn->select_db(share->tgt_dbs[all_link_idx]) ) { - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; DBUG_RETURN(spider_db_errorno(conn)); } conn->default_database.length(0); @@ -895,12 +869,6 @@ int spider_db_set_names_internal( conn->default_database.q_append(share->tgt_dbs[all_link_idx], share->tgt_dbs_lengths[all_link_idx] + 1); conn->default_database.length(share->tgt_dbs_lengths[all_link_idx]); - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; - } - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); } #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } @@ -929,19 +897,11 @@ int spider_db_query_with_set_names( spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; DBUG_ENTER("spider_db_query_with_set_names"); -/* - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); -*/ - conn->need_mon = &spider->need_mons[link_idx]; - conn->mta_conn_mutex_lock_already = TRUE; - conn->mta_conn_mutex_unlock_later = TRUE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); if ((error_num = spider_db_set_names(spider, conn, link_idx))) { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); if ( share->monitoring_kind[link_idx] && spider->need_mons[link_idx] @@ -972,8 +932,6 @@ int spider_db_query_with_set_names( -1, &spider->need_mons[link_idx]) ) { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); if ( share->monitoring_kind[link_idx] && @@ -997,10 +955,6 @@ int spider_db_query_with_set_names( } DBUG_RETURN(error_num); } - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); } @@ -1014,15 +968,16 @@ int spider_db_query_for_bulk_update( SPIDER_SHARE *share = spider->share; DBUG_ENTER("spider_db_query_for_bulk_update"); -/* - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); -*/ + pthread_mutex_assert_owner(&conn->mta_conn_mutex); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -1058,6 +1013,8 @@ int spider_db_query_for_bulk_update( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -1104,6 +1061,8 @@ int spider_db_query_for_bulk_update( } if (error_num > 0 && !conn->db_conn->is_dup_entry_error(error_num)) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -1130,6 +1089,8 @@ int spider_db_query_for_bulk_update( } DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -3639,6 +3600,7 @@ int spider_db_store_result( ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3655,6 +3617,7 @@ int spider_db_store_result( ) { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3686,6 +3649,7 @@ int spider_db_store_result( ) { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3729,6 +3693,7 @@ int spider_db_store_result( ) { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3768,6 +3733,7 @@ int spider_db_store_result( { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3796,6 +3762,7 @@ int spider_db_store_result( #endif if (!conn->mta_conn_mutex_unlock_later && !call_db_errorno) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3803,6 +3770,7 @@ int spider_db_store_result( } else { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3846,6 +3814,7 @@ int spider_db_store_result( result_list->limit_num -= current->prev->record_num; if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3869,6 +3838,7 @@ int spider_db_store_result( } else { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3880,6 +3850,7 @@ int spider_db_store_result( spider->quick_targets[link_idx] = spider; if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -4038,6 +4009,7 @@ int spider_db_store_result( ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -4063,6 +4035,7 @@ int spider_db_store_result( } else { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -4073,6 +4046,7 @@ int spider_db_store_result( result_list->hs_has_result = TRUE; if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -4158,15 +4132,15 @@ int spider_db_bulk_store_result( error_num = spider_db_bulk_open_handler(spider, conn, link_idx); if (!discard_result) { - bool tmp_mta_conn_mutex_unlock_later; - tmp_mta_conn_mutex_unlock_later = conn->mta_conn_mutex_unlock_later; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_unlock_later = TRUE; if ((tmp_error_num = spider_db_store_result(spider, link_idx, spider->get_table()))) { error_num = tmp_error_num; } - conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; + conn->mta_conn_mutex_unlock_later = FALSE; } else { if (spider->connection_ids[link_idx] == conn->connection_id) spider_db_discard_result(spider, link_idx, conn); @@ -4376,10 +4350,14 @@ int spider_db_seek_next( SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -4415,6 +4393,8 @@ int spider_db_seek_next( result_list->quick_mode, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -4442,6 +4422,8 @@ int spider_db_seek_next( DBUG_RETURN(error_num); } spider->connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -4482,6 +4464,8 @@ int spider_db_seek_next( } } else { spider->connection_ids[link_idx] = conn->connection_id; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_store_result(spider, link_idx, table))) { @@ -4608,6 +4592,7 @@ int spider_db_seek_last( } conn = spider->conns[roop_count]; spider_db_handler *dbton_handler = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -4615,6 +4600,11 @@ int spider_db_seek_last( } if ((error_num = dbton_handler->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) @@ -4624,10 +4614,14 @@ int spider_db_seek_last( } DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -4662,6 +4656,8 @@ int spider_db_seek_last( result_list->quick_mode, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -4688,6 +4684,8 @@ int spider_db_seek_last( DBUG_RETURN(error_num); } spider->connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -4808,6 +4806,7 @@ int spider_db_seek_last( } conn = spider->conns[roop_count]; spider_db_handler *dbton_handler = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -4815,6 +4814,11 @@ int spider_db_seek_last( } if ((error_num = dbton_handler->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) @@ -4824,10 +4828,14 @@ int spider_db_seek_last( } DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -4862,6 +4870,8 @@ int spider_db_seek_last( result_list->quick_mode, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -4888,6 +4898,8 @@ int spider_db_seek_last( DBUG_RETURN(error_num); } spider->connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -5556,8 +5568,6 @@ int spider_db_bulk_insert( #endif SPIDER_SHARE *share = spider->share; THD *thd = spider->trx->thd; - bool mta_conn_mutex_lock_already_backup; - bool mta_conn_mutex_unlock_later_backup; DBUG_ENTER("spider_db_bulk_insert"); if (!bulk_end) @@ -5612,61 +5622,50 @@ int spider_db_bulk_insert( sql_type = SPIDER_SQL_TYPE_INSERT_SQL; conn = spider->conns[roop_count2]; dbton_handler = spider->dbton_handler[conn->dbton_id]; - mta_conn_mutex_lock_already_backup = - conn->mta_conn_mutex_lock_already; - mta_conn_mutex_unlock_later_backup = - conn->mta_conn_mutex_unlock_later; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) { - if (!mta_conn_mutex_lock_already_backup) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } if ((error_num = dbton_handler->set_sql_for_exec(sql_type, roop_count2))) { + if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) { - if (!mta_conn_mutex_lock_already_backup) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } else { sql_type = SPIDER_SQL_TYPE_INSERT_HS; conn = spider->hs_w_conns[roop_count2]; dbton_handler = spider->dbton_handler[conn->dbton_id]; - mta_conn_mutex_lock_already_backup = - conn->mta_conn_mutex_lock_already; - mta_conn_mutex_unlock_later_backup = - conn->mta_conn_mutex_unlock_later; - if (!mta_conn_mutex_lock_already_backup) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } #endif conn->need_mon = &spider->need_mons[roop_count2]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count2))) { - conn->mta_conn_mutex_lock_already = - mta_conn_mutex_lock_already_backup; - conn->mta_conn_mutex_unlock_later = - mta_conn_mutex_unlock_later_backup; - if (!mta_conn_mutex_unlock_later_backup) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); if ( share->monitoring_kind[roop_count2] && spider->need_mons[roop_count2] @@ -5704,15 +5703,12 @@ int spider_db_bulk_insert( { conn->db_conn->set_dup_key_idx(spider, roop_count2); } - conn->mta_conn_mutex_lock_already = - mta_conn_mutex_lock_already_backup; - conn->mta_conn_mutex_unlock_later = - mta_conn_mutex_unlock_later_backup; - if (!mta_conn_mutex_unlock_later_backup) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); if ( error_num != ER_DUP_ENTRY && error_num != ER_DUP_KEY && @@ -5738,8 +5734,10 @@ int spider_db_bulk_insert( } DBUG_RETURN(error_num); } - conn->mta_conn_mutex_lock_already = mta_conn_mutex_lock_already_backup; - conn->mta_conn_mutex_unlock_later = mta_conn_mutex_unlock_later_backup; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (conn->conn_kind != SPIDER_CONN_KIND_MYSQL) { @@ -5775,11 +5773,8 @@ int spider_db_bulk_insert( } } #endif - if (!mta_conn_mutex_unlock_later_backup) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); if (first_insert_link_idx == -1) { first_insert_link_idx = roop_count2; @@ -5788,14 +5783,12 @@ int spider_db_bulk_insert( } conn = first_insert_conn; - mta_conn_mutex_lock_already_backup = conn->mta_conn_mutex_lock_already; - mta_conn_mutex_unlock_later_backup = conn->mta_conn_mutex_unlock_later; - if (!mta_conn_mutex_lock_already_backup) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[first_insert_link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) @@ -5817,15 +5810,12 @@ int spider_db_bulk_insert( else if ((error_num = dbton_handler-> show_last_insert_id(first_insert_link_idx, last_insert_id))) { - conn->mta_conn_mutex_lock_already = - mta_conn_mutex_lock_already_backup; - conn->mta_conn_mutex_unlock_later = - mta_conn_mutex_unlock_later_backup; - if (!mta_conn_mutex_unlock_later_backup) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } table->next_number_field->set_notnull(); @@ -5835,25 +5825,21 @@ int spider_db_bulk_insert( (error_num = table->next_number_field->store( last_insert_id, TRUE)) ) { - conn->mta_conn_mutex_lock_already = - mta_conn_mutex_lock_already_backup; - conn->mta_conn_mutex_unlock_later = - mta_conn_mutex_unlock_later_backup; - if (!mta_conn_mutex_unlock_later_backup) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } } - conn->mta_conn_mutex_lock_already = mta_conn_mutex_lock_already_backup; - conn->mta_conn_mutex_unlock_later = mta_conn_mutex_unlock_later_backup; - if (!mta_conn_mutex_unlock_later_backup) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); spider->store_last_insert_id = 0; #ifdef HA_CAN_BULK_ACCESS } @@ -5897,8 +5883,11 @@ int spider_db_bulk_bulk_insert( conn = spider->hs_w_conns[roop_count2]; } #endif + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((tmp_error_num = spider_db_bulk_open_handler(spider, conn, @@ -5906,6 +5895,8 @@ int spider_db_bulk_bulk_insert( { error_num = tmp_error_num; } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) @@ -5954,9 +5945,12 @@ int spider_db_bulk_bulk_insert( } conn = first_insert_conn; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[first_insert_link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if (table->next_number_field && @@ -5983,6 +5977,8 @@ int spider_db_bulk_bulk_insert( error_num = tmp_error_num; } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6110,6 +6106,7 @@ int spider_db_bulk_update_size_limit( ) { conn = spider->conns[roop_count]; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) { @@ -6119,6 +6116,12 @@ int spider_db_bulk_update_size_limit( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_BULK_UPDATE_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -6129,7 +6132,11 @@ int spider_db_bulk_update_size_limit( } if ((error_num = spider_db_query_for_bulk_update( spider, conn, roop_count, &dup_key_found))) + { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); DBUG_RETURN(error_num); + } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); } spider->reset_sql_sql(SPIDER_SQL_TYPE_BULK_UPDATE_SQL); } else { @@ -6195,6 +6202,7 @@ int spider_db_bulk_update_end( ) { conn = spider->conns[roop_count]; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) { @@ -6204,14 +6212,14 @@ int spider_db_bulk_update_end( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_BULK_UPDATE_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } if (error_num == ER_SPIDER_COND_SKIP_NUM) { - if (dbton_hdl->need_lock_before_set_sql_for_exec( - SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } continue; } DBUG_RETURN(error_num); @@ -6224,7 +6232,11 @@ int spider_db_bulk_update_end( } if ((error_num = spider_db_query_for_bulk_update( spider, conn, roop_count, dup_key_found))) + { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); goto error_query; + } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); } } if (error_num != HA_ERR_END_OF_FILE) @@ -6249,6 +6261,7 @@ int spider_db_bulk_update_end( ) { conn = spider->conns[roop_count]; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) { @@ -6258,6 +6271,12 @@ int spider_db_bulk_update_end( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_BULK_UPDATE_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -6268,7 +6287,11 @@ int spider_db_bulk_update_end( } if ((error_num = spider_db_query_for_bulk_update( spider, conn, roop_count, dup_key_found))) + { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); goto error_last_query; + } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); } } } @@ -6336,6 +6359,7 @@ int spider_db_update( #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 conn->ignore_dup_key = spider->ignore_dup_key; #endif + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_UPDATE_SQL)) { @@ -6345,6 +6369,12 @@ int spider_db_update( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_UPDATE_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_UPDATE_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -6354,10 +6384,14 @@ int spider_db_update( SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6392,6 +6426,8 @@ int spider_db_update( -1, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -6430,6 +6466,8 @@ int spider_db_update( if ((error_num = dbton_hdl->append_insert_for_recovery( SPIDER_SQL_TYPE_INSERT_SQL, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6444,6 +6482,8 @@ int spider_db_update( -1, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -6473,6 +6513,8 @@ int spider_db_update( DBUG_RETURN(error_num); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6661,6 +6703,7 @@ int spider_db_direct_update( } #endif spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -6668,6 +6711,11 @@ int spider_db_direct_update( } if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -6683,10 +6731,14 @@ int spider_db_direct_update( } else { #endif conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6724,6 +6776,8 @@ int spider_db_direct_update( ) && (error_num != HA_ERR_FOUND_DUPP_KEY || !spider->ignore_dup_key) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -6790,6 +6844,8 @@ int spider_db_direct_update( { error_num = spider_db_errorno(conn); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6798,11 +6854,13 @@ int spider_db_direct_update( } } #endif + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; #ifdef HA_CAN_BULK_ACCESS } #endif - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -6847,8 +6905,11 @@ int spider_db_bulk_direct_update( conn = spider->hs_w_conns[roop_count]; } #endif + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((tmp_error_num = spider_db_bulk_open_handler(spider, conn, @@ -6894,6 +6955,8 @@ int spider_db_bulk_direct_update( { error_num = spider_db_errorno(conn); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6902,6 +6965,8 @@ int spider_db_bulk_direct_update( } } #endif + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6958,6 +7023,7 @@ int spider_db_delete( ) { conn = spider->conns[roop_count]; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_DELETE_SQL)) { @@ -6967,6 +7033,12 @@ int spider_db_delete( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_DELETE_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_DELETE_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -6975,9 +7047,27 @@ int spider_db_delete( pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_query_with_set_names( SPIDER_SQL_TYPE_DELETE_SQL, spider, conn, roop_count))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); result_list->update_sqls[roop_count].length(0); } if ((error_num = spider->reset_sql_sql(SPIDER_SQL_TYPE_DELETE_SQL))) @@ -7089,6 +7179,7 @@ int spider_db_direct_delete( } #endif spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -7096,6 +7187,11 @@ int spider_db_direct_delete( } if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -7111,10 +7207,14 @@ int spider_db_direct_delete( } else { #endif conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -7149,6 +7249,8 @@ int spider_db_direct_delete( -1, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -7174,6 +7276,8 @@ int spider_db_direct_delete( } DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) @@ -7266,6 +7370,7 @@ int spider_db_delete_all_rows( uint dbton_id = share->use_sql_dbton_ids[roop_count]; spider_db_handler *dbton_hdl = spider->dbton_handler[dbton_id]; conn = spider->conns[roop_count]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_DELETE_SQL)) { @@ -7275,6 +7380,12 @@ int spider_db_delete_all_rows( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_DELETE_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_DELETE_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -7284,6 +7395,8 @@ int spider_db_delete_all_rows( SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, roop_count, spider->trx->thd, @@ -7306,6 +7419,8 @@ int spider_db_delete_all_rows( /* retry */ if ((error_num = spider_db_ping(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -7334,6 +7449,8 @@ int spider_db_delete_all_rows( } if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -7368,6 +7485,8 @@ int spider_db_delete_all_rows( -1, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -7394,6 +7513,8 @@ int spider_db_delete_all_rows( DBUG_RETURN(error_num); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -7421,6 +7542,8 @@ int spider_db_delete_all_rows( DBUG_RETURN(error_num); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -8802,7 +8925,14 @@ int spider_db_udf_direct_sql( c_thd->lex->sql_command = SQLCOM_INSERT; #endif + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if ( !(error_num = spider_db_udf_direct_sql_set_names(direct_sql, trx, conn)) && !(error_num = spider_db_udf_direct_sql_select_db(direct_sql, conn)) @@ -8825,9 +8955,6 @@ int spider_db_udf_direct_sql( #endif DBUG_RETURN(error_num); } - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); } #endif spider_conn_set_timeout_from_direct_sql(conn, thd, direct_sql); @@ -8846,8 +8973,6 @@ int spider_db_udf_direct_sql( DBUG_PRINT("info",("spider conn=%p", conn)); if (!direct_sql->table_count) roop_count = -1; - conn->mta_conn_mutex_lock_already = TRUE; - conn->mta_conn_mutex_unlock_later = TRUE; do { if (roop_count == direct_sql->table_count) { @@ -9059,12 +9184,14 @@ int spider_db_udf_direct_sql( if (roop_count >= 0) roop_count++; } while (status == 0); - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); if (need_trx_end && insert_start) { if (error_num) @@ -9094,19 +9221,13 @@ int spider_db_udf_direct_sql_select_db( SPIDER_CONN *conn ) { int error_num, need_mon = 0; - bool tmp_mta_conn_mutex_lock_already; SPIDER_DB_CONN *db_conn = conn->db_conn; DBUG_ENTER("spider_db_udf_direct_sql_select_db"); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (direct_sql->access_mode == 0) { #endif - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &need_mon; - } DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); if ( !conn->default_database.length() || @@ -9115,8 +9236,6 @@ int spider_db_udf_direct_sql_select_db( memcmp(direct_sql->tgt_default_db_name, conn->default_database.ptr(), direct_sql->tgt_default_db_name_length) ) { - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; - conn->mta_conn_mutex_lock_already = TRUE; if ( ( spider_db_before_query(conn, &need_mon) || @@ -9130,7 +9249,6 @@ int spider_db_udf_direct_sql_select_db( ) my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; DBUG_RETURN(error_num); } conn->default_database.length(0); @@ -9140,12 +9258,6 @@ int spider_db_udf_direct_sql_select_db( conn->default_database.q_append(direct_sql->tgt_default_db_name, direct_sql->tgt_default_db_name_length + 1); conn->default_database.length(direct_sql->tgt_default_db_name_length); - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; - } - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); } #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } @@ -9159,25 +9271,17 @@ int spider_db_udf_direct_sql_set_names( SPIDER_CONN *conn ) { int error_num, need_mon = 0; - bool tmp_mta_conn_mutex_lock_already; DBUG_ENTER("spider_db_udf_direct_sql_set_names"); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (direct_sql->access_mode == 0) { #endif - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &need_mon; - } DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); if ( !conn->access_charset || trx->udf_access_charset->cset != conn->access_charset->cset ) { - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; - conn->mta_conn_mutex_lock_already = TRUE; if ( ( spider_db_before_query(conn, &need_mon) || @@ -9192,17 +9296,10 @@ int spider_db_udf_direct_sql_set_names( my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); } - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; DBUG_RETURN(error_num); } - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; conn->access_charset = trx->udf_access_charset; } - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } #endif @@ -9266,13 +9363,18 @@ int spider_db_udf_ping_table( spider.conn_link_idx = &tmp_conn_link_idx; spider.db_request_phase = &db_request_phase; spider.db_request_id = &db_request_id; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_ping(&spider, conn, 0))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -9288,6 +9390,8 @@ int spider_db_udf_ping_table( share->server_names[0]); DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -9331,13 +9435,18 @@ int spider_db_udf_ping_table( my_error(error_num, MYF(0)); DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(&spider, conn, 0))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -9355,6 +9464,8 @@ int spider_db_udf_ping_table( -1, &need_mon) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -9363,6 +9474,8 @@ int spider_db_udf_ping_table( DBUG_PRINT("info",("spider error_num=%d", error_num)); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; spider_db_discard_result(&spider, 0, conn); @@ -9548,13 +9661,18 @@ int spider_db_udf_ping_table_mon_next( DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_ping(&spider, conn, 0))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -9565,6 +9683,8 @@ int spider_db_udf_ping_table_mon_next( } if ((error_num = spider_db_set_names(&spider, conn, 0))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -9579,6 +9699,8 @@ int spider_db_udf_ping_table_mon_next( -1, &need_mon) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); @@ -9591,13 +9713,25 @@ int spider_db_udf_ping_table_mon_next( request_key.next = NULL; if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; - if (error_num || (error_num = spider_db_errorno(conn))) + if (error_num) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) + { + DBUG_RETURN(error_num); + } my_error(HA_ERR_OUT_OF_MEM, MYF(0)); DBUG_RETURN(HA_ERR_OUT_OF_MEM); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -9678,8 +9812,22 @@ int spider_db_udf_copy_tables( spider_conn_clear_queue_at_commit(tmp_conn); if (!tmp_conn->trx_start) { + pthread_mutex_assert_not_owner(&tmp_conn->mta_conn_mutex); + pthread_mutex_lock(&tmp_conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + tmp_conn->need_mon = &tmp_spider->need_mons[0]; + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = TRUE; + tmp_conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_ping(tmp_spider, tmp_conn, 0)) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), tmp_spider->share->server_names[0]); error_num = ER_CONNECT_TO_FOREIGN_DATA_SOURCE; @@ -9689,8 +9837,21 @@ int spider_db_udf_copy_tables( (error_num = spider_db_set_names(tmp_spider, tmp_conn, 0)) || (error_num = spider_db_start_transaction(tmp_conn, tmp_spider->need_mons)) - ) + ) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); goto error_start_transaction; + } + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); } } } else { @@ -9710,8 +9871,22 @@ int spider_db_udf_copy_tables( { tmp_spider = &spider[roop_count]; tmp_conn = tmp_spider->conns[0]; + pthread_mutex_assert_not_owner(&tmp_conn->mta_conn_mutex); + pthread_mutex_lock(&tmp_conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + tmp_conn->need_mon = &tmp_spider->need_mons[0]; + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = TRUE; + tmp_conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_ping(tmp_spider, tmp_conn, 0)) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), tmp_spider->share->server_names[0]); error_num = ER_CONNECT_TO_FOREIGN_DATA_SOURCE; @@ -9724,11 +9899,23 @@ int spider_db_udf_copy_tables( (error_num = spider_db_lock_tables(tmp_spider, 0)) ) ) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); tmp_conn->table_lock = 0; if (error_num == HA_ERR_OUT_OF_MEM) my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); goto error_lock_tables; } + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); tmp_conn->table_lock = 1; } } @@ -9736,11 +9923,23 @@ int spider_db_udf_copy_tables( tmp_conn = src_tbl_conn->conn; spider_conn_set_timeout_from_share(tmp_conn, 0, copy_tables->trx->thd, src_tbl_conn->share); + pthread_mutex_assert_not_owner(&tmp_conn->mta_conn_mutex); + pthread_mutex_lock(&tmp_conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + tmp_conn->need_mon = &src_tbl_conn->need_mon; + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = TRUE; + tmp_conn->mta_conn_mutex_unlock_later = TRUE; if (select_ct->exec_query( tmp_conn, -1, &src_tbl_conn->need_mon) ) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(tmp_conn); if (error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM) my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, @@ -9769,6 +9968,10 @@ int spider_db_udf_copy_tables( my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); result->free_result(); delete result; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); goto error_db_query; @@ -9784,6 +9987,10 @@ int spider_db_udf_copy_tables( my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); result->free_result(); delete result; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); goto error_db_query; @@ -9810,6 +10017,10 @@ int spider_db_udf_copy_tables( my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); result->free_result(); delete result; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); goto error_db_query; @@ -9827,6 +10038,10 @@ int spider_db_udf_copy_tables( my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); result->free_result(); delete result; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); error_num = ER_OUT_OF_RESOURCES; @@ -9839,12 +10054,20 @@ int spider_db_udf_copy_tables( my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); result->free_result(); delete result; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); goto error_db_query; } result->free_result(); delete result; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); for (dst_tbl_conn = copy_tables->table_conn[1]; dst_tbl_conn; @@ -9865,6 +10088,12 @@ int spider_db_udf_copy_tables( } if (error_num) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); if (error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM) my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); @@ -9872,6 +10101,10 @@ int spider_db_udf_copy_tables( } error_num = HA_ERR_END_OF_FILE; end_of_file = TRUE; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); } @@ -9914,9 +10147,12 @@ int spider_db_udf_copy_tables( { tmp_conn = dst_tbl_conn->conn; insert_ct = dst_tbl_conn->copy_table; + pthread_mutex_assert_not_owner(&tmp_conn->mta_conn_mutex); pthread_mutex_lock(&tmp_conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); tmp_conn->need_mon = &dst_tbl_conn->need_mon; + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_unlock_later); tmp_conn->mta_conn_mutex_lock_already = TRUE; tmp_conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(tmp_conn, 0, @@ -9926,6 +10162,8 @@ int spider_db_udf_copy_tables( -1, &dst_tbl_conn->need_mon) ) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); tmp_conn->mta_conn_mutex_lock_already = FALSE; tmp_conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(tmp_conn); @@ -9934,6 +10172,8 @@ int spider_db_udf_copy_tables( ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); goto error_db_query; } else { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); tmp_conn->mta_conn_mutex_lock_already = FALSE; tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); @@ -10074,8 +10314,6 @@ int spider_db_open_handler( int link_idx ) { int error_num; - bool tmp_mta_conn_mutex_lock_already; - bool tmp_mta_conn_mutex_unlock_later; SPIDER_SHARE *share = spider->share; uint *handler_id_ptr = #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) @@ -10090,16 +10328,14 @@ int spider_db_open_handler( ; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; DBUG_ENTER("spider_db_open_handler"); - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &spider->need_mons[link_idx]; - } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; - tmp_mta_conn_mutex_unlock_later = conn->mta_conn_mutex_unlock_later; conn->mta_conn_mutex_unlock_later = TRUE; if (!spider->handler_opened(link_idx, conn->conn_kind)) *handler_id_ptr = conn->opened_handlers; @@ -10148,11 +10384,6 @@ int spider_db_open_handler( { my_printf_error(ER_SPIDER_HS_NUM, ER_SPIDER_HS_STR, MYF(0), conn->db_conn->get_errno(), conn->db_conn->get_error()); - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } spider->need_mons[link_idx] = ER_SPIDER_HS_NUM; error_num = ER_SPIDER_HS_NUM; goto error; @@ -10288,23 +10519,21 @@ int spider_db_open_handler( } DBUG_PRINT("info",("spider conn=%p", conn)); DBUG_PRINT("info",("spider opened_handlers=%u", conn->opened_handlers)); - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; - conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; - if (!tmp_mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); error: - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; - conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; - if (!tmp_mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } @@ -10354,6 +10583,7 @@ int spider_db_bulk_open_handler( } bool tmp_mta_conn_mutex_unlock_later; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); tmp_mta_conn_mutex_unlock_later = conn->mta_conn_mutex_unlock_later; conn->mta_conn_mutex_unlock_later = TRUE; SPIDER_DB_RESULT *result; @@ -10392,24 +10622,19 @@ int spider_db_close_handler( uint tgt_conn_kind ) { int error_num; - bool tmp_mta_conn_mutex_lock_already; - bool tmp_mta_conn_mutex_unlock_later; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; DBUG_ENTER("spider_db_close_handler"); DBUG_PRINT("info",("spider conn=%p", conn)); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider->handler_opened(link_idx, tgt_conn_kind)) { - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &spider->need_mons[link_idx]; - } - DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; - conn->mta_conn_mutex_lock_already = TRUE; - tmp_mta_conn_mutex_unlock_later = conn->mta_conn_mutex_unlock_later; - conn->mta_conn_mutex_unlock_later = TRUE; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) { @@ -10417,7 +10642,15 @@ int spider_db_close_handler( dbton_hdl->reset_sql(SPIDER_SQL_TYPE_HANDLER); if ((error_num = dbton_hdl->append_close_handler_part( SPIDER_SQL_TYPE_HANDLER, link_idx))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(error_num); + } spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, spider->share); @@ -10443,24 +10676,22 @@ int spider_db_close_handler( goto error; conn->opened_handlers--; DBUG_PRINT("info",("spider opened_handlers=%u", conn->opened_handlers)); - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; - conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; - if (!tmp_mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); error: - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; - conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; - if (!tmp_mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } @@ -10497,3 +10728,4 @@ bool spider_db_conn_is_network_error( } DBUG_RETURN(FALSE); } + diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index cf1a07715fc..b3114adbc36 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -1844,10 +1844,6 @@ void spider_db_mysql::print_warnings( if (!(db_conn->server_status & SERVER_MORE_RESULTS_EXISTS)) #endif { -/* - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); -*/ if ( spider_param_dry_access() || !mysql_real_query(db_conn, SPIDER_SQL_SHOW_WARNINGS_STR, @@ -1865,18 +1861,10 @@ void spider_db_mysql::print_warnings( { if (res) mysql_free_result(res); -/* - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); -*/ DBUG_VOID_RETURN; } /* no record is ok */ } -/* - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); -*/ num_fields = mysql_num_fields(res); if (num_fields != 3) { @@ -1895,11 +1883,6 @@ void spider_db_mysql::print_warnings( } if (res) mysql_free_result(res); - } else { -/* - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); -*/ } } } @@ -2039,14 +2022,31 @@ int spider_db_mysql::consistent_snapshot( ) { DBUG_ENTER("spider_db_mysql::consistent_snapshot"); DBUG_PRINT("info",("spider this=%p", this)); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_START_CONSISTENT_SNAPSHOT_STR, SPIDER_SQL_START_CONSISTENT_SNAPSHOT_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); @@ -2064,16 +2064,18 @@ int spider_db_mysql::start_transaction( ) { DBUG_ENTER("spider_db_mysql::start_transaction"); DBUG_PRINT("info",("spider this=%p", this)); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); if (spider_db_query( conn, SPIDER_SQL_START_TRANSACTION_STR, SPIDER_SQL_START_TRANSACTION_LEN, -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); } @@ -2082,14 +2084,31 @@ int spider_db_mysql::commit( ) { DBUG_ENTER("spider_db_mysql::commit"); DBUG_PRINT("info",("spider this=%p", this)); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_COMMIT_STR, SPIDER_SQL_COMMIT_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); @@ -2102,6 +2121,13 @@ int spider_db_mysql::rollback( int error_num; DBUG_ENTER("spider_db_mysql::rollback"); DBUG_PRINT("info",("spider this=%p", this)); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, @@ -2118,12 +2144,18 @@ int spider_db_mysql::rollback( ) conn->thd->clear_error(); else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); @@ -2160,14 +2192,31 @@ int spider_db_mysql::xa_end( sql_str.length(0); sql_str.q_append(SPIDER_SQL_XA_END_STR, SPIDER_SQL_XA_END_LEN); spider_db_append_xid_str(&sql_str, xid); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, sql_str.ptr(), sql_str.length(), -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); @@ -2186,14 +2235,31 @@ int spider_db_mysql::xa_prepare( sql_str.length(0); sql_str.q_append(SPIDER_SQL_XA_PREPARE_STR, SPIDER_SQL_XA_PREPARE_LEN); spider_db_append_xid_str(&sql_str, xid); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, sql_str.ptr(), sql_str.length(), -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); @@ -2212,14 +2278,31 @@ int spider_db_mysql::xa_commit( sql_str.length(0); sql_str.q_append(SPIDER_SQL_XA_COMMIT_STR, SPIDER_SQL_XA_COMMIT_LEN); spider_db_append_xid_str(&sql_str, xid); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, sql_str.ptr(), sql_str.length(), -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); @@ -2238,14 +2321,31 @@ int spider_db_mysql::xa_rollback( sql_str.length(0); sql_str.q_append(SPIDER_SQL_XA_ROLLBACK_STR, SPIDER_SQL_XA_ROLLBACK_LEN); spider_db_append_xid_str(&sql_str, xid); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, sql_str.ptr(), sql_str.length(), -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); @@ -2267,50 +2367,118 @@ int spider_db_mysql::set_trx_isolation( switch (trx_isolation) { case ISO_READ_UNCOMMITTED: + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_ISO_READ_UNCOMMITTED_STR, SPIDER_SQL_ISO_READ_UNCOMMITTED_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); break; case ISO_READ_COMMITTED: + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_ISO_READ_COMMITTED_STR, SPIDER_SQL_ISO_READ_COMMITTED_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); break; case ISO_REPEATABLE_READ: + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_ISO_REPEATABLE_READ_STR, SPIDER_SQL_ISO_REPEATABLE_READ_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); break; case ISO_SERIALIZABLE: + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_ISO_SERIALIZABLE_STR, SPIDER_SQL_ISO_SERIALIZABLE_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); break; @@ -2335,25 +2503,59 @@ int spider_db_mysql::set_autocommit( DBUG_PRINT("info",("spider this=%p", this)); if (autocommit) { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_AUTOCOMMIT_ON_STR, SPIDER_SQL_AUTOCOMMIT_ON_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } else { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_AUTOCOMMIT_OFF_STR, SPIDER_SQL_AUTOCOMMIT_OFF_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -2375,25 +2577,59 @@ int spider_db_mysql::set_sql_log_off( DBUG_PRINT("info",("spider this=%p", this)); if (sql_log_off) { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_SQL_LOG_ON_STR, SPIDER_SQL_SQL_LOG_ON_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } else { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_SQL_LOG_OFF_STR, SPIDER_SQL_SQL_LOG_OFF_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -2424,14 +2660,31 @@ int spider_db_mysql::set_time_zone( sql_str.q_append(SPIDER_SQL_TIME_ZONE_STR, SPIDER_SQL_TIME_ZONE_LEN); sql_str.q_append(tz_str->ptr(), tz_str->length()); sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, sql_str.ptr(), sql_str.length(), -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); @@ -4959,6 +5212,14 @@ int spider_mysql_share::discover_table_structure( ) { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (!conn->disable_reconnect) { ha_spider tmp_spider; @@ -4971,14 +5232,15 @@ int spider_mysql_share::discover_table_structure( if ((error_num = spider_db_ping(&tmp_spider, conn, 0))) { DBUG_PRINT("info",("spider spider_db_ping error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); continue; } } - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &need_mon; - conn->mta_conn_mutex_lock_already = TRUE; - conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, roop_count, trx->thd, spider_share); if ( @@ -4995,6 +5257,8 @@ int spider_mysql_share::discover_table_structure( ) ) { DBUG_PRINT("info",("spider spider_get_trx error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5014,6 +5278,8 @@ int spider_mysql_share::discover_table_structure( if (error_num || (error_num = spider_db_errorno(conn))) { DBUG_PRINT("info",("spider column store error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5022,6 +5288,8 @@ int spider_mysql_share::discover_table_structure( } /* no record */ DBUG_PRINT("info",("spider column no record error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5034,6 +5302,8 @@ int spider_mysql_share::discover_table_structure( DBUG_PRINT("info",("spider column fetch error")); res->free_result(); delete res; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5050,6 +5320,8 @@ int spider_mysql_share::discover_table_structure( if (conn->db_conn->next_result()) { DBUG_PRINT("info",("spider single result error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5062,6 +5334,8 @@ int spider_mysql_share::discover_table_structure( if (error_num || (error_num = spider_db_errorno(conn))) { DBUG_PRINT("info",("spider index store error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5070,6 +5344,8 @@ int spider_mysql_share::discover_table_structure( } /* no record */ DBUG_PRINT("info",("spider index no record error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5082,6 +5358,8 @@ int spider_mysql_share::discover_table_structure( DBUG_PRINT("info",("spider index fetch error")); res->free_result(); delete res; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5093,6 +5371,8 @@ int spider_mysql_share::discover_table_structure( if (conn->db_conn->next_result()) { DBUG_PRINT("info",("spider dual result error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5105,6 +5385,8 @@ int spider_mysql_share::discover_table_structure( if (error_num || (error_num = spider_db_errorno(conn))) { DBUG_PRINT("info",("spider table store error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5113,6 +5395,8 @@ int spider_mysql_share::discover_table_structure( } /* no record */ DBUG_PRINT("info",("spider table no record error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5125,6 +5409,8 @@ int spider_mysql_share::discover_table_structure( DBUG_PRINT("info",("spider table fetch error")); res->free_result(); delete res; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5133,6 +5419,8 @@ int spider_mysql_share::discover_table_structure( } res->free_result(); delete res; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10273,9 +10561,12 @@ int spider_mysql_handler::show_table_status( DBUG_PRINT("info",("spider sts_mode=%d", sts_mode)); if (sts_mode == 1) { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10299,6 +10590,8 @@ int spider_mysql_handler::show_table_status( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10307,6 +10600,8 @@ int spider_mysql_handler::show_table_status( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10322,11 +10617,15 @@ int spider_mysql_handler::show_table_status( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10342,6 +10641,8 @@ int spider_mysql_handler::show_table_status( request_key.next = NULL; if (spider_param_dry_access()) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10350,9 +10651,17 @@ int spider_mysql_handler::show_table_status( } if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; - if (error_num || (error_num = spider_db_errorno(conn))) + if (error_num) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) DBUG_RETURN(error_num); else { my_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM, @@ -10363,6 +10672,8 @@ int spider_mysql_handler::show_table_status( DBUG_RETURN(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10405,9 +10716,12 @@ int spider_mysql_handler::show_table_status( DBUG_RETURN(error_num); } } else { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10431,6 +10745,8 @@ int spider_mysql_handler::show_table_status( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10439,6 +10755,8 @@ int spider_mysql_handler::show_table_status( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10454,11 +10772,15 @@ int spider_mysql_handler::show_table_status( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10474,6 +10796,8 @@ int spider_mysql_handler::show_table_status( request_key.next = NULL; if (spider_param_dry_access()) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10482,6 +10806,8 @@ int spider_mysql_handler::show_table_status( } if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (error_num || (error_num = spider_db_errorno(conn))) @@ -10489,6 +10815,8 @@ int spider_mysql_handler::show_table_status( else DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10572,9 +10900,12 @@ int spider_mysql_handler::show_index( DBUG_PRINT("info",("spider crd_mode=%d", crd_mode)); if (crd_mode == 1) { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10598,6 +10929,8 @@ int spider_mysql_handler::show_index( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10606,6 +10939,8 @@ int spider_mysql_handler::show_index( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10621,11 +10956,15 @@ int spider_mysql_handler::show_index( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10643,6 +10982,8 @@ int spider_mysql_handler::show_index( { if (error_num || (error_num = spider_db_errorno(conn))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10651,6 +10992,8 @@ int spider_mysql_handler::show_index( } /* no record is ok */ } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10705,9 +11048,12 @@ int spider_mysql_handler::show_index( DBUG_RETURN(error_num); } } else { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10731,6 +11077,8 @@ int spider_mysql_handler::show_index( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10739,6 +11087,8 @@ int spider_mysql_handler::show_index( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10754,11 +11104,15 @@ int spider_mysql_handler::show_index( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10776,6 +11130,8 @@ int spider_mysql_handler::show_index( { if (error_num || (error_num = spider_db_errorno(conn))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10784,6 +11140,8 @@ int spider_mysql_handler::show_index( } /* no record is ok */ } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10850,9 +11208,12 @@ int spider_mysql_handler::show_records( SPIDER_SHARE *share = spider->share; uint pos = spider->conn_link_idx[link_idx]; DBUG_ENTER("spider_mysql_handler::show_records"); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10876,6 +11237,8 @@ int spider_mysql_handler::show_records( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10885,6 +11248,8 @@ int spider_mysql_handler::show_records( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10901,12 +11266,16 @@ int spider_mysql_handler::show_records( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_PRINT("info", ("spider error_num=%d 3", error_num)); DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10923,18 +11292,29 @@ int spider_mysql_handler::show_records( request_key.next = NULL; if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; - if (error_num || (error_num = spider_db_errorno(conn))) + if (error_num) { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_PRINT("info", ("spider error_num=%d 5", error_num)); DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info", ("spider error_num=%d 6", error_num)); + DBUG_RETURN(error_num); } else { - DBUG_PRINT("info", ("spider error_num=%d 6", + DBUG_PRINT("info", ("spider error_num=%d 7", ER_QUERY_ON_FOREIGN_DATA_SOURCE)); DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10984,9 +11364,12 @@ ha_rows spider_mysql_handler::explain_select( DBUG_RETURN(HA_POS_ERROR); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -11012,6 +11395,8 @@ ha_rows spider_mysql_handler::explain_select( { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11022,6 +11407,8 @@ ha_rows spider_mysql_handler::explain_select( { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11040,6 +11427,8 @@ ha_rows spider_mysql_handler::explain_select( error_num = spider_db_errorno(conn); if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11049,6 +11438,8 @@ ha_rows spider_mysql_handler::explain_select( } else { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11068,6 +11459,8 @@ ha_rows spider_mysql_handler::explain_select( { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11075,6 +11468,8 @@ ha_rows spider_mysql_handler::explain_select( DBUG_RETURN(HA_POS_ERROR); } else { my_errno = ER_QUERY_ON_FOREIGN_DATA_SOURCE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11082,6 +11477,8 @@ ha_rows spider_mysql_handler::explain_select( DBUG_RETURN(HA_POS_ERROR); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11114,13 +11511,18 @@ int spider_mysql_handler::lock_tables( } if (str->length()) { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11136,10 +11538,14 @@ int spider_mysql_handler::lock_tables( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11174,14 +11580,31 @@ int spider_mysql_handler::unlock_tables( { spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, spider->share); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, str->ptr(), str->length(), -1, &spider->need_mons[link_idx]) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -11204,13 +11627,18 @@ int spider_mysql_handler::disable_keys( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11226,11 +11654,15 @@ int spider_mysql_handler::disable_keys( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11253,13 +11685,18 @@ int spider_mysql_handler::enable_keys( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11275,11 +11712,15 @@ int spider_mysql_handler::enable_keys( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11303,13 +11744,18 @@ int spider_mysql_handler::check_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11325,11 +11771,15 @@ int spider_mysql_handler::check_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11353,13 +11803,18 @@ int spider_mysql_handler::repair_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11375,11 +11830,15 @@ int spider_mysql_handler::repair_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11402,13 +11861,18 @@ int spider_mysql_handler::analyze_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11424,11 +11888,15 @@ int spider_mysql_handler::analyze_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11451,13 +11919,18 @@ int spider_mysql_handler::optimize_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11473,11 +11946,15 @@ int spider_mysql_handler::optimize_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11503,6 +11980,14 @@ int spider_mysql_handler::flush_tables( } spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, share); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, str->ptr(), @@ -11510,9 +11995,17 @@ int spider_mysql_handler::flush_tables( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); @@ -11528,6 +12021,14 @@ int spider_mysql_handler::flush_logs( DBUG_PRINT("info",("spider this=%p", this)); spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, share); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_FLUSH_LOGS_STR, @@ -11535,9 +12036,17 @@ int spider_mysql_handler::flush_logs( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc index 4622f3254a1..dd81352bb5e 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -1780,16 +1780,18 @@ int spider_db_oracle::start_transaction( } DBUG_RETURN(set_trx_isolation(conn->trx_isolation, need_mon)); } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); if (spider_db_query( conn, SPIDER_SQL_START_TRANSACTION_STR, SPIDER_SQL_START_TRANSACTION_LEN, -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); } @@ -1978,14 +1980,31 @@ int spider_db_oracle::set_trx_isolation( DBUG_RETURN(exec_query(SPIDER_SQL_ISO_READ_COMMITTED_STR, SPIDER_SQL_ISO_READ_COMMITTED_LEN, -1)); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_ISO_READ_COMMITTED_STR, SPIDER_SQL_ISO_READ_COMMITTED_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); break; @@ -1996,14 +2015,31 @@ int spider_db_oracle::set_trx_isolation( DBUG_RETURN(exec_query(SPIDER_SQL_ISO_SERIALIZABLE_STR, SPIDER_SQL_ISO_SERIALIZABLE_LEN, -1)); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_ISO_SERIALIZABLE_STR, SPIDER_SQL_ISO_SERIALIZABLE_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); break; @@ -2033,14 +2069,31 @@ int spider_db_oracle::set_autocommit( DBUG_RETURN(exec_query(SPIDER_SQL_AUTOCOMMIT_ON_STR, SPIDER_SQL_AUTOCOMMIT_ON_LEN, -1)); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_AUTOCOMMIT_ON_STR, SPIDER_SQL_AUTOCOMMIT_ON_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } else { @@ -2049,14 +2102,31 @@ int spider_db_oracle::set_autocommit( DBUG_RETURN(exec_query(SPIDER_SQL_AUTOCOMMIT_OFF_STR, SPIDER_SQL_AUTOCOMMIT_OFF_LEN, -1)); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_AUTOCOMMIT_OFF_STR, SPIDER_SQL_AUTOCOMMIT_OFF_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -10390,112 +10460,6 @@ int spider_oracle_handler::show_table_status( if (sts_mode == 1) { -/* - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &spider->need_mons[link_idx]; - conn->mta_conn_mutex_lock_already = TRUE; - conn->mta_conn_mutex_unlock_later = TRUE; - spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, - share); - if ( - (error_num = spider_db_set_names(spider, conn, link_idx)) || - ( - spider_db_query( - conn, - oracle_share->show_table_status[0 + pos].ptr(), - oracle_share->show_table_status[0 + pos].length(), - -1, - &spider->need_mons[link_idx]) && - (error_num = spider_db_errorno(conn)) - ) - ) { - if ( - error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && - !conn->disable_reconnect - ) { -*/ - /* retry */ -/* - if ((error_num = spider_db_ping(spider, conn, link_idx))) - { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - DBUG_RETURN(error_num); - } - if ((error_num = spider_db_set_names(spider, conn, link_idx))) - { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - DBUG_RETURN(error_num); - } - spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, - share); - if (spider_db_query( - conn, - oracle_share->show_table_status[0 + pos].ptr(), - oracle_share->show_table_status[0 + pos].length(), - -1, - &spider->need_mons[link_idx]) - ) { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - DBUG_RETURN(spider_db_errorno(conn)); - } - } else { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - DBUG_RETURN(error_num); - } - } - st_spider_db_request_key request_key; - request_key.spider_thread_id = spider->trx->spider_thread_id; - request_key.query_id = spider->trx->thd->query_id; - request_key.handler = spider; - request_key.request_id = 1; - request_key.next = NULL; - if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) - { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - if (error_num || (error_num = spider_db_errorno(conn))) - DBUG_RETURN(error_num); - else { - my_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM, - ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR, MYF(0), - oracle_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), - oracle_share->table_names_str[spider->conn_link_idx[ - link_idx]].ptr()); - DBUG_RETURN(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM); - } - } - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - error_num = res->fetch_table_status( - sts_mode, - share->records, - share->mean_rec_length, - share->data_file_length, - share->max_data_file_length, - share->index_file_length, - auto_increment_value, - share->create_time, - share->update_time, - share->check_time - ); - res->free_result(); - delete res; - if (error_num) - DBUG_RETURN(error_num); -*/ if (!share->records) share->records = 10000; share->mean_rec_length = 65535; @@ -10506,9 +10470,12 @@ int spider_oracle_handler::show_table_status( share->update_time = (time_t) 0; share->check_time = (time_t) 0; } else { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10532,6 +10499,8 @@ int spider_oracle_handler::show_table_status( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10540,6 +10509,8 @@ int spider_oracle_handler::show_table_status( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10555,11 +10526,15 @@ int spider_oracle_handler::show_table_status( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10575,6 +10550,8 @@ int spider_oracle_handler::show_table_status( request_key.next = NULL; if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (error_num || (error_num = spider_db_errorno(conn))) @@ -10582,6 +10559,8 @@ int spider_oracle_handler::show_table_status( else DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10636,105 +10615,6 @@ int spider_oracle_handler::show_index( DBUG_PRINT("info",("spider crd_mode=%d", crd_mode)); if (crd_mode == 1) { -/* - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &spider->need_mons[link_idx]; - conn->mta_conn_mutex_lock_already = TRUE; - conn->mta_conn_mutex_unlock_later = TRUE; - spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, - share); - if ( - (error_num = spider_db_set_names(spider, conn, link_idx)) || - ( - spider_db_query( - conn, - oracle_share->show_index[0 + pos].ptr(), - oracle_share->show_index[0 + pos].length(), - -1, - &spider->need_mons[link_idx]) && - (error_num = spider_db_errorno(conn)) - ) - ) { - if ( - error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && - !conn->disable_reconnect - ) { -*/ - /* retry */ -/* - if ((error_num = spider_db_ping(spider, conn, link_idx))) - { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - DBUG_RETURN(error_num); - } - if ((error_num = spider_db_set_names(spider, conn, link_idx))) - { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - DBUG_RETURN(error_num); - } - spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, - share); - if (spider_db_query( - conn, - oracle_share->show_index[0 + pos].ptr(), - oracle_share->show_index[0 + pos].length(), - -1, - &spider->need_mons[link_idx]) - ) { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - DBUG_RETURN(spider_db_errorno(conn)); - } - } else { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - DBUG_RETURN(error_num); - } - } - st_spider_db_request_key request_key; - request_key.spider_thread_id = spider->trx->spider_thread_id; - request_key.query_id = spider->trx->thd->query_id; - request_key.handler = spider; - request_key.request_id = 1; - request_key.next = NULL; - if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) - { - if (error_num || (error_num = spider_db_errorno(conn))) - { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - DBUG_RETURN(error_num); - } -*/ - /* no record is ok */ -/* - } - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - if (res) - { - error_num = res->fetch_table_cardinality( - crd_mode, - table, - share->cardinality, - share->cardinality_upd, - share->bitmap_size - ); - } -*/ for (roop_count = 0, tmp_cardinality = share->cardinality; roop_count < (int) table->s->fields; roop_count++, tmp_cardinality++) @@ -10746,19 +10626,13 @@ int spider_oracle_handler::show_index( *tmp_cardinality = 1; } } -/* - if (res) - { - res->free_result(); - delete res; - } - if (error_num) - DBUG_RETURN(error_num); -*/ } else { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10782,6 +10656,8 @@ int spider_oracle_handler::show_index( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10790,6 +10666,8 @@ int spider_oracle_handler::show_index( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10805,11 +10683,15 @@ int spider_oracle_handler::show_index( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10827,6 +10709,8 @@ int spider_oracle_handler::show_index( { if (error_num || (error_num = spider_db_errorno(conn))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10835,6 +10719,8 @@ int spider_oracle_handler::show_index( } /* no record is ok */ } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10880,9 +10766,12 @@ int spider_oracle_handler::show_records( SPIDER_SHARE *share = spider->share; uint pos = spider->conn_link_idx[link_idx]; DBUG_ENTER("spider_oracle_handler::show_records"); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10906,6 +10795,8 @@ int spider_oracle_handler::show_records( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10915,6 +10806,8 @@ int spider_oracle_handler::show_records( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10931,12 +10824,16 @@ int spider_oracle_handler::show_records( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_PRINT("info", ("spider error_num=%d 3", error_num)); DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10953,18 +10850,29 @@ int spider_oracle_handler::show_records( request_key.next = NULL; if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; - if (error_num || (error_num = spider_db_errorno(conn))) + if (error_num) { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_PRINT("info", ("spider error_num=%d 5", error_num)); DBUG_RETURN(error_num); + } + else if (error_num || (error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info", ("spider error_num=%d 6", error_num)); + DBUG_RETURN(error_num); } else { - DBUG_PRINT("info", ("spider error_num=%d 6", + DBUG_PRINT("info", ("spider error_num=%d 7", ER_QUERY_ON_FOREIGN_DATA_SOURCE)); DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10997,9 +10905,12 @@ int spider_oracle_handler::show_autoinc( if (!oracle_share->show_autoinc) DBUG_RETURN(0); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -11023,6 +10934,8 @@ int spider_oracle_handler::show_autoinc( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11032,6 +10945,8 @@ int spider_oracle_handler::show_autoinc( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11048,12 +10963,16 @@ int spider_oracle_handler::show_autoinc( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_PRINT("info", ("spider error_num=%d 3", error_num)); DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11070,18 +10989,29 @@ int spider_oracle_handler::show_autoinc( request_key.next = NULL; if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; - if (error_num || (error_num = spider_db_errorno(conn))) + if (error_num) { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_PRINT("info", ("spider error_num=%d 5", error_num)); DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info", ("spider error_num=%d 6", error_num)); + DBUG_RETURN(error_num); } else { - DBUG_PRINT("info", ("spider error_num=%d 6", + DBUG_PRINT("info", ("spider error_num=%d 7", ER_QUERY_ON_FOREIGN_DATA_SOURCE)); DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11191,9 +11121,12 @@ ha_rows spider_oracle_handler::explain_select( DBUG_RETURN(HA_POS_ERROR); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -11219,6 +11152,8 @@ ha_rows spider_oracle_handler::explain_select( { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11229,6 +11164,8 @@ ha_rows spider_oracle_handler::explain_select( { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11247,6 +11184,8 @@ ha_rows spider_oracle_handler::explain_select( error_num = spider_db_errorno(conn); if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11256,6 +11195,8 @@ ha_rows spider_oracle_handler::explain_select( } else { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11275,6 +11216,8 @@ ha_rows spider_oracle_handler::explain_select( { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11282,6 +11225,8 @@ ha_rows spider_oracle_handler::explain_select( DBUG_RETURN(HA_POS_ERROR); } else { my_errno = ER_QUERY_ON_FOREIGN_DATA_SOURCE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11289,6 +11234,8 @@ ha_rows spider_oracle_handler::explain_select( DBUG_RETURN(HA_POS_ERROR); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11322,13 +11269,18 @@ int spider_oracle_handler::lock_tables( } if (str->length()) { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11344,10 +11296,14 @@ int spider_oracle_handler::lock_tables( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11393,13 +11349,18 @@ int spider_oracle_handler::disable_keys( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11415,11 +11376,15 @@ int spider_oracle_handler::disable_keys( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11442,13 +11407,18 @@ int spider_oracle_handler::enable_keys( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11464,11 +11434,15 @@ int spider_oracle_handler::enable_keys( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11492,13 +11466,18 @@ int spider_oracle_handler::check_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11514,11 +11493,15 @@ int spider_oracle_handler::check_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11542,13 +11525,18 @@ int spider_oracle_handler::repair_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11564,11 +11552,15 @@ int spider_oracle_handler::repair_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11591,13 +11583,18 @@ int spider_oracle_handler::analyze_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11613,11 +11610,15 @@ int spider_oracle_handler::analyze_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11640,13 +11641,18 @@ int spider_oracle_handler::optimize_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11662,11 +11668,15 @@ int spider_oracle_handler::optimize_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11692,6 +11702,14 @@ int spider_oracle_handler::flush_tables( } spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, share); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, str->ptr(), @@ -11699,9 +11717,17 @@ int spider_oracle_handler::flush_tables( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); @@ -11717,6 +11743,14 @@ int spider_oracle_handler::flush_logs( DBUG_PRINT("info",("spider this=%p", this)); spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, share); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_FLUSH_LOGS_STR, @@ -11724,9 +11758,17 @@ int spider_oracle_handler::flush_logs( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_RETURN(0); diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index 472bcea298e..accb875bfd9 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -17,6 +17,8 @@ #define SPIDER_HEX_VERSION 0x0302 #if MYSQL_VERSION_ID < 50500 +#define pthread_mutex_assert_owner(A) +#define pthread_mutex_assert_not_owner(A) #else #define my_free(A,B) my_free(A) #ifdef pthread_mutex_t @@ -39,6 +41,8 @@ #undef pthread_mutex_destroy #endif #define pthread_mutex_destroy mysql_mutex_destroy +#define pthread_mutex_assert_owner(A) mysql_mutex_assert_owner(A) +#define pthread_mutex_assert_not_owner(A) mysql_mutex_assert_not_owner(A) #ifdef pthread_cond_t #undef pthread_cond_t #endif diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index 9726afdd66e..48f7dc135e8 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -5809,13 +5809,18 @@ int spider_open_all_tables( } conn->error_mode &= spider_param_error_read_mode(thd, 0); conn->error_mode &= spider_param_error_write_mode(thd, 0); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &mon_val; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_before_query(conn, &mon_val))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5828,6 +5833,8 @@ int spider_open_all_tables( free_root(&mem_root, MYF(0)); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); From a8f6bbb7a804472f1a8f08b6f05b456c265c9a6c Mon Sep 17 00:00:00 2001 From: Sujatha Date: Tue, 30 Jun 2020 16:42:44 +0530 Subject: [PATCH 04/48] MDEV-9501: rpl.rpl_binlog_index, rpl.rpl_gtid_crash, rpl.rpl_stm_multi_query fail sporadically in buildbot with Master command COM_REGISTER_SLAVE failed Analysis: ======== Slave server will send COM_REGISTER_SLAVE command at the time of establishing a connection to master. If master is down, then the command will fail and COM_REGISTER_SLAVE failed warning is reported. 'rpl_binlog_index.test' shutsdown the master and it relocates binary logs to a new location and attempts to start master by pointing 'log-bin' to new location. During this process the slave threads are active. IO thread actively checks for the presence of master when it finds that the connection is lost it attempts a reconnect, as master is down COM_REGISTER_SLAVE command fails. As part of fix, stop the slave threads and then shutdown the master and do the binlog relocation. Once master is restarted start the slave threads and sync them with the master. In test binary logs and index files on master are relocated to /tmpdir but during master restart only --log-bin option is provided, this is incorrect. Even --log-bin-index also should be pointed to /tmpdir otherwise upon master server restart two index files will be created. One master-bin.index in /tmpdir and a new master-bin.index as per log_basename in datadir. Due to this slave will fail to connect to master. 'rpl_gtid_crash.test' tests following scenario "crashing master, causing slave IO thread to reconnect while SQL thread is running". When IO thread tries to connect to crashed master on slow platforms COM_REGISTER_SLAVE command fails. This is expected hence the warning should be added to suppression list. --- mysql-test/suite/rpl/r/rpl_binlog_index.result | 4 ++++ mysql-test/suite/rpl/r/rpl_gtid_crash.result | 3 +++ mysql-test/suite/rpl/t/rpl_binlog_index.test | 18 +++++++++++++----- mysql-test/suite/rpl/t/rpl_gtid_crash.test | 3 +++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_binlog_index.result b/mysql-test/suite/rpl/r/rpl_binlog_index.result index 6611a9ef2c0..0a53c6f76ee 100644 --- a/mysql-test/suite/rpl/r/rpl_binlog_index.result +++ b/mysql-test/suite/rpl/r/rpl_binlog_index.result @@ -3,18 +3,22 @@ include/master-slave.inc CREATE TABLE t1 (a INT); FLUSH BINARY LOGS; INSERT INTO t1 VALUES (1); +include/stop_slave.inc # Shutdown master include/rpl_stop_server.inc [server_number=1] # Move the master binlog files and the index file to a new place # Restart master with log-bin option set to the new path # Master has restarted successfully +include/start_slave.inc # Create the master-bin.index file with the old format +include/stop_slave.inc # Shutdown master include/rpl_stop_server.inc [server_number=1] # Move back the master binlog files # Remove the unneeded master-bin.index file # Restart master with log-bin option set to default # Master has restarted successfully +include/start_slave.inc # stop slave include/stop_slave.inc include/rpl_stop_server.inc [server_number=2] diff --git a/mysql-test/suite/rpl/r/rpl_gtid_crash.result b/mysql-test/suite/rpl/r/rpl_gtid_crash.result index 5f67901b7f5..630098b18c9 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_crash.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_crash.result @@ -7,6 +7,9 @@ flush tables; ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; INSERT INTO t1 VALUES (1, 0); +SET sql_log_bin=0; +call mtr.add_suppression('Master command COM_REGISTER_SLAVE failed: failed registering on master, reconnecting to try again'); +SET sql_log_bin=1; include/stop_slave.inc CHANGE MASTER TO master_host = '127.0.0.1', master_port = MASTER_PORT, MASTER_USE_GTID=CURRENT_POS; diff --git a/mysql-test/suite/rpl/t/rpl_binlog_index.test b/mysql-test/suite/rpl/t/rpl_binlog_index.test index 8586b1d7489..95c49c3d574 100644 --- a/mysql-test/suite/rpl/t/rpl_binlog_index.test +++ b/mysql-test/suite/rpl/t/rpl_binlog_index.test @@ -43,7 +43,7 @@ FLUSH BINARY LOGS; INSERT INTO t1 VALUES (1); sync_slave_with_master; - +--source include/stop_slave.inc # # Test on master # @@ -58,13 +58,15 @@ source include/rpl_stop_server.inc; --move_file $master_datadir/master-bin.index $tmpdir/master-bin.index --echo # Restart master with log-bin option set to the new path ---let $rpl_server_parameters=--log-bin=$tmpdir/master-bin +--let $rpl_server_parameters=--log-bin=$tmpdir/master-bin --log-bin-index=$tmpdir/master-bin --let $keep_include_silent=1 source include/rpl_start_server.inc; --let $keep_include_silent=0 --echo # Master has restarted successfully - +--connection slave +--source include/start_slave.inc +--connection master # # Test master can handle old format with directory path in index file # @@ -85,7 +87,10 @@ if (!$is_windows) --disable_query_log source include/write_var_to_file.inc; --enable_query_log +--sync_slave_with_master +--source include/stop_slave.inc +--connection master --echo # Shutdown master --let $rpl_server_number=1 source include/rpl_stop_server.inc; @@ -99,14 +104,17 @@ source include/rpl_stop_server.inc; --remove_file $tmpdir/master-bin.index --echo # Restart master with log-bin option set to default ---let $rpl_server_parameters=--log-bin=$master_datadir/master-bin +--let $rpl_server_parameters=--log-bin=$master_datadir/master-bin --log-bin-index=$master_datadir/master-bin --let $keep_include_silent=1 source include/rpl_start_server.inc; --let $keep_include_silent=0 --echo # Master has restarted successfully +--connection slave +--source include/start_slave.inc -connection slave; +--connection master +--sync_slave_with_master --echo # stop slave --source include/stop_slave.inc --let $rpl_server_number= 2 diff --git a/mysql-test/suite/rpl/t/rpl_gtid_crash.test b/mysql-test/suite/rpl/t/rpl_gtid_crash.test index b81cbd38cd3..84bf76501d8 100644 --- a/mysql-test/suite/rpl/t/rpl_gtid_crash.test +++ b/mysql-test/suite/rpl/t/rpl_gtid_crash.test @@ -21,6 +21,9 @@ INSERT INTO t1 VALUES (1, 0); --connection server_2 --sync_with_master +SET sql_log_bin=0; +call mtr.add_suppression('Master command COM_REGISTER_SLAVE failed: failed registering on master, reconnecting to try again'); +SET sql_log_bin=1; --source include/stop_slave.inc --replace_result $MASTER_MYPORT MASTER_PORT eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $MASTER_MYPORT, From 5c07ce406b4ce28064832e72afc79845aac7a46a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 9 Sep 2020 16:03:15 +0300 Subject: [PATCH 05/48] MDEV-23706 : Galera test failure on galera_autoinc_sst_mariabackup Remove infinite procedure and use direct INSERTs. --- .../r/galera_autoinc_sst_mariabackup.result | 69 +++++++------- .../t/galera_autoinc_sst_mariabackup.test | 95 +++++++------------ 2 files changed, 66 insertions(+), 98 deletions(-) diff --git a/mysql-test/suite/galera/r/galera_autoinc_sst_mariabackup.result b/mysql-test/suite/galera/r/galera_autoinc_sst_mariabackup.result index d0fac1e3d14..432b56a94ce 100644 --- a/mysql-test/suite/galera/r/galera_autoinc_sst_mariabackup.result +++ b/mysql-test/suite/galera/r/galera_autoinc_sst_mariabackup.result @@ -1,47 +1,44 @@ connection node_1; CREATE TABLE t1 (f1 INTEGER PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB; -CREATE PROCEDURE p1 () -BEGIN -DECLARE x INT DEFAULT 1; -DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; -WHILE 1 DO -INSERT INTO t1 VALUES (DEFAULT); -COMMIT; -END WHILE; -END| -CALL p1();; -connection node_2; -CALL p1();; +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2; connection node_2a; Killing server ... -INSERT INTO t1 VALUES (DEFAULT); +connection node_1; +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +connection node_2a; +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; connection node_1a; -INSERT INTO t1 VALUES (DEFAULT); -connection node_1; -Got one of the listed errors -connection node_2; -Got one of the listed errors -connection node_1a; +SELECT COUNT(*) FROM t1; +COUNT(*) +132 connection node_2a; -count_equal -1 -CALL mtr.add_suppression("WSREP: Action message in non-primary configuration from member 0"); -SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -VARIABLE_VALUE -2 -SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -VARIABLE_VALUE = 2 -1 -connection node_1a; -SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -VARIABLE_VALUE -2 -SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -VARIABLE_VALUE = 2 -1 -DROP PROCEDURE p1; +SELECT COUNT(*) FROM t1; +COUNT(*) +132 +connection node_1; DROP TABLE t1; CALL mtr.add_suppression("gcs_caused\\(\\) returned -1 \\(Operation not permitted\\)"); CALL mtr.add_suppression("WSREP: Action message in non-primary configuration from member 0"); +disconnect node_1a; +disconnect node_2a; diff --git a/mysql-test/suite/galera/t/galera_autoinc_sst_mariabackup.test b/mysql-test/suite/galera/t/galera_autoinc_sst_mariabackup.test index c8e053dc2b6..845bd736e21 100644 --- a/mysql-test/suite/galera/t/galera_autoinc_sst_mariabackup.test +++ b/mysql-test/suite/galera/t/galera_autoinc_sst_mariabackup.test @@ -2,90 +2,61 @@ # Test that autoincrement works correctly while the cluster membership # is changing and SST takes place. # - --source include/big_test.inc --source include/galera_cluster.inc ---source include/have_innodb.inc --source include/have_mariabackup.inc +--source include/force_restart.inc --connection node_1 ---let $connection_id = `SELECT CONNECTION_ID()` - CREATE TABLE t1 (f1 INTEGER PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB; -# Issue an endless stream of autoincrement inserts - -DELIMITER |; -CREATE PROCEDURE p1 () -BEGIN - DECLARE x INT DEFAULT 1; - DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; - - WHILE 1 DO - INSERT INTO t1 VALUES (DEFAULT); - COMMIT; - END WHILE; -END| -DELIMITER ;| - ---send CALL p1(); ---sleep 1 - ---connection node_2 ---send CALL p1(); ---sleep 1 +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); # Kill and restart node #2 - --connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2 --connection node_2a --source include/kill_galera.inc +--connection node_1 +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); + +--connection node_2a --source include/start_mysqld.inc +--source include/wait_until_connected_again.inc -INSERT INTO t1 VALUES (DEFAULT); - -# Terminate the stored procedure +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); +INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL); --connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1 --connection node_1a ---disable_query_log ---eval KILL CONNECTION $connection_id ---enable_query_log - -INSERT INTO t1 VALUES (DEFAULT); - ---connection node_1 -# CR_SERVER_LOST ---error 2013,2006 ---reap - ---connection node_2 -# CR_SERVER_LOST ---error 2013,2006 ---reap - -# Confirm that the count is correct and that the cluster is intact - ---connection node_1a ---let $count = `SELECT COUNT(*) FROM t1` +SELECT COUNT(*) FROM t1; --connection node_2a ---disable_query_log ---eval SELECT COUNT(*) = $count AS count_equal FROM t1 ---enable_query_log +SELECT COUNT(*) FROM t1; -CALL mtr.add_suppression("WSREP: Action message in non-primary configuration from member 0"); - -SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; - ---connection node_1a -SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; - -DROP PROCEDURE p1; +--connection node_1 DROP TABLE t1; CALL mtr.add_suppression("gcs_caused\\(\\) returned -1 \\(Operation not permitted\\)"); CALL mtr.add_suppression("WSREP: Action message in non-primary configuration from member 0"); + +--disconnect node_1a +--disconnect node_2a From 1bb3ad6dfc885112d05d8d73b066f18a416ca965 Mon Sep 17 00:00:00 2001 From: Geert Hendrickx Date: Thu, 27 Aug 2020 17:30:03 +0200 Subject: [PATCH 06/48] MDEV-23589: Portability: use `uname -n` instead of `hostname` Closes PR #1663 --- scripts/CMakeLists.txt | 2 +- support-files/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 33e32ea22f7..eafb051ad60 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -162,7 +162,7 @@ ELSE() SET(CHECK_PID "kill -s SIGCONT $PID > /dev/null 2> /dev/null") ENDIF() -SET(HOSTNAME "hostname") +SET(HOSTNAME "uname -n") SET(MYSQLD_USER "mysql") ENDIF(UNIX) diff --git a/support-files/CMakeLists.txt b/support-files/CMakeLists.txt index 80b6ca386df..2a17cf6d0d8 100644 --- a/support-files/CMakeLists.txt +++ b/support-files/CMakeLists.txt @@ -30,7 +30,7 @@ ELSE() SET(CXXFLAGS ${CMAKE_CXX_FLAGS}) SET(MYSQLD_USER "mysql") SET(ini_file_extension "cnf") - SET(HOSTNAME "hostname") + SET(HOSTNAME "uname -n") ENDIF() # XXX: shouldn't we just have variables for all this stuff and centralise From 75e82f71f16c3248387e00bc6e4fe4da02555325 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Wed, 9 Sep 2020 17:14:48 +0530 Subject: [PATCH 07/48] MDEV-18867 Long Time to Stop and Start fts_drop_orphaned_tables() takes long time to remove the orphaned FTS tables. In order to reduce the time, do the following: - Traverse fil_system.space_list and construct a set of table_id,index_id of all FTS_*.ibd tablespaces. - Traverse the sys_indexes table and ignore the entry from the above collection if it exist. - Existing elements in the collection can be considered as orphaned fts tables. construct the table name from (table_id,index_id) and invoke fts_drop_tables(). - Removed DICT_TF2_FTS_AUX_HEX_NAME flag usage from upgrade. - is_aux_table() in dict_table_t to check whether the given name is fts auxiliary table fts_space_set_t is a structure to store set of parent table id and index id - Remove unused FTS function in fts0fts.cc - Remove the fulltext index in row_format_redundant test case. Because it deals with the condition that SYS_TABLES does have corrupted entry and valid entry exist in SYS_INDEXES. --- .../innodb/r/row_format_redundant.result | 5 +- .../suite/innodb/t/row_format_redundant.test | 3 +- storage/innobase/fil/fil0fil.cc | 45 - storage/innobase/fts/fts0config.cc | 4 +- storage/innobase/fts/fts0fts.cc | 1564 +++-------------- storage/innobase/fts/fts0sql.cc | 11 +- storage/innobase/include/fil0fil.h | 12 - storage/innobase/include/fts0fts.h | 26 +- storage/innobase/include/fts0priv.h | 6 +- storage/innobase/include/fts0priv.ic | 10 +- storage/innobase/row/row0mysql.cc | 18 +- 11 files changed, 270 insertions(+), 1434 deletions(-) diff --git a/mysql-test/suite/innodb/r/row_format_redundant.result b/mysql-test/suite/innodb/r/row_format_redundant.result index 1a291a0e59f..6b5cd1b5ad0 100644 --- a/mysql-test/suite/innodb/r/row_format_redundant.result +++ b/mysql-test/suite/innodb/r/row_format_redundant.result @@ -5,8 +5,7 @@ SET GLOBAL innodb_file_per_table=1; # SET GLOBAL innodb_file_per_table=ON; create table t1 (a int not null, d varchar(15) not null, b -varchar(198) not null, c char(156), -fulltext ftsic(c)) engine=InnoDB +varchar(198) not null, c char(156)) engine=InnoDB row_format=redundant; insert into t1 values(123, 'abcdef', 'jghikl', 'mnop'); insert into t1 values(456, 'abcdef', 'jghikl', 'mnop'); @@ -72,7 +71,7 @@ DROP TABLE t1; Warnings: Warning 1932 Table 'test.t1' doesn't exist in engine DROP TABLE t2,t3; -FOUND 50 /\[ERROR\] InnoDB: Table `test`\.`t1` in InnoDB data dictionary contains invalid flags\. SYS_TABLES\.TYPE=1 SYS_TABLES\.MIX_LEN=255\b/ in mysqld.1.err +FOUND 6 /\[ERROR\] InnoDB: Table `test`\.`t1` in InnoDB data dictionary contains invalid flags\. SYS_TABLES\.TYPE=1 SYS_TABLES\.MIX_LEN=255\b/ in mysqld.1.err ib_buffer_pool ib_logfile0 ib_logfile1 diff --git a/mysql-test/suite/innodb/t/row_format_redundant.test b/mysql-test/suite/innodb/t/row_format_redundant.test index af3fe3b52cf..089339a0713 100644 --- a/mysql-test/suite/innodb/t/row_format_redundant.test +++ b/mysql-test/suite/innodb/t/row_format_redundant.test @@ -32,8 +32,7 @@ SET GLOBAL innodb_file_per_table=1; SET GLOBAL innodb_file_per_table=ON; create table t1 (a int not null, d varchar(15) not null, b -varchar(198) not null, c char(156), -fulltext ftsic(c)) engine=InnoDB +varchar(198) not null, c char(156)) engine=InnoDB row_format=redundant; insert into t1 values(123, 'abcdef', 'jghikl', 'mnop'); diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 88e12d3c80b..384937063eb 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -5416,51 +5416,6 @@ fil_delete_file( } } -/** -Iterate over all the spaces in the space list and fetch the -tablespace names. It will return a copy of the name that must be -freed by the caller using: delete[]. -@return DB_SUCCESS if all OK. */ -dberr_t -fil_get_space_names( -/*================*/ - space_name_list_t& space_name_list) - /*!< in/out: List to append to */ -{ - fil_space_t* space; - dberr_t err = DB_SUCCESS; - - mutex_enter(&fil_system->mutex); - - for (space = UT_LIST_GET_FIRST(fil_system->space_list); - space != NULL; - space = UT_LIST_GET_NEXT(space_list, space)) { - - if (space->purpose == FIL_TYPE_TABLESPACE) { - ulint len; - char* name; - - len = ::strlen(space->name); - name = UT_NEW_ARRAY_NOKEY(char, len + 1); - - if (name == 0) { - /* Caller to free elements allocated so far. */ - err = DB_OUT_OF_MEMORY; - break; - } - - memcpy(name, space->name, len); - name[len] = 0; - - space_name_list.push_back(name); - } - } - - mutex_exit(&fil_system->mutex); - - return(err); -} - /** Generate redo log for swapping two .ibd files @param[in] old_table old table @param[in] new_table new table diff --git a/storage/innobase/fts/fts0config.cc b/storage/innobase/fts/fts0config.cc index 768e3a2eabd..ed4340d818b 100644 --- a/storage/innobase/fts/fts0config.cc +++ b/storage/innobase/fts/fts0config.cc @@ -148,9 +148,7 @@ fts_config_create_index_param_name( ::strcpy(name, param); name[len] = '_'; - fts_write_object_id(index->id, name + len + 1, - DICT_TF2_FLAG_IS_SET(index->table, - DICT_TF2_FTS_AUX_HEX_NAME)); + fts_write_object_id(index->id, name + len + 1); return(name); } diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index 683104695e3..db549b58bd4 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -1565,18 +1565,19 @@ fts_rename_aux_tables( return(DB_SUCCESS); } -/****************************************************************//** -Drops the common ancillary tables needed for supporting an FTS index +/** Drops the common ancillary tables needed for supporting an FTS index on the given table. row_mysql_lock_data_dictionary must have been called before this. +@param[in] trx transaction to drop fts common table +@param[in] fts_table table with an FTS index +@param[in] drop_orphan True if the function is used to drop + orphaned table @return DB_SUCCESS or error code */ -static MY_ATTRIBUTE((nonnull, warn_unused_result)) -dberr_t +static dberr_t fts_drop_common_tables( -/*===================*/ - trx_t* trx, /*!< in: transaction */ - fts_table_t* fts_table) /*!< in: table with an FTS - index */ + trx_t* trx, + fts_table_t* fts_table, + bool drop_orphan=false) { ulint i; dberr_t error = DB_SUCCESS; @@ -1594,6 +1595,16 @@ fts_drop_common_tables( if (err != DB_SUCCESS && err != DB_FAIL) { error = err; } + + if (drop_orphan && err == DB_FAIL) { + char* path = fil_make_filepath( + NULL, table_name, IBD, false); + if (path != NULL) { + os_file_delete_if_exists( + innodb_data_file_key, path, NULL); + ut_free(path); + } + } } return(error); @@ -2132,37 +2143,6 @@ fts_create_index_tables( return(err); } -#if 0 -/******************************************************************//** -Return string representation of state. */ -static -const char* -fts_get_state_str( -/*==============*/ - /* out: string representation of state */ - fts_row_state state) /*!< in: state */ -{ - switch (state) { - case FTS_INSERT: - return("INSERT"); - - case FTS_MODIFY: - return("MODIFY"); - - case FTS_DELETE: - return("DELETE"); - - case FTS_NOTHING: - return("NOTHING"); - - case FTS_INVALID: - return("INVALID"); - - default: - return("UNKNOWN"); - } -} -#endif /******************************************************************//** Calculate the new state of a row given the existing state and a new event. @@ -5766,525 +5746,6 @@ fts_savepoint_rollback( } } -/** Check if a table is an FTS auxiliary table name. -@param[out] table FTS table info -@param[in] name Table name -@param[in] len Length of table name -@return true if the name matches an auxiliary table name pattern */ -static -bool -fts_is_aux_table_name( - fts_aux_table_t* table, - const char* name, - ulint len) -{ - const char* ptr; - char* end; - char my_name[MAX_FULL_NAME_LEN + 1]; - - ut_ad(len <= MAX_FULL_NAME_LEN); - ut_memcpy(my_name, name, len); - my_name[len] = 0; - end = my_name + len; - - ptr = static_cast(memchr(my_name, '/', len)); - - if (ptr != NULL) { - /* We will start the match after the '/' */ - ++ptr; - len = end - ptr; - } - - /* All auxiliary tables are prefixed with "FTS_" and the name - length will be at the very least greater than 20 bytes. */ - if (ptr != NULL && len > 20 && strncmp(ptr, "FTS_", 4) == 0) { - ulint i; - - /* Skip the prefix. */ - ptr += 4; - len -= 4; - - /* Try and read the table id. */ - if (!fts_read_object_id(&table->parent_id, ptr)) { - return(false); - } - - /* Skip the table id. */ - ptr = static_cast(memchr(ptr, '_', len)); - - if (ptr == NULL) { - return(false); - } - - /* Skip the underscore. */ - ++ptr; - ut_a(end > ptr); - len = end - ptr; - - /* First search the common table suffix array. */ - for (i = 0; fts_common_tables[i] != NULL; ++i) { - - if (strncmp(ptr, fts_common_tables[i], len) == 0) { - return(true); - } - } - - /* Could be obsolete common tables. */ - if (strncmp(ptr, "ADDED", len) == 0 - || strncmp(ptr, "STOPWORDS", len) == 0) { - return(true); - } - - /* Try and read the index id. */ - if (!fts_read_object_id(&table->index_id, ptr)) { - return(false); - } - - /* Skip the table id. */ - ptr = static_cast(memchr(ptr, '_', len)); - - if (ptr == NULL) { - return(false); - } - - /* Skip the underscore. */ - ++ptr; - ut_a(end > ptr); - len = end - ptr; - - /* Search the FT index specific array. */ - for (i = 0; i < FTS_NUM_AUX_INDEX; ++i) { - - if (strncmp(ptr, fts_get_suffix(i), len) == 0) { - return(true); - } - } - - /* Other FT index specific table(s). */ - if (strncmp(ptr, "DOC_ID", len) == 0) { - return(true); - } - } - - return(false); -} - -/**********************************************************************//** -Callback function to read a single table ID column. -@return Always return TRUE */ -static -ibool -fts_read_tables( -/*============*/ - void* row, /*!< in: sel_node_t* */ - void* user_arg) /*!< in: pointer to ib_vector_t */ -{ - int i; - fts_aux_table_t*table; - mem_heap_t* heap; - ibool done = FALSE; - ib_vector_t* tables = static_cast(user_arg); - sel_node_t* sel_node = static_cast(row); - que_node_t* exp = sel_node->select_list; - - /* Must be a heap allocated vector. */ - ut_a(tables->allocator->arg != NULL); - - /* We will use this heap for allocating strings. */ - heap = static_cast(tables->allocator->arg); - table = static_cast(ib_vector_push(tables, NULL)); - - memset(table, 0x0, sizeof(*table)); - - /* Iterate over the columns and read the values. */ - for (i = 0; exp && !done; exp = que_node_get_next(exp), ++i) { - - dfield_t* dfield = que_node_get_val(exp); - void* data = dfield_get_data(dfield); - ulint len = dfield_get_len(dfield); - - ut_a(len != UNIV_SQL_NULL); - - /* Note: The column numbers below must match the SELECT */ - switch (i) { - case 0: /* NAME */ - - if (!fts_is_aux_table_name( - table, static_cast(data), len)) { - ib_vector_pop(tables); - done = TRUE; - break; - } - - table->name = static_cast( - mem_heap_alloc(heap, len + 1)); - memcpy(table->name, data, len); - table->name[len] = 0; - break; - - case 1: /* ID */ - ut_a(len == 8); - table->id = mach_read_from_8( - static_cast(data)); - break; - - default: - ut_error; - } - } - - return(TRUE); -} - -/******************************************************************//** -Callback that sets a hex formatted FTS table's flags2 in -SYS_TABLES. The flags is stored in MIX_LEN column. -@return FALSE if all OK */ -static -ibool -fts_set_hex_format( -/*===============*/ - void* row, /*!< in: sel_node_t* */ - void* user_arg) /*!< in: bool set/unset flag */ -{ - sel_node_t* node = static_cast(row); - dfield_t* dfield = que_node_get_val(node->select_list); - - ut_ad(dtype_get_mtype(dfield_get_type(dfield)) == DATA_INT); - ut_ad(dfield_get_len(dfield) == sizeof(ib_uint32_t)); - /* There should be at most one matching record. So the value - must be the default value. */ - ut_ad(mach_read_from_4(static_cast(user_arg)) - == ULINT32_UNDEFINED); - - ulint flags2 = mach_read_from_4( - static_cast(dfield_get_data(dfield))); - - flags2 |= DICT_TF2_FTS_AUX_HEX_NAME; - - mach_write_to_4(static_cast(user_arg), flags2); - - return(FALSE); -} - -/*****************************************************************//** -Update the DICT_TF2_FTS_AUX_HEX_NAME flag in SYS_TABLES. -@return DB_SUCCESS or error code. */ -static -dberr_t -fts_update_hex_format_flag( -/*=======================*/ - trx_t* trx, /*!< in/out: transaction that - covers the update */ - table_id_t table_id, /*!< in: Table for which we want - to set the root table->flags2 */ - bool dict_locked) /*!< in: set to true if the - caller already owns the - dict_sys_t::mutex. */ -{ - pars_info_t* info; - ib_uint32_t flags2; - - static const char sql[] = - "PROCEDURE UPDATE_HEX_FORMAT_FLAG() IS\n" - "DECLARE FUNCTION my_func;\n" - "DECLARE CURSOR c IS\n" - " SELECT MIX_LEN" - " FROM SYS_TABLES" - " WHERE ID = :table_id FOR UPDATE;" - "\n" - "BEGIN\n" - "OPEN c;\n" - "WHILE 1 = 1 LOOP\n" - " FETCH c INTO my_func();\n" - " IF c % NOTFOUND THEN\n" - " EXIT;\n" - " END IF;\n" - "END LOOP;\n" - "UPDATE SYS_TABLES" - " SET MIX_LEN = :flags2" - " WHERE ID = :table_id;\n" - "CLOSE c;\n" - "END;\n"; - - flags2 = ULINT32_UNDEFINED; - - info = pars_info_create(); - - pars_info_add_ull_literal(info, "table_id", table_id); - pars_info_bind_int4_literal(info, "flags2", &flags2); - - pars_info_bind_function( - info, "my_func", fts_set_hex_format, &flags2); - - if (trx_get_dict_operation(trx) == TRX_DICT_OP_NONE) { - trx_set_dict_operation(trx, TRX_DICT_OP_INDEX); - } - - dberr_t err = que_eval_sql(info, sql, !dict_locked, trx); - - ut_a(flags2 != ULINT32_UNDEFINED); - - return(err); -} - -/*********************************************************************//** -Rename an aux table to HEX format. It's called when "%016llu" is used -to format an object id in table name, which only happens in Windows. */ -static MY_ATTRIBUTE((nonnull, warn_unused_result)) -dberr_t -fts_rename_one_aux_table_to_hex_format( -/*===================================*/ - trx_t* trx, /*!< in: transaction */ - const fts_aux_table_t* aux_table, /*!< in: table info */ - const dict_table_t* parent_table) /*!< in: parent table name */ -{ - const char* ptr; - fts_table_t fts_table; - char new_name[MAX_FULL_NAME_LEN]; - dberr_t error; - - ptr = strchr(aux_table->name, '/'); - ut_a(ptr != NULL); - ++ptr; - /* Skip "FTS_", table id and underscore */ - for (ulint i = 0; i < 2; ++i) { - ptr = strchr(ptr, '_'); - ut_a(ptr != NULL); - ++ptr; - } - - fts_table.suffix = NULL; - if (aux_table->index_id == 0) { - fts_table.type = FTS_COMMON_TABLE; - - for (ulint i = 0; fts_common_tables[i] != NULL; ++i) { - if (strcmp(ptr, fts_common_tables[i]) == 0) { - fts_table.suffix = fts_common_tables[i]; - break; - } - } - } else { - fts_table.type = FTS_INDEX_TABLE; - - /* Skip index id and underscore */ - ptr = strchr(ptr, '_'); - ut_a(ptr != NULL); - ++ptr; - - for (ulint i = 0; fts_index_selector[i].value; ++i) { - if (strcmp(ptr, fts_get_suffix(i)) == 0) { - fts_table.suffix = fts_get_suffix(i); - break; - } - } - } - - ut_a(fts_table.suffix != NULL); - - fts_table.table_id = aux_table->parent_id; - fts_table.index_id = aux_table->index_id; - fts_table.table = parent_table; - - fts_get_table_name(&fts_table, new_name); - ut_ad(strcmp(new_name, aux_table->name) != 0); - - if (trx_get_dict_operation(trx) == TRX_DICT_OP_NONE) { - trx_set_dict_operation(trx, TRX_DICT_OP_INDEX); - } - - error = row_rename_table_for_mysql(aux_table->name, new_name, trx, - false, false); - - if (error != DB_SUCCESS) { - ib::warn() << "Failed to rename aux table '" - << aux_table->name << "' to new format '" - << new_name << "'."; - } else { - ib::info() << "Renamed aux table '" << aux_table->name - << "' to '" << new_name << "'."; - } - - return(error); -} - -/**********************************************************************//** -Rename all aux tables of a parent table to HEX format. Also set aux tables' -flags2 and parent table's flags2 with DICT_TF2_FTS_AUX_HEX_NAME. -It's called when "%016llu" is used to format an object id in table name, -which only happens in Windows. -Note the ids in tables are correct but the names are old ambiguous ones. - -This function should make sure that either all the parent table and aux tables -are set DICT_TF2_FTS_AUX_HEX_NAME with flags2 or none of them are set */ -static MY_ATTRIBUTE((nonnull, warn_unused_result)) -dberr_t -fts_rename_aux_tables_to_hex_format_low( -/*====================================*/ - trx_t* trx, /*!< in: transaction */ - dict_table_t* parent_table, /*!< in: parent table */ - ib_vector_t* tables) /*!< in: aux tables to rename. */ -{ - dberr_t error; - ulint count; - - ut_ad(!DICT_TF2_FLAG_IS_SET(parent_table, DICT_TF2_FTS_AUX_HEX_NAME)); - ut_ad(!ib_vector_is_empty(tables)); - - error = fts_update_hex_format_flag(trx, parent_table->id, true); - - if (error != DB_SUCCESS) { - ib::warn() << "Setting parent table " << parent_table->name - << " to hex format failed."; - fts_sql_rollback(trx); - return(error); - } - - DICT_TF2_FLAG_SET(parent_table, DICT_TF2_FTS_AUX_HEX_NAME); - - for (count = 0; count < ib_vector_size(tables); ++count) { - dict_table_t* table; - fts_aux_table_t* aux_table; - - aux_table = static_cast( - ib_vector_get(tables, count)); - - table = dict_table_open_on_id(aux_table->id, TRUE, - DICT_TABLE_OP_NORMAL); - - ut_ad(table != NULL); - ut_ad(!DICT_TF2_FLAG_IS_SET(table, DICT_TF2_FTS_AUX_HEX_NAME)); - - /* Set HEX_NAME flag here to make sure we can get correct - new table name in following function */ - DICT_TF2_FLAG_SET(table, DICT_TF2_FTS_AUX_HEX_NAME); - error = fts_rename_one_aux_table_to_hex_format(trx, - aux_table, parent_table); - /* We will rollback the trx if the error != DB_SUCCESS, - so setting the flag here is the same with setting it in - row_rename_table_for_mysql */ - DBUG_EXECUTE_IF("rename_aux_table_fail", error = DB_ERROR;); - - if (error != DB_SUCCESS) { - dict_table_close(table, TRUE, FALSE); - - ib::warn() << "Failed to rename one aux table " - << aux_table->name << ". Will revert" - " all successful rename operations."; - - fts_sql_rollback(trx); - break; - } - - error = fts_update_hex_format_flag(trx, aux_table->id, true); - dict_table_close(table, TRUE, FALSE); - - if (error != DB_SUCCESS) { - ib::warn() << "Setting aux table " << aux_table->name - << " to hex format failed."; - - fts_sql_rollback(trx); - break; - } - } - - if (error != DB_SUCCESS) { - ut_ad(count != ib_vector_size(tables)); - - /* If rename fails, thr trx would be rolled back, we can't - use it any more, we'll start a new background trx to do - the reverting. */ - - ut_ad(!trx_is_started(trx)); - - bool not_rename = false; - - /* Try to revert those succesful rename operations - in order to revert the ibd file rename. */ - for (ulint i = 0; i <= count; ++i) { - dict_table_t* table; - fts_aux_table_t* aux_table; - trx_t* trx_bg; - dberr_t err; - - aux_table = static_cast( - ib_vector_get(tables, i)); - - table = dict_table_open_on_id(aux_table->id, TRUE, - DICT_TABLE_OP_NORMAL); - ut_ad(table != NULL); - - if (not_rename) { - DICT_TF2_FLAG_UNSET(table, - DICT_TF2_FTS_AUX_HEX_NAME); - } - - if (!DICT_TF2_FLAG_IS_SET(table, - DICT_TF2_FTS_AUX_HEX_NAME)) { - dict_table_close(table, TRUE, FALSE); - continue; - } - - trx_bg = trx_allocate_for_background(); - trx_bg->op_info = "Revert half done rename"; - trx_bg->dict_operation_lock_mode = RW_X_LATCH; - trx_start_for_ddl(trx_bg, TRX_DICT_OP_TABLE); - - DICT_TF2_FLAG_UNSET(table, DICT_TF2_FTS_AUX_HEX_NAME); - err = row_rename_table_for_mysql(table->name.m_name, - aux_table->name, - trx_bg, false, false); - - trx_bg->dict_operation_lock_mode = 0; - dict_table_close(table, TRUE, FALSE); - - if (err != DB_SUCCESS) { - ib::warn() << "Failed to revert table " - << table->name << ". Please revert" - " manually."; - fts_sql_rollback(trx_bg); - trx_free_for_background(trx_bg); - /* Continue to clear aux tables' flags2 */ - not_rename = true; - continue; - } - - fts_sql_commit(trx_bg); - trx_free_for_background(trx_bg); - } - - DICT_TF2_FLAG_UNSET(parent_table, DICT_TF2_FTS_AUX_HEX_NAME); - } - - return(error); -} - -/**********************************************************************//** -Convert an id, which is actually a decimal number but was regard as a HEX -from a string, to its real value. */ -static -ib_id_t -fts_fake_hex_to_dec( -/*================*/ - ib_id_t id) /*!< in: number to convert */ -{ - ib_id_t dec_id = 0; - char tmp_id[FTS_AUX_MIN_TABLE_ID_LENGTH]; - -#ifdef UNIV_DEBUG - int ret = -#endif /* UNIV_DEBUG */ - sprintf(tmp_id, UINT64PFx, id); - ut_ad(ret == 16); -#ifdef UNIV_DEBUG - ret = -#endif /* UNIV_DEBUG */ - sscanf(tmp_id, "%016" UINT64scan, &dec_id); - ut_ad(ret == 1); - - return dec_id; -} - /*********************************************************************//** Compare two fts_aux_table_t parent_ids. @return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */ @@ -6301,801 +5762,244 @@ fts_check_aux_table_parent_id_cmp( return static_cast(fa1->parent_id - fa2->parent_id); } -/** Mark all the fts index associated with the parent table as corrupted. -@param[in] trx transaction -@param[in, out] parent_table fts index associated with this parent table - will be marked as corrupted. */ -static -void -fts_parent_all_index_set_corrupt( - trx_t* trx, - dict_table_t* parent_table) +bool fts_check_aux_table(const char *name, + table_id_t *table_id, + index_id_t *index_id) { - fts_t* fts = parent_table->fts; + ulint len= strlen(name); + const char* ptr; + const char* end= name + len; - if (trx_get_dict_operation(trx) == TRX_DICT_OP_NONE) { - trx_set_dict_operation(trx, TRX_DICT_OP_INDEX); - } + ut_ad(len <= MAX_FULL_NAME_LEN); + ptr= static_cast(memchr(name, '/', len)); - for (ulint j = 0; j < ib_vector_size(fts->indexes); j++) { - dict_index_t* index = static_cast( - ib_vector_getp_const(fts->indexes, j)); - dict_set_corrupted(index, - trx, "DROP ORPHANED TABLE"); - } + if (ptr != NULL) + { + /* We will start the match after the '/' */ + ++ptr; + len = end - ptr; + } + + /* All auxiliary tables are prefixed with "FTS_" and the name + length will be at the very least greater than 20 bytes. */ + if (ptr && len > 20 && !memcmp(ptr, "FTS_", 4)) + { + /* Skip the prefix. */ + ptr+= 4; + len-= 4; + + const char *table_id_ptr= ptr; + /* Skip the table id. */ + ptr= static_cast(memchr(ptr, '_', len)); + + if (!ptr) + return false; + + /* Skip the underscore. */ + ++ptr; + ut_ad(end > ptr); + len= end - ptr; + + sscanf(table_id_ptr, UINT64PFx, table_id); + /* First search the common table suffix array. */ + for (ulint i = 0; fts_common_tables[i]; ++i) + { + if (!memcmp(ptr, fts_common_tables[i], len)) + return true; + } + + /* Could be obsolete common tables. */ + if (!memcmp(ptr, "ADDED", len) || !memcmp(ptr, "STOPWORDS", len)) + return true; + + const char* index_id_ptr= ptr; + /* Skip the index id. */ + ptr= static_cast(memchr(ptr, '_', len)); + if (!ptr) + return false; + + sscanf(index_id_ptr, UINT64PFx, index_id); + + /* Skip the underscore. */ + ++ptr; + ut_a(end > ptr); + len= end - ptr; + + if (len > 7) + return false; + + /* Search the FT index specific array. */ + for (ulint i = 0; i < FTS_NUM_AUX_INDEX; ++i) + { + if (!memcmp(ptr, "INDEX_", len - 1)) + return true; + } + + /* Other FT index specific table(s). */ + if (!memcmp(ptr, "DOC_ID", len)) + return true; + } + + return false; } -/** Mark the fts index which index id matches the id as corrupted. -@param[in] trx transaction -@param[in] id index id to search -@param[in, out] parent_table parent table to check with all - the index. */ -static -void -fts_set_index_corrupt( - trx_t* trx, - index_id_t id, - dict_table_t* table) +typedef std::pair fts_aux_id; +typedef std::set fts_space_set_t; + +/** Iterate over all the spaces in the space list and fetch the +fts parent table id and index id. +@param[in,out] fts_space_set store the list of tablespace id and + index id */ +static void fil_get_fts_spaces(fts_space_set_t& fts_space_set) { - fts_t* fts = table->fts; + mutex_enter(&fil_system->mutex); - if (trx_get_dict_operation(trx) == TRX_DICT_OP_NONE) { - trx_set_dict_operation(trx, TRX_DICT_OP_INDEX); - } + for (fil_space_t *space = UT_LIST_GET_FIRST(fil_system->space_list); + space != NULL; + space = UT_LIST_GET_NEXT(space_list, space)) + { + index_id_t index_id = 0; + table_id_t table_id = 0; - for (ulint j = 0; j < ib_vector_size(fts->indexes); j++) { - dict_index_t* index = static_cast( - ib_vector_getp_const(fts->indexes, j)); - if (index->id == id) { - dict_set_corrupted(index, trx, - "DROP ORPHANED TABLE"); - break; - } - } + if (space->purpose == FIL_TYPE_TABLESPACE + && fts_check_aux_table(space->name, &table_id, &index_id)) + fts_space_set.insert(std::make_pair(table_id, index_id)); + } + + mutex_exit(&fil_system->mutex); } -/** Check the index for the aux table is corrupted. -@param[in] aux_table auxiliary table -@retval nonzero if index is corrupted, zero for valid index */ -static -ulint -fts_check_corrupt_index( - fts_aux_table_t* aux_table) +/** Check whether the parent table id and index id of fts auxilary +tables with SYS_INDEXES. If it exists then we can safely ignore the +fts table from orphaned tables. +@param[in,out] fts_space_set fts space set contains set of auxiliary + table ids */ +static void fts_check_orphaned_tables(fts_space_set_t& fts_space_set) { - dict_table_t* table; - dict_index_t* index; - table = dict_table_open_on_id( - aux_table->parent_id, TRUE, DICT_TABLE_OP_NORMAL); + btr_pcur_t pcur; + mtr_t mtr; + trx_t* trx = trx_allocate_for_background(); + trx->op_info = "checking fts orphaned tables"; - if (table == NULL) { - return(0); - } + row_mysql_lock_data_dictionary(trx); - for (index = UT_LIST_GET_FIRST(table->indexes); - index; - index = UT_LIST_GET_NEXT(indexes, index)) { - if (index->id == aux_table->index_id) { - ut_ad(index->type & DICT_FTS); - dict_table_close(table, true, false); - return index->is_corrupted(); - } - } + mtr.start(); + btr_pcur_open_at_index_side( + true, dict_table_get_first_index(dict_sys->sys_indexes), + BTR_SEARCH_LEAF, &pcur, true, 0, &mtr); - dict_table_close(table, true, false); - return(0); + do + { + const rec_t *rec; + const byte *tbl_field; + const byte *index_field; + ulint len; + + btr_pcur_move_to_next_user_rec(&pcur, &mtr); + if (!btr_pcur_is_on_user_rec(&pcur)) + break; + + rec= btr_pcur_get_rec(&pcur); + if (rec_get_deleted_flag(rec, 0)) + continue; + + tbl_field= rec_get_nth_field_old(rec, 0, &len); + if (len != 8) + continue; + + index_field= rec_get_nth_field_old(rec, 1, &len); + if (len != 8) + continue; + + table_id_t table_id = mach_read_from_8(tbl_field); + index_id_t index_id = mach_read_from_8(index_field); + + fts_space_set_t::iterator it = fts_space_set.find( + fts_aux_id(table_id, index_id)); + + if (it != fts_space_set.end()) + fts_space_set.erase(*it); + else + { + it= fts_space_set.find(fts_aux_id(table_id, 0)); + if (it != fts_space_set.end()) + fts_space_set.erase(*it); + } + } while(!fts_space_set.empty()); + + btr_pcur_close(&pcur); + mtr.commit(); + row_mysql_unlock_data_dictionary(trx); + trx_free_for_background(trx); } -/* Get parent table name if it's a fts aux table -@param[in] aux_table_name aux table name -@param[in] aux_table_len aux table length -@return parent table name, or NULL */ -char* -fts_get_parent_table_name( - const char* aux_table_name, - ulint aux_table_len) +/** Drop all fts auxilary table for the respective fts_id +@param[in] fts_id fts auxilary table ids */ +static void fts_drop_all_aux_tables(trx_t *trx, fts_table_t *fts_table) { - fts_aux_table_t aux_table; - char* parent_table_name = NULL; + char fts_table_name[MAX_FULL_NAME_LEN]; + for (ulint i= 0;i < FTS_NUM_AUX_INDEX; i++) + { + fts_table->suffix= fts_get_suffix(i); + fts_get_table_name(fts_table, fts_table_name, true); - if (fts_is_aux_table_name(&aux_table, aux_table_name, aux_table_len)) { - dict_table_t* parent_table; + /* Drop all fts aux and common table */ + dberr_t err= fts_drop_table(trx, fts_table_name); - parent_table = dict_table_open_on_id( - aux_table.parent_id, TRUE, DICT_TABLE_OP_NORMAL); + if (err == DB_FAIL) + { + char *path= fil_make_filepath(NULL, fts_table_name, IBD, false); - if (parent_table != NULL) { - parent_table_name = mem_strdupl( - parent_table->name.m_name, - strlen(parent_table->name.m_name)); - - dict_table_close(parent_table, TRUE, FALSE); - } - } - - return(parent_table_name); + if (path != NULL) + { + os_file_delete_if_exists(innodb_data_file_key, path , NULL); + ut_free(path); + } + } + } } -/** Check the validity of the parent table. -@param[in] aux_table auxiliary table -@return true if it is a valid table or false if it is not */ -static -bool -fts_valid_parent_table( - const fts_aux_table_t* aux_table) +/** Drop all orphaned FTS auxiliary tables, those that don't have +a parent table or FTS index defined on them. */ +void fts_drop_orphaned_tables() { - dict_table_t* parent_table; - bool valid = false; - - parent_table = dict_table_open_on_id( - aux_table->parent_id, TRUE, DICT_TABLE_OP_NORMAL); - - if (parent_table != NULL && parent_table->fts != NULL) { - if (aux_table->index_id == 0) { - valid = true; - } else { - index_id_t id = aux_table->index_id; - dict_index_t* index; - - /* Search for the FT index in the table's list. */ - for (index = UT_LIST_GET_FIRST(parent_table->indexes); - index; - index = UT_LIST_GET_NEXT(indexes, index)) { - if (index->id == id) { - valid = true; - break; - } - - } - } - } - - if (parent_table) { - dict_table_close(parent_table, TRUE, FALSE); - } - - return(valid); -} - -/** Try to rename all aux tables of the specified parent table. -@param[in] aux_tables aux_tables to be renamed -@param[in] parent_table parent table of all aux - tables stored in tables. */ -static -void -fts_rename_aux_tables_to_hex_format( - ib_vector_t* aux_tables, - dict_table_t* parent_table) -{ - dberr_t err; - trx_t* trx_rename = trx_allocate_for_background(); - trx_rename->op_info = "Rename aux tables to hex format"; - trx_rename->dict_operation_lock_mode = RW_X_LATCH; - trx_start_for_ddl(trx_rename, TRX_DICT_OP_TABLE); - - err = fts_rename_aux_tables_to_hex_format_low(trx_rename, - parent_table, aux_tables); - - trx_rename->dict_operation_lock_mode = 0; - - if (err != DB_SUCCESS) { - - ib::warn() << "Rollback operations on all aux tables of " - "table "<< parent_table->name << ". All the fts index " - "associated with the table are marked as corrupted. " - "Please rebuild the index again."; - - /* Corrupting the fts index related to parent table. */ - trx_t* trx_corrupt; - trx_corrupt = trx_allocate_for_background(); - trx_corrupt->dict_operation_lock_mode = RW_X_LATCH; - trx_start_for_ddl(trx_corrupt, TRX_DICT_OP_TABLE); - fts_parent_all_index_set_corrupt(trx_corrupt, parent_table); - trx_corrupt->dict_operation_lock_mode = 0; - fts_sql_commit(trx_corrupt); - trx_free_for_background(trx_corrupt); - } else { - fts_sql_commit(trx_rename); - } - - trx_free_for_background(trx_rename); - ib_vector_reset(aux_tables); -} - -/** Set the hex format flag for the parent table. -@param[in, out] parent_table parent table -@param[in] trx transaction */ -static -void -fts_set_parent_hex_format_flag( - dict_table_t* parent_table, - trx_t* trx) -{ - if (!DICT_TF2_FLAG_IS_SET(parent_table, - DICT_TF2_FTS_AUX_HEX_NAME)) { - DBUG_EXECUTE_IF("parent_table_flag_fail", DBUG_SUICIDE();); - - dberr_t err = fts_update_hex_format_flag( - trx, parent_table->id, true); - - if (err != DB_SUCCESS) { - ib::fatal() << "Setting parent table " - << parent_table->name - << "to hex format failed. Please try " - << "to restart the server again, if it " - << "doesn't work, the system tables " - << "might be corrupted."; - } else { - DICT_TF2_FLAG_SET( - parent_table, DICT_TF2_FTS_AUX_HEX_NAME); - } - } -} - -/** Drop the obsolete auxilary table. -@param[in] tables tables to be dropped. */ -static -void -fts_drop_obsolete_aux_table_from_vector( - ib_vector_t* tables) -{ - dberr_t err; - - for (ulint count = 0; count < ib_vector_size(tables); - ++count) { - - fts_aux_table_t* aux_drop_table; - aux_drop_table = static_cast( - ib_vector_get(tables, count)); - trx_t* trx_drop = trx_allocate_for_background(); - trx_drop->op_info = "Drop obsolete aux tables"; - trx_drop->dict_operation_lock_mode = RW_X_LATCH; - trx_start_for_ddl(trx_drop, TRX_DICT_OP_TABLE); - - err = row_drop_table_for_mysql( - aux_drop_table->name, trx_drop, - SQLCOM_DROP_TABLE, true); - - trx_drop->dict_operation_lock_mode = 0; - - if (err != DB_SUCCESS) { - /* We don't need to worry about the - failure, since server would try to - drop it on next restart, even if - the table was broken. */ - ib::warn() << "Failed to drop obsolete aux table " - << aux_drop_table->name << ", which is " - << "harmless. will try to drop it on next " - << "restart."; - - fts_sql_rollback(trx_drop); - } else { - ib::info() << "Dropped obsolete aux" - " table '" << aux_drop_table->name - << "'."; - - fts_sql_commit(trx_drop); - } - - trx_free_for_background(trx_drop); - } -} - -/** Drop all the auxiliary table present in the vector. -@param[in] trx transaction -@param[in] tables tables to be dropped */ -static -void -fts_drop_aux_table_from_vector( - trx_t* trx, - ib_vector_t* tables) -{ - for (ulint count = 0; count < ib_vector_size(tables); - ++count) { - fts_aux_table_t* aux_drop_table; - aux_drop_table = static_cast( - ib_vector_get(tables, count)); - - /* Check for the validity of the parent table */ - if (!fts_valid_parent_table(aux_drop_table)) { - - ib::warn() << "Parent table of FTS auxiliary table " - << aux_drop_table->name << " not found."; - - dberr_t err = fts_drop_table(trx, aux_drop_table->name); - if (err == DB_FAIL) { - - char* path = fil_make_filepath( - NULL, aux_drop_table->name, IBD, false); - - if (path != NULL) { - os_file_delete_if_exists( - innodb_data_file_key, - path , NULL); - ut_free(path); - } - } - } - } -} - -/**********************************************************************//** -Check and drop all orphaned FTS auxiliary tables, those that don't have -a parent table or FTS index defined on them. -@return DB_SUCCESS or error code */ -static MY_ATTRIBUTE((nonnull)) -void -fts_check_and_drop_orphaned_tables( -/*===============================*/ - trx_t* trx, /*!< in: transaction */ - ib_vector_t* tables) /*!< in: tables to check */ -{ - mem_heap_t* heap; - ib_vector_t* aux_tables_to_rename; - ib_vector_t* invalid_aux_tables; - ib_vector_t* valid_aux_tables; - ib_vector_t* drop_aux_tables; - ib_vector_t* obsolete_aux_tables; - ib_alloc_t* heap_alloc; - - heap = mem_heap_create(1024); - heap_alloc = ib_heap_allocator_create(heap); - - /* We store all aux tables belonging to the same parent table here, - and rename all these tables in a batch mode. */ - aux_tables_to_rename = ib_vector_create(heap_alloc, - sizeof(fts_aux_table_t), 128); - - /* We store all fake auxiliary table and orphaned table here. */ - invalid_aux_tables = ib_vector_create(heap_alloc, - sizeof(fts_aux_table_t), 128); - - /* We store all valid aux tables. We use this to filter the - fake auxiliary table from invalid auxiliary tables. */ - valid_aux_tables = ib_vector_create(heap_alloc, - sizeof(fts_aux_table_t), 128); - - /* We store all auxiliary tables to be dropped. */ - drop_aux_tables = ib_vector_create(heap_alloc, - sizeof(fts_aux_table_t), 128); - - /* We store all obsolete auxiliary tables to be dropped. */ - obsolete_aux_tables = ib_vector_create(heap_alloc, - sizeof(fts_aux_table_t), 128); - - /* Sort by parent_id first, in case rename will fail */ - ib_vector_sort(tables, fts_check_aux_table_parent_id_cmp); - - for (ulint i = 0; i < ib_vector_size(tables); ++i) { - dict_table_t* parent_table; - fts_aux_table_t* aux_table; - bool drop = false; - dict_table_t* table; - fts_aux_table_t* next_aux_table = NULL; - ib_id_t orig_parent_id = 0; - ib_id_t orig_index_id = 0; - bool rename = false; - - aux_table = static_cast( - ib_vector_get(tables, i)); - - table = dict_table_open_on_id( - aux_table->id, TRUE, DICT_TABLE_OP_NORMAL); - orig_parent_id = aux_table->parent_id; - orig_index_id = aux_table->index_id; - - if (table == NULL - || strcmp(table->name.m_name, aux_table->name)) { - - bool fake_aux = false; - - if (table != NULL) { - dict_table_close(table, TRUE, FALSE); - } - - if (i + 1 < ib_vector_size(tables)) { - next_aux_table = static_cast( - ib_vector_get(tables, i + 1)); - } - - /* To know whether aux table is fake fts or - orphan fts table. */ - for (ulint count = 0; - count < ib_vector_size(valid_aux_tables); - count++) { - fts_aux_table_t* valid_aux; - valid_aux = static_cast( - ib_vector_get(valid_aux_tables, count)); - if (strcmp(valid_aux->name, - aux_table->name) == 0) { - fake_aux = true; - break; - } - } - - /* All aux tables of parent table, whose id is - last_parent_id, have been checked, try to rename - them if necessary. */ - if ((next_aux_table == NULL - || orig_parent_id != next_aux_table->parent_id) - && (!ib_vector_is_empty(aux_tables_to_rename))) { - - ib_id_t parent_id = fts_fake_hex_to_dec( - aux_table->parent_id); - - parent_table = dict_table_open_on_id( - parent_id, TRUE, - DICT_TABLE_OP_NORMAL); - - fts_rename_aux_tables_to_hex_format( - aux_tables_to_rename, parent_table); - - dict_table_close(parent_table, TRUE, - FALSE); - } - - /* If the aux table is fake aux table. Skip it. */ - if (!fake_aux) { - ib_vector_push(invalid_aux_tables, aux_table); - } - - continue; - } else if (!DICT_TF2_FLAG_IS_SET(table, - DICT_TF2_FTS_AUX_HEX_NAME)) { - - aux_table->parent_id = fts_fake_hex_to_dec( - aux_table->parent_id); - - if (aux_table->index_id != 0) { - aux_table->index_id = fts_fake_hex_to_dec( - aux_table->index_id); - } - - ut_ad(aux_table->id > aux_table->parent_id); - - /* Check whether parent table id and index id - are stored as decimal format. */ - if (fts_valid_parent_table(aux_table)) { - - parent_table = dict_table_open_on_id( - aux_table->parent_id, true, - DICT_TABLE_OP_NORMAL); - - ut_ad(parent_table != NULL); - ut_ad(parent_table->fts != NULL); - - if (!DICT_TF2_FLAG_IS_SET( - parent_table, - DICT_TF2_FTS_AUX_HEX_NAME)) { - rename = true; - } - - dict_table_close(parent_table, TRUE, FALSE); - } - - if (!rename) { - /* Reassign the original value of - aux table if it is not in decimal format */ - aux_table->parent_id = orig_parent_id; - aux_table->index_id = orig_index_id; - } - } - - if (table != NULL) { - dict_table_close(table, TRUE, FALSE); - } - - if (!rename) { - /* Check the validity of the parent table. */ - if (!fts_valid_parent_table(aux_table)) { - drop = true; - } - } - - /* Filter out the fake aux table by comparing with the - current valid auxiliary table name. */ - for (ulint count = 0; - count < ib_vector_size(invalid_aux_tables); count++) { - fts_aux_table_t* invalid_aux; - invalid_aux = static_cast( - ib_vector_get(invalid_aux_tables, count)); - if (strcmp(invalid_aux->name, aux_table->name) == 0) { - ib_vector_remove( - invalid_aux_tables, - *reinterpret_cast(invalid_aux)); - break; - } - } - - ib_vector_push(valid_aux_tables, aux_table); - - /* If the index associated with aux table is corrupted, - skip it. */ - if (fts_check_corrupt_index(aux_table) > 0) { - - if (i + 1 < ib_vector_size(tables)) { - next_aux_table = static_cast( - ib_vector_get(tables, i + 1)); - } - - if (next_aux_table == NULL - || orig_parent_id != next_aux_table->parent_id) { - - parent_table = dict_table_open_on_id( - aux_table->parent_id, TRUE, - DICT_TABLE_OP_NORMAL); - - if (!ib_vector_is_empty(aux_tables_to_rename)) { - fts_rename_aux_tables_to_hex_format( - aux_tables_to_rename, parent_table); - } else { - fts_set_parent_hex_format_flag( - parent_table, trx); - } - - dict_table_close(parent_table, TRUE, FALSE); - } - - continue; - } - - parent_table = dict_table_open_on_id( - aux_table->parent_id, TRUE, DICT_TABLE_OP_NORMAL); - - if (drop) { - ib_vector_push(drop_aux_tables, aux_table); - } else { - if (FTS_IS_OBSOLETE_AUX_TABLE(aux_table->name)) { - ib_vector_push(obsolete_aux_tables, aux_table); - continue; - } - } - - /* If the aux table is in decimal format, we should - rename it, so push it to aux_tables_to_rename */ - if (!drop && rename) { - bool rename_table = true; - for (ulint count = 0; - count < ib_vector_size(aux_tables_to_rename); - count++) { - fts_aux_table_t* rename_aux = - static_cast( - ib_vector_get(aux_tables_to_rename, - count)); - if (strcmp(rename_aux->name, - aux_table->name) == 0) { - rename_table = false; - break; - } - } - - if (rename_table) { - ib_vector_push(aux_tables_to_rename, - aux_table); - } - } - - if (i + 1 < ib_vector_size(tables)) { - next_aux_table = static_cast( - ib_vector_get(tables, i + 1)); - } - - if ((next_aux_table == NULL - || orig_parent_id != next_aux_table->parent_id) - && !ib_vector_is_empty(aux_tables_to_rename)) { - - ut_ad(rename); - ut_ad(!DICT_TF2_FLAG_IS_SET( - parent_table, DICT_TF2_FTS_AUX_HEX_NAME)); - - fts_rename_aux_tables_to_hex_format( - aux_tables_to_rename,parent_table); - } - - /* The IDs are already in correct hex format. */ - if (!drop && !rename) { - dict_table_t* table; - - table = dict_table_open_on_id( - aux_table->id, TRUE, DICT_TABLE_OP_NORMAL); - - if (table != NULL - && strcmp(table->name.m_name, aux_table->name)) { - dict_table_close(table, TRUE, FALSE); - table = NULL; - } - - if (table != NULL - && !DICT_TF2_FLAG_IS_SET( - table, - DICT_TF2_FTS_AUX_HEX_NAME)) { - - DBUG_EXECUTE_IF("aux_table_flag_fail", - ib::warn() << "Setting aux table " - << table->name << " to hex " - "format failed."; - fts_set_index_corrupt( - trx, aux_table->index_id, - parent_table); - goto table_exit;); - - dberr_t err = fts_update_hex_format_flag( - trx, table->id, true); - - if (err != DB_SUCCESS) { - ib::warn() << "Setting aux table " - << table->name << " to hex " - "format failed."; - - fts_set_index_corrupt( - trx, aux_table->index_id, - parent_table); - } else { - DICT_TF2_FLAG_SET(table, - DICT_TF2_FTS_AUX_HEX_NAME); - } - } -#ifndef DBUG_OFF -table_exit: -#endif /* !DBUG_OFF */ - - if (table != NULL) { - dict_table_close(table, TRUE, FALSE); - } - - ut_ad(parent_table != NULL); - - fts_set_parent_hex_format_flag( - parent_table, trx); - } - - if (parent_table != NULL) { - dict_table_close(parent_table, TRUE, FALSE); - } - } - - fts_drop_aux_table_from_vector(trx, invalid_aux_tables); - fts_drop_aux_table_from_vector(trx, drop_aux_tables); - fts_sql_commit(trx); - - fts_drop_obsolete_aux_table_from_vector(obsolete_aux_tables); - - /* Free the memory allocated at the beginning */ - if (heap != NULL) { - mem_heap_free(heap); - } -} - -/**********************************************************************//** -Drop all orphaned FTS auxiliary tables, those that don't have a parent -table or FTS index defined on them. */ -void -fts_drop_orphaned_tables(void) -/*==========================*/ -{ - trx_t* trx; - pars_info_t* info; - mem_heap_t* heap; - que_t* graph; - ib_vector_t* tables; - ib_alloc_t* heap_alloc; - space_name_list_t space_name_list; - dberr_t error = DB_SUCCESS; - - /* Note: We have to free the memory after we are done with the list. */ - error = fil_get_space_names(space_name_list); - - if (error == DB_OUT_OF_MEMORY) { - ib::fatal() << "Out of memory"; - } - - heap = mem_heap_create(1024); - heap_alloc = ib_heap_allocator_create(heap); - - /* We store the table ids of all the FTS indexes that were found. */ - tables = ib_vector_create(heap_alloc, sizeof(fts_aux_table_t), 128); - - /* Get the list of all known .ibd files and check for orphaned - FTS auxiliary files in that list. We need to remove them because - users can't map them back to table names and this will create - unnecessary clutter. */ - - for (space_name_list_t::iterator it = space_name_list.begin(); - it != space_name_list.end(); - ++it) { - - fts_aux_table_t* fts_aux_table; - - fts_aux_table = static_cast( - ib_vector_push(tables, NULL)); - - memset(fts_aux_table, 0x0, sizeof(*fts_aux_table)); - - if (!fts_is_aux_table_name(fts_aux_table, *it, strlen(*it))) { - ib_vector_pop(tables); - } else { - ulint len = strlen(*it); - - fts_aux_table->id = fil_space_get_id_by_name(*it); - - /* We got this list from fil0fil.cc. The tablespace - with this name must exist. */ - ut_a(fts_aux_table->id != ULINT_UNDEFINED); - - fts_aux_table->name = static_cast( - mem_heap_dup(heap, *it, len + 1)); - - fts_aux_table->name[len] = 0; - } - } - - trx = trx_allocate_for_background(); - trx->op_info = "dropping orphaned FTS tables"; - row_mysql_lock_data_dictionary(trx); - - info = pars_info_create(); - - pars_info_bind_function(info, "my_func", fts_read_tables, tables); - - graph = fts_parse_sql_no_dict_lock( - NULL, - info, - "DECLARE FUNCTION my_func;\n" - "DECLARE CURSOR c IS" - " SELECT NAME, ID" - " FROM SYS_TABLES;\n" - "BEGIN\n" - "\n" - "OPEN c;\n" - "WHILE 1 = 1 LOOP\n" - " FETCH c INTO my_func();\n" - " IF c % NOTFOUND THEN\n" - " EXIT;\n" - " END IF;\n" - "END LOOP;\n" - "CLOSE c;"); - - for (;;) { - error = fts_eval_sql(trx, graph); - - if (UNIV_LIKELY(error == DB_SUCCESS)) { - fts_check_and_drop_orphaned_tables(trx, tables); - break; /* Exit the loop. */ - } else { - ib_vector_reset(tables); - - fts_sql_rollback(trx); - - if (error == DB_LOCK_WAIT_TIMEOUT) { - ib::warn() << "lock wait timeout reading" - " SYS_TABLES. Retrying!"; - - trx->error_state = DB_SUCCESS; - } else { - ib::error() << "(" << error - << ") while reading SYS_TABLES."; - - break; /* Exit the loop. */ - } - } - } - - que_graph_free(graph); - - row_mysql_unlock_data_dictionary(trx); - - trx_free_for_background(trx); - - if (heap != NULL) { - mem_heap_free(heap); - } - - /** Free the memory allocated to store the .ibd names. */ - for (space_name_list_t::iterator it = space_name_list.begin(); - it != space_name_list.end(); - ++it) { - - UT_DELETE_ARRAY(*it); - } + fts_space_set_t fts_space_set; + fil_get_fts_spaces(fts_space_set); + + if (fts_space_set.empty()) + return; + + fts_check_orphaned_tables(fts_space_set); + + if (fts_space_set.empty()) + return; + + trx_t* trx= trx_allocate_for_background(); + trx->op_info= "Drop orphaned aux FTS tables"; + row_mysql_lock_data_dictionary(trx); + + for (fts_space_set_t::iterator it = fts_space_set.begin(); + it != fts_space_set.end(); it++) + { + fts_table_t fts_table; + dict_table_t *table= dict_table_open_on_id(it->first, TRUE, + DICT_TABLE_OP_NORMAL); + if (!table) + continue; + + FTS_INIT_FTS_TABLE(&fts_table, NULL, FTS_COMMON_TABLE, table); + fts_drop_common_tables(trx, &fts_table, true); + + fts_table.type= FTS_INDEX_TABLE; + fts_table.index_id= it->second; + fts_drop_all_aux_tables(trx, &fts_table); + + dict_table_close(table, true, false); + } + trx_commit_for_mysql(trx); + row_mysql_unlock_data_dictionary(trx); + trx->dict_operation_lock_mode= 0; + trx_free_for_background(trx); } /**********************************************************************//** diff --git a/storage/innobase/fts/fts0sql.cc b/storage/innobase/fts/fts0sql.cc index 376662bba8a..e61f2118e70 100644 --- a/storage/innobase/fts/fts0sql.cc +++ b/storage/innobase/fts/fts0sql.cc @@ -55,28 +55,23 @@ fts_get_table_id( long */ { int len; - bool hex_name = DICT_TF2_FLAG_IS_SET(fts_table->table, - DICT_TF2_FTS_AUX_HEX_NAME); ut_a(fts_table->table != NULL); switch (fts_table->type) { case FTS_COMMON_TABLE: - len = fts_write_object_id(fts_table->table_id, table_id, - hex_name); + len = fts_write_object_id(fts_table->table_id, table_id); break; case FTS_INDEX_TABLE: - len = fts_write_object_id(fts_table->table_id, table_id, - hex_name); + len = fts_write_object_id(fts_table->table_id, table_id); table_id[len] = '_'; ++len; table_id += len; - len += fts_write_object_id(fts_table->index_id, table_id, - hex_name); + len += fts_write_object_id(fts_table->index_id, table_id); break; default: diff --git a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h index e85340d1c4d..65457b414ca 100644 --- a/storage/innobase/include/fil0fil.h +++ b/storage/innobase/include/fil0fil.h @@ -1349,18 +1349,6 @@ ulint fil_space_get_id_by_name( const char* tablespace); -/** -Iterate over all the spaces in the space list and fetch the -tablespace names. It will return a copy of the name that must be -freed by the caller using: delete[]. -@return DB_SUCCESS if all OK. */ -dberr_t -fil_get_space_names( -/*================*/ - space_name_list_t& space_name_list) - /*!< in/out: Vector for collecting the names. */ - MY_ATTRIBUTE((warn_unused_result)); - /** Generate redo log for swapping two .ibd files @param[in] old_table old table @param[in] new_table new table diff --git a/storage/innobase/include/fts0fts.h b/storage/innobase/include/fts0fts.h index b7d3451e887..30a2cc56778 100644 --- a/storage/innobase/include/fts0fts.h +++ b/storage/innobase/include/fts0fts.h @@ -735,12 +735,9 @@ fts_savepoint_rollback_last_stmt( /*=============================*/ trx_t* trx); /*!< in: transaction */ -/***********************************************************************//** -Drop all orphaned FTS auxiliary tables, those that don't have a parent +/** Drop all orphaned FTS auxiliary tables, those that don't have a parent table or FTS index defined on them. */ -void -fts_drop_orphaned_tables(void); -/*==========================*/ +void fts_drop_orphaned_tables(); /** Run SYNC on the table, i.e., write out data from the cache to the FTS auxiliary INDEX table and clear the cache at the end. @@ -774,15 +771,6 @@ fts_init_doc_id( /*============*/ const dict_table_t* table); /*!< in: table */ -/* Get parent table name if it's a fts aux table -@param[in] aux_table_name aux table name -@param[in] aux_table_len aux table length -@return parent table name, or NULL */ -char* -fts_get_parent_table_name( - const char* aux_table_name, - ulint aux_table_len); - /******************************************************************//** compare two character string according to their charset. */ extern @@ -989,4 +977,14 @@ and there are no new fts index to add. @param[in] trx transaction to drop all fts tables */ void fts_clear_all(dict_table_t *table, trx_t *trx); +/** Check whether the given name is fts auxiliary table +and fetch the parent table id and index id +@param[in] name table name +@param[in,out] table_id parent table id +@param[in,out] index_id index id +@return true if it is auxilary table */ +bool fts_check_aux_table(const char *name, + table_id_t *table_id, + index_id_t *index_id); + #endif /*!< fts0fts.h */ diff --git a/storage/innobase/include/fts0priv.h b/storage/innobase/include/fts0priv.h index 4c8746c053f..2b7f31dfe54 100644 --- a/storage/innobase/include/fts0priv.h +++ b/storage/innobase/include/fts0priv.h @@ -462,11 +462,7 @@ int fts_write_object_id( /*================*/ ib_id_t id, /*!< in: a table/index id */ - char* str, /*!< in: buffer to write the id to */ - bool hex_format MY_ATTRIBUTE((unused))) - /*!< in: true for fixed hex format, - false for old ambiguous format */ - MY_ATTRIBUTE((nonnull)); + char* str); /*!< in: buffer to write the id to */ /******************************************************************//** Read the table id from the string generated by fts_write_object_id(). @return TRUE if parse successful */ diff --git a/storage/innobase/include/fts0priv.ic b/storage/innobase/include/fts0priv.ic index ed737e520d6..da14cfcb013 100644 --- a/storage/innobase/include/fts0priv.ic +++ b/storage/innobase/include/fts0priv.ic @@ -32,10 +32,7 @@ int fts_write_object_id( /*================*/ ib_id_t id, /* in: a table/index id */ - char* str, /* in: buffer to write the id to */ - bool hex_format MY_ATTRIBUTE((unused))) - /* in: true for fixed hex format, - false for old ambiguous format */ + char* str) /* in: buffer to write the id to */ { #ifdef _WIN32 @@ -60,11 +57,6 @@ fts_write_object_id( #endif /* _WIN32 */ - /* As above, but this is only for those tables failing to rename. */ - if (!hex_format) { - return(sprintf(str, "%016llu", (ulonglong) id)); - } - return(sprintf(str, "%016llx", (ulonglong) id)); } diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index 446895b8f09..6704c5cff00 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -3940,9 +3940,21 @@ loop: avoid accessing dropped fts aux tables in information scheam when parent table still exists. Note: Drop parent table will drop fts aux tables. */ - char* parent_table_name; - parent_table_name = fts_get_parent_table_name( - table_name, strlen(table_name)); + char* parent_table_name = NULL; + table_id_t table_id; + index_id_t index_id; + + if (fts_check_aux_table( + table_name, &table_id, &index_id)) { + dict_table_t* parent_table = dict_table_open_on_id( + table_id, TRUE, DICT_TABLE_OP_NORMAL); + if (parent_table != NULL) { + parent_table_name = mem_strdupl( + parent_table->name.m_name, + strlen(parent_table->name.m_name)); + dict_table_close(parent_table, TRUE, FALSE); + } + } if (parent_table_name != NULL) { ut_free(table_name); From f19da4a05a14e217e77600cd452a345d209101cf Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Mon, 7 Sep 2020 14:23:05 +0530 Subject: [PATCH 08/48] MDEV-23199 page_compression flag is missing for full_crc32 tablespace Problem: ====== Making the tablespace as page_compressed doesn't do table rebuild. It does change only the FSP_SPACE_FLAGS. During recovery: 1) InnoDB encounters FILE_CREATE redo log and opens the tablespace with old FSP_SPACE_FLAGS value. 2) Only parsing of redo log has been finished. Now InnoDB tries to load the table. If the existing tablespace flags doesn't match with table flags then InnoDB should read page0. But in fsp_flags_try_adjust(), skips the page read for full_crc32 format. 3) After that, InnoDB tries to open the clustered index and it leads to failure of page validation. Fix: === While parsing the redo log record, track FSP_SPACE_FLAGS in recv_spaces for the respective space id. Assign the flags for the tablespace when it is loaded. recv_parse_set_size_and_flags(): Parse the redo log to set the tablespace recovery size and flags. fil_space_set_recv_size_and_flags(): Changed from fil_space_set_recv_size(). To set the recovery size and flags of the tablespace. Introduce flags variable in file_name_t to maintain the tablespace flag which we encountered during parsing of redo log. is_flags_full_crc32_equal(), is_flags_non_full_crc32_equal(): Rename the variable page_ssize and space_page_ssize with fcrc32_psize and non_fcrc32_psize. --- mysql-test/suite/innodb/r/table_flags.result | 10 +++ mysql-test/suite/innodb/t/table_flags.test | 14 ++++ storage/innobase/dict/dict0load.cc | 5 +- storage/innobase/fil/fil0fil.cc | 22 +++-- storage/innobase/include/fil0fil.h | 35 ++++---- storage/innobase/log/log0recv.cc | 85 +++++++++++++------- 6 files changed, 111 insertions(+), 60 deletions(-) diff --git a/mysql-test/suite/innodb/r/table_flags.result b/mysql-test/suite/innodb/r/table_flags.result index 7ede75f021a..9ef07c6954d 100644 --- a/mysql-test/suite/innodb/r/table_flags.result +++ b/mysql-test/suite/innodb/r/table_flags.result @@ -201,3 +201,13 @@ CREATE TABLE t1(f1 INT, f2 VARCHAR(1), KEY k1(f2), FULLTEXT KEY(f2), FOREIGN KEY (f2) REFERENCES t1(f3))ENGINE=InnoDB; ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") +# +# MDEV-23199 page_compression flag is missing +# for full_crc32 tablespace +# +CREATE TABLE t1(f1 BIGINT PRIMARY KEY)ENGINE=InnoDB; +INSERT INTO t1 VALUES(1); +ALTER TABLE t1 PAGE_COMPRESSED = 1; +INSERT INTO t1 VALUES(2); +# restart +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/table_flags.test b/mysql-test/suite/innodb/t/table_flags.test index 238530d25c5..79b2c3dd77a 100644 --- a/mysql-test/suite/innodb/t/table_flags.test +++ b/mysql-test/suite/innodb/t/table_flags.test @@ -16,6 +16,7 @@ call mtr.add_suppression("InnoDB: Operating system error number .* in a file ope call mtr.add_suppression("InnoDB: The error means the system cannot find the path specified"); call mtr.add_suppression("InnoDB: If you are installing InnoDB, remember that you must create directories yourself"); call mtr.add_suppression("InnoDB: adjusting FSP_SPACE_FLAGS of file "); +call mtr.add_suppression("InnoDB: Parent table of FTS auxiliary table .* not found."); FLUSH TABLES; --enable_query_log @@ -237,3 +238,16 @@ call mtr.add_suppression("ERROR HY000: Can't create table `test`.`t1`"); CREATE TABLE t1(f1 INT, f2 VARCHAR(1), KEY k1(f2), FULLTEXT KEY(f2), FOREIGN KEY (f2) REFERENCES t1(f3))ENGINE=InnoDB; + +--echo # +--echo # MDEV-23199 page_compression flag is missing +--echo # for full_crc32 tablespace +--echo # + +CREATE TABLE t1(f1 BIGINT PRIMARY KEY)ENGINE=InnoDB; +INSERT INTO t1 VALUES(1); +ALTER TABLE t1 PAGE_COMPRESSED = 1; +INSERT INTO t1 VALUES(2); +let $shutdown_timeout = 0; +--source include/restart_mysqld.inc +DROP TABLE t1; diff --git a/storage/innobase/dict/dict0load.cc b/storage/innobase/dict/dict0load.cc index 8094e4d9c08..41abe2d0a48 100644 --- a/storage/innobase/dict/dict0load.cc +++ b/storage/innobase/dict/dict0load.cc @@ -2710,8 +2710,9 @@ dict_get_and_save_data_dir_path( if (table->data_dir_path == NULL) { /* Since we did not set the table data_dir_path, unset the flag. This does not change SYS_DATAFILES - or SYS_TABLES or FSP_FLAGS on the header page of the - tablespace, but it makes dict_table_t consistent. */ + or SYS_TABLES or FSP_SPACE_FLAGS on the header page + of the tablespace, but it makes dict_table_t + consistent. */ table->flags &= ~DICT_TF_MASK_DATA_DIR; } diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 72639d16fd6..97f0a578fe9 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -1403,22 +1403,18 @@ fil_space_get_space( return(space); } -/** Set the recovered size of a tablespace in pages. -@param id tablespace ID -@param size recovered size in pages */ UNIV_INTERN -void -fil_space_set_recv_size(ulint id, ulint size) +void fil_space_set_recv_size_and_flags(ulint id, ulint size, uint32_t flags) { - mutex_enter(&fil_system.mutex); - ut_ad(size); - ut_ad(id < SRV_LOG_SPACE_FIRST_ID); + mutex_enter(&fil_system.mutex); + ut_ad(id < SRV_LOG_SPACE_FIRST_ID); - if (fil_space_t* space = fil_space_get_space(id)) { - space->recv_size = size; - } - - mutex_exit(&fil_system.mutex); + if (fil_space_t* space= fil_space_get_space(id)) + { + if (!size) space->recv_size= size; + if (flags != FSP_FLAGS_FCRC32_MASK_MARKER) space->flags= flags; + } + mutex_exit(&fil_system.mutex); } /*******************************************************************//** diff --git a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h index d0af38bd80f..3001817a78c 100644 --- a/storage/innobase/include/fil0fil.h +++ b/storage/innobase/include/fil0fil.h @@ -311,7 +311,7 @@ public: ulint flags; /** Determine if full_crc32 is used for a data file - @param[in] flags tablespace flags (FSP_FLAGS) + @param[in] flags tablespace flags (FSP_SPACE_FLAGS) @return whether the full_crc32 algorithm is active */ static bool full_crc32(ulint flags) { return flags & FSP_FLAGS_FCRC32_MASK_MARKER; @@ -430,23 +430,23 @@ public: static bool is_flags_full_crc32_equal(ulint flags, ulint expected) { ut_ad(full_crc32(flags)); - ulint page_ssize = FSP_FLAGS_FCRC32_GET_PAGE_SSIZE(flags); + ulint fcrc32_psize = FSP_FLAGS_FCRC32_GET_PAGE_SSIZE(flags); if (full_crc32(expected)) { /* The data file may have been created with a different innodb_compression_algorithm. But we only support one innodb_page_size for all files. */ - return page_ssize - == FSP_FLAGS_FCRC32_GET_PAGE_SSIZE(expected); + return fcrc32_psize + == FSP_FLAGS_FCRC32_GET_PAGE_SSIZE(expected); } - ulint space_page_ssize = FSP_FLAGS_GET_PAGE_SSIZE(expected); + ulint non_fcrc32_psize = FSP_FLAGS_GET_PAGE_SSIZE(expected); - if (page_ssize == 5) { - if (space_page_ssize) { + if (!non_fcrc32_psize) { + if (fcrc32_psize != 5) { return false; } - } else if (space_page_ssize != page_ssize) { + } else if (fcrc32_psize != non_fcrc32_psize) { return false; } @@ -464,15 +464,15 @@ public: return false; } - ulint page_ssize = FSP_FLAGS_GET_PAGE_SSIZE(flags); - ulint space_page_ssize = FSP_FLAGS_FCRC32_GET_PAGE_SSIZE( + ulint non_fcrc32_psize = FSP_FLAGS_GET_PAGE_SSIZE(flags); + ulint fcrc32_psize = FSP_FLAGS_FCRC32_GET_PAGE_SSIZE( expected); - if (page_ssize) { - if (space_page_ssize != 5) { + if (!non_fcrc32_psize) { + if (fcrc32_psize != 5) { return false; } - } else if (space_page_ssize != page_ssize) { + } else if (fcrc32_psize != non_fcrc32_psize) { return false; } @@ -1060,11 +1060,12 @@ fil_space_free( bool x_latched); /** Set the recovered size of a tablespace in pages. -@param id tablespace ID -@param size recovered size in pages */ +@param id tablespace ID +@param size recovered size in pages +@param flags tablespace flags */ UNIV_INTERN -void -fil_space_set_recv_size(ulint id, ulint size); +void fil_space_set_recv_size_and_flags(ulint id, ulint size, uint32_t flags); + /*******************************************************************//** Returns the size of the space in pages. The tablespace must be cached in the memory cache. diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index c9035ee8b79..4698b9fa441 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -144,17 +144,21 @@ struct file_name_t { fil_status status; /** FSP_SIZE of tablespace */ - ulint size; + ulint size = 0; /** the log sequence number of the last observed MLOG_INDEX_LOAD record for the tablespace */ - lsn_t enable_lsn; + lsn_t enable_lsn = 0; + + /** Dummy flags before they have been read from the .ibd file */ + static constexpr uint32_t initial_flags = FSP_FLAGS_FCRC32_MASK_MARKER; + /** FSP_SPACE_FLAGS of tablespace */ + uint32_t flags = initial_flags; /** Constructor */ file_name_t(std::string name_, bool deleted) : name(std::move(name_)), space(NULL), - status(deleted ? DELETED: NORMAL), - size(0), enable_lsn(0) {} + status(deleted ? DELETED: NORMAL) {} /** Report a MLOG_INDEX_LOAD operation, meaning that mlog_init for any earlier LSN must be skipped. @@ -440,14 +444,18 @@ fil_name_process( case FIL_LOAD_OK: ut_ad(space != NULL); - if (f.space == NULL || f.space == space) { - - if (f.size && f.space == NULL) { - fil_space_set_recv_size(space->id, f.size); + if (!f.space) { + if (f.size + || f.flags != f.initial_flags) { + fil_space_set_recv_size_and_flags( + space->id, f.size, f.flags); } - f.name = fname.name; f.space = space; + goto same_space; + } else if (f.space == space) { +same_space: + f.name = fname.name; f.status = file_name_t::NORMAL; } else { ib::error() << "Tablespace " << space_id @@ -2441,6 +2449,44 @@ apply: mutex_exit(&recv_sys.mutex); } +/** Parse the redo log to set the space recovery size and flags +@param[in] ptr pointer to parsing redo buffer +@param[in] end_ptr end of the parsing redo buffer +@param[in] space tablespace id */ +static +void recv_parse_set_size_and_flags(const byte *ptr, byte *end_ptr, + ulint space) +{ + switch (const uint16_t offset= mach_read_from_2(ptr)) + { + default: + break; + case FSP_HEADER_OFFSET + FSP_SIZE: + case FSP_HEADER_OFFSET + FSP_SPACE_FLAGS: + ptr += 2; + ulint val= mach_parse_compressed(&ptr, end_ptr); + recv_spaces_t::iterator it= recv_spaces.find(space); + + ut_ad(!recv_sys.mlog_checkpoint_lsn || space == TRX_SYS_SPACE || + srv_is_undo_tablespace(space) || it != recv_spaces.end()); + + if (offset == FSP_HEADER_OFFSET + FSP_SIZE) + fil_space_set_recv_size_and_flags( + space, val, FSP_FLAGS_FCRC32_MASK_MARKER); + else + fil_space_set_recv_size_and_flags( + space, 0, static_cast(val)); + + if (it == recv_spaces.end() || it->second.space) + return; + + if (offset == FSP_HEADER_OFFSET + FSP_SIZE) + it->second.size= val; + else + it->second.flags= static_cast(val); + } +} + /** Tries to parse a single log record. @param[out] type log record type @param[in] ptr pointer to a buffer @@ -2527,25 +2573,8 @@ recv_parse_log_rec( return(0); } - if (*page_no == 0 && *type == MLOG_4BYTES - && apply - && mach_read_from_2(old_ptr) == FSP_HEADER_OFFSET + FSP_SIZE) { - old_ptr += 2; - - ulint size = mach_parse_compressed(&old_ptr, end_ptr); - - recv_spaces_t::iterator it = recv_spaces.find(*space); - - ut_ad(!recv_sys.mlog_checkpoint_lsn - || *space == TRX_SYS_SPACE - || srv_is_undo_tablespace(*space) - || it != recv_spaces.end()); - - if (it != recv_spaces.end() && !it->second.space) { - it->second.size = size; - } - - fil_space_set_recv_size(*space, size); + if (*page_no == 0 && *type == MLOG_4BYTES && apply) { + recv_parse_set_size_and_flags(old_ptr, end_ptr, *space); } return ulint(new_ptr - ptr); From 224c950462a22e09f4e2e37d19218c9129bccba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 26 Aug 2020 14:11:17 +0300 Subject: [PATCH 09/48] MDEV-23101 : SIGSEGV in lock_rec_unlock() when Galera is enabled Remove incorrect BF (brute force) handling from lock_rec_has_to_wait_in_queue and move condition to correct callers. Add a function to report BF lock waits and assert if incorrect BF-BF lock wait happens. wsrep_report_bf_lock_wait Add a new function to report BF lock wait. wsrep_assert_no_bf_bf_wait Add a new function to check do we have a BF-BF wait and if we have report this case and assert as it is a bug. lock_rec_has_to_wait Use new wsrep_assert_bf_wait to check BF-BF wait. lock_rec_create_low lock_table_create Use new function to report BF lock waits. lock_rec_insert_by_trx_age lock_grant_and_move_on_page lock_grant_and_move_on_rec Assert that trx is not Galera as VATS is not compatible with Galera. lock_rec_add_to_queue If there is conflicting lock in a queue make sure that transaction is BF. lock_rec_has_to_wait_in_queue Remove incorrect BF handling. If there is conflicting locks in a queue all transactions must wait. lock_rec_dequeue_from_page lock_rec_unlock If there is conflicting lock make sure it is not BF-BF case. lock_rec_queue_validate Add Galera record locking rules comment and use new function to report BF lock waits. All attempts to reproduce the original assertion have been failed. Therefore, there is no test case on this commit. --- include/mysql/service_wsrep.h | 5 + sql/sql_plugin_services.ic | 3 +- sql/wsrep_dummy.cc | 6 +- sql/wsrep_thd.cc | 20 ++ sql/wsrep_thd.h | 3 + storage/innobase/lock/lock0lock.cc | 287 +++++++++++++---------------- 6 files changed, 168 insertions(+), 156 deletions(-) diff --git a/include/mysql/service_wsrep.h b/include/mysql/service_wsrep.h index 923ba57fcdc..54b9eb9250c 100644 --- a/include/mysql/service_wsrep.h +++ b/include/mysql/service_wsrep.h @@ -115,6 +115,8 @@ extern struct wsrep_service_st { void (*wsrep_unlock_rollback_func)(); void (*wsrep_set_data_home_dir_func)(const char *data_dir); my_bool (*wsrep_thd_is_applier_func)(MYSQL_THD); + void (*wsrep_report_bf_lock_wait_func)(MYSQL_THD thd, + unsigned long long trx_id); } *wsrep_service; #ifdef MYSQL_DYNAMIC_PLUGIN @@ -161,6 +163,7 @@ extern struct wsrep_service_st { #define wsrep_unlock_rollback() wsrep_service->wsrep_unlock_rollback_func() #define wsrep_set_data_home_dir(A) wsrep_service->wsrep_set_data_home_dir_func(A) #define wsrep_thd_is_applier(T) wsrep_service->wsrep_thd_is_applier_func(T) +#define wsrep_report_bf_lock_wait(T,I) wsrep_service->wsrep_report_bf_lock_wait_func(T,I) #define wsrep_debug get_wsrep_debug() #define wsrep_log_conflicts get_wsrep_log_conflicts() @@ -223,6 +226,8 @@ bool wsrep_thd_ignore_table(THD *thd); void wsrep_unlock_rollback(); void wsrep_set_data_home_dir(const char *data_dir); my_bool wsrep_thd_is_applier(MYSQL_THD thd); +void wsrep_report_bf_lock_wait(THD *thd, + unsigned long long trx_id); #endif #ifdef __cplusplus diff --git a/sql/sql_plugin_services.ic b/sql/sql_plugin_services.ic index 20113444b64..43fe540731e 100644 --- a/sql/sql_plugin_services.ic +++ b/sql/sql_plugin_services.ic @@ -184,7 +184,8 @@ static struct wsrep_service_st wsrep_handler = { wsrep_trx_order_before, wsrep_unlock_rollback, wsrep_set_data_home_dir, - wsrep_thd_is_applier + wsrep_thd_is_applier, + wsrep_report_bf_lock_wait }; static struct thd_specifics_service_st thd_specifics_handler= diff --git a/sql/wsrep_dummy.cc b/sql/wsrep_dummy.cc index d8ab86c25f2..53941c06892 100644 --- a/sql/wsrep_dummy.cc +++ b/sql/wsrep_dummy.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 SkySQL Ab. +/* Copyright (C) 2014, 2020, MariaDB 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 @@ -154,3 +154,7 @@ void wsrep_log(void (*)(const char *, ...), const char *, ...) my_bool wsrep_thd_is_applier(MYSQL_THD thd) { return false; } + +void wsrep_report_bf_lock_wait(MYSQL_THD thd, + unsigned long long id) +{} diff --git a/sql/wsrep_thd.cc b/sql/wsrep_thd.cc index 1e60088c5f1..4dddb399bd1 100644 --- a/sql/wsrep_thd.cc +++ b/sql/wsrep_thd.cc @@ -876,3 +876,23 @@ bool wsrep_is_load_multi_commit(THD *thd) { return thd->wsrep_split_flag; } + +void wsrep_report_bf_lock_wait(THD *thd, + unsigned long long trx_id) +{ + if (thd) + { + WSREP_ERROR("Thread %s trx_id: %llu thread: %ld " + "seqno: %lld query_state: %s conf_state: %s exec_mode: %s " + "applier: %d query: %s", + wsrep_thd_is_BF(thd, false) ? "BF" : "normal", + trx_id, + thd_get_thread_id(thd), + wsrep_thd_trx_seqno(thd), + wsrep_thd_query_state_str(thd), + wsrep_thd_conflict_state_str(thd), + wsrep_thd_exec_mode_str(thd), + thd->wsrep_applier, + wsrep_thd_query(thd)); + } +} diff --git a/sql/wsrep_thd.h b/sql/wsrep_thd.h index 10efcbefbf6..46bc08a466a 100644 --- a/sql/wsrep_thd.h +++ b/sql/wsrep_thd.h @@ -45,6 +45,9 @@ extern "C" my_bool wsrep_thd_is_BF_or_commit(void *thd_ptr, my_bool sync); extern "C" my_bool wsrep_thd_is_local(void *thd_ptr, my_bool sync); extern "C" int wsrep_thd_in_locking_session(void *thd_ptr); +extern void wsrep_report_bf_lock_wait(THD *thd, + unsigned long long trx_id); + #else /* WITH_WSREP */ #define wsrep_thd_is_BF(T, S) (0) diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index 4730ae53133..e48ac6bcc92 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -644,6 +644,57 @@ lock_rec_get_insert_intention( return(lock->type_mode & LOCK_INSERT_INTENTION); } +#ifdef WITH_WSREP +/** Check if both conflicting lock and other record lock are brute force +(BF). This case is a bug so report lock information and wsrep state. +@param[in] lock_rec1 conflicting waiting record lock or NULL +@param[in] lock_rec2 other waiting record lock +@param[in] trx1 lock_rec1 can be NULL, trx +*/ +static void wsrep_assert_no_bf_bf_wait( + const lock_t* lock_rec1, + const lock_t* lock_rec2, + const trx_t* trx1) +{ + ut_ad(!lock_rec1 || lock_get_type_low(lock_rec1) == LOCK_REC); + ut_ad(lock_get_type_low(lock_rec2) == LOCK_REC); + + if (!trx1->is_wsrep() || !lock_rec2->trx->is_wsrep()) + return; + if (UNIV_LIKELY(!wsrep_thd_is_BF(trx1->mysql_thd, FALSE))) + return; + if (UNIV_LIKELY(!wsrep_thd_is_BF(lock_rec2->trx->mysql_thd, FALSE))) + return; + + mtr_t mtr; + + if (lock_rec1) { + ib::error() << "Waiting lock on table: " + << lock_rec1->index->table->name + << " index: " + << lock_rec1->index->name() + << " that has conflicting lock "; + lock_rec_print(stderr, lock_rec1, mtr); + } + + ib::error() << "Conflicting lock on table: " + << lock_rec2->index->table->name + << " index: " + << lock_rec2->index->name() + << " that has lock "; + lock_rec_print(stderr, lock_rec2, mtr); + + ib::error() << "WSREP state: "; + + wsrep_report_bf_lock_wait(trx1->mysql_thd, + trx1->id); + wsrep_report_bf_lock_wait(lock_rec2->trx->mysql_thd, + lock_rec2->trx->id); + /* BF-BF wait is a bug */ + ut_error; +} +#endif /* WITH_WSREP */ + /*********************************************************************//** Checks if a lock request for a new lock has to wait for request lock2. @return TRUE if new lock has to wait for lock2 to be removed */ @@ -751,69 +802,9 @@ lock_rec_has_to_wait( } #ifdef WITH_WSREP - /* if BF thread is locking and has conflict with another BF - thread, we need to look at trx ordering and lock types */ - if (wsrep_thd_is_BF(trx->mysql_thd, FALSE) && - wsrep_thd_is_BF(lock2->trx->mysql_thd, FALSE)) { - mtr_t mtr; - - if (UNIV_UNLIKELY(wsrep_debug)) { - ib::info() << - "BF-BF lock conflict, locking: " << for_locking; - lock_rec_print(stderr, lock2, mtr); - ib::info() << " SQL1: " - << wsrep_thd_query(trx->mysql_thd); - ib::info() << " SQL2: " - << wsrep_thd_query(lock2->trx->mysql_thd); - } - - if (wsrep_trx_order_before(trx->mysql_thd, - lock2->trx->mysql_thd) && - (type_mode & LOCK_MODE_MASK) == LOCK_X && - (lock2->type_mode & LOCK_MODE_MASK) == LOCK_X) { - if (UNIV_UNLIKELY(for_locking || wsrep_debug)) { - /* exclusive lock conflicts are not - accepted */ - ib::info() << - "BF-BF X lock conflict," - "mode: " << type_mode << - " supremum: " << lock_is_on_supremum; - ib::info() << - "conflicts states: my " - << wsrep_thd_conflict_state(trx->mysql_thd, FALSE) - << " locked " - << wsrep_thd_conflict_state(lock2->trx->mysql_thd, FALSE); - lock_rec_print(stderr, lock2, mtr); - ib::info() << " SQL1: " - << wsrep_thd_query(trx->mysql_thd); - ib::info() << " SQL2: " - << wsrep_thd_query(lock2->trx->mysql_thd); - - if (for_locking) { - return FALSE; - } - } - } else { - /* if lock2->index->n_uniq <= - lock2->index->n_user_defined_cols - operation is on uniq index - */ - if (UNIV_UNLIKELY(wsrep_debug)) { - ib::info() << - "BF conflict, modes: " - << type_mode << ":" << lock2->type_mode - << " idx: " << lock2->index->name() - << " table: " << lock2->index->table->name.m_name - << " n_uniq: " << lock2->index->n_uniq - << " n_user: " << lock2->index->n_user_defined_cols; - ib::info() << " SQL1: " - << wsrep_thd_query(trx->mysql_thd); - ib::info() << " SQL2: " - << wsrep_thd_query(lock2->trx->mysql_thd); - } - return FALSE; - } - } + /* There should not be two conflicting locks that are + brute force. If there is it is a bug. */ + wsrep_assert_no_bf_bf_wait(NULL, lock2, trx); #endif /* WITH_WSREP */ return(TRUE); @@ -1532,11 +1523,8 @@ lock_rec_create_low( trx_mutex_exit(c_lock->trx); if (UNIV_UNLIKELY(wsrep_debug)) { - ib::info() << "WSREP: c_lock canceled " - << ib::hex(c_lock->trx->id) - << " SQL: " - << wsrep_thd_query( - c_lock->trx->mysql_thd); + wsrep_report_bf_lock_wait(trx->mysql_thd, trx->id); + wsrep_report_bf_lock_wait(c_lock->trx->mysql_thd, c_lock->trx->id); } /* have to bail out here to avoid lock_set_lock... */ @@ -1615,6 +1603,7 @@ lock_rec_insert_by_trx_age( hash_table_t* hash; hash_cell_t* cell; + ut_ad(!in_lock->trx->is_wsrep()); space = in_lock->un_member.rec_lock.space; page_no = in_lock->un_member.rec_lock.page_no; rec_fold = lock_rec_fold(space, page_no); @@ -1877,27 +1866,19 @@ lock_rec_add_to_queue( = lock_rec_other_has_expl_req( mode, block, false, heap_no, trx); #ifdef WITH_WSREP - if (other_lock && trx->is_wsrep() && - !wsrep_thd_is_BF(trx->mysql_thd, FALSE) && - !wsrep_thd_is_BF(other_lock->trx->mysql_thd, FALSE)) { - - ib::info() << "WSREP BF lock conflict for my lock:\n BF:" << - ((wsrep_thd_is_BF(trx->mysql_thd, FALSE)) ? "BF" : "normal") << " exec: " << - wsrep_thd_exec_mode(trx->mysql_thd) << " conflict: " << - wsrep_thd_conflict_state(trx->mysql_thd, false) << " seqno: " << - wsrep_thd_trx_seqno(trx->mysql_thd) << " SQL: " << - wsrep_thd_query(trx->mysql_thd); - trx_t* otrx = other_lock->trx; - ib::info() << "WSREP other lock:\n BF:" << - ((wsrep_thd_is_BF(otrx->mysql_thd, FALSE)) ? "BF" : "normal") << " exec: " << - wsrep_thd_exec_mode(otrx->mysql_thd) << " conflict: " << - wsrep_thd_conflict_state(otrx->mysql_thd, false) << " seqno: " << - wsrep_thd_trx_seqno(otrx->mysql_thd) << " SQL: " << - wsrep_thd_query(otrx->mysql_thd); - } -#else - ut_a(!other_lock); + if (UNIV_UNLIKELY(other_lock && trx->is_wsrep())) { + /* Only BF transaction may be granted lock + before other conflicting lock request. */ + if (!wsrep_thd_is_BF(trx->mysql_thd, FALSE) + && !wsrep_thd_is_BF(other_lock->trx->mysql_thd, FALSE)) { + /* If it is not BF, this case is a bug. */ + wsrep_report_bf_lock_wait(trx->mysql_thd, trx->id); + wsrep_report_bf_lock_wait(other_lock->trx->mysql_thd, other_lock->trx->id); + ut_error; + } + } else #endif /* WITH_WSREP */ + ut_ad(!other_lock); } #endif /* UNIV_DEBUG */ @@ -2203,9 +2184,6 @@ lock_rec_has_to_wait_in_queue( hash = lock_hash_get(wait_lock->type_mode); for (lock = lock_rec_get_first_on_page_addr(hash, space, page_no); -#ifdef WITH_WSREP - lock && -#endif lock != wait_lock; lock = lock_rec_get_next_on_page_const(lock)) { const byte* p = (const byte*) &lock[1]; @@ -2213,24 +2191,6 @@ lock_rec_has_to_wait_in_queue( if (heap_no < lock_rec_get_n_bits(lock) && (p[bit_offset] & bit_mask) && lock_has_to_wait(wait_lock, lock)) { -#ifdef WITH_WSREP - if (wsrep_thd_is_BF(wait_lock->trx->mysql_thd, FALSE) && - wsrep_thd_is_BF(lock->trx->mysql_thd, FALSE)) { - - if (UNIV_UNLIKELY(wsrep_debug)) { - mtr_t mtr; - ib::info() << "WSREP: waiting BF trx: " << ib::hex(wait_lock->trx->id) - << " query: " << wsrep_thd_query(wait_lock->trx->mysql_thd); - lock_rec_print(stderr, wait_lock, mtr); - ib::info() << "WSREP: do not wait another BF trx: " << ib::hex(lock->trx->id) - << " query: " << wsrep_thd_query(lock->trx->mysql_thd); - lock_rec_print(stderr, lock, mtr); - } - /* don't wait for another BF lock */ - continue; - } -#endif /* WITH_WSREP */ - return(lock); } } @@ -2346,6 +2306,7 @@ lock_grant_and_move_on_page(ulint rec_fold, ulint space, ulint page_no) lock = previous->hash; } + ut_ad(!lock->trx->is_wsrep()); ut_ad(previous->hash == lock || previous == lock); /* Grant locks if there are no conflicting locks ahead. Move granted locks to the head of the list. */ @@ -2416,11 +2377,18 @@ static void lock_rec_dequeue_from_page(lock_t* in_lock) lock != NULL; lock = lock_rec_get_next_on_page(lock)) { - if (lock_get_wait(lock) - && !lock_rec_has_to_wait_in_queue(lock)) { + if (!lock_get_wait(lock)) { + continue; + } + const lock_t* c = lock_rec_has_to_wait_in_queue(lock); + if (!c) { /* Grant the lock */ ut_ad(lock->trx != in_lock->trx); lock_grant(lock); +#ifdef WITH_WSREP + } else { + wsrep_assert_no_bf_bf_wait(c, lock, c->trx); +#endif /* WITH_WSREP */ } } } else { @@ -3662,11 +3630,8 @@ lock_table_create( ut_list_insert(table->locks, c_lock, lock, TableLockGetNode()); if (UNIV_UNLIKELY(wsrep_debug)) { - ib::info() << "table lock BF conflict for " - << ib::hex(c_lock->trx->id) - << " SQL: " - << wsrep_thd_query( - c_lock->trx->mysql_thd); + wsrep_report_bf_lock_wait(trx->mysql_thd, trx->id); + wsrep_report_bf_lock_wait(c_lock->trx->mysql_thd, c_lock->trx->id); } } else { ut_list_append(table->locks, lock, TableLockGetNode()); @@ -3678,6 +3643,8 @@ lock_table_create( c_lock->trx->lock.was_chosen_as_deadlock_victim = TRUE; if (UNIV_UNLIKELY(wsrep_debug)) { + wsrep_report_bf_lock_wait(trx->mysql_thd, trx->id); + wsrep_report_bf_lock_wait(c_lock->trx->mysql_thd, c_lock->trx->id); wsrep_print_wait_locks(c_lock); } @@ -3687,14 +3654,6 @@ lock_table_create( lock_cancel_waiting_and_release( c_lock->trx->lock.wait_lock); trx_mutex_enter(trx); - - if (UNIV_UNLIKELY(wsrep_debug)) { - ib::info() << "WSREP: c_lock canceled " - << ib::hex(c_lock->trx->id) - << " SQL: " - << wsrep_thd_query( - c_lock->trx->mysql_thd); - } } trx_mutex_exit(c_lock->trx); @@ -4252,6 +4211,7 @@ lock_grant_and_move_on_rec( } lock = previous->hash; } + ut_ad(!lock->trx->is_wsrep()); /* Grant locks if there are no conflicting locks ahead. Move granted locks to the head of the list. */ for (;lock != NULL;) { @@ -4350,12 +4310,18 @@ released: for (lock = first_lock; lock != NULL; lock = lock_rec_get_next(heap_no, lock)) { - if (lock_get_wait(lock) - && !lock_rec_has_to_wait_in_queue(lock)) { - + if (!lock_get_wait(lock)) { + continue; + } + const lock_t* c = lock_rec_has_to_wait_in_queue(lock); + if (!c) { /* Grant the lock */ ut_ad(trx != lock->trx); lock_grant(lock); +#ifdef WITH_WSREP + } else { + wsrep_assert_no_bf_bf_wait(c, lock, c->trx); +#endif /* WITH_WSREP */ } } } else { @@ -5254,24 +5220,28 @@ lock_rec_queue_validate( explicit granted lock. */ #ifdef WITH_WSREP - if (other_lock->trx->is_wsrep()) { - if (!lock_get_wait(other_lock) ) { - ib::info() << "WSREP impl BF lock conflict for my impl lock:\n BF:" << - ((wsrep_thd_is_BF(impl_trx->mysql_thd, FALSE)) ? "BF" : "normal") << " exec: " << - wsrep_thd_exec_mode(impl_trx->mysql_thd) << " conflict: " << - wsrep_thd_conflict_state(impl_trx->mysql_thd, false) << " seqno: " << - wsrep_thd_trx_seqno(impl_trx->mysql_thd) << " SQL: " << - wsrep_thd_query(impl_trx->mysql_thd); - - trx_t* otrx = other_lock->trx; - - ib::info() << "WSREP other lock:\n BF:" << - ((wsrep_thd_is_BF(otrx->mysql_thd, FALSE)) ? "BF" : "normal") << " exec: " << - wsrep_thd_exec_mode(otrx->mysql_thd) << " conflict: " << - wsrep_thd_conflict_state(otrx->mysql_thd, false) << " seqno: " << - wsrep_thd_trx_seqno(otrx->mysql_thd) << " SQL: " << - wsrep_thd_query(otrx->mysql_thd); - } + /** Galera record locking rules: + * If there is no other record lock to the same record, we may grant + the lock request. + * If there is other record lock but this requested record lock is + compatible, we may grant the lock request. + * If there is other record lock and it is not compatible with + requested lock, all normal transactions must wait. + * BF (brute force) additional exceptions : + ** If BF already holds record lock for requested record, we may + grant new record lock even if there is conflicting record lock(s) + waiting on a queue. + ** If conflicting transaction holds requested record lock, + we will cancel this record lock and select conflicting transaction + for BF abort or kill victim. + ** If conflicting transaction is waiting for requested record lock + we will cancel this wait and select conflicting transaction + for BF abort or kill victim. + ** There should not be two BF transactions waiting for same record lock + */ + if (other_lock->trx->is_wsrep() && !lock_get_wait(other_lock)) { + wsrep_report_bf_lock_wait(impl_trx->mysql_thd, impl_trx->id); + wsrep_report_bf_lock_wait(other_lock->trx->mysql_thd, other_lock->trx->id); if (!lock_rec_has_expl(LOCK_X | LOCK_REC_NOT_GAP, block, heap_no, @@ -5280,9 +5250,11 @@ lock_rec_queue_validate( } } else #endif /* WITH_WSREP */ - ut_ad(lock_get_wait(other_lock)); - ut_ad(lock_rec_has_expl(LOCK_X | LOCK_REC_NOT_GAP, - block, heap_no, impl_trx)); + { + ut_ad(lock_get_wait(other_lock)); + ut_ad(lock_rec_has_expl(LOCK_X | LOCK_REC_NOT_GAP, + block, heap_no, impl_trx)); + } } mutex_exit(&impl_trx->mutex); @@ -5313,13 +5285,20 @@ lock_rec_queue_validate( mode, block, false, heap_no, lock->trx); #ifdef WITH_WSREP - ut_a(!other_lock - || wsrep_thd_is_BF(lock->trx->mysql_thd, FALSE) - || wsrep_thd_is_BF(other_lock->trx->mysql_thd, FALSE)); - -#else - ut_a(!other_lock); + if (UNIV_UNLIKELY(other_lock && lock->trx->is_wsrep())) { + /* Only BF transaction may be granted + lock before other conflicting lock + request. */ + if (!wsrep_thd_is_BF(lock->trx->mysql_thd, FALSE) + && !wsrep_thd_is_BF(other_lock->trx->mysql_thd, FALSE)) { + /* If no BF, this case is a bug. */ + wsrep_report_bf_lock_wait(lock->trx->mysql_thd, lock->trx->id); + wsrep_report_bf_lock_wait(other_lock->trx->mysql_thd, other_lock->trx->id); + ut_error; + } + } else #endif /* WITH_WSREP */ + ut_ad(!other_lock); } else if (lock_get_wait(lock) && !lock_rec_get_gap(lock)) { ut_a(lock_rec_has_to_wait_in_queue(lock)); From 8993e40dde2803156bacd9977495336eb8c03cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 10 Sep 2020 13:25:57 +0300 Subject: [PATCH 10/48] MDEV-23709 : Galera test failure on galera_fk_cascade_delete_debug Add wait_condition so that inserts to parent and child are replicated and applied before we set debug sync point. --- .../suite/galera/r/galera_fk_cascade_delete_debug.result | 1 + .../suite/galera/t/galera_fk_cascade_delete_debug.test | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/galera/r/galera_fk_cascade_delete_debug.result b/mysql-test/suite/galera/r/galera_fk_cascade_delete_debug.result index 33ae66b1989..bd76692b27c 100644 --- a/mysql-test/suite/galera/r/galera_fk_cascade_delete_debug.result +++ b/mysql-test/suite/galera/r/galera_fk_cascade_delete_debug.result @@ -46,6 +46,7 @@ ON DELETE CASCADE ) ENGINE=InnoDB; INSERT INTO parent VALUES (1); INSERT INTO child VALUES (1,0,1); +connection node_2; connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; SET GLOBAL debug_dbug = "d,sync.wsrep_apply_cb"; connection node_2; diff --git a/mysql-test/suite/galera/t/galera_fk_cascade_delete_debug.test b/mysql-test/suite/galera/t/galera_fk_cascade_delete_debug.test index f38c028b7d6..96e633f83d7 100644 --- a/mysql-test/suite/galera/t/galera_fk_cascade_delete_debug.test +++ b/mysql-test/suite/galera/t/galera_fk_cascade_delete_debug.test @@ -61,20 +61,21 @@ CREATE TABLE child ( INSERT INTO parent VALUES (1); INSERT INTO child VALUES (1,0,1); +--connection node_2 +--let $wait_condition = SELECT COUNT(*) = 1 FROM child; +--source include/wait_condition.inc + # block applier before applying --connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1 SET GLOBAL debug_dbug = "d,sync.wsrep_apply_cb"; --connection node_2 ---let $wait_condition = SELECT COUNT(*) = 1 FROM child; ---source include/wait_condition.inc DELETE FROM parent; --connection node_1a # wait until applier has reached the sync point SET SESSION DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached"; - --connection node_1 # issue conflicting write to child table, it should fail in certification --error ER_LOCK_DEADLOCK From bfd1ed5a130ecb9c1061f0e75d30463439a66277 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Fri, 11 Sep 2020 12:24:29 +0530 Subject: [PATCH 11/48] MDEV-18867 Long Time to Stop and Start - Addressing ASAN failure in fts_check_aux_table() --- storage/innobase/fts/fts0fts.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index db549b58bd4..8ff872eab29 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -5804,12 +5804,13 @@ bool fts_check_aux_table(const char *name, /* First search the common table suffix array. */ for (ulint i = 0; fts_common_tables[i]; ++i) { - if (!memcmp(ptr, fts_common_tables[i], len)) + if (!strncmp(ptr, fts_common_tables[i], len)) return true; } /* Could be obsolete common tables. */ - if (!memcmp(ptr, "ADDED", len) || !memcmp(ptr, "STOPWORDS", len)) + if ((len == 5 && !memcmp(ptr, "ADDED", len)) || + (len == 9 && !memcmp(ptr, "STOPWORDS", len))) return true; const char* index_id_ptr= ptr; @@ -5836,7 +5837,7 @@ bool fts_check_aux_table(const char *name, } /* Other FT index specific table(s). */ - if (!memcmp(ptr, "DOC_ID", len)) + if (len == 6 && !memcmp(ptr, "DOC_ID", len)) return true; } From af834c218a59b0f187edb19aa4f8bd476b9ed6ac Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Fri, 11 Sep 2020 16:37:13 +0530 Subject: [PATCH 12/48] MDEV-23199 page_compression flag is missing for full_crc32 tablespace - Changed the fil_space_set_recv_size_and_flags() to set the tablespace size when size is not zero. --- storage/innobase/fil/fil0fil.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 97f0a578fe9..8bc32aa4443 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -1411,7 +1411,7 @@ void fil_space_set_recv_size_and_flags(ulint id, ulint size, uint32_t flags) if (fil_space_t* space= fil_space_get_space(id)) { - if (!size) space->recv_size= size; + if (size) space->recv_size= size; if (flags != FSP_FLAGS_FCRC32_MASK_MARKER) space->flags= flags; } mutex_exit(&fil_system.mutex); From bc2dbdb601e0c55b61c2ecbe2e64c119e41fec70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 11 Sep 2020 12:21:00 +0300 Subject: [PATCH 13/48] MDEV-23587 : galera_3nodes.galera_var_dirty_reads2 MTR failed: 1047: WSREP has not yet prepared node for application use Add wait_condition tomake sure insert is replicated and server is after isolation back on ready state. --- .../suite/galera_3nodes/r/galera_var_dirty_reads2.result | 2 +- .../suite/galera_3nodes/t/galera_var_dirty_reads2.test | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/mysql-test/suite/galera_3nodes/r/galera_var_dirty_reads2.result b/mysql-test/suite/galera_3nodes/r/galera_var_dirty_reads2.result index 77991a6d468..b4944fc87da 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_var_dirty_reads2.result +++ b/mysql-test/suite/galera_3nodes/r/galera_var_dirty_reads2.result @@ -2,7 +2,7 @@ connection node_1; connection node_2; connection node_3; connection node_1; -CREATE TABLE t1 (f1 INTEGER); +CREATE TABLE t1 (f1 INTEGER) ENGINE=INNODB; INSERT INTO t1 VALUES (1); connection node_2; SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; diff --git a/mysql-test/suite/galera_3nodes/t/galera_var_dirty_reads2.test b/mysql-test/suite/galera_3nodes/t/galera_var_dirty_reads2.test index 6476c4fe4fa..63eff486ba3 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_var_dirty_reads2.test +++ b/mysql-test/suite/galera_3nodes/t/galera_var_dirty_reads2.test @@ -16,10 +16,13 @@ --source ../galera/include/auto_increment_offset_save.inc --connection node_1 -CREATE TABLE t1 (f1 INTEGER); +CREATE TABLE t1 (f1 INTEGER) ENGINE=INNODB; INSERT INTO t1 VALUES (1); --connection node_2 +--let $wait_condition = SELECT COUNT(*) = 1 FROM t1; +--source include/wait_condition.inc + SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; --connection node_1 @@ -28,15 +31,11 @@ SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; --connection node_2 SET SESSION wsrep_sync_wait = 0; - --let $wait_condition = SELECT VARIABLE_VALUE = 'non-Primary' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_status'; --source include/wait_condition.inc SET SESSION wsrep_dirty_reads = 1; ---let $wait_condition = SELECT COUNT(*) = 1 FROM t1; ---source include/wait_condition.inc - # Those statements should succeed --error 0 From c3a3b4596c9e1c922afb00b4222c6496535f0f40 Mon Sep 17 00:00:00 2001 From: Sachin Date: Fri, 11 Sep 2020 15:27:58 +0100 Subject: [PATCH 14/48] MDEV-17438 rpl.show_status_stop_slave_race-7126 fails with timeout on Windows Problem:- Test case uses socket which does not work on windows, So mysqlslap falls back to default connection which is defined in my.cnf and connects to master instead of slave. Since start slave/stop slave is executed on master we get error MASTER_HOST was not set Solution:- Use Port instead of socket --- mysql-test/suite/rpl/t/show_status_stop_slave_race-7126.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/suite/rpl/t/show_status_stop_slave_race-7126.test b/mysql-test/suite/rpl/t/show_status_stop_slave_race-7126.test index 38759c9b16a..b43de60738e 100644 --- a/mysql-test/suite/rpl/t/show_status_stop_slave_race-7126.test +++ b/mysql-test/suite/rpl/t/show_status_stop_slave_race-7126.test @@ -7,7 +7,7 @@ # If everything is okay, the test will end in several seconds; maybe a minute. # If the problem shows up, it will hang until testcase timeout is exceeded. ---exec $MYSQL_SLAP --silent --socket=$SLAVE_MYSOCK -q "START SLAVE; STOP SLAVE; SHOW GLOBAL STATUS" -c 2 --number-of-queries=100 --create-schema=test +--exec $MYSQL_SLAP --silent --host=127.0.0.1 -P $SLAVE_MYPORT -q "START SLAVE; STOP SLAVE; SHOW GLOBAL STATUS" -c 2 --number-of-queries=100 --create-schema=test # All done. From 269f9c948c5f6bd0bdf8382d5c2ae266a02149e6 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sat, 12 Sep 2020 09:27:46 +1000 Subject: [PATCH 15/48] mysql_upgrade: fix error text --- client/mysql_upgrade.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index d18dc97c9b8..9cc12c8d7e7 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -1108,7 +1108,7 @@ static int check_version_match(void) extract_variable_from_show(&ds_version, version_str)) { print_error("Version check failed. Got the following error when calling " - "the 'mysql' command line client", &ds_version); + "the 'mysql_upgrade' command line client", &ds_version); dynstr_free(&ds_version); return 1; /* Query failed */ } From ae8ff3a067c046bf7df1cce175078914c6879d81 Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Wed, 9 Sep 2020 11:41:06 +1000 Subject: [PATCH 16/48] MDEV-20396 Server crashes after DELETE with SEL NULL Foreign key and a virtual column in index Problem: row_ins_foreign_fill_virtual was unconditionally set virtual fields to NULL even though the field is not a part of a foreign key (but a part of an index) Solution: The new virtual value should be computed with regard to cascade updates. --- .../suite/gcol/r/innodb_virtual_fk.result | 29 +++++++++++++ .../suite/gcol/t/innodb_virtual_fk.test | 32 +++++++++++++++ storage/innobase/row/row0ins.cc | 41 ++++++++----------- 3 files changed, 79 insertions(+), 23 deletions(-) diff --git a/mysql-test/suite/gcol/r/innodb_virtual_fk.result b/mysql-test/suite/gcol/r/innodb_virtual_fk.result index d5b4755e3c5..a3cdacb67a2 100644 --- a/mysql-test/suite/gcol/r/innodb_virtual_fk.result +++ b/mysql-test/suite/gcol/r/innodb_virtual_fk.result @@ -740,3 +740,32 @@ t1 CREATE TABLE `t1` ( KEY `v4` (`v4`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 DROP TABLE t1; +# +# MDEV-20396 Server crashes after DELETE with SEL NULL Foreign key and a +# virtual column in index +# +CREATE TABLE parent +( +ID int unsigned NOT NULL, +PRIMARY KEY (ID) +); +CREATE TABLE child +( +ID int unsigned NOT NULL, +ParentID int unsigned NULL, +Value int unsigned NOT NULL DEFAULT 0, +Flag int unsigned AS (Value) VIRTUAL, +PRIMARY KEY (ID), +KEY (ParentID, Flag), +FOREIGN KEY (ParentID) REFERENCES parent (ID) ON DELETE SET NULL +ON UPDATE CASCADE +); +INSERT INTO parent (ID) VALUES (100); +INSERT INTO child (ID,ParentID,Value) VALUES (123123,100,1); +DELETE FROM parent WHERE ID=100; +select * from child; +ID ParentID Value Flag +123123 NULL 1 1 +INSERT INTO parent (ID) VALUES (100); +UPDATE child SET ParentID=100 WHERE ID=123123; +DROP TABLE child, parent; diff --git a/mysql-test/suite/gcol/t/innodb_virtual_fk.test b/mysql-test/suite/gcol/t/innodb_virtual_fk.test index c484bb5dc0c..226bacabaef 100644 --- a/mysql-test/suite/gcol/t/innodb_virtual_fk.test +++ b/mysql-test/suite/gcol/t/innodb_virtual_fk.test @@ -605,3 +605,35 @@ ALTER TABLE t1 ADD CONSTRAINT fk FOREIGN KEY (v4) REFERENCES nosuch(col); SHOW CREATE TABLE t1; # Cleanup DROP TABLE t1; + +--echo # +--echo # MDEV-20396 Server crashes after DELETE with SEL NULL Foreign key and a +--echo # virtual column in index +--echo # +CREATE TABLE parent +( + ID int unsigned NOT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE child +( + ID int unsigned NOT NULL, + ParentID int unsigned NULL, + Value int unsigned NOT NULL DEFAULT 0, + Flag int unsigned AS (Value) VIRTUAL, + PRIMARY KEY (ID), + KEY (ParentID, Flag), + FOREIGN KEY (ParentID) REFERENCES parent (ID) ON DELETE SET NULL + ON UPDATE CASCADE +); + +INSERT INTO parent (ID) VALUES (100); +INSERT INTO child (ID,ParentID,Value) VALUES (123123,100,1); +DELETE FROM parent WHERE ID=100; +select * from child; +INSERT INTO parent (ID) VALUES (100); +UPDATE child SET ParentID=100 WHERE ID=123123; + +# Cleanup +DROP TABLE child, parent; diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index af6d2f5fa83..87f62125c03 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -945,8 +945,6 @@ row_ins_foreign_fill_virtual( &ext, cascade->heap); n_diff = update->n_fields; - update->n_fields += n_v_fld; - if (index->table->vc_templ == NULL) { /** This can occur when there is a cascading delete or update after restart. */ @@ -979,7 +977,7 @@ row_ins_foreign_fill_virtual( return DB_COMPUTE_VALUE_FAILED; } - upd_field = upd_get_nth_field(update, n_diff); + upd_field = update->fields + n_diff; upd_field->old_v_val = static_cast( mem_heap_alloc(cascade->heap, @@ -989,30 +987,27 @@ row_ins_foreign_fill_virtual( upd_field_set_v_field_no(upd_field, i, index); - if (node->is_delete - ? (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) - : (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL)) { + bool set_null = + node->is_delete + ? (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) + : (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL); - dfield_set_null(&upd_field->new_val); + dfield_t* new_vfield = innobase_get_computed_value( + update->old_vrow, col, index, + &vc.heap, update->heap, NULL, thd, + mysql_table, record, NULL, + set_null ? update : node->update, foreign); + + if (new_vfield == NULL) { + return DB_COMPUTE_VALUE_FAILED; } - if (!node->is_delete - && (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE)) { + dfield_copy(&upd_field->new_val, new_vfield); - dfield_t* new_vfield = innobase_get_computed_value( - update->old_vrow, col, index, - &vc.heap, update->heap, NULL, thd, - mysql_table, record, NULL, - node->update, foreign); - - if (new_vfield == NULL) { - return DB_COMPUTE_VALUE_FAILED; - } - - dfield_copy(&(upd_field->new_val), new_vfield); - } - - n_diff++; + if (!dfield_datas_are_binary_equal( + upd_field->old_v_val, + &upd_field->new_val, 0)) + n_diff++; } update->n_fields = n_diff; From 80075ba011fb1b90aaf349a17a6f94145c5c8864 Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Mon, 7 Sep 2020 19:43:23 +0300 Subject: [PATCH 17/48] MDEV-19264 Better support MariaDB GTID for Mariabackup's --slave-info option Parse SHOW SLAVE STATUS output for the "Using_Gtid" column. If the value is "No", then old log file and position is backed up, otherwise gtid_slave_pos is backed up. --- extra/mariabackup/backup_mysql.cc | 5 +- .../suite/mariabackup/rpl_slave_info.result | 37 ++++++++ .../suite/mariabackup/rpl_slave_info.test | 84 +++++++++++++++++++ 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/mariabackup/rpl_slave_info.result create mode 100644 mysql-test/suite/mariabackup/rpl_slave_info.test diff --git a/extra/mariabackup/backup_mysql.cc b/extra/mariabackup/backup_mysql.cc index 171c4407ed5..1d7242c5c75 100644 --- a/extra/mariabackup/backup_mysql.cc +++ b/extra/mariabackup/backup_mysql.cc @@ -1199,6 +1199,7 @@ write_slave_info(MYSQL *connection) char *master = NULL; char *filename = NULL; char *gtid_executed = NULL; + char *using_gtid = NULL; char *position = NULL; char *gtid_slave_pos = NULL; char *ptr; @@ -1209,6 +1210,7 @@ write_slave_info(MYSQL *connection) {"Relay_Master_Log_File", &filename}, {"Exec_Master_Log_Pos", &position}, {"Executed_Gtid_Set", >id_executed}, + {"Using_Gtid", &using_gtid}, {NULL, NULL} }; @@ -1249,7 +1251,8 @@ write_slave_info(MYSQL *connection) ut_a(asprintf(&mysql_slave_position, "master host '%s', purge list '%s'", master, gtid_executed) != -1); - } else if (gtid_slave_pos && *gtid_slave_pos) { + } else if (gtid_slave_pos && *gtid_slave_pos && + !(using_gtid && !strncmp(using_gtid, "No", 2))) { /* MariaDB >= 10.0 with GTID enabled */ result = backup_file_printf(XTRABACKUP_SLAVE_INFO, "SET GLOBAL gtid_slave_pos = '%s';\n" diff --git a/mysql-test/suite/mariabackup/rpl_slave_info.result b/mysql-test/suite/mariabackup/rpl_slave_info.result new file mode 100644 index 00000000000..13044fd6c39 --- /dev/null +++ b/mysql-test/suite/mariabackup/rpl_slave_info.result @@ -0,0 +1,37 @@ +include/master-slave.inc +[connection master] +connection slave; +############### +# If Using_Gtid != 'No', backup gtid_slave_pos +######################## +include/stop_slave.inc +change master to master_use_gtid=slave_pos; +include/start_slave.inc +connection master; +CREATE TABLE t(i INT); +connection slave; +"using_gtid: Slave_Pos" +FOUND 1 /gtid_slave_pos/ in xtrabackup_slave_info +NOT FOUND /MASTER_LOG_FILE/ in xtrabackup_slave_info +############### +# If Using_Gtid != 'No' and !gtid_slave_pos, backup master position +######################## +include/stop_slave.inc +SET GLOBAL gtid_slave_pos=""; +NOT FOUND /gtid_slave_pos/ in xtrabackup_slave_info +FOUND 1 /MASTER_LOG_FILE/ in xtrabackup_slave_info +############### +# If Using_Gtid == 'No', backup Exec_Master_Log_Pos +######################## +change master to master_use_gtid=no; +include/start_slave.inc +connection master; +INSERT INTO t VALUES(1); +connection slave; +"using_gtid: No" +NOT FOUND /gtid_slave_pos/ in xtrabackup_slave_info +FOUND 1 /MASTER_LOG_FILE/ in xtrabackup_slave_info +connection master; +DROP TABLE t; +connection slave; +include/rpl_end.inc diff --git a/mysql-test/suite/mariabackup/rpl_slave_info.test b/mysql-test/suite/mariabackup/rpl_slave_info.test new file mode 100644 index 00000000000..ca7682d8af9 --- /dev/null +++ b/mysql-test/suite/mariabackup/rpl_slave_info.test @@ -0,0 +1,84 @@ +--source include/master-slave.inc + +--connection slave + +--echo ############### +--echo # If Using_Gtid != 'No', backup gtid_slave_pos +--echo ######################## + +--source include/stop_slave.inc +change master to master_use_gtid=slave_pos; +--source include/start_slave.inc + +--connection master +CREATE TABLE t(i INT); +--sync_slave_with_master + +--let $using_gtid=query_get_value(SHOW SLAVE STATUS,Using_Gtid,1) +--echo "using_gtid: $using_gtid" + +--let $targetdir=$MYSQLTEST_VARDIR/tmp/backup +--disable_result_log +exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group-suffix=.2 --slave-info --backup --target-dir=$targetdir; +--enable_result_log + +--let SEARCH_FILE=$targetdir/xtrabackup_slave_info +--let SEARCH_PATTERN=gtid_slave_pos +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=MASTER_LOG_FILE +--source include/search_pattern_in_file.inc + +rmdir $targetdir; + +--echo ############### +--echo # If Using_Gtid != 'No' and !gtid_slave_pos, backup master position +--echo ######################## + +--source include/stop_slave.inc +SET GLOBAL gtid_slave_pos=""; + +--let $targetdir=$MYSQLTEST_VARDIR/tmp/backup +--disable_result_log +exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group-suffix=.2 --slave-info --backup --target-dir=$targetdir; +--enable_result_log + +--let SEARCH_FILE=$targetdir/xtrabackup_slave_info +--let SEARCH_PATTERN=gtid_slave_pos +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=MASTER_LOG_FILE +--source include/search_pattern_in_file.inc + +rmdir $targetdir; + +--echo ############### +--echo # If Using_Gtid == 'No', backup Exec_Master_Log_Pos +--echo ######################## + +change master to master_use_gtid=no; +--source include/start_slave.inc + +--connection master +INSERT INTO t VALUES(1); +--sync_slave_with_master + +--let $using_gtid=query_get_value(SHOW SLAVE STATUS,Using_Gtid,1) +--echo "using_gtid: $using_gtid" + +--let $targetdir=$MYSQLTEST_VARDIR/tmp/backup +--disable_result_log +exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group-suffix=.2 --slave-info --backup --target-dir=$targetdir; +--enable_result_log + +--let SEARCH_FILE=$targetdir/xtrabackup_slave_info +--let SEARCH_PATTERN=gtid_slave_pos +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=MASTER_LOG_FILE +--source include/search_pattern_in_file.inc + +rmdir $targetdir; + +# Cleanup +--connection master +DROP TABLE t; +--sync_slave_with_master +--source include/rpl_end.inc From 5768f57d243e3fa945d79fcdc1a3eacb1e4ebb0d Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Mon, 14 Sep 2020 21:19:56 +1000 Subject: [PATCH 18/48] mtr: main.mysql_upgrade - record after correcting error message --- mysql-test/r/mysql_upgrade.result | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/mysql_upgrade.result b/mysql-test/r/mysql_upgrade.result index 69637f4078f..a1464bb4853 100644 --- a/mysql-test/r/mysql_upgrade.result +++ b/mysql-test/r/mysql_upgrade.result @@ -142,7 +142,7 @@ test Phase 7/7: Running 'FLUSH PRIVILEGES' OK DROP USER mysqltest1@'%'; -Version check failed. Got the following error when calling the 'mysql' command line client +Version check failed. Got the following error when calling the 'mysql_upgrade' command line client ERROR 1045 (28000): Access denied for user 'mysqltest1'@'localhost' (using password: YES) FATAL ERROR: Upgrade failed Run mysql_upgrade with a non existing server socket @@ -405,7 +405,7 @@ OK # Bug #21489398: MYSQL_UPGRADE: FATAL ERROR: UPGRADE FAILED - IMPROVE ERROR # Run mysql_upgrade with unauthorized access -Version check failed. Got the following error when calling the 'mysql' command line client +Version check failed. Got the following error when calling the 'mysql_upgrade' command line client ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) FATAL ERROR: Upgrade failed # From 7730b7bace215154ab5f8234a3e7a5a343ee3ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 14 Sep 2020 08:21:53 +0300 Subject: [PATCH 19/48] MDEV-23617 : galera_sr.galera_sr_rollback_retry MTR failed: 1213: Deadlock found when trying to get lock Add corrected wait_condition to wait until rows are in streaming replication log. --- .../galera_sr/r/galera_sr_rollback_retry.result | 15 ++++++++------- .../galera_sr/t/galera_sr_rollback_retry.test | 10 ++++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/mysql-test/suite/galera_sr/r/galera_sr_rollback_retry.result b/mysql-test/suite/galera_sr/r/galera_sr_rollback_retry.result index 054f7cf2eae..1117a50ded1 100644 --- a/mysql-test/suite/galera_sr/r/galera_sr_rollback_retry.result +++ b/mysql-test/suite/galera_sr/r/galera_sr_rollback_retry.result @@ -11,10 +11,11 @@ INSERT INTO t1 VALUES (3); INSERT INTO t1 VALUES (4); INSERT INTO t1 VALUES (5); connection node_2; -SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; connection node_1; ROLLBACK; connection node_2; +SELECT * FROM t1; +f1 SET AUTOCOMMIT=OFF; START TRANSACTION; INSERT INTO t1 VALUES (1); @@ -23,11 +24,11 @@ INSERT INTO t1 VALUES (3); INSERT INTO t1 VALUES (4); INSERT INTO t1 VALUES (5); COMMIT; -SELECT COUNT(*) = 5 FROM t1; -COUNT(*) = 5 -1 +SELECT COUNT(*) AS EXPECT_5 FROM t1; +EXPECT_5 +5 connection node_1; -SELECT COUNT(*) = 5 FROM t1; -COUNT(*) = 5 -1 +SELECT COUNT(*) AS EXPECT_5 FROM t1; +EXPECT_5 +5 DROP TABLE t1; diff --git a/mysql-test/suite/galera_sr/t/galera_sr_rollback_retry.test b/mysql-test/suite/galera_sr/t/galera_sr_rollback_retry.test index c6c443a0828..e5d204d85c8 100644 --- a/mysql-test/suite/galera_sr/t/galera_sr_rollback_retry.test +++ b/mysql-test/suite/galera_sr/t/galera_sr_rollback_retry.test @@ -19,8 +19,7 @@ INSERT INTO t1 VALUES (4); INSERT INTO t1 VALUES (5); --connection node_2 -SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; ---let $wait_condition = SELECT COUNT(*) > 0 FROM t1; +--let $wait_condition = SELECT COUNT(*) > 0 FROM mysql.wsrep_streaming_log --source include/wait_condition.inc --connection node_1 @@ -33,6 +32,7 @@ ROLLBACK; --connection node_2 --let $wait_condition = SELECT COUNT(*) = 0 FROM t1; --source include/wait_condition.inc +SELECT * FROM t1; # # It should be possible to reissue the same transaction against node #2 @@ -47,9 +47,11 @@ INSERT INTO t1 VALUES (4); INSERT INTO t1 VALUES (5); COMMIT; -SELECT COUNT(*) = 5 FROM t1; +SELECT COUNT(*) AS EXPECT_5 FROM t1; --connection node_1 -SELECT COUNT(*) = 5 FROM t1; +--let $wait_condition = SELECT COUNT(*) = 5 FROM t1; +--source include/wait_condition.inc +SELECT COUNT(*) AS EXPECT_5 FROM t1; DROP TABLE t1; From b69e980a38b0bd81aee836fdfb46707fb510ef18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 14 Sep 2020 18:21:17 +0300 Subject: [PATCH 20/48] MDEV-20581 Fix MTR test wsrep.variables Made the test work with --repeat option by adding galera_wait_ready.inc at the end of test. Recorded the test output. --- mysql-test/suite/wsrep/r/variables.result | 9 +++------ mysql-test/suite/wsrep/t/variables.test | 8 +++++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/mysql-test/suite/wsrep/r/variables.result b/mysql-test/suite/wsrep/r/variables.result index db5ce3d2a77..1ff221f1459 100644 --- a/mysql-test/suite/wsrep/r/variables.result +++ b/mysql-test/suite/wsrep/r/variables.result @@ -163,7 +163,7 @@ SET GLOBAL wsrep_provider=none; call mtr.add_suppression("WSREP: Failed to get provider options"); SELECT @@global.wsrep_provider; @@global.wsrep_provider -/usr/lib/libgalera_4_smm.so +libgalera_smm.so SELECT @@global.wsrep_slave_threads; @@global.wsrep_slave_threads 1 @@ -182,7 +182,7 @@ wsrep_thread_count 0 SELECT @@global.wsrep_provider; @@global.wsrep_provider -/usr/lib/libgalera_4_smm.so +libgalera_smm.so SELECT @@global.wsrep_cluster_address; @@global.wsrep_cluster_address @@ -212,7 +212,7 @@ EXPECT_2 2 SELECT @@global.wsrep_provider; @@global.wsrep_provider -/usr/lib/libgalera_4_smm.so +libgalera_smm.so SELECT @@global.wsrep_cluster_address; @@global.wsrep_cluster_address gcomm:// @@ -268,7 +268,4 @@ SELECT @@global.wsrep_sst_auth; @@global.wsrep_sst_auth NULL SET @@global.wsrep_sst_auth= @wsrep_sst_auth_saved; -SET GLOBAL wsrep_slave_threads= @wsrep_slave_threads_saved; -SET GLOBAL wsrep_cluster_address= @wsrep_cluster_address_saved; -SET GLOBAL wsrep_provider_options= @wsrep_provider_options_saved; # End of test. diff --git a/mysql-test/suite/wsrep/t/variables.test b/mysql-test/suite/wsrep/t/variables.test index cf5280fa688..89b1ff99012 100644 --- a/mysql-test/suite/wsrep/t/variables.test +++ b/mysql-test/suite/wsrep/t/variables.test @@ -160,12 +160,14 @@ SELECT @@global.wsrep_sst_auth; SET @@global.wsrep_sst_auth= @wsrep_sst_auth_saved; # Reset (for mtr internal checks) + +--disable_query_log SET GLOBAL wsrep_slave_threads= @wsrep_slave_threads_saved; +eval SET GLOBAL wsrep_provider= '$WSREP_PROVIDER'; SET GLOBAL wsrep_cluster_address= @wsrep_cluster_address_saved; SET GLOBAL wsrep_provider_options= @wsrep_provider_options_saved; ---disable_query_log -eval SET GLOBAL wsrep_provider= '$WSREP_PROVIDER'; --enable_query_log ---echo # End of test. +--source include/galera_wait_ready.inc +--echo # End of test. From de76bebc5798313e3798a35e02468e42254dd608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 14 Sep 2020 18:21:48 +0300 Subject: [PATCH 21/48] MDEV-23659 : Update Galera disabled.def file --- mysql-test/suite/wsrep/disabled.def | 1 - 1 file changed, 1 deletion(-) diff --git a/mysql-test/suite/wsrep/disabled.def b/mysql-test/suite/wsrep/disabled.def index 0e2027b7153..11577bfe8b0 100644 --- a/mysql-test/suite/wsrep/disabled.def +++ b/mysql-test/suite/wsrep/disabled.def @@ -10,4 +10,3 @@ # ############################################################################## -variables : MDEV-17585,MDEV-20581 Crash on wsrep.variables test case From 873cc1e77a734d1806b2cd0217042d1f9f19e5e7 Mon Sep 17 00:00:00 2001 From: Sujatha Date: Wed, 16 Sep 2020 14:03:32 +0530 Subject: [PATCH 22/48] MDEV-21839: Handle crazy offset to SHOW BINLOG EVENTS Problem: ======= SHOW BINLOG EVENTS FROM <"random"-pos> caused a variety of failures as reported in MDEV-18046. They are fixed but that approach is not future-proof as well as is not optimal to create extra check for being constructed event parameters. Analysis: ========= "show binlog events from " code considers the user given position as a valid event start position. The code starts reading data from this event start position onwards and tries to map it to a set of known events. Each event has a specific event structure and asserts have been added to ensure that, read event data, satisfies the event specific requirements. When a random position is supplied to "show binlog events command" the event structure specific checks will fail and they result in assert. For example: https://jira.mariadb.org/browse/MDEV-18046 In the bug description user executes CREATE TABLE/INSERT and ALTER SQL commands. When a crazy offset like "SHOW BINLOG EVENTS FROM 365" is provided code assumes offset 365 as valid event begin and proceeds to EVENT_LEN_OFFSET reads some random length and comes up with a crazy event which didn't exits in the binary log. In this quoted example scenario, event read at offset 365 is considered as "Update_rows_log_event", which is not present in binary log. Since this is a random event its validation fails and code results in assert/segmentation fault, as shown below. mysqld: /data/src/10.4/sql/log_event.cc:10863: Rows_log_event::Rows_log_event( const char*, uint, const Format_description_log_event*): Assertion `var_header_len >= 2' failed. 181220 15:27:02 [ERROR] mysqld got signal 6 ; #7 0x00007fa0d96abee2 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6 #8 0x000055e744ef82de in Rows_log_event::Rows_log_event (this=0x7fa05800d390, buf=0x7fa05800d080 "", event_len=254, description_event=0x7fa058006d60) at /data/src/10.4/sql/log_event.cc:10863 #9 0x000055e744f00cf8 in Update_rows_log_event::Update_rows_log_event Since we are reading random data repeating the same command SHOW BINLOG EVENTS FROM 365 produces different types of crashes with different events. MDEV-18046 reported 10 such crashes. In order to avoid such scenarios user provided starting offset needs to be validated for its correctness. Best way of doing this is to make use of checksums if they are available. MDEV-18046 fix introduced the checksum based validation. The issue still remains in cases where binlog checksums are disabled. Please find the following bug reports. MDEV-22473: binlog.binlog_show_binlog_event_random_pos failed in buildbot, server crashed in read_log_event MDEV-22455: Server crashes in Table_map_log_event, binlog.binlog_invalid_read_in_rotate failed in buildbot Fix: ==== When binlog checksum is disabled, perform scan(via reading event by event), to validate the requested FROM offset. Starting from offset 4 read the event_length of next_event in the binary log. Using the next_event length advance current offset to point to next event. Repeat this process till the current offset is less than or equal to crazy offset. If current offset is higher than crazy offset provide appropriate invalid input offset error. --- mysql-test/r/ctype_cp932_binlog_stm.result | 2 +- ...binlog_show_binlog_event_random_pos.result | 3 + .../binlog_show_binlog_event_random_pos.test | 5 ++ sql/sql_repl.cc | 57 +++++++++++++++++-- 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/ctype_cp932_binlog_stm.result b/mysql-test/r/ctype_cp932_binlog_stm.result index 75d05aa9f0a..c92026cf5a4 100644 --- a/mysql-test/r/ctype_cp932_binlog_stm.result +++ b/mysql-test/r/ctype_cp932_binlog_stm.result @@ -56,7 +56,7 @@ master-bin.000001 # Query # # use `test`; DROP TABLE `t4` /* generated by server End of 5.0 tests call mtr.add_suppression("Error in Log_event::read_log_event\\\(\\\): 'Found invalid"); SHOW BINLOG EVENTS FROM 504; -ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Wrong offset or I/O error +ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Invalid input pos specified please provide valid one. Bug#44352 UPPER/LOWER function doesn't work correctly on cp932 and sjis environment. CREATE TABLE t1 (a varchar(16)) character set cp932; INSERT INTO t1 VALUES (0x8372835E),(0x8352835E); diff --git a/mysql-test/suite/binlog/r/binlog_show_binlog_event_random_pos.result b/mysql-test/suite/binlog/r/binlog_show_binlog_event_random_pos.result index 358422c5842..c2e634ebe82 100644 --- a/mysql-test/suite/binlog/r/binlog_show_binlog_event_random_pos.result +++ b/mysql-test/suite/binlog/r/binlog_show_binlog_event_random_pos.result @@ -9,4 +9,7 @@ INSERT INTO t1 VALUES (repeat('a', 255), repeat('a', 255),repeat('a', 255),repea INSERT INTO t1 VALUES (repeat('a', 255), repeat('a', 255),repeat('a', 255),repeat('a', 255),repeat('a', 255)); UPDATE t1 SET c1=repeat('b',255); INSERT INTO t1 VALUES (repeat('a', 255), repeat('a', 255),repeat('a', 255),repeat('a', 255),repeat('a', 255)); +SHOW BINLOG EVENTS FROM POS; +ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Invalid pos specified. Requested from pos:POS is greater than actual file size:MAX_POS + DROP TABLE t1; diff --git a/mysql-test/suite/binlog/t/binlog_show_binlog_event_random_pos.test b/mysql-test/suite/binlog/t/binlog_show_binlog_event_random_pos.test index e6a9e1cb2c1..05e6967c538 100644 --- a/mysql-test/suite/binlog/t/binlog_show_binlog_event_random_pos.test +++ b/mysql-test/suite/binlog/t/binlog_show_binlog_event_random_pos.test @@ -34,4 +34,9 @@ while ($pos <= $max_pos) --enable_query_log } +# Testing a case where input position is greater than actual binlog file size. +--replace_result $pos POS $max_pos MAX_POS +--error 1220 +eval SHOW BINLOG EVENTS FROM $pos; + DROP TABLE t1; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 38c2b9b5b8e..2d644ffc5ef 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -3842,6 +3842,7 @@ bool mysql_show_binlog_events(THD* thd) { Protocol *protocol= thd->protocol; List field_list; + char errmsg_buf[MYSYS_ERRMSG_SIZE]; const char *errmsg = 0; bool ret = TRUE; /* @@ -3856,6 +3857,9 @@ bool mysql_show_binlog_events(THD* thd) Master_info *mi= 0; LOG_INFO linfo; LEX_MASTER_INFO *lex_mi= &thd->lex->mi; + enum enum_binlog_checksum_alg checksum_alg; + my_off_t binlog_size; + MY_STAT s; DBUG_ENTER("mysql_show_binlog_events"); @@ -3904,10 +3908,6 @@ bool mysql_show_binlog_events(THD* thd) mi= 0; } - /* Validate user given position using checksum */ - if (lex_mi->pos == pos && !opt_master_verify_checksum) - verify_checksum_once= true; - unit->set_limit(thd->lex->current_select); limit_start= unit->offset_limit_cnt; limit_end= unit->select_limit_cnt; @@ -3934,6 +3934,17 @@ bool mysql_show_binlog_events(THD* thd) if ((file=open_binlog(&log, linfo.log_file_name, &errmsg)) < 0) goto err; + my_stat(linfo.log_file_name, &s, MYF(0)); + binlog_size= s.st_size; + if (lex_mi->pos > binlog_size) + { + sprintf(errmsg_buf, "Invalid pos specified. Requested from pos:%llu is " + "greater than actual file size:%lu\n", lex_mi->pos, + (ulong)s.st_size); + errmsg= errmsg_buf; + goto err; + } + /* to account binlog event header size */ @@ -3985,7 +3996,43 @@ bool mysql_show_binlog_events(THD* thd) } } - my_b_seek(&log, pos); + if (lex_mi->pos > BIN_LOG_HEADER_SIZE) + { + checksum_alg= description_event->checksum_alg; + /* Validate user given position using checksum */ + if (checksum_alg != BINLOG_CHECKSUM_ALG_OFF && + checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF) + { + if (!opt_master_verify_checksum) + verify_checksum_once= true; + my_b_seek(&log, pos); + } + else + { + my_off_t cur_pos= my_b_tell(&log); + ulong next_event_len= 0; + uchar buff[IO_SIZE]; + while (cur_pos < pos) + { + my_b_seek(&log, cur_pos + EVENT_LEN_OFFSET); + if (my_b_read(&log, (uchar *)buff, sizeof(next_event_len))) + { + mysql_mutex_unlock(log_lock); + errmsg = "Could not read event_length"; + goto err; + } + next_event_len= uint4korr(buff); + cur_pos= cur_pos + next_event_len; + } + if (cur_pos > pos) + { + mysql_mutex_unlock(log_lock); + errmsg= "Invalid input pos specified please provide valid one."; + goto err; + } + my_b_seek(&log, cur_pos); + } + } for (event_count = 0; (ev = Log_event::read_log_event(&log, (mysql_mutex_t*) 0, From 96426dac914e5989da0ba7faa86726e060461219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 16 Sep 2020 15:23:41 +0300 Subject: [PATCH 23/48] MDEV-21655 : galera.galera_wan_restart_ist MTR fails sporadically: WSREP did not transition to state READY Replace sleeps with proper wait_conditions to wait correct cluster configuration. --- .../galera/r/galera_wan_restart_ist.result | 55 +++++++++----- .../galera/t/galera_wan_restart_ist.test | 76 +++++++++++++++---- 2 files changed, 98 insertions(+), 33 deletions(-) diff --git a/mysql-test/suite/galera/r/galera_wan_restart_ist.result b/mysql-test/suite/galera/r/galera_wan_restart_ist.result index 8a2a7d0818e..58ed9f057da 100644 --- a/mysql-test/suite/galera/r/galera_wan_restart_ist.result +++ b/mysql-test/suite/galera/r/galera_wan_restart_ist.result @@ -4,11 +4,11 @@ connection node_1; connection node_2; connection node_3; connection node_4; -SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -VARIABLE_VALUE = 4 -1 +SELECT VARIABLE_VALUE AS EXPECT_4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +EXPECT_4 +4 connection node_1; -CREATE TABLE t1 (f1 INTEGER); +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=INNODB; INSERT INTO t1 VALUES (1); connection node_2; INSERT INTO t1 VALUES (2); @@ -20,60 +20,78 @@ connection node_3; INSERT INTO t1 VALUES (13); Shutting down server ... connection node_1; +SELECT VARIABLE_VALUE AS EXPECT_3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +EXPECT_3 +3 INSERT INTO t1 VALUES (11); connection node_2; INSERT INTO t1 VALUES (12); connection node_4; INSERT INTO t1 VALUES (14); connection node_3; +SELECT VARIABLE_VALUE AS EXPECT_4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +EXPECT_4 +4 INSERT INTO t1 VALUES (131); connection node_2; INSERT INTO t1 VALUES (22); Shutting down server ... connection node_1; +SELECT VARIABLE_VALUE AS EXPECT_3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +EXPECT_3 +3 INSERT INTO t1 VALUES (21); connection node_3; INSERT INTO t1 VALUES (23); connection node_4; INSERT INTO t1 VALUES (24); connection node_2; +SELECT VARIABLE_VALUE AS EXPECT_4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +EXPECT_4 +4 INSERT INTO t1 VALUES (221); connection node_4; INSERT INTO t1 VALUES (34); Shutting down server ... connection node_1; +SELECT VARIABLE_VALUE AS EXPECT_3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +EXPECT_3 +3 INSERT INTO t1 VALUES (31); connection node_2; INSERT INTO t1 VALUES (32); connection node_3; INSERT INTO t1 VALUES (33); connection node_4; +SELECT VARIABLE_VALUE AS EXPECT_4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +EXPECT_4 +4 INSERT INTO t1 VALUES (341); connection node_1; -SELECT COUNT(*) = 19 FROM t1; -COUNT(*) = 19 -1 +SELECT COUNT(*) AS EXPECT_19 FROM t1; +EXPECT_19 +19 connection node_2; SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; VARIABLE_VALUE = 4 1 -SELECT COUNT(*) = 19 FROM t1; -COUNT(*) = 19 -1 +SELECT COUNT(*) AS EXPECT_19 FROM t1; +EXPECT_19 +19 connection node_3; SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; VARIABLE_VALUE = 4 1 -SELECT COUNT(*) = 19 FROM t1; -COUNT(*) = 19 -1 +SELECT COUNT(*) AS EXPECT_19 FROM t1; +EXPECT_19 +19 connection node_4; SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; VARIABLE_VALUE = 4 1 -SELECT COUNT(*) = 19 FROM t1; -COUNT(*) = 19 -1 +SELECT COUNT(*) AS EXPECT_19 FROM t1; +EXPECT_19 +19 connection node_1; DROP TABLE t1; CALL mtr.add_suppression("There are no nodes in the same segment that will ever be able to become donors, yet there is a suitable donor outside"); @@ -84,5 +102,6 @@ CALL mtr.add_suppression("There are no nodes in the same segment that will ever CALL mtr.add_suppression("Action message in non-primary configuration from member 0"); connection node_4; CALL mtr.add_suppression("Action message in non-primary configuration from member 0"); -disconnect node_2; -disconnect node_1; +connection node_1; +disconnect node_3; +disconnect node_4; diff --git a/mysql-test/suite/galera/t/galera_wan_restart_ist.test b/mysql-test/suite/galera/t/galera_wan_restart_ist.test index 1cf5d4c7f74..8a011d60851 100644 --- a/mysql-test/suite/galera/t/galera_wan_restart_ist.test +++ b/mysql-test/suite/galera/t/galera_wan_restart_ist.test @@ -10,7 +10,7 @@ --source include/big_test.inc --source include/galera_cluster.inc ---source include/have_innodb.inc +--source include/force_restart.inc --connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3 --connect node_4, 127.0.0.1, root, , test, $NODE_MYPORT_4 @@ -22,10 +22,13 @@ --let $node_4=node_4 --source include/auto_increment_offset_save.inc -SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +--let $wait_condition = SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc + +SELECT VARIABLE_VALUE AS EXPECT_4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; --connection node_1 -CREATE TABLE t1 (f1 INTEGER); +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=INNODB; INSERT INTO t1 VALUES (1); --connection node_2 @@ -46,9 +49,13 @@ INSERT INTO t1 VALUES (13); --echo Shutting down server ... --source include/shutdown_mysqld.inc ---sleep 5 + --connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc +SELECT VARIABLE_VALUE AS EXPECT_3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; + INSERT INTO t1 VALUES (11); --connection node_2 @@ -59,9 +66,12 @@ INSERT INTO t1 VALUES (14); --connection node_3 --source include/start_mysqld.inc ---sleep 5 --source include/wait_until_connected_again.inc +--let $wait_condition = SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc +SELECT VARIABLE_VALUE AS EXPECT_4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; + INSERT INTO t1 VALUES (131); # @@ -73,9 +83,12 @@ INSERT INTO t1 VALUES (22); --echo Shutting down server ... --source include/shutdown_mysqld.inc ---sleep 5 --connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc +SELECT VARIABLE_VALUE AS EXPECT_3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; + INSERT INTO t1 VALUES (21); --connection node_3 @@ -86,9 +99,12 @@ INSERT INTO t1 VALUES (24); --connection node_2 --source include/start_mysqld.inc ---sleep 5 --source include/wait_until_connected_again.inc +--let $wait_condition = SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc +SELECT VARIABLE_VALUE AS EXPECT_4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; + INSERT INTO t1 VALUES (221); # @@ -100,9 +116,12 @@ INSERT INTO t1 VALUES (34); --echo Shutting down server ... --source include/shutdown_mysqld.inc ---sleep 5 --connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc +SELECT VARIABLE_VALUE AS EXPECT_3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; + INSERT INTO t1 VALUES (31); --connection node_2 @@ -113,9 +132,12 @@ INSERT INTO t1 VALUES (33); --connection node_4 --source include/start_mysqld.inc ---sleep 5 --source include/wait_until_connected_again.inc +--let $wait_condition = SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc +SELECT VARIABLE_VALUE AS EXPECT_4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; + INSERT INTO t1 VALUES (341); @@ -124,22 +146,44 @@ INSERT INTO t1 VALUES (341); # --connection node_1 ---let $wait_condition = SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +--let $wait_condition = SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc +--let $wait_condition = SELECT COUNT(*) = 19 FROM t1 --source include/wait_condition.inc -SELECT COUNT(*) = 19 FROM t1; +SELECT COUNT(*) AS EXPECT_19 FROM t1; --connection node_2 +--let $wait_condition = SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -SELECT COUNT(*) = 19 FROM t1; + +--let $wait_condition = SELECT COUNT(*) = 19 FROM t1 +--source include/wait_condition.inc + +SELECT COUNT(*) AS EXPECT_19 FROM t1; + --connection node_3 +--let $wait_condition = SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -SELECT COUNT(*) = 19 FROM t1; + +--let $wait_condition = SELECT COUNT(*) = 19 FROM t1 +--source include/wait_condition.inc + +SELECT COUNT(*) AS EXPECT_19 FROM t1; --connection node_4 +--let $wait_condition = SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +--source include/wait_condition.inc SELECT VARIABLE_VALUE = 4 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -SELECT COUNT(*) = 19 FROM t1; + +--let $wait_condition = SELECT COUNT(*) = 19 FROM t1 +--source include/wait_condition.inc + +SELECT COUNT(*) AS EXPECT_19 FROM t1; + --connection node_1 DROP TABLE t1; @@ -158,4 +202,6 @@ CALL mtr.add_suppression("Action message in non-primary configuration from membe # Restore original auto_increment_offset values. --source include/auto_increment_offset_restore.inc ---source include/galera_end.inc +--connection node_1 +--disconnect node_3 +--disconnect node_4 From e3e657373a53ceebe29c043c9d60c85b844d0501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 17 Sep 2020 08:25:07 +0300 Subject: [PATCH 24/48] MDEV-21769 : `galera_3nodes.galera_safe_to_bootstrap` fails Add wait_condition to wait correct cluster configuration. --- .../r/galera_safe_to_bootstrap.result | 6 ++++-- .../galera_3nodes/t/galera_safe_to_bootstrap.cnf | 10 ++++++++++ .../galera_3nodes/t/galera_safe_to_bootstrap.test | 15 ++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 mysql-test/suite/galera_3nodes/t/galera_safe_to_bootstrap.cnf diff --git a/mysql-test/suite/galera_3nodes/r/galera_safe_to_bootstrap.result b/mysql-test/suite/galera_3nodes/r/galera_safe_to_bootstrap.result index 45b4d63fb4f..8b3211b2b26 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_safe_to_bootstrap.result +++ b/mysql-test/suite/galera_3nodes/r/galera_safe_to_bootstrap.result @@ -2,7 +2,8 @@ connection node_1; connection node_2; connection node_3; connection node_1; -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0'] include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0'] include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0'] @@ -48,6 +49,7 @@ CALL mtr.add_suppression("Failed to prepare for incremental state transfer"); SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( - `f1` int(11) DEFAULT NULL + `f1` int(11) NOT NULL, + PRIMARY KEY (`f1`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 DROP TABLE t1; diff --git a/mysql-test/suite/galera_3nodes/t/galera_safe_to_bootstrap.cnf b/mysql-test/suite/galera_3nodes/t/galera_safe_to_bootstrap.cnf new file mode 100644 index 00000000000..7e35da18707 --- /dev/null +++ b/mysql-test/suite/galera_3nodes/t/galera_safe_to_bootstrap.cnf @@ -0,0 +1,10 @@ +!include ../galera_3nodes.cnf + +[mariadb.1] +wsrep_debug=1 + +[mariadb.2] +wsrep_debug=1 + +[mariadb.3] +wsrep_debug=1 diff --git a/mysql-test/suite/galera_3nodes/t/galera_safe_to_bootstrap.test b/mysql-test/suite/galera_3nodes/t/galera_safe_to_bootstrap.test index b7b6c66e5ad..e0b2e26927c 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_safe_to_bootstrap.test +++ b/mysql-test/suite/galera_3nodes/t/galera_safe_to_bootstrap.test @@ -2,6 +2,7 @@ # Test the safe_to_bootstrap in grastate.dat # --source include/galera_cluster.inc +--source include/force_restart.inc --let $galera_connection_name = node_3 --let $galera_server_number = 3 @@ -14,7 +15,11 @@ --source ../galera/include/auto_increment_offset_save.inc --connection node_1 -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); + +--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +--source include/wait_condition.inc # # At start, all grastate.dat files have safe_to_boostrap: 0 @@ -151,10 +156,18 @@ SET SESSION wsrep_on = OFF; --source include/start_mysqld.inc --source include/wait_until_connected_again.inc +--let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +--source include/wait_condition.inc + + --connection node_2 --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.2.expect --source include/start_mysqld.inc +--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +--source include/wait_condition.inc + + --connection node_3 --let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.3.expect --source include/start_mysqld.inc From f381e019b602951586e47458eb884924c0945e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 17 Sep 2020 12:55:06 +0300 Subject: [PATCH 25/48] MDEV-23574 : galera_3nodes.galera_ipv6_mariabackup_section MTR failed: Could not open '../galera/include/have_mariabackup.inc' Test case and configuration cleanup. --- mysql-test/suite/galera_3nodes/r/GAL-501.result | 6 +++--- .../galera_3nodes/r/galera_ipv6_mariabackup.result | 6 +++--- .../r/galera_ipv6_mariabackup_section.result | 6 +++--- .../galera_3nodes/r/galera_ipv6_mysqldump.result | 6 +++--- .../suite/galera_3nodes/r/galera_ipv6_rsync.result | 6 +++--- .../galera_3nodes/r/galera_ipv6_rsync_section.result | 6 +++--- mysql-test/suite/galera_3nodes/t/GAL-501.cnf | 3 +++ mysql-test/suite/galera_3nodes/t/GAL-501.opt | 1 - mysql-test/suite/galera_3nodes/t/GAL-501.test | 5 +++-- .../galera_3nodes/t/galera_ipv6_mariabackup.cnf | 3 +++ .../galera_3nodes/t/galera_ipv6_mariabackup.opt | 1 - .../galera_3nodes/t/galera_ipv6_mariabackup.test | 4 ++-- .../t/galera_ipv6_mariabackup_section.cnf | 12 +++++++----- .../t/galera_ipv6_mariabackup_section.opt | 1 - .../t/galera_ipv6_mariabackup_section.test | 4 ++-- .../suite/galera_3nodes/t/galera_ipv6_mysqldump.cnf | 3 +++ .../suite/galera_3nodes/t/galera_ipv6_mysqldump.opt | 1 - .../suite/galera_3nodes/t/galera_ipv6_mysqldump.test | 4 ++-- .../suite/galera_3nodes/t/galera_ipv6_rsync.cnf | 3 +++ .../suite/galera_3nodes/t/galera_ipv6_rsync.opt | 1 - .../suite/galera_3nodes/t/galera_ipv6_rsync.test | 4 ++-- .../galera_3nodes/t/galera_ipv6_rsync_section.cnf | 11 +++++++---- .../galera_3nodes/t/galera_ipv6_rsync_section.opt | 1 - .../galera_3nodes/t/galera_ipv6_rsync_section.test | 4 ++-- .../galera_3nodes/t/galera_safe_to_bootstrap.cnf | 6 +++--- 25 files changed, 60 insertions(+), 48 deletions(-) delete mode 100644 mysql-test/suite/galera_3nodes/t/GAL-501.opt delete mode 100644 mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.opt delete mode 100644 mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.opt delete mode 100644 mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.opt delete mode 100644 mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.opt delete mode 100644 mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync_section.opt diff --git a/mysql-test/suite/galera_3nodes/r/GAL-501.result b/mysql-test/suite/galera_3nodes/r/GAL-501.result index bcf74142144..4ddf3b2bce6 100644 --- a/mysql-test/suite/galera_3nodes/r/GAL-501.result +++ b/mysql-test/suite/galera_3nodes/r/GAL-501.result @@ -7,11 +7,11 @@ VARIABLE_VALUE = 3 connection node_2; SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; connection node_1; -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); connection node_2; SET GLOBAL wsrep_provider_options='gmcast.isolate=0'; -SELECT COUNT(*) = 1 FROM t1; -COUNT(*) = 1 +SELECT COUNT(*) AS EXPECT_1 FROM t1; +EXPECT_1 1 DROP TABLE t1; diff --git a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result index 5665ed5f46a..d0ed868c761 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result +++ b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result @@ -7,12 +7,12 @@ VARIABLE_VALUE = 3 connection node_2; SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; connection node_1; -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); connection node_2; SET GLOBAL wsrep_provider_options='gmcast.isolate=0'; -SELECT COUNT(*) = 1 FROM t1; -COUNT(*) = 1 +SELECT COUNT(*) AS EXPECT_1 FROM t1; +EXPECT_1 1 DROP TABLE t1; connection node_1; diff --git a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result index 5a844537327..1d12e638296 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result +++ b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result @@ -7,12 +7,12 @@ VARIABLE_VALUE = 3 connection node_2; SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; connection node_1; -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); connection node_2; SET GLOBAL wsrep_provider_options='gmcast.isolate=0'; -SELECT COUNT(*) = 1 FROM t1; -COUNT(*) = 1 +SELECT COUNT(*) AS EXPECT_1 FROM t1; +EXPECT_1 1 DROP TABLE t1; connection node_1; diff --git a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mysqldump.result b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mysqldump.result index 3564dc8c5a1..512bb5c8c78 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mysqldump.result +++ b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mysqldump.result @@ -12,12 +12,12 @@ SET GLOBAL wsrep_sst_method = 'mysqldump'; Shutting down server ... connection node_1; Cleaning var directory ... -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); connection node_2; Starting server ... -SELECT COUNT(*) = 1 FROM t1; -COUNT(*) = 1 +SELECT COUNT(*) AS EXPECT_1 FROM t1; +EXPECT_1 1 DROP TABLE t1; SELECT VARIABLE_VALUE LIKE '%[::1]%' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_incoming_addresses'; diff --git a/mysql-test/suite/galera_3nodes/r/galera_ipv6_rsync.result b/mysql-test/suite/galera_3nodes/r/galera_ipv6_rsync.result index bcf74142144..4ddf3b2bce6 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_ipv6_rsync.result +++ b/mysql-test/suite/galera_3nodes/r/galera_ipv6_rsync.result @@ -7,11 +7,11 @@ VARIABLE_VALUE = 3 connection node_2; SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; connection node_1; -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); connection node_2; SET GLOBAL wsrep_provider_options='gmcast.isolate=0'; -SELECT COUNT(*) = 1 FROM t1; -COUNT(*) = 1 +SELECT COUNT(*) AS EXPECT_1 FROM t1; +EXPECT_1 1 DROP TABLE t1; diff --git a/mysql-test/suite/galera_3nodes/r/galera_ipv6_rsync_section.result b/mysql-test/suite/galera_3nodes/r/galera_ipv6_rsync_section.result index bcf74142144..4ddf3b2bce6 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_ipv6_rsync_section.result +++ b/mysql-test/suite/galera_3nodes/r/galera_ipv6_rsync_section.result @@ -7,11 +7,11 @@ VARIABLE_VALUE = 3 connection node_2; SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; connection node_1; -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); connection node_2; SET GLOBAL wsrep_provider_options='gmcast.isolate=0'; -SELECT COUNT(*) = 1 FROM t1; -COUNT(*) = 1 +SELECT COUNT(*) AS EXPECT_1 FROM t1; +EXPECT_1 1 DROP TABLE t1; diff --git a/mysql-test/suite/galera_3nodes/t/GAL-501.cnf b/mysql-test/suite/galera_3nodes/t/GAL-501.cnf index 7002cb5bdfd..3b18a86093c 100644 --- a/mysql-test/suite/galera_3nodes/t/GAL-501.cnf +++ b/mysql-test/suite/galera_3nodes/t/GAL-501.cnf @@ -10,6 +10,7 @@ wsrep_node_address=[::1] wsrep_provider_options='base_port=@mysqld.1.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.1.#galera_port;ist.recv_addr=[::1]' wsrep_sst_receive_address='[::1]:@mysqld.1.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.1.port' +bind-address=:: [mysqld.2] wsrep_cluster_address='gcomm://[::1]:@mysqld.1.#galera_port' @@ -17,6 +18,7 @@ wsrep_node_address=[::1] wsrep_provider_options='base_port=@mysqld.2.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.2.#galera_port;ist.recv_addr=[::1]' wsrep_sst_receive_address='[::1]:@mysqld.2.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.2.port' +bind-address=:: [mysqld.3] wsrep_cluster_address='gcomm://[::1]:@mysqld.1.#galera_port' @@ -24,3 +26,4 @@ wsrep_node_address=[::1] wsrep_provider_options='base_port=@mysqld.3.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.3.#galera_port;ist.recv_addr=[::1]' wsrep_sst_receive_address='[::1]:@mysqld.3.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.3.port' +bind-address=:: diff --git a/mysql-test/suite/galera_3nodes/t/GAL-501.opt b/mysql-test/suite/galera_3nodes/t/GAL-501.opt deleted file mode 100644 index c2bb4d156af..00000000000 --- a/mysql-test/suite/galera_3nodes/t/GAL-501.opt +++ /dev/null @@ -1 +0,0 @@ ---bind-address=:: diff --git a/mysql-test/suite/galera_3nodes/t/GAL-501.test b/mysql-test/suite/galera_3nodes/t/GAL-501.test index a36f21630ac..39f514c07bc 100644 --- a/mysql-test/suite/galera_3nodes/t/GAL-501.test +++ b/mysql-test/suite/galera_3nodes/t/GAL-501.test @@ -6,6 +6,7 @@ --source include/galera_cluster.inc --source include/check_ipv6.inc +--source include/force_restart.inc # Confirm that initial handshake happened over ipv6 @@ -21,7 +22,7 @@ SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; --let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; --source include/wait_condition.inc -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); --connection node_2 @@ -33,6 +34,6 @@ SET GLOBAL wsrep_provider_options='gmcast.isolate=0'; --let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready'; --source include/wait_condition.inc -SELECT COUNT(*) = 1 FROM t1; +SELECT COUNT(*) AS EXPECT_1 FROM t1; DROP TABLE t1; diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.cnf b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.cnf index 5ac00fa056b..3861b17557d 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.cnf +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.cnf @@ -10,18 +10,21 @@ wsrep-cluster-address=gcomm:// wsrep_provider_options='base_host=[::1];base_port=@mysqld.1.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.1.#galera_port;ist.recv_addr=[::1]:@mysqld.1.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.1.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.1.port' +bind-address=:: [mysqld.2] wsrep_cluster_address='gcomm://[::1]:@mysqld.1.#galera_port' wsrep_provider_options='base_host=[::1];base_port=@mysqld.2.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.2.#galera_port;ist.recv_addr=[::1]:@mysqld.2.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.2.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.2.port' +bind-address=:: [mysqld.3] wsrep_cluster_address='gcomm://[::1]:@mysqld.1.#galera_port' wsrep_provider_options='base_host=[::1];base_port=@mysqld.3.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.3.#galera_port;ist.recv_addr=[::1]:@mysqld.3.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.3.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.3.port' +bind-address=:: [SST] transferfmt=@ENV.MTR_GALERA_TFMT diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.opt b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.opt deleted file mode 100644 index c2bb4d156af..00000000000 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.opt +++ /dev/null @@ -1 +0,0 @@ ---bind-address=:: diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test index ae489117942..a5dabe3d735 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test @@ -18,7 +18,7 @@ SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; --let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; --source include/wait_condition.inc -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); --connection node_2 @@ -30,7 +30,7 @@ SET GLOBAL wsrep_provider_options='gmcast.isolate=0'; --let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready'; --source include/wait_condition.inc -SELECT COUNT(*) = 1 FROM t1; +SELECT COUNT(*) AS EXPECT_1 FROM t1; DROP TABLE t1; diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.cnf b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.cnf index dc294854056..aa3da690416 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.cnf +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.cnf @@ -3,35 +3,37 @@ # decoy value - should not be read by mysqld or sst scripts [mysqld] innodb-data-home-dir=/tmp - -[galera] +bind-address=:: innodb-data-home-dir= wsrep_sst_method=mariabackup wsrep_sst_auth="root:" wsrep_node_address=::1 -[galera.1] +[mysqld.1] wsrep-cluster-address=gcomm:// wsrep_provider_options='base_host=[::1];base_port=@mysqld.1.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.1.#galera_port;ist.recv_addr=[::1]:@mysqld.1.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.1.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.1.port' wsrep_node_name=node_1 +bind-address=:: -[galera.2] +[mysqld.2] wsrep_cluster_address='gcomm://[::1]:@mysqld.1.#galera_port' wsrep_provider_options='base_host=[::1];base_port=@mysqld.2.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.2.#galera_port;ist.recv_addr=[::1]:@mysqld.2.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.2.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.2.port' wsrep_node_name=node_2 wsrep_sst_donor=node_1 +bind-address=:: -[galera.3] +[mysqld.3] wsrep_cluster_address='gcomm://[::1]:@mysqld.1.#galera_port' wsrep_provider_options='base_host=[::1];base_port=@mysqld.3.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.3.#galera_port;ist.recv_addr=[::1]:@mysqld.3.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.3.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.3.port' wsrep_node_name=node_3 wsrep_sst_donor=node_1 +bind-address=:: [SST] transferfmt=@ENV.MTR_GALERA_TFMT diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.opt b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.opt deleted file mode 100644 index c2bb4d156af..00000000000 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.opt +++ /dev/null @@ -1 +0,0 @@ ---bind-address=:: diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.test b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.test index 2c5aae8534d..e17ea364195 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.test +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.test @@ -18,7 +18,7 @@ SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; --let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; --source include/wait_condition.inc -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); --connection node_2 @@ -30,7 +30,7 @@ SET GLOBAL wsrep_provider_options='gmcast.isolate=0'; --let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready'; --source include/wait_condition.inc -SELECT COUNT(*) = 1 FROM t1; +SELECT COUNT(*) AS EXPECT_1 FROM t1; DROP TABLE t1; diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.cnf b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.cnf index 80dd0c41cc3..5e77a45210b 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.cnf +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.cnf @@ -9,18 +9,21 @@ wsrep-cluster-address=gcomm:// wsrep_provider_options='base_host=[::1];base_port=@mysqld.1.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.1.#galera_port;ist.recv_addr=[::1]:@mysqld.1.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.1.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.1.port' +bind-address=:: [mysqld.2] wsrep_cluster_address='gcomm://[::1]:@mysqld.1.#galera_port' wsrep_provider_options='base_host=[::1];base_port=@mysqld.2.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.2.#galera_port;ist.recv_addr=[::1]:@mysqld.2.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.2.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.2.port' +bind-address=:: [mysqld.3] wsrep_cluster_address='gcomm://[::1]:@mysqld.1.#galera_port' wsrep_provider_options='base_host=[::1];base_port=@mysqld.3.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.3.#galera_port;ist.recv_addr=[::1]:@mysqld.3.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.3.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.3.port' +bind-address=:: [SST] sockopt=",pf=ip6" diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.opt b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.opt deleted file mode 100644 index c2bb4d156af..00000000000 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.opt +++ /dev/null @@ -1 +0,0 @@ ---bind-address=:: diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.test b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.test index c9e08f58950..4904a49c73b 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.test +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.test @@ -54,7 +54,7 @@ SET GLOBAL wsrep_sst_method = 'mysqldump'; --remove_files_wildcard $MYSQLTEST_VARDIR/mysqld.2/data/mysql --remove_files_wildcard $MYSQLTEST_VARDIR/mysqld.2/data -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); --connection node_2 @@ -70,7 +70,7 @@ INSERT INTO t1 VALUES (1); --let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready'; --source include/wait_condition.inc -SELECT COUNT(*) = 1 FROM t1; +SELECT COUNT(*) AS EXPECT_1 FROM t1; DROP TABLE t1; diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.cnf b/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.cnf index 80dd0c41cc3..5e77a45210b 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.cnf +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.cnf @@ -9,18 +9,21 @@ wsrep-cluster-address=gcomm:// wsrep_provider_options='base_host=[::1];base_port=@mysqld.1.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.1.#galera_port;ist.recv_addr=[::1]:@mysqld.1.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.1.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.1.port' +bind-address=:: [mysqld.2] wsrep_cluster_address='gcomm://[::1]:@mysqld.1.#galera_port' wsrep_provider_options='base_host=[::1];base_port=@mysqld.2.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.2.#galera_port;ist.recv_addr=[::1]:@mysqld.2.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.2.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.2.port' +bind-address=:: [mysqld.3] wsrep_cluster_address='gcomm://[::1]:@mysqld.1.#galera_port' wsrep_provider_options='base_host=[::1];base_port=@mysqld.3.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.3.#galera_port;ist.recv_addr=[::1]:@mysqld.3.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.3.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.3.port' +bind-address=:: [SST] sockopt=",pf=ip6" diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.opt b/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.opt deleted file mode 100644 index c2bb4d156af..00000000000 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.opt +++ /dev/null @@ -1 +0,0 @@ ---bind-address=:: diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.test b/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.test index fff776d98b6..448611e34e0 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.test +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.test @@ -16,7 +16,7 @@ SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; --let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; --source include/wait_condition.inc -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); --connection node_2 @@ -28,6 +28,6 @@ SET GLOBAL wsrep_provider_options='gmcast.isolate=0'; --let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready'; --source include/wait_condition.inc -SELECT COUNT(*) = 1 FROM t1; +SELECT COUNT(*) AS EXPECT_1 FROM t1; DROP TABLE t1; diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync_section.cnf b/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync_section.cnf index 7cac8e1451e..809b83bb782 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync_section.cnf +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync_section.cnf @@ -4,28 +4,31 @@ [mysqld] innodb-data-home-dir=/tmp -[mariadb] +[mysqld] innodb-data-home-dir= wsrep_sst_method=rsync wsrep_node_address=::1 -[mariadb.1] +[mysqld.1] wsrep-cluster-address=gcomm:// wsrep_provider_options='base_host=[::1];base_port=@mysqld.1.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.1.#galera_port;ist.recv_addr=[::1]:@mysqld.1.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.1.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.1.port' +bind-address=:: -[mariadb.2] +[mysqld.2] wsrep_cluster_address='gcomm://[::1]:@mysqld.1.#galera_port' wsrep_provider_options='base_host=[::1];base_port=@mysqld.2.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.2.#galera_port;ist.recv_addr=[::1]:@mysqld.2.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.2.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.2.port' +bind-address=:: -[mariadb.3] +[mysqld.3] wsrep_cluster_address='gcomm://[::1]:@mysqld.1.#galera_port' wsrep_provider_options='base_host=[::1];base_port=@mysqld.3.#galera_port;gmcast.listen_addr=tcp://[::]:@mysqld.3.#galera_port;ist.recv_addr=[::1]:@mysqld.3.#ist_port' wsrep_sst_receive_address='[::1]:@mysqld.3.#sst_port' wsrep_node_incoming_address='[::1]:@mysqld.3.port' +bind-address=:: [SST] sockopt=",pf=ip6" diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync_section.opt b/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync_section.opt deleted file mode 100644 index c2bb4d156af..00000000000 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync_section.opt +++ /dev/null @@ -1 +0,0 @@ ---bind-address=:: diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync_section.test b/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync_section.test index fff776d98b6..448611e34e0 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync_section.test +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync_section.test @@ -16,7 +16,7 @@ SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; --let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; --source include/wait_condition.inc -CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB; +CREATE TABLE t1 (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); --connection node_2 @@ -28,6 +28,6 @@ SET GLOBAL wsrep_provider_options='gmcast.isolate=0'; --let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready'; --source include/wait_condition.inc -SELECT COUNT(*) = 1 FROM t1; +SELECT COUNT(*) AS EXPECT_1 FROM t1; DROP TABLE t1; diff --git a/mysql-test/suite/galera_3nodes/t/galera_safe_to_bootstrap.cnf b/mysql-test/suite/galera_3nodes/t/galera_safe_to_bootstrap.cnf index 7e35da18707..880a413f4b6 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_safe_to_bootstrap.cnf +++ b/mysql-test/suite/galera_3nodes/t/galera_safe_to_bootstrap.cnf @@ -1,10 +1,10 @@ !include ../galera_3nodes.cnf -[mariadb.1] +[mysqld.1] wsrep_debug=1 -[mariadb.2] +[mysqld.2] wsrep_debug=1 -[mariadb.3] +[mysqld.3] wsrep_debug=1 From bfe612b738d43561d430fa022f9b4545e733ec86 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 17 Sep 2020 18:05:53 +0200 Subject: [PATCH 26/48] MDEV-23663 - Add HAVE_INTEL_RDRAND flag for building WolfSSL, where appropiate --- extra/wolfssl/CMakeLists.txt | 19 ++++++++++++++----- extra/wolfssl/user_settings.h.in | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/extra/wolfssl/CMakeLists.txt b/extra/wolfssl/CMakeLists.txt index e2ba345e3c8..12eb26c9ef7 100644 --- a/extra/wolfssl/CMakeLists.txt +++ b/extra/wolfssl/CMakeLists.txt @@ -19,6 +19,8 @@ ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") MY_CHECK_C_COMPILER_FLAG(-maes) MY_CHECK_C_COMPILER_FLAG(-msse4) MY_CHECK_C_COMPILER_FLAG(-mpclmul) + MY_CHECK_C_COMPILER_FLAG(-mrdrnd) + MY_CHECK_C_COMPILER_FLAG(-mrdseed) IF(have_C__maes AND have_C__msse4 AND have_C__mpclmul) SET(WOLFSSL_INTELASM ON) ENDIF() @@ -113,20 +115,27 @@ IF(WOLFSSL_INTELASM) LIST(APPEND WOLFCRYPT_SOURCES ${WOLFCRYPT_SRCDIR}/cpuid.c) IF(MSVC) LIST(APPEND WOLFCRYPT_SOURCES ${WOLFCRYPT_SRCDIR}/aes_asm.asm) + SET(WOLFSSL_X86_64_BUILD 1) + SET(HAVE_INTEL_RDSEED 1) + SET(HAVE_INTEL_RDRAND 1) IF(CMAKE_C_COMPILER_ID MATCHES Clang) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes") - ELSE() - SET(HAVE_INTEL_RDSEED 1) - SET(WOLFSSL_X86_64_BUILD 1) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes -msse4.2 -mpclmul -mrdrnd -mrdseed") ENDIF() ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") - SET(HAVE_INTEL_RDSEED 1) SET(USE_INTEL_SPEEDUP 1) LIST(APPEND WOLFCRYPT_SOURCES ${WOLFCRYPT_SRCDIR}/aes_asm.S ${WOLFCRYPT_SRCDIR}/sha512_asm.S ${WOLFCRYPT_SRCDIR}/sha256_asm.S) ADD_DEFINITIONS(-maes -msse4 -mpclmul) + IF(have_C__mrdrnd) + SET(HAVE_INTEL_RDRAND 1) + ADD_DEFINITIONS(-mrdrnd) + ENDIF() + IF(have_C__mrdseed) + SET(HAVE_INTEL_RDSEED 1) + ADD_DEFINITIONS(-mrdseed) + ENDIF() ENDIF() ENDIF() diff --git a/extra/wolfssl/user_settings.h.in b/extra/wolfssl/user_settings.h.in index 98f05079e05..e381e87ce71 100644 --- a/extra/wolfssl/user_settings.h.in +++ b/extra/wolfssl/user_settings.h.in @@ -32,6 +32,7 @@ #cmakedefine USE_FAST_MATH #cmakedefine TFM_TIMING_RESISTANT #cmakedefine HAVE_INTEL_RDSEED +#cmakedefine HAVE_INTEL_RDRAND #cmakedefine USE_INTEL_SPEEDUP #cmakedefine USE_FAST_MATH #cmakedefine WOLFSSL_X86_64_BUILD From ade782c001affa69df80ed51e807e16198a9fe04 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 17 Sep 2020 22:27:45 +0200 Subject: [PATCH 27/48] MDEV-23741 Windows : error when renaming file in ALTER TABLE The presumed reason for the error is that the file was opened by 3rd party antivirus or backup program, causing ERROR_SHARING_VIOLATION on rename. The fix, actually a workaround, is to retry MoveFileEx couple of times before finally giving up. We expect 3rd party programs not to hold file for extended time. --- mysql-test/main/windows_debug.result | 4 ++ mysql-test/main/windows_debug.test | 11 ++++++ mysys/my_rename.c | 59 ++++++++++++++++++++++++++-- 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 mysql-test/main/windows_debug.result create mode 100644 mysql-test/main/windows_debug.test diff --git a/mysql-test/main/windows_debug.result b/mysql-test/main/windows_debug.result new file mode 100644 index 00000000000..7cc40b6de26 --- /dev/null +++ b/mysql-test/main/windows_debug.result @@ -0,0 +1,4 @@ +# mdev-23741 sharing violation when renaming .frm file in ALTER +CREATE TABLE t(i int); +SET STATEMENT debug_dbug='+d, win_simulate_rename_error' FOR ALTER TABLE t ADD PRIMARY KEY (i); +DROP TABLE t; diff --git a/mysql-test/main/windows_debug.test b/mysql-test/main/windows_debug.test new file mode 100644 index 00000000000..bb0880ddc55 --- /dev/null +++ b/mysql-test/main/windows_debug.test @@ -0,0 +1,11 @@ +# Windows-specific tests , debug mode + +--source include/have_debug.inc +--source include/windows.inc + +--echo # mdev-23741 sharing violation when renaming .frm file in ALTER +CREATE TABLE t(i int); +SET STATEMENT debug_dbug='+d,rename_sharing_violation' FOR ALTER TABLE t ADD PRIMARY KEY (i); +DROP TABLE t; + +#End of 10.3 tests diff --git a/mysys/my_rename.c b/mysys/my_rename.c index 81b43064ea8..5702af94272 100644 --- a/mysys/my_rename.c +++ b/mysys/my_rename.c @@ -19,8 +19,62 @@ #include "m_string.h" #undef my_rename - /* On unix rename deletes to file if it exists */ +#ifdef _WIN32 + +#define RENAME_MAX_RETRIES 50 + +/* + On Windows, bad 3rd party programs (backup or anitivirus, or something else) + can have file open with a sharing mode incompatible with renaming, i.e they + won't use FILE_SHARE_DELETE when opening file. + + The following function will do a couple of retries, in case MoveFileEx returns + ERROR_SHARING_VIOLATION. +*/ +static BOOL win_rename_with_retries(const char *from, const char *to) +{ +#ifndef DBUG_OFF + FILE *fp = NULL; + DBUG_EXECUTE_IF("rename_sharing_violation", + { + fp= fopen(from, "r"); + DBUG_ASSERT(fp); + } + ); +#endif + + for (int retry= RENAME_MAX_RETRIES; retry--;) + { + DWORD ret = MoveFileEx(from, to, + MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING); + + DBUG_ASSERT(fp == NULL || (ret == FALSE && GetLastError() == ERROR_SHARING_VIOLATION)); + + if (!ret && (GetLastError() == ERROR_SHARING_VIOLATION)) + { +#ifndef DBUG_OFF + /* + If error was injected in via DBUG_EXECUTE_IF, close the file + that is causing ERROR_SHARING_VIOLATION, so that retry succeeds. + */ + if (fp) + { + fclose(fp); + fp= NULL; + } +#endif + + Sleep(10); + } + else + return ret; + } + return FALSE; +} +#endif + + /* On unix rename deletes to file if it exists */ int my_rename(const char *from, const char *to, myf MyFlags) { int error = 0; @@ -28,8 +82,7 @@ int my_rename(const char *from, const char *to, myf MyFlags) DBUG_PRINT("my",("from %s to %s MyFlags %lu", from, to, MyFlags)); #if defined(__WIN__) - if (!MoveFileEx(from, to, MOVEFILE_COPY_ALLOWED | - MOVEFILE_REPLACE_EXISTING)) + if (!win_rename_with_retries(from, to)) { my_osmaperr(GetLastError()); #elif defined(HAVE_RENAME) From 29847a37363ad439639dd414ec9f76a6678130d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 18 Sep 2020 07:32:36 +0300 Subject: [PATCH 28/48] MDEV-23751 : galera_3nodes test failures on ipv6 sst tests Fix assertion text it was too tight for some systems. --- .../suite/galera_3nodes/r/galera_ipv6_mariabackup.result | 2 +- .../r/galera_ipv6_mariabackup_section.result | 2 +- .../suite/galera_3nodes/t/galera_ipv6_mariabackup.test | 8 ++++---- .../galera_3nodes/t/galera_ipv6_mariabackup_section.test | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result index 8ec1ff090ff..248c89afe99 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result +++ b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result @@ -21,4 +21,4 @@ connection node_1; include/assert_grep.inc [Streaming the backup to joiner at \[::1\]] include/assert_grep.inc [async IST sender starting to serve tcp://\[::1\]:] include/assert_grep.inc [IST receiver addr using tcp://\[::1\]] -include/assert_grep.inc [Prepared IST receiver for 3-6, listening at: tcp://\[::1\]] +include/assert_grep.inc [, listening at: tcp://\[::1\]] diff --git a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result index dc72260d979..d50a4339694 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result +++ b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result @@ -22,4 +22,4 @@ include/assert_grep.inc [Streaming the backup to joiner at \[::1\]] include/assert_grep.inc [async IST sender starting to serve tcp://\[::1\]:] connection node_2; include/assert_grep.inc [IST receiver addr using tcp://\[::1\]] -include/assert_grep.inc [Prepared IST receiver for 3-6, listening at: tcp://\[::1\]] +include/assert_grep.inc [, listening at: tcp://\[::1\]] diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test index d492a735bbf..2050f78cda9 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test @@ -63,8 +63,8 @@ DROP TABLE t1; --let $assert_select = IST receiver addr using tcp://\[::1\] --source include/assert_grep.inc -# The receiver expects seqnos 3-6 only once. ---let $assert_count = 1 ---let $assert_text = Prepared IST receiver for 3-6, listening at: tcp://\[::1\] ---let $assert_select = Prepared IST receiver for 3-6, listening at: tcp://\[::1\] +# The receiver expects IST +--let $assert_count = 2 +--let $assert_text = , listening at: tcp://\[::1\] +--let $assert_select = , listening at: tcp://\[::1\] --source include/assert_grep.inc diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.test b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.test index 688e6950d54..559ebfd8db2 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.test +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.test @@ -65,8 +65,8 @@ DROP TABLE t1; --let $assert_select = IST receiver addr using tcp://\[::1\] --source include/assert_grep.inc -# The receiver expects seqnos 3-6 only once. ---let $assert_count = 1 ---let $assert_text = Prepared IST receiver for 3-6, listening at: tcp://\[::1\] ---let $assert_select = Prepared IST receiver for 3-6, listening at: tcp://\[::1\] +# The receiver expects IST +--let $assert_count = 2 +--let $assert_text = , listening at: tcp://\[::1\] +--let $assert_select = , listening at: tcp://\[::1\] --source include/assert_grep.inc From 69d536a22dc1988e89697c55549fc3c272fbbf2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 18 Sep 2020 07:32:36 +0300 Subject: [PATCH 29/48] MDEV-23751 : galera_3nodes test failures on ipv6 sst tests Fix assertion text it was too tight for some systems. This is backport from 10.4 and for Galera 3. --- .../suite/galera_3nodes/r/galera_ipv6_mariabackup.result | 2 +- .../r/galera_ipv6_mariabackup_section.result | 2 +- .../suite/galera_3nodes/t/galera_ipv6_mariabackup.test | 6 ++++-- .../galera_3nodes/t/galera_ipv6_mariabackup_section.test | 8 ++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result index d0ed868c761..21403542ebe 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result +++ b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result @@ -19,4 +19,4 @@ connection node_1; include/assert_grep.inc [Streaming the backup to joiner at \[::1\]] include/assert_grep.inc [async IST sender starting to serve tcp://\[::1\]:] include/assert_grep.inc [IST receiver addr using tcp://\[::1\]] -include/assert_grep.inc [Prepared IST receiver, listening at: tcp://\[::1\]] +include/assert_grep.inc [, listening at: tcp://\[::1\]] diff --git a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result index 1d12e638296..9a7a2eac18e 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result +++ b/mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result @@ -20,4 +20,4 @@ include/assert_grep.inc [Streaming the backup to joiner at \[::1\]] include/assert_grep.inc [async IST sender starting to serve tcp://\[::1\]:] connection node_2; include/assert_grep.inc [IST receiver addr using tcp://\[::1\]] -include/assert_grep.inc [Prepared IST receiver, listening at: tcp://\[::1\]] +include/assert_grep.inc [, listening at: tcp://\[::1\]] diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test index a5dabe3d735..dc3331d1be3 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test @@ -56,6 +56,8 @@ DROP TABLE t1; --let $assert_select = IST receiver addr using tcp://\[::1\] --source include/assert_grep.inc ---let $assert_text = Prepared IST receiver, listening at: tcp://\[::1\] ---let $assert_select = Prepared IST receiver, listening at: tcp://\[::1\] +# The receiver expects IST +--let $assert_count = 1 +--let $assert_text = , listening at: tcp://\[::1\] +--let $assert_select = , listening at: tcp://\[::1\] --source include/assert_grep.inc diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.test b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.test index e17ea364195..c88ff99790c 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.test +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup_section.test @@ -64,8 +64,8 @@ DROP TABLE t1; --let $assert_select = IST receiver addr using tcp://\[::1\] --source include/assert_grep.inc -# There will be only one Prepared IST and in Galera 3 segnos are not printed ---let $assert_count= 1 ---let $assert_text = Prepared IST receiver, listening at: tcp://\[::1\] ---let $assert_select = Prepared IST receiver, listening at: tcp://\[::1\] +# The receiver expects IST +--let $assert_count = 1 +--let $assert_text = , listening at: tcp://\[::1\] +--let $assert_select = , listening at: tcp://\[::1\] --source include/assert_grep.inc From fba6ffe433fdba7aa397f1de8eb4ee0a74f55800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 21 Sep 2020 12:10:27 +0300 Subject: [PATCH 30/48] MDEV-23741: Fix the result --- mysql-test/main/windows_debug.result | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/main/windows_debug.result b/mysql-test/main/windows_debug.result index 7cc40b6de26..e6816cdd99b 100644 --- a/mysql-test/main/windows_debug.result +++ b/mysql-test/main/windows_debug.result @@ -1,4 +1,4 @@ # mdev-23741 sharing violation when renaming .frm file in ALTER CREATE TABLE t(i int); -SET STATEMENT debug_dbug='+d, win_simulate_rename_error' FOR ALTER TABLE t ADD PRIMARY KEY (i); +SET STATEMENT debug_dbug='+d,rename_sharing_violation' FOR ALTER TABLE t ADD PRIMARY KEY (i); DROP TABLE t; From 0a224edc3e24b28a3b2abcd3538a3d7d63d667c6 Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Sat, 19 Sep 2020 00:08:38 +0300 Subject: [PATCH 31/48] MDEV-23711 make mariabackup innodb redo log read error message more clear log_group_read_log_seg() returns error when: 1) Calculated log block number does not correspond to read log block number. This can be caused by: a) Garbage or an incompletely written log block. We can exclude this case by checking log block checksum if it's enabled(see innodb-log-checksums, encrypted log block contains checksum always). b) The log block is overwritten. In this case checksum will be correct and read log block number will be greater then requested one. 2) When log block length is wrong. In this case recv_sys->found_corrupt_log is set. 3) When redo log block checksum is wrong. In this case innodb code writes messages to error log with the following prefix: "Invalid log block checksum." The fix processes all the cases above. --- extra/mariabackup/xtrabackup.cc | 19 ++++- .../mariabackup/innodb_redo_overwrite.opt | 1 + .../mariabackup/innodb_redo_overwrite.result | 28 ++++++++ .../mariabackup/innodb_redo_overwrite.test | 70 +++++++++++++++++++ storage/innobase/log/log0recv.cc | 2 + 5 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 mysql-test/suite/mariabackup/innodb_redo_overwrite.opt create mode 100644 mysql-test/suite/mariabackup/innodb_redo_overwrite.result create mode 100644 mysql-test/suite/mariabackup/innodb_redo_overwrite.test diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index 4845f51e6b2..231e3c04f16 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -2773,6 +2773,7 @@ static bool xtrabackup_copy_logfile(bool last = false) ut_a(dst_log_file != NULL); ut_ad(recv_sys != NULL); + bool overwritten_block; lsn_t start_lsn; lsn_t end_lsn; @@ -2799,6 +2800,12 @@ static bool xtrabackup_copy_logfile(bool last = false) } if (lsn == start_lsn) { + overwritten_block= !recv_sys->found_corrupt_log + && (innodb_log_checksums || log_sys->log.is_encrypted()) + && log_block_calc_checksum_crc32(log_sys->buf) == + log_block_get_checksum(log_sys->buf) + && log_block_get_hdr_no(log_sys->buf) > + log_block_convert_lsn_to_no(start_lsn); start_lsn = 0; } else { mutex_enter(&recv_sys->mutex); @@ -2809,9 +2816,15 @@ static bool xtrabackup_copy_logfile(bool last = false) log_mutex_exit(); if (!start_lsn) { - die(recv_sys->found_corrupt_log - ? "xtrabackup_copy_logfile() failed: corrupt log." - : "xtrabackup_copy_logfile() failed."); + const char *reason = recv_sys->found_corrupt_log + ? "corrupt log." + : (overwritten_block + ? "redo log block is overwritten, please increase redo log size with innodb_log_file_size parameter." + : ((innodb_log_checksums || log_sys->log.is_encrypted()) + ? "redo log block checksum does not match." + : "unknown reason as innodb_log_checksums is switched off and redo" + " log is not encrypted.")); + die("xtrabackup_copy_logfile() failed: %s", reason); return true; } } while (start_lsn == end_lsn); diff --git a/mysql-test/suite/mariabackup/innodb_redo_overwrite.opt b/mysql-test/suite/mariabackup/innodb_redo_overwrite.opt new file mode 100644 index 00000000000..7111d384b40 --- /dev/null +++ b/mysql-test/suite/mariabackup/innodb_redo_overwrite.opt @@ -0,0 +1 @@ +--loose-innodb-log-file-size=1048576 --loose-innodb-log-files-in-group=2 diff --git a/mysql-test/suite/mariabackup/innodb_redo_overwrite.result b/mysql-test/suite/mariabackup/innodb_redo_overwrite.result new file mode 100644 index 00000000000..571bfd35c70 --- /dev/null +++ b/mysql-test/suite/mariabackup/innodb_redo_overwrite.result @@ -0,0 +1,28 @@ +CREATE TABLE t(i INT) ENGINE=INNODB; +INSERT INTO t VALUES +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9), +(0), (1), (2), (3), (4), (5), (6), (7), (8), (9); +# Generate enough data to overwrite innodb redo log +# on the next "INSERT INTO t SELECT * FROM t" execution. +INSERT INTO t SELECT * FROM t; +INSERT INTO t SELECT * FROM t; +INSERT INTO t SELECT * FROM t; +INSERT INTO t SELECT * FROM t; +INSERT INTO t SELECT * FROM t; +INSERT INTO t SELECT * FROM t; +INSERT INTO t SELECT * FROM t; +INSERT INTO t SELECT * FROM t; +INSERT INTO t SELECT * FROM t; +# xtrabackup backup +FOUND 1 /failed: redo log block is overwritten/ in backup.log +FOUND 1 /failed: redo log block checksum does not match/ in backup.log +FOUND 1 /failed: unknown reason/ in backup.log +DROP TABLE t; diff --git a/mysql-test/suite/mariabackup/innodb_redo_overwrite.test b/mysql-test/suite/mariabackup/innodb_redo_overwrite.test new file mode 100644 index 00000000000..55e754f18d7 --- /dev/null +++ b/mysql-test/suite/mariabackup/innodb_redo_overwrite.test @@ -0,0 +1,70 @@ +--source include/have_innodb.inc +--source include/have_debug_sync.inc + +CREATE TABLE t(i INT) ENGINE=INNODB; + +INSERT INTO t VALUES + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), + (0), (1), (2), (3), (4), (5), (6), (7), (8), (9); +--echo # Generate enough data to overwrite innodb redo log +--echo # on the next "INSERT INTO t SELECT * FROM t" execution. +--let $i = 0 +while ($i < 9) { +INSERT INTO t SELECT * FROM t; +--inc $i +} + +--echo # xtrabackup backup +--let $targetdir=$MYSQLTEST_VARDIR/tmp/backup +--let $backuplog=$MYSQLTEST_VARDIR/tmp/backup.log + +--let before_innodb_log_copy_thread_started=INSERT INTO test.t SELECT * FROM test.t + +--disable_result_log +--error 1 +--exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir --dbug=+d,mariabackup_events > $backuplog +--enable_result_log + +--let SEARCH_PATTERN=failed: redo log block is overwritten +--let SEARCH_FILE=$backuplog +--source include/search_pattern_in_file.inc +--remove_file $backuplog +--rmdir $targetdir + +--let before_innodb_log_copy_thread_started=INSERT INTO test.t VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9) + +--disable_result_log +--error 1 +--exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir --dbug=+d,mariabackup_events,log_checksum_mismatch > $backuplog +--enable_result_log + +--let SEARCH_PATTERN=failed: redo log block checksum does not match +--let SEARCH_FILE=$backuplog +--source include/search_pattern_in_file.inc +--remove_file $backuplog +--rmdir $targetdir + +--let before_innodb_log_copy_thread_started=INSERT INTO test.t SELECT * FROM test.t LIMIT 50000 + +--disable_result_log +--error 1 +--exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir --innodb-log-checksums=0 --dbug=+d,mariabackup_events > $backuplog +--enable_result_log + +--let SEARCH_PATTERN=failed: unknown reason +--let SEARCH_FILE=$backuplog +--source include/search_pattern_in_file.inc +--remove_file $backuplog +--rmdir $targetdir + +--let before_innodb_log_copy_thread_started= + +DROP TABLE t; diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index cf05563be02..446e0afe576 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -965,6 +965,8 @@ fail: } }); + DBUG_EXECUTE_IF("log_checksum_mismatch", { cksum = crc + 1; }); + if (crc != cksum) { ib::error() << "Invalid log block checksum." << " block: " << block_number From 6c4c88dbb899adf4a7a3c9313a0e705c660b6994 Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Mon, 21 Sep 2020 12:52:44 +0300 Subject: [PATCH 32/48] MDEV-18867: Remove an orphan function --- storage/innobase/fts/fts0fts.cc | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index 8ff872eab29..8a6901bd15b 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -5746,22 +5746,6 @@ fts_savepoint_rollback( } } -/*********************************************************************//** -Compare two fts_aux_table_t parent_ids. -@return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */ -UNIV_INLINE -int -fts_check_aux_table_parent_id_cmp( -/*==============================*/ - const void* p1, /*!< in: id1 */ - const void* p2) /*!< in: id2 */ -{ - const fts_aux_table_t* fa1 = static_cast(p1); - const fts_aux_table_t* fa2 = static_cast(p2); - - return static_cast(fa1->parent_id - fa2->parent_id); -} - bool fts_check_aux_table(const char *name, table_id_t *table_id, index_id_t *index_id) From a0e2a293bcc25fb10888fd00bd63bce04c195524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 21 Sep 2020 13:59:13 +0300 Subject: [PATCH 33/48] Fix try. --- .../suite/galera_3nodes/galera_2x3nodes.cnf | 6 ++ .../r/galera_gtid_2_cluster.result | 76 ++++++++++++++++++- .../t/galera_gtid_2_cluster.test | 14 +++- 3 files changed, 91 insertions(+), 5 deletions(-) diff --git a/mysql-test/suite/galera_3nodes/galera_2x3nodes.cnf b/mysql-test/suite/galera_3nodes/galera_2x3nodes.cnf index 477789175fb..34ef09875ea 100644 --- a/mysql-test/suite/galera_3nodes/galera_2x3nodes.cnf +++ b/mysql-test/suite/galera_3nodes/galera_2x3nodes.cnf @@ -28,6 +28,7 @@ wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.1.#gale wsrep_sst_receive_address=127.0.0.2:@mysqld.1.#sst_port wsrep_node_incoming_address=127.0.0.1:@mysqld.1.port wsrep_sst_receive_address='127.0.0.1:@mysqld.1.#sst_port' +wsrep-on=1 [mysqld.2] #galera_port=@OPT.port @@ -39,6 +40,7 @@ wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.2.#gale wsrep_sst_receive_address=127.0.0.2:@mysqld.2.#sst_port wsrep_node_incoming_address=127.0.0.1:@mysqld.2.port wsrep_sst_receive_address='127.0.0.1:@mysqld.2.#sst_port' +wsrep-on=1 [mysqld.3] #galera_port=@OPT.port @@ -50,6 +52,7 @@ wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.3.#gale wsrep_sst_receive_address=127.0.0.2:@mysqld.3.#sst_port wsrep_node_incoming_address=127.0.0.1:@mysqld.3.port wsrep_sst_receive_address='127.0.0.1:@mysqld.3.#sst_port' +wsrep-on=1 [mysqld.4] @@ -64,6 +67,7 @@ wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.4.#gale wsrep_sst_receive_address=127.0.0.2:@mysqld.4.#sst_port wsrep_node_incoming_address=127.0.0.1:@mysqld.4.port wsrep_sst_receive_address='127.0.0.1:@mysqld.4.#sst_port' +wsrep-on=1 [mysqld.5] wsrep_cluster_name=cluster2 @@ -76,6 +80,7 @@ wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.5.#gale wsrep_sst_receive_address=127.0.0.2:@mysqld.5.#sst_port wsrep_node_incoming_address=127.0.0.1:@mysqld.5.port wsrep_sst_receive_address='127.0.0.1:@mysqld.5.#sst_port' +wsrep-on=1 [mysqld.6] wsrep_cluster_name=cluster2 @@ -88,6 +93,7 @@ wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.6.#gale wsrep_sst_receive_address=127.0.0.2:@mysqld.6.#sst_port wsrep_node_incoming_address=127.0.0.1:@mysqld.6.port wsrep_sst_receive_address='127.0.0.1:@mysqld.6.#sst_port' +wsrep-on=1 [ENV] NODE_MYPORT_1= @mysqld.1.port diff --git a/mysql-test/suite/galera_3nodes/r/galera_gtid_2_cluster.result b/mysql-test/suite/galera_3nodes/r/galera_gtid_2_cluster.result index 35ca84119e7..43064cf6441 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_gtid_2_cluster.result +++ b/mysql-test/suite/galera_3nodes/r/galera_gtid_2_cluster.result @@ -1,27 +1,38 @@ +connection node_1; cluster 1 node 1 SHOW STATUS LIKE 'wsrep_cluster_size'; Variable_name Value wsrep_cluster_size 3 +connection node_2; cluster 1 node 2 SHOW STATUS LIKE 'wsrep_cluster_size'; Variable_name Value wsrep_cluster_size 3 +connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3; +connection node_3; cluster 1 node 3 SHOW STATUS LIKE 'wsrep_cluster_size'; Variable_name Value wsrep_cluster_size 3 +connect node_4, 127.0.0.1, root, , test, $NODE_MYPORT_4; +connection node_4; cluster 2 node 1 SHOW STATUS LIKE 'wsrep_cluster_size'; Variable_name Value wsrep_cluster_size 3 +connect node_5, 127.0.0.1, root, , test, $NODE_MYPORT_5; +connection node_5; cluster 2 node 2 SHOW STATUS LIKE 'wsrep_cluster_size'; Variable_name Value wsrep_cluster_size 3 +connect node_6, 127.0.0.1, root, , test, $NODE_MYPORT_6; +connection node_6; cluster 2 node 3 SHOW STATUS LIKE 'wsrep_cluster_size'; Variable_name Value wsrep_cluster_size 3 +connection node_1; change master to master_host='127.0.0.1', master_user='root', master_port=NODE_MYPORT_4, master_use_gtid=current_pos, ignore_server_ids=(12,13);; start slave; include/wait_for_slave_to_start.inc @@ -31,6 +42,7 @@ select @@gtid_binlog_state; select @@gtid_slave_pos; @@gtid_slave_pos +connection node_4; change master to master_host='127.0.0.1', master_user='root', master_port=NODE_MYPORT_1, master_use_gtid=current_pos, ignore_server_ids=(22,23);; start slave; include/wait_for_slave_to_start.inc @@ -41,15 +53,19 @@ select @@gtid_slave_pos; @@gtid_slave_pos cluster 1 node 1 +connection node_1; create table t1 (cluster_domain_id int ,node_server_id int, seq_no int); insert into t1 values (1, 11, 2); select @@gtid_binlog_state; @@gtid_binlog_state 1-11-2 #wait for sync cluster 1 and 2 +connection node_1; include/save_master_gtid.inc +connection node_4; include/sync_with_master_gtid.inc cluster 2 node 1 +connection node_4; select @@gtid_binlog_state; @@gtid_binlog_state 1-11-2 @@ -62,31 +78,40 @@ cluster_domain_id node_server_id seq_no 1 11 2 2 21 1 #wait for sync cluster 1 and 2 +connection node_1; include/save_master_gtid.inc +connection node_4; include/sync_with_master_gtid.inc cluster 1 node 2 +connection node_2; select @@gtid_binlog_state; @@gtid_binlog_state -1-11-2,2-21-1 +1-11-2 insert into t1 values (1, 12, 3); select @@gtid_binlog_state; @@gtid_binlog_state 1-11-2,1-12-3,2-21-1 #wait for sync cluster 1 and 2 +connection node_1; include/save_master_gtid.inc +connection node_4; include/sync_with_master_gtid.inc cluster 1 node 3 +connection node_3; select @@gtid_binlog_state; @@gtid_binlog_state -1-11-2,1-12-3,2-21-1 +1-11-2,2-21-1 insert into t1 values (1, 13, 4); select @@gtid_binlog_state; @@gtid_binlog_state 1-12-3,1-11-2,1-13-4,2-21-1 #wait for sync cluster 1 and 2 +connection node_1; include/save_master_gtid.inc +connection node_4; include/sync_with_master_gtid.inc cluster 2 node 2 +connection node_5; select @@gtid_binlog_state; @@gtid_binlog_state 1-12-3,1-11-2,1-13-4,2-21-1 @@ -95,9 +120,12 @@ select @@gtid_binlog_state; @@gtid_binlog_state 1-12-3,1-11-2,1-13-4,2-21-1,2-22-2 #wait for sync cluster 2 and 1 +connection node_4; include/save_master_gtid.inc +connection node_1; include/sync_with_master_gtid.inc cluster 2 node 3 +connection node_6; select @@gtid_binlog_state; @@gtid_binlog_state 1-12-3,1-11-2,1-13-4,2-21-1,2-22-2 @@ -106,9 +134,12 @@ select @@gtid_binlog_state; @@gtid_binlog_state 1-12-3,1-11-2,1-13-4,2-21-1,2-22-2,2-23-3 #wait for sync cluster 2 and 1 +connection node_4; include/save_master_gtid.inc +connection node_1; include/sync_with_master_gtid.inc cluster 1 node 1 +connection node_1; select @@gtid_binlog_state; @@gtid_binlog_state 1-12-3,1-11-2,1-13-4,2-21-1,2-22-2,2-23-3 @@ -119,15 +150,21 @@ change master to master_use_gtid=no, ignore_server_ids=(); reset master; set global GTID_SLAVE_POS=""; cluster 2 node 1 +connection node_4; stop slave; reset slave; change master to master_use_gtid=no, ignore_server_ids=(); reset master; set global GTID_SLAVE_POS=""; +connection node_2; reset master; +connection node_3; reset master; +connection node_5; reset master; +connection node_6; reset master; +connection node_1; change master to master_host='127.0.0.1', master_user='root', master_port=NODE_MYPORT_6, master_use_gtid=current_pos, ignore_server_ids=(12,13);; start slave; include/wait_for_slave_to_start.inc @@ -137,6 +174,7 @@ select @@gtid_binlog_state; select @@gtid_slave_pos; @@gtid_slave_pos +connection node_4; change master to master_host='127.0.0.1', master_user='root', master_port=NODE_MYPORT_3, master_use_gtid=current_pos, ignore_server_ids=(22,23);; start slave; include/wait_for_slave_to_start.inc @@ -147,15 +185,19 @@ select @@gtid_slave_pos; @@gtid_slave_pos cluster 1 node 1 -create table t1 (cluster_domain_id int ,node_server_id int, seq_no int); +connection node_1; +create table t1 (cluster_domain_id int not null,node_server_id int not null, seq_no int not null, primary key(cluster_domain_id, node_server_id,seq_no)) engine=innodb; insert into t1 values (1, 11, 2); select @@gtid_binlog_state; @@gtid_binlog_state 1-11-2 #wait for sync cluster 1 and 2 +connection node_1; include/save_master_gtid.inc +connection node_4; include/sync_with_master_gtid.inc cluster 2 node 1 +connection node_4; insert into t1 values (2, 21, 1); select @@gtid_binlog_state; @@gtid_binlog_state @@ -165,9 +207,12 @@ cluster_domain_id node_server_id seq_no 1 11 2 2 21 1 #wait for sync cluster 1 and 2 +connection node_1; include/save_master_gtid.inc +connection node_4; include/sync_with_master_gtid.inc cluster 1 node 2 +connection node_2; select @@gtid_binlog_state; @@gtid_binlog_state 1-11-2,2-21-1 @@ -176,9 +221,12 @@ select @@gtid_binlog_state; @@gtid_binlog_state 1-11-2,1-12-3,2-21-1 #wait for sync cluster 1 and 2 +connection node_1; include/save_master_gtid.inc +connection node_4; include/sync_with_master_gtid.inc cluster 1 node 3 +connection node_3; select @@gtid_binlog_state; @@gtid_binlog_state 1-11-2,1-12-3,2-21-1 @@ -187,9 +235,12 @@ select @@gtid_binlog_state; @@gtid_binlog_state 1-12-3,1-11-2,1-13-4,2-21-1 #wait for sync cluster 1 and 2 +connection node_1; include/save_master_gtid.inc +connection node_4; include/sync_with_master_gtid.inc cluster 2 node 2 +connection node_5; select @@gtid_binlog_state; @@gtid_binlog_state 1-12-3,1-11-2,1-13-4,2-21-1 @@ -198,9 +249,12 @@ select @@gtid_binlog_state; @@gtid_binlog_state 1-12-3,1-11-2,1-13-4,2-21-1,2-22-2 #wait for sync cluster 2 and 1 +connection node_4; include/save_master_gtid.inc +connection node_1; include/sync_with_master_gtid.inc cluster 2 node 3 +connection node_6; select @@gtid_binlog_state; @@gtid_binlog_state 1-12-3,1-11-2,1-13-4,2-21-1,2-22-2 @@ -209,9 +263,12 @@ select @@gtid_binlog_state; @@gtid_binlog_state 1-12-3,1-11-2,1-13-4,2-21-1,2-22-2,2-23-3 #wait for sync cluster 2 and 1 +connection node_4; include/save_master_gtid.inc +connection node_1; include/sync_with_master_gtid.inc cluster 1 node 1 +connection node_1; select @@gtid_binlog_state; @@gtid_binlog_state 1-12-3,1-11-2,1-13-4,2-21-1,2-22-2,2-23-3 @@ -221,11 +278,24 @@ change master to master_use_gtid=no, ignore_server_ids=(); reset master; set global GTID_SLAVE_POS=""; cluster 2 node 1 +connection node_4; stop slave; change master to master_use_gtid=no, ignore_server_ids=(); reset master; set global GTID_SLAVE_POS=""; +connection node_2; +set session wsrep_on=off; reset master; +set session wsrep_on=on; +connection node_3; +set session wsrep_on=off; reset master; +set session wsrep_on=on; +connection node_5; +set session wsrep_on=off; reset master; +set session wsrep_on=on; +connection node_6; +set session wsrep_on=off; reset master; +set session wsrep_on=on; diff --git a/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.test b/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.test index c679db1305d..2bb8d06462c 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.test +++ b/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.test @@ -10,7 +10,7 @@ --source include/big_test.inc --source include/galera_cluster.inc ---source include/have_innodb.inc +--source include/force_restart.inc --connection node_1 --echo cluster 1 node 1 @@ -29,6 +29,7 @@ SHOW STATUS LIKE 'wsrep_cluster_size'; --connection node_4 --echo cluster 2 node 1 SHOW STATUS LIKE 'wsrep_cluster_size'; +call mtr.add_suppression("Slave I/O: Got fatal error 1236 from master when reading data from binary log.*"); --connect node_5, 127.0.0.1, root, , test, $NODE_MYPORT_5 --connection node_5 @@ -193,7 +194,7 @@ select @@gtid_slave_pos; --echo cluster 1 node 1 --connection node_1 -create table t1 (cluster_domain_id int ,node_server_id int, seq_no int); +create table t1 (cluster_domain_id int not null,node_server_id int not null, seq_no int not null, primary key(cluster_domain_id, node_server_id,seq_no)) engine=innodb; insert into t1 values (1, 11, 2); select @@gtid_binlog_state; @@ -283,10 +284,19 @@ reset master; set global GTID_SLAVE_POS=""; --connection node_2 +set session wsrep_on=off; reset master; +set session wsrep_on=on; --connection node_3 +set session wsrep_on=off; reset master; +set session wsrep_on=on; --connection node_5 +set session wsrep_on=off; reset master; +set session wsrep_on=on; --connection node_6 +set session wsrep_on=off; reset master; +set session wsrep_on=on; + From a3bdce8f1e268e3ac57644faf91c9c5ad43f5291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 21 Sep 2020 14:01:56 +0300 Subject: [PATCH 34/48] MDEV-23659 : Update Galera disabled.def file --- mysql-test/suite/galera_3nodes/disabled.def | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/suite/galera_3nodes/disabled.def b/mysql-test/suite/galera_3nodes/disabled.def index c6d3ece75d1..0e2706f2dc3 100644 --- a/mysql-test/suite/galera_3nodes/disabled.def +++ b/mysql-test/suite/galera_3nodes/disabled.def @@ -10,6 +10,7 @@ # ############################################################################## +galera_gtid_2_cluster : MDEV-23775 Galera test failure on galera_3nodes.galera_gtid_2_cluster galera_ist_gcache_rollover : MDEV-23578 WSREP: exception caused by message: {v=0,t=1,ut=255,o=4,s=0,sr=0,as=1,f=6,src=50524cfe,srcvid=view_id(REG,50524cfe,4),insvid=view_id(UNKNOWN,00000000,0),ru=00000000,r=[-1,-1],fs=75,nl=(} galera_slave_options_do :MDEV-8798 galera_slave_options_ignore : MDEV-8798 From e33f7b6faaacf49881fd913115b0735c62aba395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 21 Sep 2020 15:55:27 +0300 Subject: [PATCH 35/48] MDEV-23776 Test encryption.create_or_replace fails with a warning The test encryption.create_or_replace would occasionally fail with a warning message from fil_check_pending_ops(). fil_crypt_find_space_to_rotate(): While waiting for available I/O capacity, check fil_space_t::is_stopping() and release a handle if necessary. fil_space_crypt_close_tablespace(): Wake up the waiters in fil_crypt_find_space_to_rotate(). --- storage/innobase/fil/fil0crypt.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc index 09f2730edec..16b2093b691 100644 --- a/storage/innobase/fil/fil0crypt.cc +++ b/storage/innobase/fil/fil0crypt.cc @@ -1483,6 +1483,11 @@ static bool fil_crypt_find_space_to_rotate( { /* we need iops to start rotating */ while (!state->should_shutdown() && !fil_crypt_alloc_iops(state)) { + if (state->space && state->space->is_stopping()) { + fil_space_release(state->space); + state->space = NULL; + } + os_event_reset(fil_crypt_threads_event); os_event_wait_time(fil_crypt_threads_event, 100000); } @@ -2506,6 +2511,7 @@ fil_space_crypt_close_tablespace( /* wakeup throttle (all) sleepers */ os_event_set(fil_crypt_throttle_sleep_event); + os_event_set(fil_crypt_threads_event); os_thread_sleep(20000); dict_mutex_enter_for_mysql(); From a9d8f5c1a55e03312211c637a1a916cc57573a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 21 Sep 2020 16:14:35 +0300 Subject: [PATCH 36/48] MDEV-23776: Split encryption.create_or_replace Let us shrink the test encryption.create_or_replace so that it can run on the CI system, also on the embedded server. encryption.create_or_replace_big: Renamed from the original test, with the subset of encryption.create_or_replace omitted. --- ...ce.result => create_or_replace_big.result} | 9 +-- ..._replace.opt => create_or_replace_big.opt} | 0 ...eplace.test => create_or_replace_big.test} | 58 +------------------ 3 files changed, 2 insertions(+), 65 deletions(-) rename mysql-test/suite/encryption/r/{create_or_replace.result => create_or_replace_big.result} (82%) rename mysql-test/suite/encryption/t/{create_or_replace.opt => create_or_replace_big.opt} (100%) rename mysql-test/suite/encryption/t/{create_or_replace.test => create_or_replace_big.test} (63%) diff --git a/mysql-test/suite/encryption/r/create_or_replace.result b/mysql-test/suite/encryption/r/create_or_replace_big.result similarity index 82% rename from mysql-test/suite/encryption/r/create_or_replace.result rename to mysql-test/suite/encryption/r/create_or_replace_big.result index 1671043b50d..87f56cc3e2c 100644 --- a/mysql-test/suite/encryption/r/create_or_replace.result +++ b/mysql-test/suite/encryption/r/create_or_replace_big.result @@ -12,15 +12,8 @@ INSERT /*! IGNORE */ INTO table1_int_autoinc VALUES (4, NULL, NULL); INSERT IGNORE INTO `table0_int_autoinc` ( `col_int_key` ) VALUES ( 1 ), ( 3 ), ( 4 ), ( 1 ); INSERT IGNORE INTO `table1_int_autoinc` ( `col_int` ) VALUES ( 1 ), ( 0 ), ( 7 ), ( 9 ); INSERT IGNORE INTO `table10_int_autoinc` ( `col_int` ) VALUES ( 6 ), ( 2 ), ( 3 ), ( 6 ); -connect con1,localhost,root,,test; -connect con2,localhost,root,,test; -connection default; -drop table if exists create_or_replace_t, table1_int_autoinc, table0_int_autoinc, table10_int_autoinc; -disconnect con1; -disconnect con2; -SET GLOBAL innodb_encrypt_tables = OFF; -SET GLOBAL innodb_encryption_threads = 4; # Wait max 10 min for key encryption threads to decrypt all spaces # Success! SET GLOBAL innodb_encryption_threads = 0; SET GLOBAL innodb_encrypt_tables = OFF; +DROP TABLE table0_int_autoinc, table1_int_autoinc, table10_int_autoinc; diff --git a/mysql-test/suite/encryption/t/create_or_replace.opt b/mysql-test/suite/encryption/t/create_or_replace_big.opt similarity index 100% rename from mysql-test/suite/encryption/t/create_or_replace.opt rename to mysql-test/suite/encryption/t/create_or_replace_big.opt diff --git a/mysql-test/suite/encryption/t/create_or_replace.test b/mysql-test/suite/encryption/t/create_or_replace_big.test similarity index 63% rename from mysql-test/suite/encryption/t/create_or_replace.test rename to mysql-test/suite/encryption/t/create_or_replace_big.test index 3b2970e5162..133bdfa3cb2 100644 --- a/mysql-test/suite/encryption/t/create_or_replace.test +++ b/mysql-test/suite/encryption/t/create_or_replace_big.test @@ -55,62 +55,6 @@ INSERT IGNORE INTO `table0_int_autoinc` ( `col_int_key` ) VALUES ( 1 ), ( 3 ), ( INSERT IGNORE INTO `table1_int_autoinc` ( `col_int` ) VALUES ( 1 ), ( 0 ), ( 7 ), ( 9 ); INSERT IGNORE INTO `table10_int_autoinc` ( `col_int` ) VALUES ( 6 ), ( 2 ), ( 3 ), ( 6 ); ---connect (con1,localhost,root,,test) ---connect (con2,localhost,root,,test) - ---disable_abort_on_error ---disable_warnings ---disable_query_log - -let $i = 500; -while ($i) -{ -connection con1; -send SET GLOBAL innodb_encrypt_tables = ON; -connection default; -CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table1_int_autoinc`; -connection con2; -send CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table10_int_autoinc`; -connection default; -send CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table0_int_autoinc`; -connection con1; ---reap; -send SET GLOBAL innodb_encrypt_tables = OFF; -connection con2; ---reap; -connection default; ---reap; -send CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table1_int_autoinc`; -connection con2; -send CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table10_int_autoinc`; -connection con1; ---reap; -send SET GLOBAL innodb_encrypt_tables = ON; -connection default; ---reap; -send CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table1_int_autoinc`; -connection con2; ---reap; -CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table10_int_autoinc`; -CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table0_int_autoinc`; -connection con1; ---reap; -connection default; ---reap; -dec $i; -} - ---enable_query_log -connection default; -drop table if exists create_or_replace_t, table1_int_autoinc, table0_int_autoinc, table10_int_autoinc; ---disconnect con1 ---disconnect con2 ---enable_abort_on_error ---enable_warnings - -SET GLOBAL innodb_encrypt_tables = OFF; -SET GLOBAL innodb_encryption_threads = 4; - --echo # Wait max 10 min for key encryption threads to decrypt all spaces let $cnt=600; while ($cnt) @@ -137,6 +81,6 @@ if (!$success) SET GLOBAL innodb_encryption_threads = 0; SET GLOBAL innodb_encrypt_tables = OFF; -# Make sure that all dirty pages are flushed +DROP TABLE table0_int_autoinc, table1_int_autoinc, table10_int_autoinc; -- source include/restart_mysqld.inc From 407d170c926d91d176dd8aca2040462db4241fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 21 Sep 2020 16:29:29 +0300 Subject: [PATCH 37/48] MDEV-23711 fixup: GCC -Og -Wmaybe-uninitialized --- extra/mariabackup/xtrabackup.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index 231e3c04f16..33a64356366 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -2773,7 +2773,7 @@ static bool xtrabackup_copy_logfile(bool last = false) ut_a(dst_log_file != NULL); ut_ad(recv_sys != NULL); - bool overwritten_block; + bool overwritten_block = false; lsn_t start_lsn; lsn_t end_lsn; From e05650e6868eab2dbb9f58c4786bcc71afc4ffce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 21 Sep 2020 16:35:28 +0300 Subject: [PATCH 38/48] MDEV-23776: Add the reduced encryption.create_or_replace test This was forgotten in commit a9d8f5c1a55e03312211c637a1a916cc57573a73. --- .../encryption/r/create_or_replace.result | 21 +++++ .../suite/encryption/t/create_or_replace.test | 80 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 mysql-test/suite/encryption/r/create_or_replace.result create mode 100644 mysql-test/suite/encryption/t/create_or_replace.test diff --git a/mysql-test/suite/encryption/r/create_or_replace.result b/mysql-test/suite/encryption/r/create_or_replace.result new file mode 100644 index 00000000000..62dac4ccc43 --- /dev/null +++ b/mysql-test/suite/encryption/r/create_or_replace.result @@ -0,0 +1,21 @@ +SET @save_threads = @@GLOBAL.innodb_encryption_threads; +SET @save_tables = @@GLOBAL.innodb_encrypt_tables; +SET default_storage_engine = InnoDB; +SET GLOBAL innodb_encryption_threads = 4; +CREATE TABLE `table10_int_autoinc` (`col_int_key` int, pk int auto_increment, `col_int` int, key (`col_int_key` ),primary key (pk)) engine=innodb; +INSERT /*! IGNORE */ INTO table10_int_autoinc VALUES (NULL, NULL, -474021888) , (1, NULL, NULL) , (1141047296, NULL, NULL) , (NULL, NULL, NULL) , (NULL, NULL, 1) , (NULL, NULL, 9) , (0, NULL, 1225785344) , (NULL, NULL, 1574174720) , (2, NULL, NULL) , (6, NULL, 3); +CREATE TABLE `table1_int_autoinc` (`col_int_key` int, pk int auto_increment, `col_int` int,key (`col_int_key` ), primary key (pk)) engine=innodb; +CREATE TABLE `table0_int_autoinc` (`col_int_key` int, pk int auto_increment, `col_int` int, key (`col_int_key` ),primary key (pk)) engine=innodb; +INSERT /*! IGNORE */ INTO table1_int_autoinc VALUES (4, NULL, NULL); +INSERT IGNORE INTO `table0_int_autoinc` ( `col_int_key` ) VALUES ( 1 ), ( 3 ), ( 4 ), ( 1 ); +INSERT IGNORE INTO `table1_int_autoinc` ( `col_int` ) VALUES ( 1 ), ( 0 ), ( 7 ), ( 9 ); +INSERT IGNORE INTO `table10_int_autoinc` ( `col_int` ) VALUES ( 6 ), ( 2 ), ( 3 ), ( 6 ); +connect con1,localhost,root,,test; +connect con2,localhost,root,,test; +disconnect con1; +disconnect con2; +connection default; +drop table create_or_replace_t, table1_int_autoinc, table0_int_autoinc, +table10_int_autoinc; +SET GLOBAL innodb_encryption_threads = @save_threads; +SET GLOBAL innodb_encrypt_tables = @save_tables; diff --git a/mysql-test/suite/encryption/t/create_or_replace.test b/mysql-test/suite/encryption/t/create_or_replace.test new file mode 100644 index 00000000000..8d571794713 --- /dev/null +++ b/mysql-test/suite/encryption/t/create_or_replace.test @@ -0,0 +1,80 @@ +--source include/have_innodb.inc +--source include/have_file_key_management_plugin.inc +--source include/count_sessions.inc + +SET @save_threads = @@GLOBAL.innodb_encryption_threads; +SET @save_tables = @@GLOBAL.innodb_encrypt_tables; + +SET default_storage_engine = InnoDB; + +# +# MDEV-8173: InnoDB; Failing assertion: crypt_data->type == 1 +# + +SET GLOBAL innodb_encryption_threads = 4; + +CREATE TABLE `table10_int_autoinc` (`col_int_key` int, pk int auto_increment, `col_int` int, key (`col_int_key` ),primary key (pk)) engine=innodb; +INSERT /*! IGNORE */ INTO table10_int_autoinc VALUES (NULL, NULL, -474021888) , (1, NULL, NULL) , (1141047296, NULL, NULL) , (NULL, NULL, NULL) , (NULL, NULL, 1) , (NULL, NULL, 9) , (0, NULL, 1225785344) , (NULL, NULL, 1574174720) , (2, NULL, NULL) , (6, NULL, 3); + +CREATE TABLE `table1_int_autoinc` (`col_int_key` int, pk int auto_increment, `col_int` int,key (`col_int_key` ), primary key (pk)) engine=innodb; + +CREATE TABLE `table0_int_autoinc` (`col_int_key` int, pk int auto_increment, `col_int` int, key (`col_int_key` ),primary key (pk)) engine=innodb; + +INSERT /*! IGNORE */ INTO table1_int_autoinc VALUES (4, NULL, NULL); +INSERT IGNORE INTO `table0_int_autoinc` ( `col_int_key` ) VALUES ( 1 ), ( 3 ), ( 4 ), ( 1 ); +INSERT IGNORE INTO `table1_int_autoinc` ( `col_int` ) VALUES ( 1 ), ( 0 ), ( 7 ), ( 9 ); +INSERT IGNORE INTO `table10_int_autoinc` ( `col_int` ) VALUES ( 6 ), ( 2 ), ( 3 ), ( 6 ); + +--connect (con1,localhost,root,,test) +--connect (con2,localhost,root,,test) + +--disable_query_log + +let $i = 100; +while ($i) +{ +connection con1; +send SET GLOBAL innodb_encrypt_tables = ON; +connection default; +CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table1_int_autoinc`; +connection con2; +send CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table10_int_autoinc`; +connection default; +send CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table0_int_autoinc`; +connection con1; +--reap; +send SET GLOBAL innodb_encrypt_tables = OFF; +connection con2; +--reap; +connection default; +--reap; +send CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table1_int_autoinc`; +connection con2; +send CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table10_int_autoinc`; +connection con1; +--reap; +send SET GLOBAL innodb_encrypt_tables = ON; +connection default; +--reap; +send CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table1_int_autoinc`; +connection con2; +--reap; +CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table10_int_autoinc`; +CREATE OR REPLACE TABLE `create_or_replace_t` AS SELECT * FROM `table0_int_autoinc`; +connection con1; +--reap; +connection default; +--reap; +dec $i; +} + +--enable_query_log +disconnect con1; +disconnect con2; +connection default; +drop table create_or_replace_t, table1_int_autoinc, table0_int_autoinc, +table10_int_autoinc; + +SET GLOBAL innodb_encryption_threads = @save_threads; +SET GLOBAL innodb_encrypt_tables = @save_tables; +--source include/wait_until_count_sessions.inc From 4c19227929b0d86616337585fb95a4bb8fe0d4b2 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 12 Dec 2017 11:24:39 +1100 Subject: [PATCH 39/48] systemd: mariadb@bootstrap - clear ExecStartPre and ExecStartPost This is just to make sure no ExecStartPre/Post actions from the multi-instance MariaDB service definition are executed when a user attempts to start mariadb@bootstrap. Fixes: 3723c70a3045 --- support-files/use_galera_new_cluster.conf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/support-files/use_galera_new_cluster.conf b/support-files/use_galera_new_cluster.conf index 90e0365ffd8..79d191094d4 100644 --- a/support-files/use_galera_new_cluster.conf +++ b/support-files/use_galera_new_cluster.conf @@ -15,8 +15,13 @@ ConditionPathExists= Type=oneshot Restart=no +# Don't install or try to prepare for galera SST. +ExecStartPre= + # Override the multi instance service for a bootstrap start instance ExecStart= ExecStart=/usr/bin/echo "Please use galera_new_cluster to start the mariadb service with --wsrep-new-cluster" ExecStart=/usr/bin/false +# This isn't a service meant to execute anything but a message +ExecStartPost= From eb38b1f703fb84299680f9c5a75ea970be7aee1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 22 Sep 2020 10:41:06 +0300 Subject: [PATCH 40/48] Revert "MDEV-23776 Test encryption.create_or_replace fails with a warning" This reverts commit e33f7b6faaacf49881fd913115b0735c62aba395. The change seems to have introduced intermittent failures of the test encryption.innodb-bad-key-change on many platforms. The failure that we were trying to address was not reproduced on 10.2. It could be related to commit a7dd7c899356b2d3a7f79e6ebba5d854ed63ae9d (MDEV-23651) or de942c9f618b590a01a7960c171d7e50e435708f (MDEV-15983) or other changes that reduced contention on fil_system.mutex in 10.3. The fix that we are hereby reverting from 10.2 seems to work fine on 10.3 and 10.4. --- storage/innobase/fil/fil0crypt.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc index 16b2093b691..09f2730edec 100644 --- a/storage/innobase/fil/fil0crypt.cc +++ b/storage/innobase/fil/fil0crypt.cc @@ -1483,11 +1483,6 @@ static bool fil_crypt_find_space_to_rotate( { /* we need iops to start rotating */ while (!state->should_shutdown() && !fil_crypt_alloc_iops(state)) { - if (state->space && state->space->is_stopping()) { - fil_space_release(state->space); - state->space = NULL; - } - os_event_reset(fil_crypt_threads_event); os_event_wait_time(fil_crypt_threads_event, 100000); } @@ -2511,7 +2506,6 @@ fil_space_crypt_close_tablespace( /* wakeup throttle (all) sleepers */ os_event_set(fil_crypt_throttle_sleep_event); - os_event_set(fil_crypt_threads_event); os_thread_sleep(20000); dict_mutex_enter_for_mysql(); From 732cd7fd5346885ae41293d7ebe44110188155d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 22 Sep 2020 11:13:51 +0300 Subject: [PATCH 41/48] MDEV-23705 Assertion 'table->data_dir_path || !space' After DISCARD TABLESPACE, the tablespace of a table will no longer exist, and dict_get_and_save_data_dir_path() would invoke dict_get_first_path() to read an entry from SYS_DATAFILES. For some reason, DISCARD TABLESPACE would not to remove the entry from there. dict_get_and_save_data_dir_path(): If the tablespace has been discarded, do not bother trying to read the name. Side note: The tables SYS_TABLESPACES and SYS_DATAFILES are redundant and subject to removal in MDEV-22343. --- mysql-test/suite/innodb/r/truncate.result | 11 +++++++++++ mysql-test/suite/innodb/t/truncate.test | 10 ++++++++++ storage/innobase/dict/dict0load.cc | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/innodb/r/truncate.result b/mysql-test/suite/innodb/r/truncate.result index 5e9fd60d4fe..571aa2da1c5 100644 --- a/mysql-test/suite/innodb/r/truncate.result +++ b/mysql-test/suite/innodb/r/truncate.result @@ -39,3 +39,14 @@ TRUNCATE t1; SELECT * FROM t1; a DROP TEMPORARY TABLE t1; +# +# MDEV-23705 Assertion 'table->data_dir_path || !space' +# +CREATE TABLE t(c INT) ENGINE=InnoDB; +ALTER TABLE t DISCARD TABLESPACE; +RENAME TABLE t TO u; +TRUNCATE u; +Warnings: +Warning 1814 Tablespace has been discarded for table `u` +TRUNCATE u; +DROP TABLE u; diff --git a/mysql-test/suite/innodb/t/truncate.test b/mysql-test/suite/innodb/t/truncate.test index cd1d827e157..ca9ccb677e9 100644 --- a/mysql-test/suite/innodb/t/truncate.test +++ b/mysql-test/suite/innodb/t/truncate.test @@ -50,3 +50,13 @@ INSERT INTO t1 VALUES(1); TRUNCATE t1; SELECT * FROM t1; DROP TEMPORARY TABLE t1; + +--echo # +--echo # MDEV-23705 Assertion 'table->data_dir_path || !space' +--echo # +CREATE TABLE t(c INT) ENGINE=InnoDB; +ALTER TABLE t DISCARD TABLESPACE; +RENAME TABLE t TO u; +TRUNCATE u; +TRUNCATE u; +DROP TABLE u; diff --git a/storage/innobase/dict/dict0load.cc b/storage/innobase/dict/dict0load.cc index 4014d28c2fb..af14c6a4770 100644 --- a/storage/innobase/dict/dict0load.cc +++ b/storage/innobase/dict/dict0load.cc @@ -2739,7 +2739,8 @@ dict_get_and_save_data_dir_path( { ut_ad(!dict_table_is_temporary(table)); - if (!table->data_dir_path && table->space) { + if (!table->data_dir_path && table->space + && !dict_table_is_discarded(table)) { char* path = fil_space_get_first_path(table->space); if (!dict_mutex_own) { From 98ac2d425e6e5320afd498882b43e96d79f65f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 21 Sep 2020 12:05:18 +0300 Subject: [PATCH 42/48] MDEV-21170 : Galera test failure on galera_sr.GCF-1043[A|B] Add error printout when mysql.wsrep_streaming_log lock fails. However, tests are very undeterministic and not suitable for mtr environment. Thus, they are removed. --- mysql-test/suite/galera_sr/r/GCF-1043A.result | 21 ------------------- mysql-test/suite/galera_sr/r/GCF-1043B.result | 21 ------------------- mysql-test/suite/galera_sr/t/GCF-1043A.test | 13 ------------ mysql-test/suite/galera_sr/t/GCF-1043B.test | 13 ------------ sql/wsrep_schema.cc | 5 +++++ 5 files changed, 5 insertions(+), 68 deletions(-) delete mode 100644 mysql-test/suite/galera_sr/r/GCF-1043A.result delete mode 100644 mysql-test/suite/galera_sr/r/GCF-1043B.result delete mode 100644 mysql-test/suite/galera_sr/t/GCF-1043A.test delete mode 100644 mysql-test/suite/galera_sr/t/GCF-1043B.test diff --git a/mysql-test/suite/galera_sr/r/GCF-1043A.result b/mysql-test/suite/galera_sr/r/GCF-1043A.result deleted file mode 100644 index cc90461291d..00000000000 --- a/mysql-test/suite/galera_sr/r/GCF-1043A.result +++ /dev/null @@ -1,21 +0,0 @@ -connection node_2; -connection node_1; -connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; -Running a concurrent test with the following queries: -DELETE FROM t1 -REPLACE INTO t1 VALUES (1,'y'),(2,'x') -REPLACE INTO t1 VALUES (1,'y'),(2,'y'),(3,'y') -connection node_1; -DROP TABLE IF EXISTS t1; -CREATE TABLE t1 (f1 INTEGER PRIMARY KEY AUTO_INCREMENT, f2 CHAR(255)) ENGINE=InnoDB; -SET SESSION wsrep_sync_wait = 0; -SET SESSION wsrep_trx_fragment_size = 1;;; -connection node_1a; -SET SESSION wsrep_sync_wait = 0; -SET SESSION wsrep_trx_fragment_size = 1;;; -connection node_2; -SET SESSION wsrep_sync_wait = 0; -SET SESSION wsrep_trx_fragment_size = 1;;; -include/diff_servers.inc [servers=1 2] -DROP TABLE t1; -Concurrent test end diff --git a/mysql-test/suite/galera_sr/r/GCF-1043B.result b/mysql-test/suite/galera_sr/r/GCF-1043B.result deleted file mode 100644 index a10295c00b9..00000000000 --- a/mysql-test/suite/galera_sr/r/GCF-1043B.result +++ /dev/null @@ -1,21 +0,0 @@ -connection node_2; -connection node_1; -connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; -Running a concurrent test with the following queries: -DELETE FROM t1 -INSERT INTO t1 VALUES (1,'y'),(2,'x') -UPDATE t1 SET f2 = 'y' WHERE f1 = 1 OR f1 = 2; -connection node_1; -DROP TABLE IF EXISTS t1; -CREATE TABLE t1 (f1 INTEGER PRIMARY KEY AUTO_INCREMENT, f2 CHAR(255)) ENGINE=InnoDB; -SET SESSION wsrep_sync_wait = 0; -SET SESSION wsrep_trx_fragment_size = 1;;; -connection node_1a; -SET SESSION wsrep_sync_wait = 0; -SET SESSION wsrep_trx_fragment_size = 1;;; -connection node_2; -SET SESSION wsrep_sync_wait = 0; -SET SESSION wsrep_trx_fragment_size = 1;;; -include/diff_servers.inc [servers=1 2] -DROP TABLE t1; -Concurrent test end diff --git a/mysql-test/suite/galera_sr/t/GCF-1043A.test b/mysql-test/suite/galera_sr/t/GCF-1043A.test deleted file mode 100644 index c76623742d7..00000000000 --- a/mysql-test/suite/galera_sr/t/GCF-1043A.test +++ /dev/null @@ -1,13 +0,0 @@ -# -# Assertion `retval == WSREP_OK || retval == WSREP_TRX_FAIL || retval == WSREP_BF_ABORT || retval == WSREP_CONN_FAIL' failed with SR -# - ---source include/galera_cluster.inc - ---let $count = 1000; ---let $wsrep_trx_fragment_size = 1; ---let $query_node_1 = DELETE FROM t1 ---let $query_node_1a = REPLACE INTO t1 VALUES (1,'y'),(2,'x') ---let $query_node_2 = REPLACE INTO t1 VALUES (1,'y'),(2,'y'),(3,'y') - ---source suite/galera/include/galera_concurrent_test.inc diff --git a/mysql-test/suite/galera_sr/t/GCF-1043B.test b/mysql-test/suite/galera_sr/t/GCF-1043B.test deleted file mode 100644 index e3b6b7439ca..00000000000 --- a/mysql-test/suite/galera_sr/t/GCF-1043B.test +++ /dev/null @@ -1,13 +0,0 @@ -# -# Assertion `retval == WSREP_OK || retval == WSREP_TRX_FAIL || retval == WSREP_BF_ABORT || retval == WSREP_CONN_FAIL' failed with SR -# - ---source include/galera_cluster.inc - ---let $count = 1000; ---let $wsrep_trx_fragment_size = 1; ---let $query_node_1 = DELETE FROM t1 ---let $query_node_1a = INSERT INTO t1 VALUES (1,'y'),(2,'x') ---let $query_node_2 = UPDATE t1 SET f2 = 'y' WHERE f1 = 1 OR f1 = 2; - ---source suite/galera/include/galera_concurrent_test.inc diff --git a/sql/wsrep_schema.cc b/sql/wsrep_schema.cc index df9c7b78c9b..b1ad718255d 100644 --- a/sql/wsrep_schema.cc +++ b/sql/wsrep_schema.cc @@ -232,6 +232,11 @@ static int open_table(THD* thd, NULL, lock_type); if (!open_n_lock_single_table(thd, &tables, tables.lock_type, flags)) { + if (thd->is_error()) { + WSREP_WARN("Can't lock table %s.%s : %d (%s)", + schema_name->str, table_name->str, + thd->get_stmt_da()->sql_errno(), thd->get_stmt_da()->message()); + } close_thread_tables(thd); my_error(ER_NO_SUCH_TABLE, MYF(0), schema_name->str, table_name->str); DBUG_RETURN(1); From 98f03e5a2234a8588ff26fda39dd1e481d5849a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 21 Sep 2020 12:14:49 +0300 Subject: [PATCH 43/48] MDEV-23659 : Update Galera disabled.def file --- mysql-test/suite/galera_sr/disabled.def | 2 -- 1 file changed, 2 deletions(-) diff --git a/mysql-test/suite/galera_sr/disabled.def b/mysql-test/suite/galera_sr/disabled.def index 1d8b79a8fb5..c0e5857d6bc 100644 --- a/mysql-test/suite/galera_sr/disabled.def +++ b/mysql-test/suite/galera_sr/disabled.def @@ -10,8 +10,6 @@ # ############################################################################## -GCF-1018B : MDEV-21613 galera_sr.GCF-1018B MTR failed: Failed to open table mysql.wsrep_streaming_log for writing -GCF-1043A : MDEV-21170 Galera test failure on galera_sr.GCF-1043A GCF-1060 : MDEV-20848 galera_sr.GCF_1060 galera-features#56 : MDEV-18542 galera_sr.galera-features#56 From 2af8f712de3a9d518a70904e65ff8cf18beb5f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 22 Sep 2020 13:08:09 +0300 Subject: [PATCH 44/48] MDEV-23776: Re-apply the fix and make the test more robust The test that was added in commit e05650e6868eab2dbb9f58c4786bcc71afc4ffce would break a subsequent run of a test encryption.innodb-bad-key-change because some pages in the system tablespace would be encrypted with a different key. The failure was repeatable with the following invocation: ./mtr --no-reorder \ encryption.create_or_replace,cbc \ encryption.innodb-bad-key-change,cbc Because the crash was unrelated to the code changes that we reverted in commit eb38b1f703fb84299680f9c5a75ea970be7aee1d we can safely re-apply those fixes. --- mysql-test/suite/encryption/r/create_or_replace.result | 2 -- mysql-test/suite/encryption/t/create_or_replace.opt | 1 + mysql-test/suite/encryption/t/create_or_replace.test | 2 -- storage/innobase/fil/fil0crypt.cc | 6 ++++++ 4 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 mysql-test/suite/encryption/t/create_or_replace.opt diff --git a/mysql-test/suite/encryption/r/create_or_replace.result b/mysql-test/suite/encryption/r/create_or_replace.result index 62dac4ccc43..69ea113289b 100644 --- a/mysql-test/suite/encryption/r/create_or_replace.result +++ b/mysql-test/suite/encryption/r/create_or_replace.result @@ -1,5 +1,4 @@ SET @save_threads = @@GLOBAL.innodb_encryption_threads; -SET @save_tables = @@GLOBAL.innodb_encrypt_tables; SET default_storage_engine = InnoDB; SET GLOBAL innodb_encryption_threads = 4; CREATE TABLE `table10_int_autoinc` (`col_int_key` int, pk int auto_increment, `col_int` int, key (`col_int_key` ),primary key (pk)) engine=innodb; @@ -18,4 +17,3 @@ connection default; drop table create_or_replace_t, table1_int_autoinc, table0_int_autoinc, table10_int_autoinc; SET GLOBAL innodb_encryption_threads = @save_threads; -SET GLOBAL innodb_encrypt_tables = @save_tables; diff --git a/mysql-test/suite/encryption/t/create_or_replace.opt b/mysql-test/suite/encryption/t/create_or_replace.opt new file mode 100644 index 00000000000..66892f34897 --- /dev/null +++ b/mysql-test/suite/encryption/t/create_or_replace.opt @@ -0,0 +1 @@ +--innodb-encrypt-tables diff --git a/mysql-test/suite/encryption/t/create_or_replace.test b/mysql-test/suite/encryption/t/create_or_replace.test index 8d571794713..2ebd599d460 100644 --- a/mysql-test/suite/encryption/t/create_or_replace.test +++ b/mysql-test/suite/encryption/t/create_or_replace.test @@ -3,7 +3,6 @@ --source include/count_sessions.inc SET @save_threads = @@GLOBAL.innodb_encryption_threads; -SET @save_tables = @@GLOBAL.innodb_encrypt_tables; SET default_storage_engine = InnoDB; @@ -76,5 +75,4 @@ drop table create_or_replace_t, table1_int_autoinc, table0_int_autoinc, table10_int_autoinc; SET GLOBAL innodb_encryption_threads = @save_threads; -SET GLOBAL innodb_encrypt_tables = @save_tables; --source include/wait_until_count_sessions.inc diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc index 09f2730edec..16b2093b691 100644 --- a/storage/innobase/fil/fil0crypt.cc +++ b/storage/innobase/fil/fil0crypt.cc @@ -1483,6 +1483,11 @@ static bool fil_crypt_find_space_to_rotate( { /* we need iops to start rotating */ while (!state->should_shutdown() && !fil_crypt_alloc_iops(state)) { + if (state->space && state->space->is_stopping()) { + fil_space_release(state->space); + state->space = NULL; + } + os_event_reset(fil_crypt_threads_event); os_event_wait_time(fil_crypt_threads_event, 100000); } @@ -2506,6 +2511,7 @@ fil_space_crypt_close_tablespace( /* wakeup throttle (all) sleepers */ os_event_set(fil_crypt_throttle_sleep_event); + os_event_set(fil_crypt_threads_event); os_thread_sleep(20000); dict_mutex_enter_for_mysql(); From e5e83daf32300115d857b49fdbd35460bbf51d52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 22 Sep 2020 13:09:51 +0300 Subject: [PATCH 45/48] Make DISCARD TABLESPACE more robust dict_load_table_low(): Copy the 'discarded' flag to file_unreadable. This allows to avoid a potentially harmful call to dict_stats_init() in ha_innobase::open(). --- storage/innobase/dict/dict0load.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/innobase/dict/dict0load.cc b/storage/innobase/dict/dict0load.cc index af14c6a4770..22fc70a4e42 100644 --- a/storage/innobase/dict/dict0load.cc +++ b/storage/innobase/dict/dict0load.cc @@ -2686,7 +2686,7 @@ static const char* dict_load_table_low(const table_name_t& name, *table = dict_mem_table_create( name.m_name, space_id, n_cols + n_v_col, n_v_col, flags, flags2); (*table)->id = table_id; - (*table)->file_unreadable = false; + (*table)->file_unreadable = !!(flags2 & DICT_TF2_DISCARDED); return(NULL); } From 3eb81136e1c087af3fef38ae89e3357f4c306f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 22 Sep 2020 13:40:05 +0300 Subject: [PATCH 46/48] MDEV-22939 Server crashes in row_make_new_pathname() The statement ALTER TABLE...DISCARD TABLESPACE is problematic, because its designed purpose is to break the referential integrity of the data dictionary and make a table point to nowhere. ha_innobase::commit_inplace_alter_table(): Check whether the table has been discarded. (This is a bit late to check it, right before committing the change.) Previously, we performed this check only in a specific branch of the function commit_set_autoinc(). Note: We intentionally allow non-rebuilding ALTER TABLE even if the tablespace has been discarded, to remain compatible with MySQL. (See the various tests with "wl5522" in the name, such as innodb.innodb-wl5522.) The test case would crash starting with 10.3 only, but it does not hurt to minimize the code and test difference between 10.2 and 10.3. --- mysql-test/suite/innodb/r/alter_table.result | 10 ++++++++++ mysql-test/suite/innodb/t/alter_table.test | 11 +++++++++++ storage/innobase/handler/handler0alter.cc | 18 +++++++++--------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/mysql-test/suite/innodb/r/alter_table.result b/mysql-test/suite/innodb/r/alter_table.result index 94262ac29c3..fc08f29e515 100644 --- a/mysql-test/suite/innodb/r/alter_table.result +++ b/mysql-test/suite/innodb/r/alter_table.result @@ -60,3 +60,13 @@ CREATE TABLE t1(a INT NOT NULL UNIQUE) ENGINE=InnoDB; INSERT INTO t1 SELECT * FROM seq_1_to_128; ALTER TABLE t1 ADD b TINYINT AUTO_INCREMENT PRIMARY KEY, DROP KEY a; DROP TABLE t1; +# +# MDEV-22939 Server crashes in row_make_new_pathname() +# +CREATE TABLE t (a INT) ENGINE=INNODB; +ALTER TABLE t DISCARD TABLESPACE; +ALTER TABLE t ENGINE INNODB; +ERROR HY000: Tablespace has been discarded for table `t` +ALTER TABLE t FORCE; +ERROR HY000: Tablespace has been discarded for table `t` +DROP TABLE t; diff --git a/mysql-test/suite/innodb/t/alter_table.test b/mysql-test/suite/innodb/t/alter_table.test index 6bc30d2e8ee..5050abdc087 100644 --- a/mysql-test/suite/innodb/t/alter_table.test +++ b/mysql-test/suite/innodb/t/alter_table.test @@ -68,3 +68,14 @@ CREATE TABLE t1(a INT NOT NULL UNIQUE) ENGINE=InnoDB; INSERT INTO t1 SELECT * FROM seq_1_to_128; ALTER TABLE t1 ADD b TINYINT AUTO_INCREMENT PRIMARY KEY, DROP KEY a; DROP TABLE t1; + +--echo # +--echo # MDEV-22939 Server crashes in row_make_new_pathname() +--echo # +CREATE TABLE t (a INT) ENGINE=INNODB; +ALTER TABLE t DISCARD TABLESPACE; +--error ER_TABLESPACE_DISCARDED +ALTER TABLE t ENGINE INNODB; +--error ER_TABLESPACE_DISCARDED +ALTER TABLE t FORCE; +DROP TABLE t; diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 09bfc5f5503..f0b12183b22 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -7209,12 +7209,6 @@ commit_set_autoinc( && (ha_alter_info->create_info->used_fields & HA_CREATE_USED_AUTO)) { - if (dict_table_is_discarded(ctx->old_table)) { - my_error(ER_TABLESPACE_DISCARDED, MYF(0), - old_table->s->table_name.str); - DBUG_RETURN(true); - } - /* An AUTO_INCREMENT value was supplied by the user. It must be persisted to the data file. */ const Field* ai = old_table->found_next_number_field; @@ -8411,9 +8405,15 @@ ha_innobase::commit_inplace_alter_table( = static_cast(*pctx); DBUG_ASSERT(new_clustered == ctx->need_rebuild()); - - fail = commit_set_autoinc(ha_alter_info, ctx, altered_table, - table); + if (ctx->need_rebuild() + && dict_table_is_discarded(ctx->old_table)) { + my_error(ER_TABLESPACE_DISCARDED, MYF(0), + table->s->table_name.str); + fail = true; + } else { + fail = commit_set_autoinc(ha_alter_info, ctx, + altered_table, table); + } if (fail) { } else if (ctx->need_rebuild()) { From 78efa1093076307946873f322b45a14d1ed5ffb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 22 Sep 2020 13:55:36 +0300 Subject: [PATCH 47/48] MDEV-22939: Restore an AUTO_INCREMENT check It turns out that we must check for DISCARD TABLESPACE both when the table is being rebuilt and when the AUTO_INCREMENT value of the table is being added. This was caught by the test innodb.alter_missing_tablespace. Somehow I failed to run all tests. Sorry! --- storage/innobase/handler/handler0alter.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index f0b12183b22..7eacb83fa2f 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -7209,6 +7209,12 @@ commit_set_autoinc( && (ha_alter_info->create_info->used_fields & HA_CREATE_USED_AUTO)) { + if (dict_table_is_discarded(ctx->old_table)) { + my_error(ER_TABLESPACE_DISCARDED, MYF(0), + old_table->s->table_name.str); + DBUG_RETURN(true); + } + /* An AUTO_INCREMENT value was supplied by the user. It must be persisted to the data file. */ const Field* ai = old_table->found_next_number_field; From d7c82610c14f5102258640c73c1d78ea22f942c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 23 Sep 2020 09:29:05 +0300 Subject: [PATCH 48/48] Fix the WolfSSL build on FreeBSD Port some CMake tweaks of commit 4adc1269cc2d487bb12f96b0827c4a74f1a05382 from 10.5. --- extra/wolfssl/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extra/wolfssl/CMakeLists.txt b/extra/wolfssl/CMakeLists.txt index 12eb26c9ef7..953d377ebcf 100644 --- a/extra/wolfssl/CMakeLists.txt +++ b/extra/wolfssl/CMakeLists.txt @@ -1,6 +1,6 @@ IF(MSVC) PROJECT(wolfssl C ASM_MASM) -ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") +ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64") PROJECT(wolfssl C ASM) ELSE() PROJECT(wolfssl C) @@ -9,7 +9,7 @@ ENDIF() IF(CMAKE_SIZEOF_VOID_P MATCHES 8) IF(MSVC) SET(WOLFSSL_INTELASM ON) -ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") +ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64") IF(CMAKE_C_COMPILER_ID MATCHES GNU AND CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9) MESSAGE_ONCE(NO_INTEL_ASSEMBLY "Disable Intel assembly for WolfSSL - compiler is too old") ELSEIF(WITH_MSAN) @@ -121,7 +121,7 @@ IF(WOLFSSL_INTELASM) IF(CMAKE_C_COMPILER_ID MATCHES Clang) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes -msse4.2 -mpclmul -mrdrnd -mrdseed") ENDIF() - ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") + ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64") SET(USE_INTEL_SPEEDUP 1) LIST(APPEND WOLFCRYPT_SOURCES ${WOLFCRYPT_SRCDIR}/aes_asm.S