From 65ee216c35d843da7883d255219ab011e20340c2 Mon Sep 17 00:00:00 2001 From: Kentoku SHIBA Date: Sun, 23 Aug 2020 12:30:14 +0900 Subject: MDEV-22246 Result rows duplicated by spider engine fix the following type mrr scan (select 0,`id`,`node` from `auto_test_remote`.`tbl_a` where (`id` <> 0) order by `id`)union all(select 1,`id`,`node` from `auto_test_remote`.`tbl_a` where (`id` <> 0) order by `id`) order by `id` --- storage/spider/ha_spider.cc | 89 +++++++++++++++++++++ storage/spider/ha_spider.h | 2 + .../spider/bugfix/include/mdev_22246_deinit.inc | 14 ++++ .../spider/bugfix/include/mdev_22246_init.inc | 48 +++++++++++ .../mysql-test/spider/bugfix/r/mdev_22246.result | 79 +++++++++++++++++++ .../mysql-test/spider/bugfix/t/mdev_22246.cnf | 4 + .../mysql-test/spider/bugfix/t/mdev_22246.test | 92 ++++++++++++++++++++++ storage/spider/spd_db_conn.cc | 6 ++ storage/spider/spd_db_include.h | 1 + 9 files changed, 335 insertions(+) create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_22246_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_22246_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_22246.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_22246.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_22246.test diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index ce9447a61a9..51ceee310ae 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -1590,6 +1590,7 @@ int ha_spider::reset() multi_range_keys = NULL; } #endif + multi_range_num = 0; ft_handler = NULL; ft_current = NULL; ft_count = 0; @@ -4131,6 +4132,64 @@ int ha_spider::read_range_next() DBUG_RETURN(check_ha_range_eof()); } +void ha_spider::reset_no_where_cond() +{ + uint roop_count; + DBUG_ENTER("ha_spider::reset_no_where_cond"); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (sql_kinds & (SPIDER_SQL_KIND_SQL | SPIDER_SQL_KIND_HANDLER)) + { +#endif + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_handler[share->use_sql_dbton_ids[roop_count]]->no_where_cond = + FALSE; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } + if (sql_kinds & SPIDER_SQL_KIND_HS) + { + for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++) + { + dbton_handler[share->use_hs_dbton_ids[roop_count]]->no_where_cond = + FALSE; + } + } +#endif + DBUG_VOID_RETURN; +} + +bool ha_spider::check_no_where_cond() +{ + uint roop_count; + DBUG_ENTER("ha_spider::check_no_where_cond"); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (sql_kinds & (SPIDER_SQL_KIND_SQL | SPIDER_SQL_KIND_HANDLER)) + { +#endif + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + if (dbton_handler[share->use_sql_dbton_ids[roop_count]]->no_where_cond) + { + DBUG_RETURN(TRUE); + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } + if (sql_kinds & SPIDER_SQL_KIND_HS) + { + for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++) + { + if (dbton_handler[share->use_hs_dbton_ids[roop_count]]->no_where_cond) + { + DBUG_RETURN(TRUE); + } + } + } +#endif + DBUG_RETURN(FALSE); +} + #ifdef HA_MRR_USE_DEFAULT_IMPL #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 ha_rows ha_spider::multi_range_read_info_const( @@ -4276,6 +4335,7 @@ int ha_spider::multi_range_read_init( DBUG_PRINT("info",("spider n_ranges=%u", n_ranges)); multi_range_num = n_ranges; mrr_have_range = FALSE; + reset_no_where_cond(); DBUG_RETURN( handler::multi_range_read_init( seq, @@ -4749,6 +4809,10 @@ int ha_spider::read_multi_range_first_internal( result_list.current = result_list.current->prev; } } + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } set_where_to_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); set_where_to_pos_sql(SPIDER_SQL_TYPE_HANDLER); } @@ -5224,6 +5288,15 @@ int ha_spider::read_multi_range_first_internal( DBUG_PRINT("info",("spider range_res8=%d", range_res)); } #endif + if (check_no_where_cond()) + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res = 1; +#else + multi_range_curr = multi_range_end; +#endif + break; + } } #ifdef HA_MRR_USE_DEFAULT_IMPL while (!range_res); @@ -5637,6 +5710,10 @@ int ha_spider::read_multi_range_first_internal( } else DBUG_RETURN(error_num); } + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } multi_range_cnt = 0; if ((error_num = reset_sql_sql( SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) @@ -5858,6 +5935,10 @@ int ha_spider::read_multi_range_next( #ifdef HA_MRR_USE_DEFAULT_IMPL DBUG_PRINT("info",("spider range_res2=%d", range_res)); #endif + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } set_where_to_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); set_where_to_pos_sql(SPIDER_SQL_TYPE_HANDLER); result_list.limit_num = @@ -6279,6 +6360,10 @@ int ha_spider::read_multi_range_next( #endif ) DBUG_RETURN(error_num); + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } spider_db_free_one_result_for_start_next(this); spider_first_split_read_param(this); #ifndef WITHOUT_SPIDER_BG_SEARCH @@ -7086,6 +7171,10 @@ int ha_spider::read_multi_range_next( } else DBUG_RETURN(error_num); } + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } multi_range_cnt = 0; if ((error_num = reset_sql_sql( SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h index 847f7a8e170..5bc58397f28 100644 --- a/storage/spider/ha_spider.h +++ b/storage/spider/ha_spider.h @@ -330,6 +330,8 @@ public: bool sorted ); int read_range_next(); + void reset_no_where_cond(); + bool check_no_where_cond(); #ifdef HA_MRR_USE_DEFAULT_IMPL #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 ha_rows multi_range_read_info_const( diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_deinit.inc new file mode 100644 index 00000000000..9d255152dd8 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_deinit.inc @@ -0,0 +1,14 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_init.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_init.inc new file mode 100644 index 00000000000..48226ba2811 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_init.inc @@ -0,0 +1,48 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +if (!$HAVE_PARTITION) +{ + --source group_by_order_by_limit_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a"' + PARTITION BY HASH(id) ( + PARTITION pt1 COMMENT='srv "s_2_1"', + PARTITION pt2 COMMENT='srv "s_2_2"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + id bigint NOT NULL, + node text, + PRIMARY KEY (id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT * FROM tbl_a ORDER BY id; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_a ( + id bigint NOT NULL, + node text, + PRIMARY KEY (id) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT * FROM tbl_a ORDER BY id; diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_22246.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_22246.result new file mode 100644 index 00000000000..4884f60637e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_22246.result @@ -0,0 +1,79 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-22246 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +id bigint NOT NULL, +node text, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (id,node) VALUES (1,'DB-G0'),(2,'DB-G1'); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT * FROM tbl_a; +id node +2 DB-G1 +1 DB-G0 +SELECT * FROM tbl_a WHERE id != 0; +id node +1 DB-G0 +2 DB-G1 +connection child2_1; +SELECT * FROM tbl_a ORDER BY id; +id node +2 DB-G1 +connection child2_2; +SELECT * FROM tbl_a ORDER BY id; +id node +1 DB-G0 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.cnf new file mode 100644 index 00000000000..e0ffb99c38e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.cnf @@ -0,0 +1,4 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf +!include ../my_2_2.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.test new file mode 100644 index 00000000000..63b04c14e11 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.test @@ -0,0 +1,92 @@ +--source ../include/mdev_22246_init.inc +--echo +--echo this test is for MDEV-22246 +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +--connection child2_2 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +--disable_query_log +echo CHILD2_2_CREATE_TABLES; +eval $CHILD2_2_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + id bigint NOT NULL, + node text, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + id bigint NOT NULL, + node text, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (id,node) VALUES (1,'DB-G0'),(2,'DB-G1'); + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +SELECT * FROM tbl_a; +SELECT * FROM tbl_a WHERE id != 0; + +--connection child2_1 +eval $CHILD2_1_SELECT_TABLES; + +--connection child2_2 +eval $CHILD2_2_SELECT_TABLES; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--connection child2_2 +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/mdev_22246_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index 2df148b6ea4..e0538259fb2 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -1742,6 +1742,7 @@ int spider_db_append_key_where_internal( int key_count; uint length; uint store_length; + uint current_pos = str->length(); const uchar *ptr, *another_ptr; const key_range *use_key, *another_key; KEY_PART_INFO *key_part; @@ -2715,6 +2716,11 @@ int spider_db_append_key_where_internal( DBUG_RETURN(error_num); end: + if (spider->multi_range_num && current_pos == str->length()) + { + DBUG_PRINT("info", ("spider no key where condition")); + dbton_hdl->no_where_cond = TRUE; + } /* use condition */ if (dbton_hdl->append_condition_part(NULL, 0, sql_type, FALSE)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h index bff3d95cacb..41e24e06c21 100644 --- a/storage/spider/spd_db_include.h +++ b/storage/spider/spd_db_include.h @@ -1355,6 +1355,7 @@ public: SPIDER_LINK_IDX_CHAIN *link_idx_chain; #endif bool strict_group_by; + bool no_where_cond; spider_db_handler(ha_spider *spider, spider_db_share *db_share) : dbton_id(db_share->dbton_id), spider(spider), db_share(db_share), first_link_idx(-1) {} -- cgit v1.2.1 From 04ce29354b6053f0334ad1b8d5acaa0974b10fd8 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 24 Aug 2020 09:17:47 +0400 Subject: MDEV-23551 Performance degratation in temporal literals in 10.4 Problem: Queries like this showed performance degratation in 10.4 over 10.3: SELECT temporal_literal FROM t1; SELECT temporal_literal + 1 FROM t1; SELECT COUNT(*) FROM t1 WHERE temporal_column = temporal_literal; SELECT COUNT(*) FROM t1 WHERE temporal_column = string_literal; Fix: Replacing the universal member "MYSQL_TIME cached_time" in Item_temporal_literal to data type specific containers: - Date in Item_date_literal - Time in Item_time_literal - Datetime in Item_datetime_literal This restores the performance, and make it even better in some cases. See benchmark results in MDEV. Also, this change makes futher separations of Date, Time, Datetime from each other, which will make it possible not to derive them from a too heavy (40 bytes) MYSQL_TIME, and replace them to smaller data type specific containers. --- sql/field.cc | 21 ++++---- sql/item.cc | 27 +++++------ sql/item.h | 143 +++++++++++++++++++++++++++++++++++++++--------------- sql/sql_select.cc | 9 ++-- sql/sql_show.cc | 8 +-- sql/sql_type.cc | 14 ++++-- sql/sql_type.h | 60 +++++++++++++++++++++++ sql/table.cc | 3 +- 8 files changed, 205 insertions(+), 80 deletions(-) diff --git a/sql/field.cc b/sql/field.cc index bac5dd95b5a..4a82eae6a0e 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5818,9 +5818,7 @@ Item *Field_temporal::get_equal_const_item_datetime(THD *thd, See comments about truncation in the same place in Field_time::get_equal_const_item(). */ - return new (thd->mem_root) Item_datetime_literal(thd, - dt.get_mysql_time(), - decimals()); + return new (thd->mem_root) Item_datetime_literal(thd, &dt, decimals()); } break; case ANY_SUBST: @@ -5832,7 +5830,7 @@ Item *Field_temporal::get_equal_const_item_datetime(THD *thd, if (!dt.is_valid_datetime()) return NULL; return new (thd->mem_root) - Item_datetime_literal_for_invalid_dates(thd, dt.get_mysql_time(), + Item_datetime_literal_for_invalid_dates(thd, &dt, dt.get_mysql_time()-> second_part ? TIME_SECOND_PART_DIGITS : 0); @@ -6183,7 +6181,7 @@ Item *Field_time::get_equal_const_item(THD *thd, const Context &ctx, (assuming CURRENT_DATE is '2015-08-30' */ - return new (thd->mem_root) Item_time_literal(thd, tm.get_mysql_time(), + return new (thd->mem_root) Item_time_literal(thd, &tm, tm.get_mysql_time()-> second_part ? TIME_SECOND_PART_DIGITS : @@ -6212,8 +6210,7 @@ Item *Field_time::get_equal_const_item(THD *thd, const Context &ctx, decimals()); if (!tm.is_valid_time()) return NULL; - return new (thd->mem_root) Item_time_literal(thd, tm.get_mysql_time(), - decimals()); + return new (thd->mem_root) Item_time_literal(thd, &tm, decimals()); } break; } @@ -6772,12 +6769,12 @@ Item *Field_newdate::get_equal_const_item(THD *thd, const Context &ctx, */ if (!dt.hhmmssff_is_zero()) return new (thd->mem_root) - Item_datetime_literal_for_invalid_dates(thd, dt.get_mysql_time(), + Item_datetime_literal_for_invalid_dates(thd, &dt, dt.get_mysql_time()-> second_part ? TIME_SECOND_PART_DIGITS : 0); - return new (thd->mem_root) - Item_date_literal_for_invalid_dates(thd, Date(&dt).get_mysql_time()); + Date d(&dt); + return new (thd->mem_root) Item_date_literal_for_invalid_dates(thd, &d); } break; case IDENTITY_SUBST: @@ -6792,8 +6789,8 @@ Item *Field_newdate::get_equal_const_item(THD *thd, const Context &ctx, Datetime dt(thd, const_item, Datetime::Options(TIME_CONV_NONE, thd)); if (!dt.is_valid_datetime()) return NULL; - return new (thd->mem_root) - Item_date_literal(thd, Date(&dt).get_mysql_time()); + Date d(&dt); + return new (thd->mem_root) Item_date_literal(thd, &d); } break; } diff --git a/sql/item.cc b/sql/item.cc index 22a8cb169b3..d8074dbb013 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -6998,7 +6998,7 @@ void Item_date_literal::print(String *str, enum_query_type query_type) { str->append("DATE'"); char buf[MAX_DATE_STRING_REP_LENGTH]; - my_date_to_str(&cached_time, buf); + my_date_to_str(cached_time.get_mysql_time(), buf); str->append(buf); str->append('\''); } @@ -7013,7 +7013,7 @@ Item *Item_date_literal::clone_item(THD *thd) bool Item_date_literal::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { fuzzydate |= sql_mode_for_dates(thd); - *ltime= cached_time; + cached_time.copy_to_mysql_time(ltime); return (null_value= check_date_with_warn(thd, ltime, fuzzydate, MYSQL_TIMESTAMP_ERROR)); } @@ -7023,7 +7023,7 @@ void Item_datetime_literal::print(String *str, enum_query_type query_type) { str->append("TIMESTAMP'"); char buf[MAX_DATE_STRING_REP_LENGTH]; - my_datetime_to_str(&cached_time, buf, decimals); + my_datetime_to_str(cached_time.get_mysql_time(), buf, decimals); str->append(buf); str->append('\''); } @@ -7038,7 +7038,7 @@ Item *Item_datetime_literal::clone_item(THD *thd) bool Item_datetime_literal::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { fuzzydate |= sql_mode_for_dates(thd); - *ltime= cached_time; + cached_time.copy_to_mysql_time(ltime); return (null_value= check_date_with_warn(thd, ltime, fuzzydate, MYSQL_TIMESTAMP_ERROR)); } @@ -7048,7 +7048,7 @@ void Item_time_literal::print(String *str, enum_query_type query_type) { str->append("TIME'"); char buf[MAX_DATE_STRING_REP_LENGTH]; - my_time_to_str(&cached_time, buf, decimals); + my_time_to_str(cached_time.get_mysql_time(), buf, decimals); str->append(buf); str->append('\''); } @@ -7062,7 +7062,7 @@ Item *Item_time_literal::clone_item(THD *thd) bool Item_time_literal::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - *ltime= cached_time; + cached_time.copy_to_mysql_time(ltime); if (fuzzydate & TIME_TIME_ONLY) return (null_value= false); return (null_value= check_date_with_warn(thd, ltime, fuzzydate, @@ -9922,23 +9922,20 @@ Item *Item_cache_temporal::convert_to_basic_const_item(THD *thd) Item *Item_cache_datetime::make_literal(THD *thd) { - MYSQL_TIME ltime; - unpack_time(val_datetime_packed(thd), <ime, MYSQL_TIMESTAMP_DATETIME); - return new (thd->mem_root) Item_datetime_literal(thd, <ime, decimals); + Datetime dt(thd, this, TIME_CONV_NONE | TIME_FRAC_NONE); + return new (thd->mem_root) Item_datetime_literal(thd, &dt, decimals); } Item *Item_cache_date::make_literal(THD *thd) { - MYSQL_TIME ltime; - unpack_time(val_datetime_packed(thd), <ime, MYSQL_TIMESTAMP_DATE); - return new (thd->mem_root) Item_date_literal(thd, <ime); + Date d(thd, this, TIME_CONV_NONE | TIME_FRAC_NONE); + return new (thd->mem_root) Item_date_literal(thd, &d); } Item *Item_cache_time::make_literal(THD *thd) { - MYSQL_TIME ltime; - unpack_time(val_time_packed(thd), <ime, MYSQL_TIMESTAMP_TIME); - return new (thd->mem_root) Item_time_literal(thd, <ime, decimals); + Time t(thd, this); + return new (thd->mem_root) Item_time_literal(thd, &t, decimals); } diff --git a/sql/item.h b/sql/item.h index 95ca06ac211..bff60d60506 100644 --- a/sql/item.h +++ b/sql/item.h @@ -4820,29 +4820,20 @@ public: class Item_temporal_literal :public Item_literal { -protected: - MYSQL_TIME cached_time; public: - /** - Constructor for Item_date_literal. - @param ltime DATE value. - */ - Item_temporal_literal(THD *thd, const MYSQL_TIME *ltime) + Item_temporal_literal(THD *thd) :Item_literal(thd) { collation.set(&my_charset_numeric, DERIVATION_NUMERIC, MY_REPERTOIRE_ASCII); decimals= 0; - cached_time= *ltime; } - Item_temporal_literal(THD *thd, const MYSQL_TIME *ltime, uint dec_arg): + Item_temporal_literal(THD *thd, uint dec_arg): Item_literal(thd) { collation.set(&my_charset_numeric, DERIVATION_NUMERIC, MY_REPERTOIRE_ASCII); decimals= dec_arg; - cached_time= *ltime; } - const MYSQL_TIME *const_ptr_mysql_time() const { return &cached_time; } int save_in_field(Field *field, bool no_conversions) { return save_date_in_field(field, no_conversions); } }; @@ -4853,27 +4844,62 @@ public: */ class Item_date_literal: public Item_temporal_literal { +protected: + Date cached_time; + bool update_null() + { + return maybe_null && + (null_value= cached_time.check_date_with_warn(current_thd)); + } public: - Item_date_literal(THD *thd, const MYSQL_TIME *ltime) - :Item_temporal_literal(thd, ltime) + Item_date_literal(THD *thd, const Date *ltime) + :Item_temporal_literal(thd), + cached_time(*ltime) { + DBUG_ASSERT(cached_time.is_valid_date()); max_length= MAX_DATE_WIDTH; /* If date has zero month or day, it can return NULL in case of NO_ZERO_DATE or NO_ZERO_IN_DATE. - We can't just check the current sql_mode here in constructor, + If date is `February 30`, it can return NULL in case if + no ALLOW_INVALID_DATES is set. + We can't set null_value using the current sql_mode here in constructor, because sql_mode can change in case of prepared statements between PREPARE and EXECUTE. + Here we only set maybe_null to true if the value has such anomalies. + Later (during execution time), if maybe_null is true, then the value + will be checked per row, according to the execution time sql_mode. + The check_date() below call should cover all cases mentioned. */ - maybe_null= !ltime->month || !ltime->day; + maybe_null= cached_time.check_date(TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE); } const Type_handler *type_handler() const { return &type_handler_newdate; } void print(String *str, enum_query_type query_type); + const MYSQL_TIME *const_ptr_mysql_time() const + { + return cached_time.get_mysql_time(); + } Item *clone_item(THD *thd); - longlong val_int() { return Date(this).to_longlong(); } - double val_real() { return Date(this).to_double(); } - String *val_str(String *to) { return Date(this).to_string(to); } - my_decimal *val_decimal(my_decimal *to) { return Date(this).to_decimal(to); } + longlong val_int() + { + return update_null() ? 0 : cached_time.to_longlong(); + } + double val_real() + { + return update_null() ? 0 : cached_time.to_double(); + } + String *val_str(String *to) + { + return update_null() ? 0 : cached_time.to_string(to); + } + my_decimal *val_decimal(my_decimal *to) + { + return update_null() ? 0 : cached_time.to_decimal(to); + } + longlong val_datetime_packed(THD *thd) + { + return update_null() ? 0 : cached_time.valid_date_to_packed(); + } bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); Item *get_copy(THD *thd) { return get_item_copy(thd, this); } @@ -4885,19 +4911,31 @@ public: */ class Item_time_literal: public Item_temporal_literal { +protected: + Time cached_time; public: - Item_time_literal(THD *thd, const MYSQL_TIME *ltime, uint dec_arg): - Item_temporal_literal(thd, ltime, dec_arg) + Item_time_literal(THD *thd, const Time *ltime, uint dec_arg): + Item_temporal_literal(thd, dec_arg), + cached_time(*ltime) { + DBUG_ASSERT(cached_time.is_valid_time()); max_length= MIN_TIME_WIDTH + (decimals ? decimals + 1 : 0); } const Type_handler *type_handler() const { return &type_handler_time2; } void print(String *str, enum_query_type query_type); + const MYSQL_TIME *const_ptr_mysql_time() const + { + return cached_time.get_mysql_time(); + } Item *clone_item(THD *thd); - longlong val_int() { return Time(this).to_longlong(); } - double val_real() { return Time(this).to_double(); } - String *val_str(String *to) { return Time(this).to_string(to, decimals); } - my_decimal *val_decimal(my_decimal *to) { return Time(this).to_decimal(to); } + longlong val_int() { return cached_time.to_longlong(); } + double val_real() { return cached_time.to_double(); } + String *val_str(String *to) { return cached_time.to_string(to, decimals); } + my_decimal *val_decimal(my_decimal *to) { return cached_time.to_decimal(to); } + longlong val_time_packed(THD *thd) + { + return cached_time.valid_time_to_packed(); + } bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); bool val_native(THD *thd, Native *to) { @@ -4913,26 +4951,49 @@ public: */ class Item_datetime_literal: public Item_temporal_literal { +protected: + Datetime cached_time; + bool update_null() + { + return maybe_null && + (null_value= cached_time.check_date_with_warn(current_thd)); + } public: - Item_datetime_literal(THD *thd, const MYSQL_TIME *ltime, uint dec_arg): - Item_temporal_literal(thd, ltime, dec_arg) + Item_datetime_literal(THD *thd, const Datetime *ltime, uint dec_arg): + Item_temporal_literal(thd, dec_arg), + cached_time(*ltime) { + DBUG_ASSERT(cached_time.is_valid_datetime()); max_length= MAX_DATETIME_WIDTH + (decimals ? decimals + 1 : 0); // See the comment on maybe_null in Item_date_literal - maybe_null= !ltime->month || !ltime->day; + maybe_null= cached_time.check_date(TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE); } const Type_handler *type_handler() const { return &type_handler_datetime2; } void print(String *str, enum_query_type query_type); + const MYSQL_TIME *const_ptr_mysql_time() const + { + return cached_time.get_mysql_time(); + } Item *clone_item(THD *thd); - longlong val_int() { return Datetime(this).to_longlong(); } - double val_real() { return Datetime(this).to_double(); } + longlong val_int() + { + return update_null() ? 0 : cached_time.to_longlong(); + } + double val_real() + { + return update_null() ? 0 : cached_time.to_double(); + } String *val_str(String *to) { - return Datetime(this).to_string(to, decimals); + return update_null() ? NULL : cached_time.to_string(to, decimals); } my_decimal *val_decimal(my_decimal *to) { - return Datetime(this).to_decimal(to); + return update_null() ? NULL : cached_time.to_decimal(to); + } + longlong val_datetime_packed(THD *thd) + { + return update_null() ? 0 : cached_time.valid_datetime_to_packed(); } bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); Item *get_copy(THD *thd) @@ -4969,11 +5030,14 @@ class Item_date_literal_for_invalid_dates: public Item_date_literal in sql_mode=TRADITIONAL. */ public: - Item_date_literal_for_invalid_dates(THD *thd, const MYSQL_TIME *ltime) - :Item_date_literal(thd, ltime) { } + Item_date_literal_for_invalid_dates(THD *thd, const Date *ltime) + :Item_date_literal(thd, ltime) + { + maybe_null= false; + } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - *ltime= cached_time; + cached_time.copy_to_mysql_time(ltime); return (null_value= false); } }; @@ -4987,11 +5051,14 @@ class Item_datetime_literal_for_invalid_dates: public Item_datetime_literal { public: Item_datetime_literal_for_invalid_dates(THD *thd, - const MYSQL_TIME *ltime, uint dec_arg) - :Item_datetime_literal(thd, ltime, dec_arg) { } + const Datetime *ltime, uint dec_arg) + :Item_datetime_literal(thd, ltime, dec_arg) + { + maybe_null= false; + } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - *ltime= cached_time; + cached_time.copy_to_mysql_time(ltime); return (null_value= false); } }; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 19e36632f0c..7091ffc2c58 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -722,8 +722,9 @@ bool vers_select_conds_t::init_from_sysvar(THD *thd) if (type != SYSTEM_TIME_UNSPECIFIED && type != SYSTEM_TIME_ALL) { DBUG_ASSERT(type == SYSTEM_TIME_AS_OF); + Datetime dt(&in.ltime); start.item= new (thd->mem_root) - Item_datetime_literal(thd, &in.ltime, TIME_SECOND_PART_DIGITS); + Item_datetime_literal(thd, &dt, TIME_SECOND_PART_DIGITS); if (!start.item) return true; } @@ -787,15 +788,17 @@ Item* period_get_condition(THD *thd, TABLE_LIST *table, SELECT_LEX *select, { case SYSTEM_TIME_UNSPECIFIED: case SYSTEM_TIME_HISTORY: + { thd->variables.time_zone->gmt_sec_to_TIME(&max_time, TIMESTAMP_MAX_VALUE); max_time.second_part= TIME_MAX_SECOND_PART; - curr= newx Item_datetime_literal(thd, &max_time, TIME_SECOND_PART_DIGITS); + Datetime dt(&max_time); + curr= newx Item_datetime_literal(thd, &dt, TIME_SECOND_PART_DIGITS); if (conds->type == SYSTEM_TIME_UNSPECIFIED) cond1= newx Item_func_eq(thd, conds->field_end, curr); else cond1= newx Item_func_lt(thd, conds->field_end, curr); break; - break; + } case SYSTEM_TIME_AS_OF: cond1= newx Item_func_le(thd, conds->field_start, conds->start.item); cond2= newx Item_func_gt(thd, conds->field_end, conds->start.item); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 2f8de331d30..3ffb5338053 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -10082,11 +10082,6 @@ int finalize_schema_table(st_plugin_int *plugin) DBUG_RETURN(0); } -/* - This is used to create a timestamp field -*/ - -MYSQL_TIME zero_time={ 0,0,0,0,0,0,0,0, MYSQL_TIMESTAMP_TIME }; /** Output trigger information (SHOW CREATE TRIGGER) to the client. @@ -10171,8 +10166,9 @@ static bool show_create_trigger_impl(THD *thd, Trigger *trigger) MY_CS_NAME_SIZE), mem_root); + static const Datetime zero_datetime(Datetime::zero()); Item_datetime_literal *tmp= (new (mem_root) - Item_datetime_literal(thd, &zero_time, 2)); + Item_datetime_literal(thd, &zero_datetime, 2)); tmp->set_name(thd, STRING_WITH_LEN("Created"), system_charset_info); fields.push_back(tmp, mem_root); diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 85052a1c1bc..0c26e947789 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -8391,7 +8391,10 @@ Type_handler_date_common::create_literal_item(THD *thd, if (tmp.is_valid_temporal() && tmp.get_mysql_time()->time_type == MYSQL_TIMESTAMP_DATE && !have_important_literal_warnings(&st)) - item= new (thd->mem_root) Item_date_literal(thd, tmp.get_mysql_time()); + { + Date d(&tmp); + item= new (thd->mem_root) Item_date_literal(thd, &d); + } literal_warn(thd, item, str, length, cs, &st, "DATE", send_error); return item; } @@ -8410,8 +8413,10 @@ Type_handler_temporal_with_date::create_literal_item(THD *thd, if (tmp.is_valid_temporal() && tmp.get_mysql_time()->time_type == MYSQL_TIMESTAMP_DATETIME && !have_important_literal_warnings(&st)) - item= new (thd->mem_root) Item_datetime_literal(thd, tmp.get_mysql_time(), - st.precision); + { + Datetime dt(&tmp); + item= new (thd->mem_root) Item_datetime_literal(thd, &dt, st.precision); + } literal_warn(thd, item, str, length, cs, &st, "DATETIME", send_error); return item; } @@ -8430,8 +8435,7 @@ Type_handler_time_common::create_literal_item(THD *thd, Time tmp(thd, &st, str, length, cs, opt); if (tmp.is_valid_time() && !have_important_literal_warnings(&st)) - item= new (thd->mem_root) Item_time_literal(thd, tmp.get_mysql_time(), - st.precision); + item= new (thd->mem_root) Item_time_literal(thd, &tmp, st.precision); literal_warn(thd, item, str, length, cs, &st, "TIME", send_error); return item; } diff --git a/sql/sql_type.h b/sql/sql_type.h index 8726208b788..2064a55dc14 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -1722,6 +1722,11 @@ public: { return is_valid_time() ? Temporal::to_packed() : 0; } + longlong valid_time_to_packed() const + { + DBUG_ASSERT(is_valid_time_slow()); + return Temporal::to_packed(); + } long fraction_remainder(uint dec) const { DBUG_ASSERT(is_valid_time()); @@ -1896,6 +1901,11 @@ public: { return ::check_date_with_warn(thd, this, flags, MYSQL_TIMESTAMP_ERROR); } + bool check_date_with_warn(THD *thd) + { + return ::check_date_with_warn(thd, this, Temporal::sql_mode_for_dates(thd), + MYSQL_TIMESTAMP_ERROR); + } static date_conv_mode_t comparison_flags_for_get_date() { return TIME_INVALID_DATES | TIME_FUZZY_DATES; } }; @@ -1964,11 +1974,37 @@ public: datetime_to_date(this); DBUG_ASSERT(is_valid_date_slow()); } + explicit Date(const Temporal_hybrid *from) + { + *(static_cast(this))= *from; + DBUG_ASSERT(is_valid_date_slow()); + } bool is_valid_date() const { DBUG_ASSERT(is_valid_value_slow()); return time_type == MYSQL_TIMESTAMP_DATE; } + bool check_date(date_conv_mode_t flags, int *warnings) const + { + DBUG_ASSERT(is_valid_date_slow()); + return ::check_date(this, (year || month || day), + ulonglong(flags & TIME_MODE_FOR_XXX_TO_DATE), + warnings); + } + bool check_date(THD *thd, int *warnings) const + { + return check_date(Temporal::sql_mode_for_dates(thd), warnings); + } + bool check_date(date_conv_mode_t flags) const + { + int dummy; /* unused */ + return check_date(flags, &dummy); + } + bool check_date(THD *thd) const + { + int dummy; + return check_date(Temporal::sql_mode_for_dates(thd), &dummy); + } const MYSQL_TIME *get_mysql_time() const { DBUG_ASSERT(is_valid_date_slow()); @@ -2011,6 +2047,11 @@ public: return Temporal_with_date::yearweek(week_behaviour); } + longlong valid_date_to_packed() const + { + DBUG_ASSERT(is_valid_date_slow()); + return Temporal::to_packed(); + } longlong to_longlong() const { return is_valid_date() ? (longlong) TIME_to_ulonglong_date(this) : 0LL; @@ -2197,6 +2238,16 @@ public: { round(thd, dec, time_round_mode_t(fuzzydate), warn); } + explicit Datetime(const Temporal_hybrid *from) + { + *(static_cast(this))= *from; + DBUG_ASSERT(is_valid_datetime_slow()); + } + explicit Datetime(const MYSQL_TIME *from) + { + *(static_cast(this))= *from; + DBUG_ASSERT(is_valid_datetime_slow()); + } bool is_valid_datetime() const { @@ -2219,6 +2270,10 @@ public: int dummy; /* unused */ return check_date(flags, &dummy); } + bool check_date(THD *thd) const + { + return check_date(Temporal::sql_mode_for_dates(thd)); + } bool hhmmssff_is_zero() const { DBUG_ASSERT(is_valid_datetime_slow()); @@ -2327,6 +2382,11 @@ public: { return is_valid_datetime() ? Temporal::to_packed() : 0; } + longlong valid_datetime_to_packed() const + { + DBUG_ASSERT(is_valid_datetime_slow()); + return Temporal::to_packed(); + } long fraction_remainder(uint dec) const { DBUG_ASSERT(is_valid_datetime()); diff --git a/sql/table.cc b/sql/table.cc index ca0af28a79d..6fa2ef51f89 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -9365,7 +9365,8 @@ bool TR_table::query(MYSQL_TIME &commit_time, bool backwards) SELECT_LEX &slex= *(thd->lex->first_select_lex()); Name_resolution_context_backup backup(slex.context, *this); Item *field= newx Item_field(thd, &slex.context, (*this)[FLD_COMMIT_TS]); - Item *value= newx Item_datetime_literal(thd, &commit_time, 6); + Datetime dt(&commit_time); + Item *value= newx Item_datetime_literal(thd, &dt, 6); COND *conds; if (backwards) conds= newx Item_func_ge(thd, field, value); -- cgit v1.2.1 From 056766c042e975a91b016246357e9e6929b60b1a Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 24 Aug 2020 14:27:32 +0400 Subject: The patch for MDEV-23551 did not compile on some compilers. Fixing. --- sql/sql_type.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sql/sql_type.h b/sql/sql_type.h index 2064a55dc14..c1b13dfa811 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -1056,6 +1056,13 @@ public: } // End of constuctors + bool copy_valid_value_to_mysql_time(MYSQL_TIME *ltime) const + { + DBUG_ASSERT(is_valid_temporal()); + *ltime= *this; + return false; + } + longlong to_longlong() const { if (!is_valid_temporal()) @@ -1976,7 +1983,7 @@ public: } explicit Date(const Temporal_hybrid *from) { - *(static_cast(this))= *from; + from->copy_valid_value_to_mysql_time(this); DBUG_ASSERT(is_valid_date_slow()); } bool is_valid_date() const @@ -2240,7 +2247,7 @@ public: } explicit Datetime(const Temporal_hybrid *from) { - *(static_cast(this))= *from; + from->copy_valid_value_to_mysql_time(this); DBUG_ASSERT(is_valid_datetime_slow()); } explicit Datetime(const MYSQL_TIME *from) -- cgit v1.2.1 From 329301d2e647db099e1554663578f0352125d1c9 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 24 Aug 2020 22:55:39 +0400 Subject: MDEV-23562 Assertion `time_type == MYSQL_TIMESTAMP_DATETIME' failed upon SELECT from versioned table The code in vers_select_conds_t::init_from_sysvar() assumed that the value of the system_versioning_asof is DATETIME. But it also could be DATE after a query like this: SET system_versioning_asof = DATE(NOW()); Fixing Sys_var_vers_asof::update() to convert the value of the assignment source to DATETIME if it returned DATE. Now vers_select_conds_t::init_from_sysvar() always gets a DATETIME value. --- mysql-test/suite/versioning/r/sysvars.result | 9 +++++++++ mysql-test/suite/versioning/t/sysvars.test | 10 ++++++++++ sql/sys_vars.ic | 6 +++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/versioning/r/sysvars.result b/mysql-test/suite/versioning/r/sysvars.result index ac0a1237902..66513741631 100644 --- a/mysql-test/suite/versioning/r/sysvars.result +++ b/mysql-test/suite/versioning/r/sysvars.result @@ -186,4 +186,13 @@ SELECT @@global.system_versioning_asof; @@global.system_versioning_asof 2002-01-01 00:00:00.000000 SET @@global.system_versioning_asof= DEFAULT; +# +# MDEV-23562 Assertion `time_type == MYSQL_TIMESTAMP_DATETIME' failed upon SELECT from versioned table +# +CREATE TABLE t1 (a INT) WITH SYSTEM VERSIONING; +SET system_versioning_asof= DATE(NOW()); +SELECT * FROM t1; +a +DROP TABLE t1; +SET system_versioning_asof= DEFAULT; # End of 10.4 tests diff --git a/mysql-test/suite/versioning/t/sysvars.test b/mysql-test/suite/versioning/t/sysvars.test index 7c5e818ec81..a1026418e98 100644 --- a/mysql-test/suite/versioning/t/sysvars.test +++ b/mysql-test/suite/versioning/t/sysvars.test @@ -138,4 +138,14 @@ SET @@global.system_versioning_asof= timestamp'2001-12-31 23:59:59.9999999'; SELECT @@global.system_versioning_asof; SET @@global.system_versioning_asof= DEFAULT; +--echo # +--echo # MDEV-23562 Assertion `time_type == MYSQL_TIMESTAMP_DATETIME' failed upon SELECT from versioned table +--echo # + +CREATE TABLE t1 (a INT) WITH SYSTEM VERSIONING; +SET system_versioning_asof= DATE(NOW()); +SELECT * FROM t1; +DROP TABLE t1; +SET system_versioning_asof= DEFAULT; + --echo # End of 10.4 tests diff --git a/sql/sys_vars.ic b/sql/sys_vars.ic index 8e8ec4f00bc..94bfb3bb1bb 100644 --- a/sql/sys_vars.ic +++ b/sql/sys_vars.ic @@ -2669,7 +2669,11 @@ private: Datetime::Options opt(TIME_CONV_NONE | TIME_NO_ZERO_IN_DATE | TIME_NO_ZERO_DATE, thd); - res= var->value->get_date(thd, &out.ltime, opt); + /* + var->value is allowed to return DATETIME and DATE + Make sure to convert DATE to DATETIME. + */ + res= Datetime(thd, var->value, opt).copy_to_mysql_time(&out.ltime); } else // set DEFAULT from global var { -- cgit v1.2.1 From 2000d05c2ed85563e35c4548d9518249ddf403df Mon Sep 17 00:00:00 2001 From: Kentoku SHIBA Date: Sun, 23 Aug 2020 12:30:14 +0900 Subject: MDEV-22246 Result rows duplicated by spider engine fix the following type mrr scan (select 0,`id`,`node` from `auto_test_remote`.`tbl_a` where (`id` <> 0) order by `id`)union all(select 1,`id`,`node` from `auto_test_remote`.`tbl_a` where (`id` <> 0) order by `id`) order by `id` --- storage/spider/ha_spider.cc | 89 +++++++++++++++++++++ storage/spider/ha_spider.h | 2 + .../spider/bugfix/include/mdev_22246_deinit.inc | 14 ++++ .../spider/bugfix/include/mdev_22246_init.inc | 48 +++++++++++ .../mysql-test/spider/bugfix/r/mdev_22246.result | 79 +++++++++++++++++++ .../mysql-test/spider/bugfix/t/mdev_22246.cnf | 4 + .../mysql-test/spider/bugfix/t/mdev_22246.test | 92 ++++++++++++++++++++++ storage/spider/spd_db_conn.cc | 6 ++ storage/spider/spd_db_include.h | 1 + 9 files changed, 335 insertions(+) create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_22246_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_22246_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_22246.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_22246.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_22246.test diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index d2d0ddf376f..1f4439161b2 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -1832,6 +1832,7 @@ int ha_spider::reset() multi_range_keys = NULL; } #endif + multi_range_num = 0; ft_handler = NULL; ft_current = NULL; ft_count = 0; @@ -4354,6 +4355,64 @@ int ha_spider::read_range_next() DBUG_RETURN(check_ha_range_eof()); } +void ha_spider::reset_no_where_cond() +{ + uint roop_count; + DBUG_ENTER("ha_spider::reset_no_where_cond"); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (sql_kinds & (SPIDER_SQL_KIND_SQL | SPIDER_SQL_KIND_HANDLER)) + { +#endif + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_handler[share->use_sql_dbton_ids[roop_count]]->no_where_cond = + FALSE; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } + if (sql_kinds & SPIDER_SQL_KIND_HS) + { + for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++) + { + dbton_handler[share->use_hs_dbton_ids[roop_count]]->no_where_cond = + FALSE; + } + } +#endif + DBUG_VOID_RETURN; +} + +bool ha_spider::check_no_where_cond() +{ + uint roop_count; + DBUG_ENTER("ha_spider::check_no_where_cond"); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (sql_kinds & (SPIDER_SQL_KIND_SQL | SPIDER_SQL_KIND_HANDLER)) + { +#endif + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + if (dbton_handler[share->use_sql_dbton_ids[roop_count]]->no_where_cond) + { + DBUG_RETURN(TRUE); + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } + if (sql_kinds & SPIDER_SQL_KIND_HS) + { + for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++) + { + if (dbton_handler[share->use_hs_dbton_ids[roop_count]]->no_where_cond) + { + DBUG_RETURN(TRUE); + } + } + } +#endif + DBUG_RETURN(FALSE); +} + #ifdef HA_MRR_USE_DEFAULT_IMPL #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 ha_rows ha_spider::multi_range_read_info_const( @@ -4497,6 +4556,7 @@ int ha_spider::multi_range_read_init( DBUG_PRINT("info",("spider n_ranges=%u", n_ranges)); multi_range_num = n_ranges; mrr_have_range = FALSE; + reset_no_where_cond(); DBUG_RETURN( handler::multi_range_read_init( seq, @@ -4969,6 +5029,10 @@ int ha_spider::read_multi_range_first_internal( result_list.current = result_list.current->prev; } } + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } set_where_to_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); set_where_to_pos_sql(SPIDER_SQL_TYPE_HANDLER); } @@ -5444,6 +5508,15 @@ int ha_spider::read_multi_range_first_internal( DBUG_PRINT("info",("spider range_res8=%d", range_res)); } #endif + if (check_no_where_cond()) + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res = 1; +#else + multi_range_curr = multi_range_end; +#endif + break; + } } #ifdef HA_MRR_USE_DEFAULT_IMPL while (!range_res); @@ -5856,6 +5929,10 @@ int ha_spider::read_multi_range_first_internal( } else DBUG_RETURN(error_num); } + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } multi_range_cnt = 0; if ((error_num = reset_sql_sql( SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) @@ -6077,6 +6154,10 @@ int ha_spider::read_multi_range_next( #ifdef HA_MRR_USE_DEFAULT_IMPL DBUG_PRINT("info",("spider range_res2=%d", range_res)); #endif + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } set_where_to_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); set_where_to_pos_sql(SPIDER_SQL_TYPE_HANDLER); result_list.limit_num = @@ -6497,6 +6578,10 @@ int ha_spider::read_multi_range_next( #endif ) DBUG_RETURN(error_num); + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } spider_db_free_one_result_for_start_next(this); spider_first_split_read_param(this); #ifndef WITHOUT_SPIDER_BG_SEARCH @@ -7303,6 +7388,10 @@ int ha_spider::read_multi_range_next( } else DBUG_RETURN(error_num); } + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } multi_range_cnt = 0; if ((error_num = reset_sql_sql( SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h index edd7b8c881f..cb0a2abcc06 100644 --- a/storage/spider/ha_spider.h +++ b/storage/spider/ha_spider.h @@ -355,6 +355,8 @@ public: bool sorted ); int read_range_next(); + void reset_no_where_cond(); + bool check_no_where_cond(); #ifdef HA_MRR_USE_DEFAULT_IMPL #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 ha_rows multi_range_read_info_const( diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_deinit.inc new file mode 100644 index 00000000000..9d255152dd8 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_deinit.inc @@ -0,0 +1,14 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_init.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_init.inc new file mode 100644 index 00000000000..48226ba2811 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_init.inc @@ -0,0 +1,48 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +if (!$HAVE_PARTITION) +{ + --source group_by_order_by_limit_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a"' + PARTITION BY HASH(id) ( + PARTITION pt1 COMMENT='srv "s_2_1"', + PARTITION pt2 COMMENT='srv "s_2_2"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + id bigint NOT NULL, + node text, + PRIMARY KEY (id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT * FROM tbl_a ORDER BY id; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_a ( + id bigint NOT NULL, + node text, + PRIMARY KEY (id) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT * FROM tbl_a ORDER BY id; diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_22246.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_22246.result new file mode 100644 index 00000000000..749c750e018 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_22246.result @@ -0,0 +1,79 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-22246 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +id bigint NOT NULL, +node text, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (id,node) VALUES (1,'DB-G0'),(2,'DB-G1'); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT * FROM tbl_a; +id node +2 DB-G1 +1 DB-G0 +SELECT * FROM tbl_a WHERE id != 0; +id node +2 DB-G1 +1 DB-G0 +connection child2_1; +SELECT * FROM tbl_a ORDER BY id; +id node +2 DB-G1 +connection child2_2; +SELECT * FROM tbl_a ORDER BY id; +id node +1 DB-G0 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.cnf new file mode 100644 index 00000000000..e0ffb99c38e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.cnf @@ -0,0 +1,4 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf +!include ../my_2_2.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.test new file mode 100644 index 00000000000..63b04c14e11 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.test @@ -0,0 +1,92 @@ +--source ../include/mdev_22246_init.inc +--echo +--echo this test is for MDEV-22246 +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +--connection child2_2 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +--disable_query_log +echo CHILD2_2_CREATE_TABLES; +eval $CHILD2_2_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + id bigint NOT NULL, + node text, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + id bigint NOT NULL, + node text, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (id,node) VALUES (1,'DB-G0'),(2,'DB-G1'); + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +SELECT * FROM tbl_a; +SELECT * FROM tbl_a WHERE id != 0; + +--connection child2_1 +eval $CHILD2_1_SELECT_TABLES; + +--connection child2_2 +eval $CHILD2_2_SELECT_TABLES; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--connection child2_2 +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/mdev_22246_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index a54067281b1..08d2591a07e 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -1717,6 +1717,7 @@ int spider_db_append_key_where_internal( int key_count; uint length; uint store_length; + uint current_pos = str->length(); const uchar *ptr, *another_ptr; const key_range *use_key, *another_key; KEY_PART_INFO *key_part; @@ -2690,6 +2691,11 @@ int spider_db_append_key_where_internal( DBUG_RETURN(error_num); end: + if (spider->multi_range_num && current_pos == str->length()) + { + DBUG_PRINT("info", ("spider no key where condition")); + dbton_hdl->no_where_cond = TRUE; + } /* use condition */ if (dbton_hdl->append_condition_part(NULL, 0, sql_type, FALSE)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h index 046fe66435c..9b005ba7ccd 100644 --- a/storage/spider/spd_db_include.h +++ b/storage/spider/spd_db_include.h @@ -1323,6 +1323,7 @@ public: #ifdef SPIDER_HAS_GROUP_BY_HANDLER SPIDER_LINK_IDX_CHAIN *link_idx_chain; #endif + bool no_where_cond; spider_db_handler(ha_spider *spider, spider_db_share *db_share) : dbton_id(db_share->dbton_id), spider(spider), db_share(db_share), first_link_idx(-1) {} -- cgit v1.2.1 From 4a90bb85c0cb1407b0f112245e47ec995dc767c7 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Mon, 24 Aug 2020 20:53:51 +0300 Subject: InnoDB: fix debug assertion --- storage/innobase/row/row0upd.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index 63c1ea8d662..800c7a6d1f3 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -2438,7 +2438,7 @@ row_upd_sec_index_entry( #ifdef UNIV_DEBUG mtr_commit(&mtr); mtr_start(&mtr); - ut_ad(btr_validate_index(index, 0, false)); + ut_ad(btr_validate_index(index, 0, false) == DB_SUCCESS); ut_ad(0); #endif /* UNIV_DEBUG */ break; -- cgit v1.2.1 From a16f4927dbde19c546b1ba3726529914f8c91730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 24 Aug 2020 14:09:40 +0300 Subject: MDEV-22055: Assertion `active() == false' failed in wsrep::transaction::start_transaction upon ROLLBACK AND CHAIN The optional AND CHAIN clause is a convenience for initiating a new transaction as soon as the old transaction terminates. Therefore, do not start new transaction if it is already started at wsrep_start_transaction. --- mysql-test/suite/galera/r/MDEV-22055.result | 18 ++++++++++++++++++ mysql-test/suite/galera/t/MDEV-22055.test | 19 +++++++++++++++++++ sql/wsrep_trans_observer.h | 8 +++++--- 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 mysql-test/suite/galera/r/MDEV-22055.result create mode 100644 mysql-test/suite/galera/t/MDEV-22055.test diff --git a/mysql-test/suite/galera/r/MDEV-22055.result b/mysql-test/suite/galera/r/MDEV-22055.result new file mode 100644 index 00000000000..651f8501a0a --- /dev/null +++ b/mysql-test/suite/galera/r/MDEV-22055.result @@ -0,0 +1,18 @@ +connection node_2; +connection node_1; +ROLLBACK AND CHAIN; +CREATE TABLE t1(a int not null primary key) engine=innodb; +INSERT INTO t1 values (1); +BEGIN; +INSERT INTO t1 values (2); +ROLLBACK AND CHAIN; +SELECT * FROM t1; +a +1 +connection node_2; +SET SESSION wsrep_sync_wait=15; +SELECT * FROM t1; +a +1 +connection node_1; +DROP TABLE t1; diff --git a/mysql-test/suite/galera/t/MDEV-22055.test b/mysql-test/suite/galera/t/MDEV-22055.test new file mode 100644 index 00000000000..ae29c456bf0 --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-22055.test @@ -0,0 +1,19 @@ +--source include/galera_cluster.inc + +ROLLBACK AND CHAIN; + +CREATE TABLE t1(a int not null primary key) engine=innodb; +INSERT INTO t1 values (1); + +BEGIN; +INSERT INTO t1 values (2); +ROLLBACK AND CHAIN; + +SELECT * FROM t1; + +--connection node_2 +SET SESSION wsrep_sync_wait=15; +SELECT * FROM t1; + +--connection node_1 +DROP TABLE t1; diff --git a/sql/wsrep_trans_observer.h b/sql/wsrep_trans_observer.h index 1044cab76ad..05970e8b12f 100644 --- a/sql/wsrep_trans_observer.h +++ b/sql/wsrep_trans_observer.h @@ -133,9 +133,11 @@ static inline size_t wsrep_fragments_certified_for_stmt(THD* thd) static inline int wsrep_start_transaction(THD* thd, wsrep_trx_id_t trx_id) { - return (thd->wsrep_cs().state() != wsrep::client_state::s_none ? - thd->wsrep_cs().start_transaction(wsrep::transaction_id(trx_id)) : - 0); + if (thd->wsrep_cs().state() != wsrep::client_state::s_none) { + if (wsrep_is_active(thd) == false) + return thd->wsrep_cs().start_transaction(wsrep::transaction_id(trx_id)); + } + return 0; } /**/ -- cgit v1.2.1 From 88e70f4caea34e0d7677b1fa646151b8b87dd3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 24 Aug 2020 16:50:53 +0300 Subject: MDEV-23558: Galera heap-buffer-overflow at wsrep_schema.cc:1067 Key buffer needs to contain max field widths i.e. add MAX_FIELD_WIDTH. --- sql/wsrep_schema.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/wsrep_schema.cc b/sql/wsrep_schema.cc index 619a535f916..df9c7b78c9b 100644 --- a/sql/wsrep_schema.cc +++ b/sql/wsrep_schema.cc @@ -935,7 +935,7 @@ int Wsrep_schema::update_fragment_meta(THD* thd, Wsrep_schema_impl::binlog_off binlog_off(thd); int error; - uchar key[MAX_KEY_LENGTH]; + uchar key[MAX_KEY_LENGTH+MAX_FIELD_WIDTH]; key_part_map key_map= 0; TABLE* frag_table= 0; @@ -997,7 +997,7 @@ static int remove_fragment(THD* thd, seqno.get()); int ret= 0; int error; - uchar key[MAX_KEY_LENGTH]; + uchar key[MAX_KEY_LENGTH+MAX_FIELD_WIDTH]; key_part_map key_map= 0; DBUG_ASSERT(server_id.is_undefined() == false); @@ -1120,7 +1120,7 @@ int Wsrep_schema::replay_transaction(THD* orig_thd, int ret= 1; int error; TABLE* frag_table= 0; - uchar key[MAX_KEY_LENGTH]; + uchar key[MAX_KEY_LENGTH+MAX_FIELD_WIDTH]; key_part_map key_map= 0; for (std::vector::const_iterator i= fragments.begin(); -- cgit v1.2.1 From 6fa40b85be8cd35d337a4b4b7cf910a81518d298 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Tue, 25 Aug 2020 10:15:04 +0300 Subject: MDEV-23554 Wrong default value for foreign_key_checks variable Sys_var_bit::session_save_default() ignored reverse_semantics property. --- mysql-test/suite/innodb/r/foreign_key.result | 1 - mysql-test/suite/innodb/t/foreign_key.test | 1 - mysql-test/suite/sys_vars/r/foreign_key_checks_basic.result | 2 +- mysql-test/suite/sys_vars/r/unique_checks_basic.result | 2 +- sql/sys_vars.ic | 7 +++++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mysql-test/suite/innodb/r/foreign_key.result b/mysql-test/suite/innodb/r/foreign_key.result index bab4ea16643..fb4175c0327 100644 --- a/mysql-test/suite/innodb/r/foreign_key.result +++ b/mysql-test/suite/innodb/r/foreign_key.result @@ -167,7 +167,6 @@ PRIMARY KEY (store_id), UNIQUE KEY idx_unique_manager (manager_staff_id), CONSTRAINT fk_store_staff FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id) ON DELETE RESTRICT ON UPDATE CASCADE ) ENGINE=InnoDB; -SET FOREIGN_KEY_CHECKS=DEFAULT; LOCK TABLE staff WRITE; UNLOCK TABLES; DROP TABLES staff, store; diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test index 40bc3a32a4f..e0d83338dc2 100644 --- a/mysql-test/suite/innodb/t/foreign_key.test +++ b/mysql-test/suite/innodb/t/foreign_key.test @@ -136,7 +136,6 @@ CREATE TABLE store ( UNIQUE KEY idx_unique_manager (manager_staff_id), CONSTRAINT fk_store_staff FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id) ON DELETE RESTRICT ON UPDATE CASCADE ) ENGINE=InnoDB; -SET FOREIGN_KEY_CHECKS=DEFAULT; LOCK TABLE staff WRITE; UNLOCK TABLES; diff --git a/mysql-test/suite/sys_vars/r/foreign_key_checks_basic.result b/mysql-test/suite/sys_vars/r/foreign_key_checks_basic.result index 834d693edb8..0bf9d859d40 100644 --- a/mysql-test/suite/sys_vars/r/foreign_key_checks_basic.result +++ b/mysql-test/suite/sys_vars/r/foreign_key_checks_basic.result @@ -7,7 +7,7 @@ SET @@session.foreign_key_checks = 1; SET @@session.foreign_key_checks = DEFAULT; SELECT @@session.foreign_key_checks; @@session.foreign_key_checks -0 +1 '#---------------------FN_DYNVARS_032_02-------------------------#' SET foreign_key_checks = 1; SELECT @@foreign_key_checks; diff --git a/mysql-test/suite/sys_vars/r/unique_checks_basic.result b/mysql-test/suite/sys_vars/r/unique_checks_basic.result index 60cf2795309..83fb9edb4cd 100644 --- a/mysql-test/suite/sys_vars/r/unique_checks_basic.result +++ b/mysql-test/suite/sys_vars/r/unique_checks_basic.result @@ -7,7 +7,7 @@ SET @@session.unique_checks= 1; SET @@session.unique_checks= DEFAULT; SELECT @@session.unique_checks; @@session.unique_checks -0 +1 '#--------------------FN_DYNVARS_005_04-------------------------#' SET @@session.unique_checks =1; SELECT @@session.unique_checks; diff --git a/sql/sys_vars.ic b/sql/sys_vars.ic index a18440e550d..f547bd741fc 100644 --- a/sql/sys_vars.ic +++ b/sql/sys_vars.ic @@ -1704,13 +1704,16 @@ public: return false; } void session_save_default(THD *thd, set_var *var) - { var->save_result.ulonglong_value= global_var(ulonglong) & bitmask; } + { + var->save_result.ulonglong_value= + (reverse_semantics == !(global_var(ulonglong) & bitmask)); + } void global_save_default(THD *thd, set_var *var) { var->save_result.ulonglong_value= option.def_value; } uchar *valptr(THD *thd, ulonglong val) { - thd->sys_var_tmp.my_bool_value= reverse_semantics ^ ((val & bitmask) != 0); + thd->sys_var_tmp.my_bool_value= (reverse_semantics == !(val & bitmask)); return (uchar*) &thd->sys_var_tmp.my_bool_value; } uchar *session_value_ptr(THD *thd, const LEX_STRING *base) -- cgit v1.2.1 From 0be70a1b773ce66ef1803fcce19522fd9c60c07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 17 Aug 2020 08:57:13 +0300 Subject: MDEV-23483: Set Galera SST thd as system thread Revert change to MDL and set SST donor thread as a system thread. Joiner thread was already a system thread. --- mysql-test/suite/galera/t/mdev-22543.test | 20 ++++++++++---------- sql/mdl.cc | 25 ++++++++----------------- sql/wsrep_sst.cc | 18 +++++------------- sql/wsrep_utils.cc | 4 +++- sql/wsrep_utils.h | 2 +- 5 files changed, 27 insertions(+), 42 deletions(-) diff --git a/mysql-test/suite/galera/t/mdev-22543.test b/mysql-test/suite/galera/t/mdev-22543.test index 53662e36942..1e7d3712639 100644 --- a/mysql-test/suite/galera/t/mdev-22543.test +++ b/mysql-test/suite/galera/t/mdev-22543.test @@ -5,15 +5,15 @@ --source include/galera_cluster.inc --source include/have_debug.inc --source include/have_debug_sync.inc - + --let $node_1 = node_1 --let $node_2 = node_2 --source include/auto_increment_offset_save.inc - + --let $galera_connection_name = node_1_ctrl --let $galera_server_number = 1 --source include/galera_connect.inc - + # # Run UPDATE on node_1 and make it block before table locks are taken. # This should block FTWRL. @@ -23,10 +23,10 @@ CREATE TABLE t1 (f1 INT PRIMARY KEY, f2 INT); INSERT INTO t1 VALUES (1, 1); SET DEBUG_SYNC = "before_lock_tables_takes_lock SIGNAL sync_point_reached WAIT_FOR sync_point_continue"; --send UPDATE t1 SET f2 = 2 WHERE f1 = 1 - + --connection node_1_ctrl SET DEBUG_SYNC = "now WAIT_FOR sync_point_reached"; - + # # Restart node_2, force SST. # @@ -40,19 +40,19 @@ SET DEBUG_SYNC = "now WAIT_FOR sync_point_reached"; # If the bug is present, FTWRL times out on node_1 in couple of # seconds and node_2 fails to join. --sleep 10 - + --connection node_1_ctrl SET DEBUG_SYNC = "now SIGNAL sync_point_continue"; - + --connection node_1 --reap SET DEBUG_SYNC = "RESET"; - + --connection node_2 --enable_reconnect --source include/wait_until_connected_again.inc - + --connection node_1 DROP TABLE t1; - + --source include/auto_increment_offset_restore.inc diff --git a/sql/mdl.cc b/sql/mdl.cc index 14a1f17fe86..9eeb82eeffd 100644 --- a/sql/mdl.cc +++ b/sql/mdl.cc @@ -25,7 +25,6 @@ #include #include "wsrep_mysqld.h" #include "wsrep_thd.h" -#include "wsrep_sst.h" #ifdef HAVE_PSI_INTERFACE static PSI_mutex_key key_MDL_wait_LOCK_wait_status; @@ -2138,26 +2137,18 @@ MDL_context::acquire_lock(MDL_request *mdl_request, double lock_wait_timeout) wait_status= m_wait.timed_wait(m_owner, &abs_shortwait, FALSE, mdl_request->key.get_wait_state_name()); - THD* thd= m_owner->get_thd(); - if (wait_status != MDL_wait::EMPTY) break; /* Check if the client is gone while we were waiting. */ - if (! thd_is_connected(thd)) + if (! thd_is_connected(m_owner->get_thd())) { -#if defined(WITH_WSREP) && !defined(EMBEDDED_LIBRARY) - // During SST client might not be connected - if (!wsrep_is_sst_progress()) -#endif - { - /* - * The client is disconnected. Don't wait forever: - * assume it's the same as a wait timeout, this - * ensures all error handling is correct. - */ - wait_status= MDL_wait::TIMEOUT; - break; - } + /* + * The client is disconnected. Don't wait forever: + * assume it's the same as a wait timeout, this + * ensures all error handling is correct. + */ + wait_status= MDL_wait::TIMEOUT; + break; } mysql_prlock_wrlock(&lock->m_rwlock); diff --git a/sql/wsrep_sst.cc b/sql/wsrep_sst.cc index a6accd52910..af3a80cb67c 100644 --- a/sql/wsrep_sst.cc +++ b/sql/wsrep_sst.cc @@ -1,4 +1,4 @@ -/* Copyright 2008-2015 Codership Oy +/* Copyright 2008-2020 Codership Oy 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 @@ -192,7 +192,6 @@ bool wsrep_before_SE() static bool sst_complete = false; static bool sst_needed = false; -static bool sst_in_progress = false; #define WSREP_EXTEND_TIMEOUT_INTERVAL 30 #define WSREP_TIMEDWAIT_SECONDS 10 @@ -1545,11 +1544,11 @@ static void* sst_donor_thread (void* a) wsrep_uuid_t ret_uuid= WSREP_UUID_UNDEFINED; // seqno of complete SST wsrep_seqno_t ret_seqno= WSREP_SEQNO_UNDEFINED; - // SST is now in progress - sst_in_progress= true; - wsp::thd thd(FALSE); // we turn off wsrep_on for this THD so that it can - // operate with wsrep_ready == OFF + // We turn off wsrep_on for this THD so that it can + // operate with wsrep_ready == OFF + // We also set this SST thread THD as system thread + wsp::thd thd(FALSE, true); wsp::process proc(arg->cmd, "r", arg->env); err= proc.error(); @@ -1648,8 +1647,6 @@ wait_signal: wsrep->sst_sent (wsrep, &state_id, -err); proc.wait(); - sst_in_progress= false; - return NULL; } @@ -1824,8 +1821,3 @@ void wsrep_SE_initialized() { SE_initialized = true; } - -bool wsrep_is_sst_progress() -{ - return (sst_in_progress); -} diff --git a/sql/wsrep_utils.cc b/sql/wsrep_utils.cc index 599ece4cb40..e86be3e5d93 100644 --- a/sql/wsrep_utils.cc +++ b/sql/wsrep_utils.cc @@ -413,7 +413,7 @@ process::wait () return err_; } -thd::thd (my_bool won) : init(), ptr(new THD(0)) +thd::thd (my_bool won, bool system_thread) : init(), ptr(new THD(0)) { if (ptr) { @@ -421,6 +421,8 @@ thd::thd (my_bool won) : init(), ptr(new THD(0)) ptr->store_globals(); ptr->variables.option_bits&= ~OPTION_BIN_LOG; // disable binlog ptr->variables.wsrep_on = won; + if (system_thread) + ptr->system_thread= SYSTEM_THREAD_GENERIC; ptr->security_ctx->master_access= ~(ulong)0; lex_start(ptr); } diff --git a/sql/wsrep_utils.h b/sql/wsrep_utils.h index 616a6d3f457..d4d9e62a620 100644 --- a/sql/wsrep_utils.h +++ b/sql/wsrep_utils.h @@ -298,7 +298,7 @@ class thd public: - thd(my_bool wsrep_on); + thd(my_bool wsrep_on, bool system_thread=false); ~thd(); THD* const ptr; }; -- cgit v1.2.1 From c0e5cf79ad13fad4b34fa7d0777cc90035db93c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 25 Aug 2020 15:23:20 +0300 Subject: MDEV-22543: Remove orphan declaration of wsrep_is_sst_progress --- sql/wsrep_sst.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/sql/wsrep_sst.h b/sql/wsrep_sst.h index 5a749d529fb..063cab5f0f1 100644 --- a/sql/wsrep_sst.h +++ b/sql/wsrep_sst.h @@ -74,14 +74,12 @@ extern void wsrep_SE_init_grab(); /*! grab init critical section */ extern void wsrep_SE_init_wait(); /*! wait for SE init to complete */ extern void wsrep_SE_init_done(); /*! signal that SE init is complte */ extern void wsrep_SE_initialized(); /*! mark SE initialization complete */ -extern bool wsrep_is_sst_progress(); #else #define wsrep_SE_initialized() do { } while(0) #define wsrep_SE_init_grab() do { } while(0) #define wsrep_SE_init_done() do { } while(0) #define wsrep_sst_continue() (0) -#define wsrep_is_sst_progress() (0) #endif /* WITH_WSREP */ #endif /* WSREP_SST_H */ -- cgit v1.2.1 From d8ba2930d665579e4da1f795094ab7396b453d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 25 Aug 2020 15:25:22 +0300 Subject: MDEV-23566 SIGSEGV in mtr_t::init mtr_t::init(): Correct the debug assertion that was added in commit c89366866bca2df46b0592719a1f6b6dabf470cb (MDEV-22970). When the original failure scenario involves the system tablespace, we could have m_user_space==nullptr. Let us compare m_user_space_id instead. --- storage/innobase/include/mtr0log.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/storage/innobase/include/mtr0log.h b/storage/innobase/include/mtr0log.h index ee611f6f2ee..2bcd69d8899 100644 --- a/storage/innobase/include/mtr0log.h +++ b/storage/innobase/include/mtr0log.h @@ -513,7 +513,8 @@ inline void mtr_t::init(buf_block_t *b) { if (UNIV_LIKELY_NULL(m_freed_pages)) { - ut_ad(m_user_space->id == b->page.id().space()); + ut_ad(m_log_mode != MTR_LOG_ALL || + m_user_space_id == b->page.id().space()); if (m_freed_pages->remove_if_exists(b->page.id().page_no()) && m_freed_pages->empty()) { -- cgit v1.2.1 From 8cf8ad86d4b6f3479d80f3d8e8c2bcf463966924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 25 Aug 2020 15:32:15 +0300 Subject: MDEV-23547 InnoDB: Failing assertion: *len in row_upd_ext_fetch This bug was originally repeated on 10.4 after defining a UNIQUE KEY on a TEXT column, which is implemented by MDEV-371 by creating the index on a hidden virtual column. While row_vers_vc_matches_cluster() is executing in a purge thread to find out if an index entry may be removed in a secondary index that comprises a virtual column, another purge thread may process the undo log record that this check is interested in, and write a null BLOB pointer in that record. This would trip the assertion. To prevent this from occurring, we must propagate the 'missing BLOB' error up the call stack. row_upd_ext_fetch(): Return NULL when the error occurs. row_upd_index_replace_new_col_val(): Return whether the previous version was built successfully. row_upd_index_replace_new_col_vals_index_pos(): Check the error result. Yes, we would intentionally crash on this error if it occurs outside the purge thread. row_upd_index_replace_new_col_vals(): Check for the error condition, and simplify the logic. trx_undo_prev_version_build(): Check for the error condition. --- storage/innobase/include/row0upd.h | 30 ++++----- storage/innobase/row/row0upd.cc | 127 ++++++++++++++++++------------------- storage/innobase/trx/trx0rec.cc | 6 +- 3 files changed, 78 insertions(+), 85 deletions(-) diff --git a/storage/innobase/include/row0upd.h b/storage/innobase/include/row0upd.h index 04701042658..b60770b01fb 100644 --- a/storage/innobase/include/row0upd.h +++ b/storage/innobase/include/row0upd.h @@ -257,24 +257,18 @@ row_upd_index_replace_new_col_vals_index_pos( mem_heap_t* heap) /*!< in: memory heap for allocating and copying the new values */ MY_ATTRIBUTE((nonnull)); -/***********************************************************//** -Replaces the new column values stored in the update vector to the index entry -given. */ -void -row_upd_index_replace_new_col_vals( -/*===============================*/ - dtuple_t* entry, /*!< in/out: index entry where replaced; - the clustered index record must be - covered by a lock or a page latch to - prevent deletion (rollback or purge) */ - dict_index_t* index, /*!< in: index; NOTE that this may also be a - non-clustered index */ - const upd_t* update, /*!< in: an update vector built for the - CLUSTERED index so that the field number in - an upd_field is the clustered index position */ - mem_heap_t* heap) /*!< in: memory heap for allocating and - copying the new values */ - MY_ATTRIBUTE((nonnull)); +/** Replace the new column values stored in the update vector, +during trx_undo_prev_version_build(). +@param entry clustered index tuple where the values are replaced + (the clustered index leaf page latch must be held) +@param index clustered index +@param update update vector for the clustered index +@param heap memory heap for allocating and copying values +@return whether the previous version was built successfully */ +bool +row_upd_index_replace_new_col_vals(dtuple_t *entry, const dict_index_t &index, + const upd_t *update, mem_heap_t *heap) + MY_ATTRIBUTE((nonnull, warn_unused_result)); /***********************************************************//** Replaces the new column values stored in the update vector. */ void diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index 800c7a6d1f3..6d210cfd6bb 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -1206,7 +1206,9 @@ containing also the reference to the external part @param[in,out] len input - length of prefix to fetch; output: fetched length of the prefix @param[in,out] heap heap where to allocate -@return BLOB prefix */ +@return BLOB prefix +@retval NULL if the record is incomplete (should only happen +in row_vers_vc_matches_cluster() executed concurrently with another purge) */ static byte* row_upd_ext_fetch( @@ -1221,10 +1223,7 @@ row_upd_ext_fetch( *len = btr_copy_externally_stored_field_prefix( buf, *len, page_size, data, local_len); - /* We should never update records containing a half-deleted BLOB. */ - ut_a(*len); - - return(buf); + return *len ? buf : NULL; } /** Replaces the new column value stored in the update vector in @@ -1235,9 +1234,11 @@ the given index entry field. @param[in] uf update field @param[in,out] heap memory heap for allocating and copying the new value -@param[in] page_size page size */ +@param[in] page_size page size +@return whether the previous version was built successfully */ +MY_ATTRIBUTE((nonnull, warn_unused_result)) static -void +bool row_upd_index_replace_new_col_val( dfield_t* dfield, const dict_field_t* field, @@ -1252,7 +1253,7 @@ row_upd_index_replace_new_col_val( dfield_copy_data(dfield, &uf->new_val); if (dfield_is_null(dfield)) { - return; + return true; } len = dfield_get_len(dfield); @@ -1270,6 +1271,9 @@ row_upd_index_replace_new_col_val( data = row_upd_ext_fetch(data, l, page_size, &len, heap); + if (UNIV_UNLIKELY(!data)) { + return false; + } } len = dtype_get_at_most_n_mbchars(col->prtype, @@ -1283,7 +1287,7 @@ row_upd_index_replace_new_col_val( dfield_dup(dfield, heap); } - return; + return true; } switch (uf->orig_len) { @@ -1322,6 +1326,8 @@ row_upd_index_replace_new_col_val( dfield_set_ext(dfield); break; } + + return true; } /***********************************************************//** @@ -1379,68 +1385,57 @@ row_upd_index_replace_new_col_vals_index_pos( update, i, false); } - if (uf) { - row_upd_index_replace_new_col_val( - dtuple_get_nth_field(entry, i), - field, col, uf, heap, page_size); + if (uf && UNIV_UNLIKELY(!row_upd_index_replace_new_col_val( + dtuple_get_nth_field(entry, i), + field, col, uf, heap, + page_size))) { + ut_error; } } } -/***********************************************************//** -Replaces the new column values stored in the update vector to the index entry -given. */ -void -row_upd_index_replace_new_col_vals( -/*===============================*/ - dtuple_t* entry, /*!< in/out: index entry where replaced; - the clustered index record must be - covered by a lock or a page latch to - prevent deletion (rollback or purge) */ - dict_index_t* index, /*!< in: index; NOTE that this may also be a - non-clustered index */ - const upd_t* update, /*!< in: an update vector built for the - CLUSTERED index so that the field number in - an upd_field is the clustered index position */ - mem_heap_t* heap) /*!< in: memory heap for allocating and - copying the new values */ +/** Replace the new column values stored in the update vector, +during trx_undo_prev_version_build(). +@param entry clustered index tuple where the values are replaced + (the clustered index leaf page latch must be held) +@param index clustered index +@param update update vector for the clustered index +@param heap memory heap for allocating and copying values +@return whether the previous version was built successfully */ +bool +row_upd_index_replace_new_col_vals(dtuple_t *entry, const dict_index_t &index, + const upd_t *update, mem_heap_t *heap) { - ulint i; - const dict_index_t* clust_index - = dict_table_get_first_index(index->table); - const page_size_t& page_size = dict_table_page_size(index->table); - - ut_ad(!index->table->skip_alter_undo); - - dtuple_set_info_bits(entry, update->info_bits); - - for (i = 0; i < dict_index_get_n_fields(index); i++) { - const dict_field_t* field; - const dict_col_t* col; - const upd_field_t* uf; - - field = dict_index_get_nth_field(index, i); - col = dict_field_get_col(field); - if (dict_col_is_virtual(col)) { - const dict_v_col_t* vcol = reinterpret_cast< - const dict_v_col_t*>( - col); - - uf = upd_get_field_by_field_no( - update, vcol->v_pos, true); - } else { - uf = upd_get_field_by_field_no( - update, - dict_col_get_clust_pos(col, clust_index), - false); - } - - if (uf) { - row_upd_index_replace_new_col_val( - dtuple_get_nth_field(entry, i), - field, col, uf, heap, page_size); - } - } + ut_ad(index.is_primary()); + const page_size_t& page_size= dict_table_page_size(index.table); + + ut_ad(!index.table->skip_alter_undo); + dtuple_set_info_bits(entry, update->info_bits); + + for (ulint i= 0; i < index.n_fields; i++) + { + const dict_field_t *field= &index.fields[i]; + const dict_col_t* col= dict_field_get_col(field); + const upd_field_t *uf; + + if (col->is_virtual()) + { + const dict_v_col_t *vcol= reinterpret_cast(col); + uf= upd_get_field_by_field_no(update, vcol->v_pos, true); + } + else + uf= upd_get_field_by_field_no(update, dict_col_get_clust_pos(col, &index), + false); + + if (!uf) + continue; + + if (!row_upd_index_replace_new_col_val(dtuple_get_nth_field(entry, i), + field, col, uf, heap, page_size)) + return false; + } + + return true; } /** Replaces the virtual column values stored in the update vector. diff --git a/storage/innobase/trx/trx0rec.cc b/storage/innobase/trx/trx0rec.cc index ee022b4f1fd..623d8990381 100644 --- a/storage/innobase/trx/trx0rec.cc +++ b/storage/innobase/trx/trx0rec.cc @@ -2446,7 +2446,11 @@ trx_undo_prev_version_build( /* The page containing the clustered index record corresponding to entry is latched in mtr. Thus the following call is safe. */ - row_upd_index_replace_new_col_vals(entry, index, update, heap); + if (!row_upd_index_replace_new_col_vals(entry, *index, update, + heap)) { + ut_a(v_status & TRX_UNDO_PREV_IN_PURGE); + return false; + } /* Get number of externally stored columns in updated record */ const ulint n_ext = dtuple_get_n_ext(entry); -- cgit v1.2.1 From 62d1e3bf67a12eb6f48ac615bda119e2ed65cf16 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 24 Aug 2020 18:52:44 +0200 Subject: MDEV-23569 temporary tables can overwrite existing files for internal temporary tables: don't use realpath(), and let them overwrite whatever orphan temp files might've left in the tmpdir (see main.error_simulation test). for user created temporary tables: we have to use realpath(), (see 3a726ab6e2e, remember DATA/INDEX DIRECTORY). don't allow them to overwrite existing files. This bug was reported by RACK911 LABS --- mysql-test/r/temp_table_symlink.result | 13 +++++++++++++ mysql-test/t/temp_table_symlink.test | 32 ++++++++++++++++++++++++++++++++ storage/maria/ma_create.c | 6 +++--- storage/myisam/mi_create.c | 6 +++--- 4 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 mysql-test/r/temp_table_symlink.result create mode 100644 mysql-test/t/temp_table_symlink.test diff --git a/mysql-test/r/temp_table_symlink.result b/mysql-test/r/temp_table_symlink.result new file mode 100644 index 00000000000..1c5c68170ff --- /dev/null +++ b/mysql-test/r/temp_table_symlink.result @@ -0,0 +1,13 @@ +create table d1 (a int); +create temporary table t1 (a int); +create temporary table t2 (a int); +Got one of the listed errors +create temporary table t3 (a int) engine=Aria; +Got one of the listed errors +select * from information_schema.columns where table_schema='test'; +Got one of the listed errors +flush tables; +select * from d1; +a +drop temporary table t1; +drop table d1; diff --git a/mysql-test/t/temp_table_symlink.test b/mysql-test/t/temp_table_symlink.test new file mode 100644 index 00000000000..9297b472805 --- /dev/null +++ b/mysql-test/t/temp_table_symlink.test @@ -0,0 +1,32 @@ +source include/not_windows.inc; + +# +# MDEV-23569 temporary tables can overwrite existing files +# + +let datadir=`select @@datadir`; +create table d1 (a int); +create temporary table t1 (a int); +perl; +chdir "$ENV{MYSQL_TMP_DIR}/mysqld.1/"; +for (<#sql*.MYI>) { + /^#sql(.*)_([0-9a-f]+_)([0-9a-f]+)\.MYI$/ or die; + symlink "$ENV{datadir}/test/d1.MYI", sprintf "#sql$1_$2%x.MYI", hex($3)+1; + symlink "$ENV{datadir}/test/d1.MYI", sprintf "#sql$1_$2%x.MAI", hex($3)+1; + symlink "$ENV{datadir}/test/d1.MYI", sprintf "#sql$1_$2%x.MAI", hex($3)+2; + symlink "$ENV{datadir}/test/d1.MYI", "#sql_$1_0.MAI"; +} +EOF + +error 1,1030; +create temporary table t2 (a int); +error 1,1030; +create temporary table t3 (a int) engine=Aria; +error 1,1030; +select * from information_schema.columns where table_schema='test'; + +flush tables; +select * from d1; +drop temporary table t1; +remove_files_wildcard $MYSQL_TMP_DIR/mysqld.1 *sql*; +drop table d1; diff --git a/storage/maria/ma_create.c b/storage/maria/ma_create.c index 263d8a307b1..e1d2d89020d 100644 --- a/storage/maria/ma_create.c +++ b/storage/maria/ma_create.c @@ -322,7 +322,7 @@ int maria_create(const char *name, enum data_file_type datafile_type, { options|= HA_OPTION_TMP_TABLE; tmp_table= TRUE; - create_mode|= O_NOFOLLOW; + create_mode|= O_NOFOLLOW | (internal_table ? 0 : O_EXCL); /* "CREATE TEMPORARY" tables are not crash-safe (dropped at restart) */ ci->transactional= FALSE; flags&= ~HA_CREATE_PAGE_CHECKSUM; @@ -887,8 +887,8 @@ int maria_create(const char *name, enum data_file_type datafile_type, { char *iext= strrchr(name, '.'); int have_iext= iext && !strcmp(iext, MARIA_NAME_IEXT); - fn_format(kfilename, name, "", MARIA_NAME_IEXT, - MY_UNPACK_FILENAME | MY_RETURN_REAL_PATH | + fn_format(kfilename, name, "", MARIA_NAME_IEXT, MY_UNPACK_FILENAME | + (internal_table ? 0 : MY_RETURN_REAL_PATH) | (have_iext ? MY_REPLACE_EXT : MY_APPEND_EXT)); klinkname_ptr= NullS; /* diff --git a/storage/myisam/mi_create.c b/storage/myisam/mi_create.c index 855ac8337b9..7d6095b8a09 100644 --- a/storage/myisam/mi_create.c +++ b/storage/myisam/mi_create.c @@ -184,7 +184,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, if (flags & HA_CREATE_TMP_TABLE) { options|= HA_OPTION_TMP_TABLE; - create_mode|= O_NOFOLLOW; + create_mode|= O_NOFOLLOW | (internal_table ? 0 : O_EXCL); } if (flags & HA_CREATE_CHECKSUM || (options & HA_OPTION_CHECKSUM)) { @@ -618,8 +618,8 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, { char *iext= strrchr(name, '.'); int have_iext= iext && !strcmp(iext, MI_NAME_IEXT); - fn_format(kfilename, name, "", MI_NAME_IEXT, - MY_UNPACK_FILENAME | MY_RETURN_REAL_PATH | + fn_format(kfilename, name, "", MI_NAME_IEXT, MY_UNPACK_FILENAME | + (internal_table ? 0 : MY_RETURN_REAL_PATH) | (have_iext ? MY_REPLACE_EXT : MY_APPEND_EXT)); klinkname_ptr= 0; /* Replace the current file */ -- cgit v1.2.1 From 6586bb51f3167fad9e353e8c9cd69f51e0acec21 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Tue, 25 Aug 2020 22:21:07 +0300 Subject: MDEV-23467 SIGSEGV in fill_record/fill_record_n_invoke_before_triggers on INSERT DELAYED Field::make_new_field() resets invisible property (needed for "CREATE .. SELECT" f.ex.). Recover invisible property in Delayed_insert::get_local_table() (unireg_check works by the same principle). --- mysql-test/main/invisible_field.result | 6 ++++++ mysql-test/main/invisible_field.test | 8 ++++++++ sql/sql_insert.cc | 1 + 3 files changed, 15 insertions(+) diff --git a/mysql-test/main/invisible_field.result b/mysql-test/main/invisible_field.result index 053a9fd8e50..ee45567d212 100644 --- a/mysql-test/main/invisible_field.result +++ b/mysql-test/main/invisible_field.result @@ -617,3 +617,9 @@ a b 1 3 2 4 drop table t1; +# +# MDEV-23467 SIGSEGV in fill_record/fill_record_n_invoke_before_triggers on INSERT DELAYED +# +create table t1 (a int, b int invisible); +insert delayed into t1 values (1); +drop table t1; diff --git a/mysql-test/main/invisible_field.test b/mysql-test/main/invisible_field.test index 0e3994a78ce..7a48347ec29 100644 --- a/mysql-test/main/invisible_field.test +++ b/mysql-test/main/invisible_field.test @@ -271,3 +271,11 @@ select a,b from t1; #cleanup drop table t1; + +--echo # +--echo # MDEV-23467 SIGSEGV in fill_record/fill_record_n_invoke_before_triggers on INSERT DELAYED +--echo # +create table t1 (a int, b int invisible); +insert delayed into t1 values (1); +# cleanup +drop table t1; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index a24cb61449b..b574e7ab9d7 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2614,6 +2614,7 @@ TABLE *Delayed_insert::get_local_table(THD* client_thd) if (!(*field= (*org_field)->make_new_field(client_thd->mem_root, copy, 1))) goto error; (*field)->unireg_check= (*org_field)->unireg_check; + (*field)->invisible= (*org_field)->invisible; (*field)->orig_table= copy; // Remove connection (*field)->move_field_offset(adjust_ptrs); // Point at copy->record[0] memdup_vcol(client_thd, (*field)->vcol_info); -- cgit v1.2.1 From 95831888e8a89a4e141e76d51dbfc0701552c824 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Tue, 25 Aug 2020 22:21:08 +0300 Subject: part_records() signature fix --- sql/ha_partition.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 6a12c8a4800..b80c2174658 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -1614,9 +1614,8 @@ public: return h; } - ha_rows part_records(void *_part_elem) + ha_rows part_records(partition_element *part_elem) { - partition_element *part_elem= reinterpret_cast(_part_elem); DBUG_ASSERT(m_part_info); uint32 sub_factor= m_part_info->num_subparts ? m_part_info->num_subparts : 1; uint32 part_id= part_elem->id * sub_factor; -- cgit v1.2.1 From e1a9b7ca7b84f7096fa768f6cedb1b4981958bed Mon Sep 17 00:00:00 2001 From: Kentoku SHIBA Date: Mon, 24 Aug 2020 10:29:23 +0900 Subject: Fix indents of Spider --- storage/spider/spd_conn.cc | 2 +- storage/spider/spd_environ.h | 12 ++++++------ storage/spider/spd_include.h | 2 +- storage/spider/spd_table.h | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index 100fe922825..404d3b6754e 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -1095,7 +1095,7 @@ SPIDER_CONN *spider_get_conn( } else - { /* did not enable conncetion pool , create_conn */ + { /* did not enable conncetion pool , create_conn */ DBUG_PRINT("info",("spider create new conn")); if (!(conn = spider_create_conn(share, spider, link_idx, base_link_idx, conn_kind, error_num))) diff --git a/storage/spider/spd_environ.h b/storage/spider/spd_environ.h index 528bed160c9..320b0edeb30 100644 --- a/storage/spider/spd_environ.h +++ b/storage/spider/spd_environ.h @@ -24,12 +24,12 @@ #define SPIDER_HANDLER_START_BULK_INSERT_HAS_FLAGS #endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100100 +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100100 #define SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE #define SPIDER_NET_HAS_THD #endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100211 +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100211 #define HANDLER_HAS_TOP_TABLE_FIELDS #define HANDLER_HAS_DIRECT_UPDATE_ROWS #define HANDLER_HAS_DIRECT_AGGREGATE @@ -40,22 +40,22 @@ #define HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT #endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100300 +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100300 #define SPIDER_UPDATE_ROW_HAS_CONST_NEW_DATA #endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100309 +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100309 #define SPIDER_MDEV_16246 #endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100400 +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100400 #define SPIDER_USE_CONST_ITEM_FOR_STRING_INT_REAL_DECIMAL_DATE_ITEM #define SPIDER_SQL_CACHE_IS_IN_LEX #define SPIDER_LIKE_FUNC_HAS_GET_NEGATED #define HA_HAS_CHECKSUM_EXTENDED #endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100500 +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100500 #define SPIDER_I_S_USE_SHOW_FOR_COLUMN #endif #endif /* SPD_ENVIRON_INCLUDED */ diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index 31c75b68d6e..343e90e75b6 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -228,7 +228,7 @@ const char SPIDER_empty_string = ""; #define SPIDER_HAS_HASH_VALUE_TYPE #endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100400 +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100400 #define SPIDER_date_mode_t(A) date_mode_t(A) #define SPIDER_str_to_datetime(A,B,C,D,E) str_to_datetime_or_date(A,B,C,D,E) #define SPIDER_get_linkage(A) A->get_linkage() diff --git a/storage/spider/spd_table.h b/storage/spider/spd_table.h index c57f4e4d4c0..c3f1dc09db5 100644 --- a/storage/spider/spd_table.h +++ b/storage/spider/spd_table.h @@ -738,8 +738,8 @@ Field *spider_field_exchange( #endif int spider_set_direct_limit_offset( - ha_spider* spider - ); + ha_spider *spider +); bool spider_check_index_merge( TABLE *table, -- cgit v1.2.1 From 8f8f2aea93835899345454f87768fd649749e29c Mon Sep 17 00:00:00 2001 From: Kentoku SHIBA Date: Tue, 25 Aug 2020 20:41:33 +0900 Subject: MDEV-23561 Spider doesn't work with ps protocol --- storage/spider/ha_spider.cc | 18 +-- .../mysql-test/spider/bugfix/r/xa_cmd.result | 2 - storage/spider/spd_copy_tables.cc | 6 +- storage/spider/spd_db_conn.cc | 6 +- storage/spider/spd_include.h | 29 ++++- storage/spider/spd_ping_table.cc | 77 +++++++---- storage/spider/spd_sys_table.cc | 143 +++++++-------------- storage/spider/spd_sys_table.h | 32 ++--- storage/spider/spd_table.cc | 41 +++--- storage/spider/spd_trx.cc | 133 +++++-------------- 10 files changed, 193 insertions(+), 294 deletions(-) diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 51ceee310ae..366554855d0 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -11401,11 +11401,7 @@ int ha_spider::create( uint sql_command = thd_sql_command(thd), roop_count; SPIDER_TRX *trx; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; bool need_lock = FALSE; DBUG_ENTER("ha_spider::create"); DBUG_PRINT("info",("spider this=%p", this)); @@ -11657,11 +11653,7 @@ int ha_spider::rename_table( TABLE *table_tables = NULL; SPIDER_ALTER_TABLE *alter_table_from, *alter_table_to; SPIDER_LGTM_TBLHND_SHARE *from_lgtm_tblhnd_share, *to_lgtm_tblhnd_share; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; bool need_lock = FALSE; DBUG_ENTER("ha_spider::rename_table"); DBUG_PRINT("info",("spider this=%p", this)); @@ -11885,11 +11877,7 @@ int ha_spider::delete_table( TABLE *table_tables = NULL; uint sql_command = thd_sql_command(thd); SPIDER_ALTER_TABLE *alter_table; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; bool need_lock = FALSE; DBUG_ENTER("ha_spider::delete_table"); DBUG_PRINT("info",("spider this=%p", this)); diff --git a/storage/spider/mysql-test/spider/bugfix/r/xa_cmd.result b/storage/spider/mysql-test/spider/bugfix/r/xa_cmd.result index 3ff39317de6..846dc6c737b 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/xa_cmd.result +++ b/storage/spider/mysql-test/spider/bugfix/r/xa_cmd.result @@ -33,8 +33,6 @@ XA START 'test'; INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); XA END 'test'; XA PREPARE 'test'; -Warnings: -Warning 1030 Got error 131 "Command not supported by the engine" from storage engine Aria XA COMMIT 'test'; connection child2_1; SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; diff --git a/storage/spider/spd_copy_tables.cc b/storage/spider/spd_copy_tables.cc index 28bc5464e13..51e3b920eea 100644 --- a/storage/spider/spd_copy_tables.cc +++ b/storage/spider/spd_copy_tables.cc @@ -353,11 +353,7 @@ int spider_udf_get_copy_tgt_tables( ) { int error_num, roop_count; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; char table_key[MAX_KEY_LENGTH]; SPIDER_COPY_TABLE_CONN *table_conn = NULL, *src_table_conn_prev = NULL, *dst_table_conn_prev = NULL; diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index e0538259fb2..88371d85d5a 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -10036,9 +10036,9 @@ int spider_db_open_item_string( if (str) { THD *thd = NULL; - TABLE *table; + TABLE *UNINIT_VAR(table); my_bitmap_map *saved_map = NULL; - Time_zone *saved_time_zone; + Time_zone *UNINIT_VAR(saved_time_zone); String str_value; char tmp_buf[MAX_FIELD_WIDTH]; spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); @@ -10761,7 +10761,7 @@ int spider_db_udf_direct_sql( #else if (direct_sql->real_table_used) { - if (spider_sys_open_tables(c_thd, &direct_sql->table_list_first, + if (spider_sys_open_and_lock_tables(c_thd, &direct_sql->table_list_first, &direct_sql->open_tables_backup)) { direct_sql->real_table_used = FALSE; diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index 343e90e75b6..d339c63911d 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -238,6 +238,33 @@ const char SPIDER_empty_string = ""; #define SPIDER_get_linkage(A) A->linkage #endif +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100500 +typedef start_new_trans *SPIDER_Open_tables_backup; +#elif MYSQL_VERSION_ID < 50500 +typedef Open_tables_state SPIDER_Open_tables_backup; +#else +typedef Open_tables_backup SPIDER_Open_tables_backup; +#endif + +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100500 +#define SPIDER_reset_n_backup_open_tables_state(A,B,C) do { \ + if (!(*(B) = new start_new_trans(A))) \ + { \ + DBUG_RETURN(C); \ + } \ +} while (0) +#define SPIDER_restore_backup_open_tables_state(A,B) do { \ + (*(B))->restore_old_transaction(); \ + delete *(B); \ +} while (0) +#define SPIDER_sys_close_thread_tables(A) (A)->commit_whole_transaction_and_close_tables() +#else +#define SPIDER_REQUIRE_DEFINE_FOR_SECONDARY_OPEN_TABLES_BACKUP +#define SPIDER_reset_n_backup_open_tables_state(A,B,C) (A)->reset_n_backup_open_tables_state(B) +#define SPIDER_restore_backup_open_tables_state(A,B) (A)->restore_backup_open_tables_state(B) +#define SPIDER_sys_close_thread_tables(A) close_thread_tables(A) +#endif + #define spider_bitmap_size(A) ((A + 7) / 8) #define spider_set_bit(BITMAP, BIT) \ ((BITMAP)[(BIT) / 8] |= (1 << ((BIT) & 7))) @@ -1330,7 +1357,7 @@ typedef struct st_spider_direct_sql TABLE_LIST *table_list_first; TABLE_LIST *table_list; uchar *real_table_bitmap; - Open_tables_backup open_tables_backup; + SPIDER_Open_tables_backup open_tables_backup; THD *open_tables_thd; #endif diff --git a/storage/spider/spd_ping_table.cc b/storage/spider/spd_ping_table.cc index e233fc1fd86..18d60fddb5d 100644 --- a/storage/spider/spd_ping_table.cc +++ b/storage/spider/spd_ping_table.cc @@ -290,11 +290,7 @@ int spider_get_ping_table_mon( ) { int error_num; TABLE *table_link_mon = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; char table_key[MAX_KEY_LENGTH]; SPIDER_TABLE_MON *table_mon, *table_mon_prev = NULL; SPIDER_SHARE *tmp_share; @@ -475,11 +471,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( int *error_num ) { TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; char table_key[MAX_KEY_LENGTH]; SPIDER_TABLE_MON_LIST *table_mon_list = NULL; @@ -698,12 +690,9 @@ int spider_get_ping_table_gtid_pos( int error_num, source_link_idx, need_mon; char table_key[MAX_KEY_LENGTH]; TABLE *table_tables, *table_gtid_pos; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup_tables; - Open_tables_state open_tables_backup_gtid_pos; -#else - Open_tables_backup open_tables_backup_tables; - Open_tables_backup open_tables_backup_gtid_pos; + SPIDER_Open_tables_backup open_tables_backup_tables; +#ifdef SPIDER_REQUIRE_DEFINE_FOR_SECONDARY_OPEN_TABLES_BACKUP + SPIDER_Open_tables_backup open_tables_backup_gtid_pos; #endif MEM_ROOT mem_root; long link_status; @@ -721,6 +710,7 @@ int spider_get_ping_table_gtid_pos( db_name = setted db_name and table_name = setted table_name */ +#ifdef SPIDER_REQUIRE_DEFINE_FOR_SECONDARY_OPEN_TABLES_BACKUP if ( !(table_tables = spider_open_sys_table( thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, @@ -736,6 +726,44 @@ int spider_get_ping_table_gtid_pos( &open_tables_backup_gtid_pos, need_lock, &error_num)) ) goto error_open_table_gtid_pos; +#else + TABLE_LIST tables_tables; + TABLE_LIST tables_gtid_pos; + TABLE_LIST *tables = &tables_tables; + LEX_CSTRING db_name = + { + "mysql", + sizeof("mysql") - 1 + }; + LEX_CSTRING tbl_name_tables = + { + SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN + }; + LEX_CSTRING tbl_name_gtid_pos = + { + SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR, + SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_LEN + }; + tables_tables.init_one_table(&db_name, &tbl_name_tables, 0, TL_READ); + tables_gtid_pos.init_one_table(&db_name, &tbl_name_gtid_pos, 0, TL_READ); + MDL_REQUEST_INIT(&tables_tables.mdl_request, MDL_key::TABLE, + SPIDER_TABLE_LIST_db_str(&tables_tables), + SPIDER_TABLE_LIST_table_name_str(&tables_tables), + MDL_SHARED_READ, MDL_TRANSACTION); + MDL_REQUEST_INIT(&tables_gtid_pos.mdl_request, MDL_key::TABLE, + SPIDER_TABLE_LIST_db_str(&tables_gtid_pos), + SPIDER_TABLE_LIST_table_name_str(&tables_gtid_pos), + MDL_SHARED_READ, MDL_TRANSACTION); + tables_tables.next_global = &tables_gtid_pos; + if (spider_sys_open_and_lock_tables(thd, &tables, + &open_tables_backup_tables)) + { + goto error_open_table_tables; + } + table_tables = tables_tables.table; + table_gtid_pos = tables_gtid_pos.table; +#endif table_tables->use_all_columns(); table_gtid_pos->use_all_columns(); @@ -822,8 +850,10 @@ int spider_get_ping_table_gtid_pos( { goto error_sys_index_end; } - spider_close_sys_table(thd, table_gtid_pos, &open_tables_backup_gtid_pos, - need_lock); +#ifdef SPIDER_REQUIRE_DEFINE_FOR_SECONDARY_OPEN_TABLES_BACKUP + spider_close_sys_table(thd, table_gtid_pos, + &open_tables_backup_gtid_pos, need_lock); +#endif spider_close_sys_table(thd, table_tables, &open_tables_backup_tables, need_lock); @@ -835,9 +865,12 @@ error_get_sys_tables_link_status: spider_sys_index_end(table_tables); error_sys_index_end: error_get_sys_table_by_idx: - spider_close_sys_table(thd, table_gtid_pos, &open_tables_backup_gtid_pos, +#ifdef SPIDER_REQUIRE_DEFINE_FOR_SECONDARY_OPEN_TABLES_BACKUP + spider_close_sys_table(thd, table_gtid_pos, + &open_tables_backup_gtid_pos, need_lock); error_open_table_gtid_pos: +#endif spider_close_sys_table(thd, table_tables, &open_tables_backup_tables, need_lock); error_open_table_tables: @@ -852,11 +885,7 @@ int spider_init_ping_table_mon_cache( int error_num, same; uint old_elements; TABLE *table_link_mon = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; SPIDER_MON_KEY mon_key; DBUG_ENTER("spider_init_ping_table_mon_cache"); diff --git a/storage/spider/spd_sys_table.cc b/storage/spider/spd_sys_table.cc index 899689bc863..0ed8640eb48 100644 --- a/storage/spider/spd_sys_table.cc +++ b/storage/spider/spd_sys_table.cc @@ -228,28 +228,15 @@ inline int spider_delete_sys_table_row(TABLE *table, int record_number = 0, return error_num; } -#if MYSQL_VERSION_ID < 50500 TABLE *spider_open_sys_table( THD *thd, const char *table_name, int table_name_length, bool write, - Open_tables_state *open_tables_backup, + SPIDER_Open_tables_backup *open_tables_backup, bool need_lock, int *error_num -) -#else -TABLE *spider_open_sys_table( - THD *thd, - const char *table_name, - int table_name_length, - bool write, - Open_tables_backup *open_tables_backup, - bool need_lock, - int *error_num -) -#endif -{ +) { TABLE *table; TABLE_LIST tables; #if MYSQL_VERSION_ID < 50500 @@ -306,7 +293,7 @@ TABLE *spider_open_sys_table( } #if MYSQL_VERSION_ID < 50500 } else { - thd->reset_n_backup_open_tables_state(open_tables_backup); + SPIDER_reset_n_backup_open_tables_state(thd, open_tables_backup, NULL); if (!(table = (TABLE*) spider_malloc(spider_current_trx, 12, sizeof(*table), MYF(MY_WME)))) @@ -601,28 +588,18 @@ TABLE *spider_open_sys_table( error: spider_free(spider_current_trx, table, MYF(0)); error_malloc: - thd->restore_backup_open_tables_state(open_tables_backup); + SPIDER_restore_backup_open_tables_state(thd, open_tables_backup); #endif error_col_num_chk: DBUG_RETURN(NULL); } -#if MYSQL_VERSION_ID < 50500 -void spider_close_sys_table( - THD *thd, - TABLE *table, - Open_tables_state *open_tables_backup, - bool need_lock -) -#else void spider_close_sys_table( THD *thd, TABLE *table, - Open_tables_backup *open_tables_backup, + SPIDER_Open_tables_backup *open_tables_backup, bool need_lock -) -#endif -{ +) { DBUG_ENTER("spider_close_sys_table"); #if MYSQL_VERSION_ID < 50500 if (need_lock) @@ -632,7 +609,7 @@ void spider_close_sys_table( table->file->ha_reset(); closefrm(table, TRUE); spider_free(spider_current_trx, table, MYF(0)); - thd->restore_backup_open_tables_state(open_tables_backup); + SPIDER_restore_backup_open_tables_state(thd, open_tables_backup); } #else spider_sys_close_table(thd, open_tables_backup); @@ -642,20 +619,28 @@ void spider_close_sys_table( #if MYSQL_VERSION_ID < 50500 #else -bool spider_sys_open_tables( +bool spider_sys_open_and_lock_tables( THD *thd, TABLE_LIST **tables, - Open_tables_backup *open_tables_backup + SPIDER_Open_tables_backup *open_tables_backup ) { uint counter; + uint flags = MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | + MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | MYSQL_OPEN_IGNORE_FLUSH | + MYSQL_LOCK_IGNORE_TIMEOUT | MYSQL_LOCK_LOG_TABLE; ulonglong utime_after_lock_backup = thd->utime_after_lock; - DBUG_ENTER("spider_sys_open_tables"); - thd->reset_n_backup_open_tables_state(open_tables_backup); - if (open_tables(thd, tables, &counter, - MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | - MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT | MYSQL_LOCK_LOG_TABLE - )) { - thd->restore_backup_open_tables_state(open_tables_backup); + DBUG_ENTER("spider_sys_open_and_lock_tables"); + SPIDER_reset_n_backup_open_tables_state(thd, open_tables_backup, TRUE); + if (open_tables(thd, tables, &counter, flags)) + { + SPIDER_restore_backup_open_tables_state(thd, open_tables_backup); + thd->utime_after_lock = utime_after_lock_backup; + DBUG_RETURN(TRUE); + } + if (lock_tables(thd, *tables, counter, flags)) + { + SPIDER_sys_close_thread_tables(thd); + SPIDER_restore_backup_open_tables_state(thd, open_tables_backup); thd->utime_after_lock = utime_after_lock_backup; DBUG_RETURN(TRUE); } @@ -666,13 +651,15 @@ bool spider_sys_open_tables( TABLE *spider_sys_open_table( THD *thd, TABLE_LIST *tables, - Open_tables_backup *open_tables_backup + SPIDER_Open_tables_backup *open_tables_backup ) { TABLE *table; ulonglong utime_after_lock_backup = thd->utime_after_lock; DBUG_ENTER("spider_sys_open_table"); if (open_tables_backup) - thd->reset_n_backup_open_tables_state(open_tables_backup); + { + SPIDER_reset_n_backup_open_tables_state(thd, open_tables_backup, NULL); + } if ((table = open_ltable(thd, tables, tables->lock_type, MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT | MYSQL_LOCK_LOG_TABLE @@ -680,19 +667,23 @@ TABLE *spider_sys_open_table( table->use_all_columns(); table->s->no_replicate = 1; } else if (open_tables_backup) - thd->restore_backup_open_tables_state(open_tables_backup); + { + SPIDER_restore_backup_open_tables_state(thd, open_tables_backup); + } thd->utime_after_lock = utime_after_lock_backup; DBUG_RETURN(table); } void spider_sys_close_table( THD *thd, - Open_tables_backup *open_tables_backup + SPIDER_Open_tables_backup *open_tables_backup ) { DBUG_ENTER("spider_sys_close_table"); - close_thread_tables(thd); if (open_tables_backup) - thd->restore_backup_open_tables_state(open_tables_backup); + { + SPIDER_sys_close_thread_tables(thd); + SPIDER_restore_backup_open_tables_state(thd, open_tables_backup); + } DBUG_VOID_RETURN; } #endif @@ -2879,11 +2870,7 @@ int spider_sys_update_tables_link_status( ) { int error_num; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; DBUG_ENTER("spider_sys_update_tables_link_status"); if ( !(table_tables = spider_open_sys_table( @@ -2917,11 +2904,7 @@ int spider_sys_log_tables_link_failed( ) { int error_num; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; DBUG_ENTER("spider_sys_log_tables_link_failed"); if ( !(table_tables = spider_open_sys_table( @@ -2956,11 +2939,7 @@ int spider_sys_log_xa_failed( ) { int error_num; TABLE *table_tables = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; DBUG_ENTER("spider_sys_log_xa_failed"); if ( !(table_tables = spider_open_sys_table( @@ -3305,11 +3284,7 @@ int spider_sys_insert_or_update_table_sts( ) { int error_num; TABLE *table_sts = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; DBUG_ENTER("spider_sys_insert_or_update_table_sts"); if ( !(table_sts = spider_open_sys_table( @@ -3346,11 +3321,7 @@ int spider_sys_insert_or_update_table_crd( ) { int error_num; TABLE *table_crd = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; DBUG_ENTER("spider_sys_insert_or_update_table_crd"); if ( !(table_crd = spider_open_sys_table( @@ -3386,11 +3357,7 @@ int spider_sys_delete_table_sts( ) { int error_num; TABLE *table_sts = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; DBUG_ENTER("spider_sys_delete_table_sts"); if ( !(table_sts = spider_open_sys_table( @@ -3424,11 +3391,7 @@ int spider_sys_delete_table_crd( ) { int error_num; TABLE *table_crd = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; DBUG_ENTER("spider_sys_delete_table_crd"); if ( !(table_crd = spider_open_sys_table( @@ -3464,11 +3427,7 @@ int spider_sys_get_table_sts( int error_num; char table_key[MAX_KEY_LENGTH]; TABLE *table_sts = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; DBUG_ENTER("spider_sys_get_table_sts"); if ( !(table_sts = spider_open_sys_table( @@ -3517,17 +3476,14 @@ int spider_sys_get_table_crd( char table_key[MAX_KEY_LENGTH]; bool index_inited = FALSE; TABLE *table_crd = NULL; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; DBUG_ENTER("spider_sys_get_table_crd"); - start_new_trans new_trans(thd); if ( !(table_crd = spider_open_sys_table( thd, SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR, SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN, TRUE, - 0, need_lock, &error_num)) + &open_tables_backup, need_lock, &error_num)) ) { goto error; } @@ -3560,8 +3516,8 @@ int spider_sys_get_table_crd( goto error; } - thd->commit_whole_transaction_and_close_tables(); - new_trans.restore_old_transaction(); + spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock); + table_crd = NULL; DBUG_RETURN(0); error: @@ -3569,8 +3525,7 @@ error: spider_sys_index_end(table_crd); if (table_crd) - thd->commit_whole_transaction_and_close_tables(); - new_trans.restore_old_transaction(); + spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock); DBUG_RETURN(error_num); } diff --git a/storage/spider/spd_sys_table.h b/storage/spider/spd_sys_table.h index eb87cd5268f..d5faf6793d4 100644 --- a/storage/spider/spd_sys_table.h +++ b/storage/spider/spd_sys_table.h @@ -86,30 +86,12 @@ public: uint link_id_length; }; -#if MYSQL_VERSION_ID < 50500 -TABLE *spider_open_sys_table( - THD *thd, - const char *table_name, - int table_name_length, - bool write, - Open_tables_state *open_tables_backup, - bool need_lock, - int *error_num -); - -void spider_close_sys_table( - THD *thd, - TABLE *table, - Open_tables_state *open_tables_backup, - bool need_lock -); -#else TABLE *spider_open_sys_table( THD *thd, const char *table_name, int table_name_length, bool write, - Open_tables_backup *open_tables_backup, + SPIDER_Open_tables_backup *open_tables_backup, bool need_lock, int *error_num ); @@ -117,25 +99,27 @@ TABLE *spider_open_sys_table( void spider_close_sys_table( THD *thd, TABLE *table, - Open_tables_backup *open_tables_backup, + SPIDER_Open_tables_backup *open_tables_backup, bool need_lock ); -bool spider_sys_open_tables( +#if MYSQL_VERSION_ID < 50500 +#else +bool spider_sys_open_and_lock_tables( THD *thd, TABLE_LIST **tables, - Open_tables_backup *open_tables_backup + SPIDER_Open_tables_backup *open_tables_backup ); TABLE *spider_sys_open_table( THD *thd, TABLE_LIST *tables, - Open_tables_backup *open_tables_backup + SPIDER_Open_tables_backup *open_tables_backup ); void spider_sys_close_table( THD *thd, - Open_tables_backup *open_tables_backup + SPIDER_Open_tables_backup *open_tables_backup ); #endif diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index 1f0dcb82e8f..1664b4a1bf5 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -4906,11 +4906,7 @@ SPIDER_SHARE *spider_get_share( int semi_table_lock_conn; int search_link_idx; uint sql_command = thd_sql_command(thd); -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; MEM_ROOT mem_root; TABLE *table_tables = NULL; bool init_mem_root = FALSE; @@ -5047,11 +5043,10 @@ SPIDER_SHARE *spider_get_share( SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); init_mem_root = TRUE; - start_new_trans new_trans(thd); if ( !(table_tables = spider_open_sys_table( thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, - SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, 0, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup, FALSE, error_num)) ) { for (roop_count = 0; @@ -5088,8 +5083,9 @@ SPIDER_SHARE *spider_get_share( share->init_error_time = (time_t) time((time_t*) 0); share->init = TRUE; spider_free_share(share); - thd->commit_whole_transaction_and_close_tables(); - new_trans.restore_old_transaction(); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, FALSE); + table_tables = NULL; goto error_open_sys_table; } } else { @@ -5097,8 +5093,9 @@ SPIDER_SHARE *spider_get_share( sizeof(long) * share->all_link_count); share->link_status_init = TRUE; } - thd->commit_whole_transaction_and_close_tables(); - new_trans.restore_old_transaction(); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, FALSE); + table_tables = NULL; } share->have_recovery_link = spider_conn_check_recovery_link(share); if (init_mem_root) @@ -5604,12 +5601,11 @@ SPIDER_SHARE *spider_get_share( { SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); init_mem_root = TRUE; - start_new_trans new_trans(thd); if ( !(table_tables = spider_open_sys_table( thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, - SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, 0, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup, FALSE, error_num)) ) { for (roop_count = 0; @@ -5640,8 +5636,9 @@ SPIDER_SHARE *spider_get_share( } pthread_mutex_unlock(&share->mutex); spider_free_share(share); - thd->commit_whole_transaction_and_close_tables(); - new_trans.restore_old_transaction(); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, FALSE); + table_tables = NULL; goto error_open_sys_table; } } else { @@ -5649,9 +5646,9 @@ SPIDER_SHARE *spider_get_share( sizeof(long) * share->all_link_count); share->link_status_init = TRUE; } - thd->commit_whole_transaction_and_close_tables(); - new_trans.restore_old_transaction(); - table_tables= 0; + spider_close_sys_table(thd, table_tables, + &open_tables_backup, FALSE); + table_tables = NULL; } share->have_recovery_link = spider_conn_check_recovery_link(share); if (init_mem_root) @@ -6601,11 +6598,7 @@ int spider_open_all_tables( long *long_info; longlong *longlong_info; MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; DBUG_ENTER("spider_open_all_tables"); if ( !(table_tables = spider_open_sys_table( @@ -9603,7 +9596,7 @@ int spider_discover_table_structure( #ifdef WITH_PARTITION_STORAGE_ENGINE partition_info *part_info = thd->work_part_info; #endif - Open_tables_backup open_tables_backup; + SPIDER_Open_tables_backup open_tables_backup; TABLE *table_tables; #ifdef WITH_PARTITION_STORAGE_ENGINE uint str_len; diff --git a/storage/spider/spd_trx.cc b/storage/spider/spd_trx.cc index 78af5623b94..0eda9d31df6 100644 --- a/storage/spider/spd_trx.cc +++ b/storage/spider/spd_trx.cc @@ -2136,11 +2136,7 @@ int spider_internal_xa_commit( SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; DBUG_ENTER("spider_internal_xa_commit"); @@ -2324,11 +2320,7 @@ int spider_internal_xa_rollback( SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; bool server_lost = FALSE; bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; @@ -2566,11 +2558,7 @@ int spider_internal_xa_prepare( int error_num; SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; DBUG_ENTER("spider_internal_xa_prepare"); @@ -2741,11 +2729,7 @@ int spider_internal_xa_recover( int cnt = 0; char xa_key[MAX_KEY_LENGTH]; MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; DBUG_ENTER("spider_internal_xa_recover"); /* select @@ -2800,50 +2784,24 @@ int spider_initinal_xa_recover( uint len ) { int error_num; - static THD *thd = NULL; - static TABLE *table_xa = NULL; - static READ_RECORD *read_record = NULL; -#if MYSQL_VERSION_ID < 50500 - static Open_tables_state *open_tables_backup = NULL; -#else - static Open_tables_backup *open_tables_backup = NULL; -#endif + THD *thd; + TABLE *table_xa; + READ_RECORD *read_record; + SPIDER_Open_tables_backup open_tables_backup; int cnt = 0; MEM_ROOT mem_root; DBUG_ENTER("spider_initinal_xa_recover"); - if (!open_tables_backup) + if (!(read_record = new READ_RECORD)) { -#if MYSQL_VERSION_ID < 50500 - if (!(open_tables_backup = new Open_tables_state)) -#else - if (!(open_tables_backup = new Open_tables_backup)) -#endif - { - error_num = HA_ERR_OUT_OF_MEM; - goto error_create_state; - } - } - if (!read_record) - { - if (!(read_record = new READ_RECORD)) - { - error_num = HA_ERR_OUT_OF_MEM; - goto error_create_read_record; - } + error_num = HA_ERR_OUT_OF_MEM; + goto error_create_read_record; } -/* - if (!thd) + if (!(thd = spider_create_tmp_thd())) { -*/ - if (!(thd = spider_create_tmp_thd())) - { - error_num = HA_ERR_OUT_OF_MEM; - goto error_create_thd; - } -/* + error_num = HA_ERR_OUT_OF_MEM; + goto error_create_thd; } -*/ /* select @@ -2854,17 +2812,14 @@ int spider_initinal_xa_recover( from mysql.spider_xa */ - if (!table_xa) - { - if ( - !(table_xa = spider_open_sys_table( - thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, - FALSE, open_tables_backup, TRUE, &error_num)) - ) - goto error_open_table; - SPIDER_init_read_record(read_record, thd, table_xa, NULL, NULL, TRUE, - FALSE, FALSE); - } + if ( + !(table_xa = spider_open_sys_table( + thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, + FALSE, &open_tables_backup, TRUE, &error_num)) + ) + goto error_open_table; + SPIDER_init_read_record(read_record, thd, table_xa, NULL, NULL, TRUE, + FALSE, FALSE); SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); while ((!(read_record->SPIDER_read_record_read_record(read_record))) && cnt < (int) len) @@ -2874,30 +2829,15 @@ int spider_initinal_xa_recover( } free_root(&mem_root, MYF(0)); -/* - if (cnt < (int) len) - { -*/ - end_read_record(read_record); - spider_close_sys_table(thd, table_xa, open_tables_backup, TRUE); - table_xa = NULL; - spider_free_tmp_thd(thd); - thd = NULL; - delete read_record; - read_record = NULL; - delete open_tables_backup; - open_tables_backup = NULL; -/* - } -*/ - DBUG_RETURN(cnt); - -/* -error: - end_read_record(&read_record_info); + end_read_record(read_record); spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); table_xa = NULL; -*/ + spider_free_tmp_thd(thd); + thd = NULL; + delete read_record; + read_record = NULL; + DBUG_RETURN(cnt); + error_open_table: spider_free_tmp_thd(thd); thd = NULL; @@ -2905,9 +2845,6 @@ error_create_thd: delete read_record; read_record = NULL; error_create_read_record: - delete open_tables_backup; - open_tables_backup = NULL; -error_create_state: DBUG_RETURN(0); } @@ -2928,11 +2865,7 @@ int spider_internal_xa_commit_by_xid( SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; DBUG_ENTER("spider_internal_xa_commit_by_xid"); @@ -3163,11 +3096,7 @@ int spider_internal_xa_rollback_by_xid( SPIDER_CONN *conn; uint force_commit = spider_param_force_commit(thd); MEM_ROOT mem_root; -#if MYSQL_VERSION_ID < 50500 - Open_tables_state open_tables_backup; -#else - Open_tables_backup open_tables_backup; -#endif + SPIDER_Open_tables_backup open_tables_backup; bool table_xa_opened = FALSE; bool table_xa_member_opened = FALSE; DBUG_ENTER("spider_internal_xa_rollback_by_xid"); -- cgit v1.2.1 From 65f30050aafb3821ba63a3b837c98cf4d2334254 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Mon, 24 Aug 2020 17:22:21 +0530 Subject: MDEV-18335: Assertion `!error || error == 137' failed in subselect_rowid_merge_engine::init When duplicates are removed from a table using a hash, if the record is a duplicate it is marked as deleted. The handler API check if the record is deleted and send an error flag HA_ERR_RECORD_DELETED. When we scan over the table if the thread is not killed then we skip the records marked as HA_ERR_RECORD_DELETED. The issue here is when a query is aborted by a user (this is happening when the LIMIT for ROWS EXAMINED is exceeded), the scan over the table does not skip the records for which HA_ERR_RECORD_DELETED is sent. It just returns an error flag HA_ERR_ABORTED_BY_USER. This error flag is not checked at the upper level and hence we hit the assert. If the query is aborted by the user we should just skip reading rows and return control to the upper levels of execution. --- mysql-test/main/subselect4.result | 31 +++++++++++++++++++++++++++++++ mysql-test/main/subselect4.test | 36 ++++++++++++++++++++++++++++++++++++ sql/item_subselect.cc | 3 +++ 3 files changed, 70 insertions(+) diff --git a/mysql-test/main/subselect4.result b/mysql-test/main/subselect4.result index d1d3b514549..020a7064291 100644 --- a/mysql-test/main/subselect4.result +++ b/mysql-test/main/subselect4.result @@ -2686,4 +2686,35 @@ SELECT * FROM t2; f bar DROP TABLE t1, t2; +# +# MDEV-18335: Assertion `!error || error == 137' failed in subselect_rowid_merge_engine::init +# +CREATE TABLE t1 (i1 int,v1 varchar(1),KEY (v1,i1)); +INSERT INTO t1 VALUES +(9,'y'),(4,'q'),(0,null),(0,'p'),(null,'j'); +CREATE TABLE t2 (pk int); +INSERT INTO t2 VALUES (1),(2); +CREATE TABLE t3 (v2 varchar(1)); +INSERT INTO t3 VALUES +('p'),('j'),('y'),('q'); +CREATE TABLE t4 (v2 varchar(1)); +INSERT INTO t4 VALUES +('a'),('a'),('b'),('b'),('c'),('c'), +('d'),('d'),('e'),('e'),('f'),('f'), +('g'),('g'),('h'),('h'),('i'),('i'), +('j'),('j'),('k'),('k'),('l'),('l'), +('m'),('m'),('n'),('n'),('o'),('o'), +('p'),('p'),('q'),('q'),('r'),('r'), +('s'),('s'),('t'),('t'),('u'),('u'),('v'),('v'), +('w'),('w'),('x'),('x'), (NULL),(NULL); +SET @save_join_cache_level=@@join_cache_level; +SET join_cache_level=0; +select 1 +from t2 join t1 on +('i','w') not in (select t1.v1,t4.v2 from t4,t1,t3 where t3.v2 = t1.v1) LIMIT ROWS EXAMINED 500; +1 +Warnings: +Warning 1931 Query execution was interrupted. The query examined at least 3020 rows, which exceeds LIMIT ROWS EXAMINED (500). The query result may be incomplete +SET join_cache_level= @save_join_cache_level; +DROP TABLE t1,t2,t3,t4; # End of 10.2 tests diff --git a/mysql-test/main/subselect4.test b/mysql-test/main/subselect4.test index 6eada9b27d9..6f5eb1f2985 100644 --- a/mysql-test/main/subselect4.test +++ b/mysql-test/main/subselect4.test @@ -2201,4 +2201,40 @@ SELECT * FROM t2; DROP TABLE t1, t2; +--echo # +--echo # MDEV-18335: Assertion `!error || error == 137' failed in subselect_rowid_merge_engine::init +--echo # + +CREATE TABLE t1 (i1 int,v1 varchar(1),KEY (v1,i1)); +INSERT INTO t1 VALUES +(9,'y'),(4,'q'),(0,null),(0,'p'),(null,'j'); + +CREATE TABLE t2 (pk int); +INSERT INTO t2 VALUES (1),(2); + +CREATE TABLE t3 (v2 varchar(1)); +INSERT INTO t3 VALUES +('p'),('j'),('y'),('q'); + +CREATE TABLE t4 (v2 varchar(1)); +INSERT INTO t4 VALUES +('a'),('a'),('b'),('b'),('c'),('c'), +('d'),('d'),('e'),('e'),('f'),('f'), +('g'),('g'),('h'),('h'),('i'),('i'), +('j'),('j'),('k'),('k'),('l'),('l'), +('m'),('m'),('n'),('n'),('o'),('o'), +('p'),('p'),('q'),('q'),('r'),('r'), +('s'),('s'),('t'),('t'),('u'),('u'),('v'),('v'), +('w'),('w'),('x'),('x'), (NULL),(NULL); + +SET @save_join_cache_level=@@join_cache_level; +SET join_cache_level=0; + +select 1 +from t2 join t1 on +('i','w') not in (select t1.v1,t4.v2 from t4,t1,t3 where t3.v2 = t1.v1) LIMIT ROWS EXAMINED 500; +SET join_cache_level= @save_join_cache_level; + +DROP TABLE t1,t2,t3,t4; + --echo # End of 10.2 tests diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index c32cd5ef84a..bc5111667ff 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -6281,6 +6281,9 @@ subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts, while (TRUE) { error= tmp_table->file->ha_rnd_next(tmp_table->record[0]); + + if (error == HA_ERR_ABORTED_BY_USER) + break; /* This is a temp table that we fully own, there should be no other cause to stop the iteration than EOF. -- cgit v1.2.1 From 21a96581fd1dd11c5605dd89e3adbaabdf6de5eb Mon Sep 17 00:00:00 2001 From: Stepan Patryshev Date: Wed, 26 Aug 2020 04:16:55 +0300 Subject: MDEV-23583 Fix up community suite/galera_3nodes/disabled.def --- mysql-test/suite/galera_3nodes/disabled.def | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mysql-test/suite/galera_3nodes/disabled.def b/mysql-test/suite/galera_3nodes/disabled.def index 1683485981b..415da407cf7 100644 --- a/mysql-test/suite/galera_3nodes/disabled.def +++ b/mysql-test/suite/galera_3nodes/disabled.def @@ -1,2 +1,21 @@ +############################################################################## +# +# List the test cases that are to be disabled temporarily. +# +# Separate the test case name and the comment with ':'. +# +# : MDEV- +# +# Do not use any TAB characters for whitespace. +# +############################################################################## + +galera_ipv6_mariabackup : MDEV-23573 Could not open '../galera/include/have_mariabackup.inc' +galera_ipv6_mariabackup_section : MDEV-23574 Could not open '../galera/include/have_mariabackup.inc' +galera_ipv6_mysqldump : MDEV-23576 WSREP_SST: [ERROR] rsync daemon port '16008' has been taken +galera_ipv6_rsyn : MDEV-23581 WSREP_SST: [ERROR] rsync daemon port '16008' has been taken +galera_ipv6_rsync_section : MDEV-23580 WSREP_SST: [ERROR] rsync daemon port '16008' has been taken +galera_ipv6_xtrabackup-v2 : MDEV-23575 WSREP_SST: [ERROR] innobackupex not in path +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 -- cgit v1.2.1 From 571764c04fc9b736366959b2c0e00d9bd0eb5a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 26 Aug 2020 13:32:15 +0300 Subject: MDEV-23584 : Galera assertion failure "thd->transaction.stmt.is_empty() at transaction.cc:69 If statement still contains changes it must be committed before actual transaction is committed. This assertion was found using randgen and happens only on applier. No repeatable test case found. --- sql/wsrep_high_priority_service.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sql/wsrep_high_priority_service.cc b/sql/wsrep_high_priority_service.cc index ec195bb57cf..0aeedbd7516 100644 --- a/sql/wsrep_high_priority_service.cc +++ b/sql/wsrep_high_priority_service.cc @@ -301,9 +301,15 @@ int Wsrep_high_priority_service::commit(const wsrep::ws_handle& ws_handle, DBUG_ASSERT(thd->wsrep_trx().active()); thd->wsrep_cs().prepare_for_ordering(ws_handle, ws_meta, true); thd_proc_info(thd, "committing"); + int ret=0; const bool is_ordered= !ws_meta.seqno().is_undefined(); - int ret= trans_commit(thd); + + if (!thd->transaction.stmt.is_empty()) + ret= trans_commit_stmt(thd); + + if (ret == 0) + ret= trans_commit(thd); if (ret == 0) { -- cgit v1.2.1 From b47d61d04fe59368a4d2c2de1bd04d9a8b5a20e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 27 Aug 2020 09:34:53 +0300 Subject: MDEV-23585: Fix HAVE_CLMUL_INSTRUCTION MDEV-22641 in commit dec3f8ca69e5eb19a4be7a175d3834874c4d880b refactored a SIMD implementation of CRC-32 for the ISO 3309 polynomial that uses the IA-32/AMD64 carry-less multiplication (pclmul) instructions. The code was previously only available in Mariabackup; it was changed to be a general replacement of the zlib crc32(). There exist AMD64 systems where CMAKE_SYSTEM_PROCESSOR matches the pattern i[36]86 but not x86_64 or amd64. This would cause a link failure, because mysys/checksum.c would basically assume that the compiler support for instruction is always available on GCC-compatible compilers on AMD64. Furthermore, we were unnecessarily disabling the SIMD acceleration for 32-bit executables. Note: Until MDEV-22749 has been implemented, the PCLMUL instruction will not be used on Microsoft Windows. Closes: #1660 --- config.h.cmake | 2 ++ mysys/CMakeLists.txt | 2 +- mysys/checksum.c | 3 +-- mysys/crc32/crc32_x86.c | 3 --- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/config.h.cmake b/config.h.cmake index ff0a039b3ac..0de5c2be3e0 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -102,6 +102,8 @@ /* Libraries */ #cmakedefine HAVE_LIBWRAP 1 #cmakedefine HAVE_SYSTEMD 1 + +#cmakedefine HAVE_CLMUL_INSTRUCTION 1 #cmakedefine HAVE_CRC32_VPMSUM 1 /* Support ARMv8 crc + crypto */ diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index 14a4ea9e9bb..3122decfde1 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -58,7 +58,7 @@ IF (WIN32) my_win_popen.cc) ENDIF() -IF(NOT MSVC AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64") +IF(NOT MSVC AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i[36]86") #Check for PCLMUL instruction (x86) CHECK_C_SOURCE_COMPILES(" int main() diff --git a/mysys/checksum.c b/mysys/checksum.c index 948b9be6164..6e6633600a9 100644 --- a/mysys/checksum.c +++ b/mysys/checksum.c @@ -30,8 +30,7 @@ static unsigned int my_crc32_zlib(unsigned int crc, const void *data, my_crc32_t my_checksum= my_crc32_zlib; #endif -#if __GNUC__ >= 4 && defined(__x86_64__) - +#ifdef HAVE_CLMUL_INSTRUCTION extern int crc32_pclmul_enabled(); extern unsigned int crc32_pclmul(unsigned int, const void *, size_t); diff --git a/mysys/crc32/crc32_x86.c b/mysys/crc32/crc32_x86.c index 3f176a6c145..608ba3927c7 100644 --- a/mysys/crc32/crc32_x86.c +++ b/mysys/crc32/crc32_x86.c @@ -57,8 +57,6 @@ typedef uint8_t byte; # define _gcry_bswap32 __builtin_bswap32 -#if __GNUC__ >= 4 && defined(__x86_64__) - #if defined(_GCRY_GCC_VERSION) && _GCRY_GCC_VERSION >= 40400 /* 4.4 */ /* Prevent compiler from issuing SSE instructions between asm blocks. */ # pragma GCC target("no-sse") @@ -542,4 +540,3 @@ unsigned int crc32_pclmul(unsigned int crc32, const void *buf, size_t len) crc32_intel_pclmul(&crc32, buf, len); return ~crc32; } -#endif -- cgit v1.2.1 From 05aa7ae7ba667ae9f35ad762ea435a67dcc58c0d Mon Sep 17 00:00:00 2001 From: Kentoku SHIBA Date: Wed, 26 Aug 2020 22:25:26 +0900 Subject: Fix a compiler warning --- storage/spider/spd_ping_table.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/spider/spd_ping_table.cc b/storage/spider/spd_ping_table.cc index 18d60fddb5d..f220a9d97c2 100644 --- a/storage/spider/spd_ping_table.cc +++ b/storage/spider/spd_ping_table.cc @@ -759,6 +759,7 @@ int spider_get_ping_table_gtid_pos( if (spider_sys_open_and_lock_tables(thd, &tables, &open_tables_backup_tables)) { + error_num = my_errno; goto error_open_table_tables; } table_tables = tables_tables.table; -- cgit v1.2.1 From fe5dbfe723427a3606c41409626dc853f997e679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 27 Aug 2020 11:42:35 +0300 Subject: MDEV-23585: Fix the 32-bit build on GCC 4 GCC before version 5 would fail to emit the CPUID instruction when targeting IA-32 in -fPIC mode. Therefore, we must add the CPUID instruction to the HAVE_CLMUL_INSTRUCTION check. This means that the PCLMUL accelerated crc32() function will not be available on i686 executables that are compiled with GCC 4. The limitation does not impact AMD64 builds or non-PIC x86 builds, or other compilers (clang, or GCC 5 or newer). --- mysys/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index 3122decfde1..f72608aa1a9 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -59,10 +59,12 @@ IF (WIN32) ENDIF() IF(NOT MSVC AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i[36]86") - #Check for PCLMUL instruction (x86) + #Check for CPUID and PCLMUL. GCC before version 5 would refuse to emit the + #CPUID instruction for -m32 -fPIC because it would clobber the EBX register. CHECK_C_SOURCE_COMPILES(" int main() { + asm volatile (\"cpuid\" : : \"a\"(1) : \"ebx\"); asm volatile (\"pclmulqdq \\$0x00, %%xmm1, %%xmm0\":::\"cc\"); return 0; }" HAVE_CLMUL_INSTRUCTION) -- cgit v1.2.1 From b3e43eeec72ed5678bd9364b75ea4adf3a2fb881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 27 Aug 2020 13:52:15 +0300 Subject: Remove xtrabackup and innobackupex test cases. --- .../r/galera_innobackupex_backup.result | 17 ----- .../r/galera_ipv6_xtrabackup-v2.result | 22 ------ .../galera_3nodes/t/galera_innobackupex_backup.cnf | 4 -- .../t/galera_innobackupex_backup.test | 80 ---------------------- .../galera_3nodes/t/galera_ipv6_xtrabackup-v2.cnf | 29 -------- .../galera_3nodes/t/galera_ipv6_xtrabackup-v2.opt | 1 - .../galera_3nodes/t/galera_ipv6_xtrabackup-v2.test | 58 ---------------- 7 files changed, 211 deletions(-) delete mode 100644 mysql-test/suite/galera_3nodes/r/galera_innobackupex_backup.result delete mode 100644 mysql-test/suite/galera_3nodes/r/galera_ipv6_xtrabackup-v2.result delete mode 100644 mysql-test/suite/galera_3nodes/t/galera_innobackupex_backup.cnf delete mode 100644 mysql-test/suite/galera_3nodes/t/galera_innobackupex_backup.test delete mode 100644 mysql-test/suite/galera_3nodes/t/galera_ipv6_xtrabackup-v2.cnf delete mode 100644 mysql-test/suite/galera_3nodes/t/galera_ipv6_xtrabackup-v2.opt delete mode 100644 mysql-test/suite/galera_3nodes/t/galera_ipv6_xtrabackup-v2.test diff --git a/mysql-test/suite/galera_3nodes/r/galera_innobackupex_backup.result b/mysql-test/suite/galera_3nodes/r/galera_innobackupex_backup.result deleted file mode 100644 index 6ed7587303d..00000000000 --- a/mysql-test/suite/galera_3nodes/r/galera_innobackupex_backup.result +++ /dev/null @@ -1,17 +0,0 @@ -connection node_1; -connection node_2; -connection node_3; -connection node_1; -CREATE TABLE t1 (f1 INTEGER); -INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); -connection node_2; -SELECT COUNT(*) = 10 FROM t1; -COUNT(*) = 10 -1 -Killing server ... -connection node_1; -INSERT INTO t1 VALUES (11),(12),(13),(14),(15),(16),(17),(18),(19),(20); -SELECT COUNT(*) = 20 FROM t1; -COUNT(*) = 20 -1 -DROP TABLE t1; diff --git a/mysql-test/suite/galera_3nodes/r/galera_ipv6_xtrabackup-v2.result b/mysql-test/suite/galera_3nodes/r/galera_ipv6_xtrabackup-v2.result deleted file mode 100644 index 5665ed5f46a..00000000000 --- a/mysql-test/suite/galera_3nodes/r/galera_ipv6_xtrabackup-v2.result +++ /dev/null @@ -1,22 +0,0 @@ -SELECT VARIABLE_VALUE LIKE '%[::1]%' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_incoming_addresses'; -VARIABLE_VALUE LIKE '%[::1]%' -1 -SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -VARIABLE_VALUE = 3 -1 -connection node_2; -SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; -connection node_1; -CREATE TABLE t1 (f1 INTEGER) 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 -1 -DROP TABLE t1; -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\]] diff --git a/mysql-test/suite/galera_3nodes/t/galera_innobackupex_backup.cnf b/mysql-test/suite/galera_3nodes/t/galera_innobackupex_backup.cnf deleted file mode 100644 index 35ecb8b5937..00000000000 --- a/mysql-test/suite/galera_3nodes/t/galera_innobackupex_backup.cnf +++ /dev/null @@ -1,4 +0,0 @@ -!include ../galera_3nodes.cnf - -[mysqld] -wsrep-causal-reads=OFF diff --git a/mysql-test/suite/galera_3nodes/t/galera_innobackupex_backup.test b/mysql-test/suite/galera_3nodes/t/galera_innobackupex_backup.test deleted file mode 100644 index 8dfb4660f3e..00000000000 --- a/mysql-test/suite/galera_3nodes/t/galera_innobackupex_backup.test +++ /dev/null @@ -1,80 +0,0 @@ -# -# This test uses innobackupex to take a backup on node #2 and then restores that node from backup -# - ---source include/galera_cluster.inc ---source include/have_innodb.inc ---source include/have_mariabackup.inc - ---let $galera_connection_name = node_3 ---let $galera_server_number = 3 ---source include/galera_connect.inc - -# Save original auto_increment_offset values. ---let $node_1=node_1 ---let $node_2=node_2 ---let $node_3=node_3 ---source ../galera/include/auto_increment_offset_save.inc - ---connection node_1 -CREATE TABLE t1 (f1 INTEGER); -INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); - ---connection node_2 -SELECT COUNT(*) = 10 FROM t1; - ---exec rm -rf $MYSQL_TMP_DIR/innobackupex_backup ---exec mariabackup --innobackupex --defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group=mysqld.2 --galera-info --port=$NODE_MYPORT_2 --host=127.0.0.1 --no-timestamp $MYSQL_TMP_DIR/innobackupex_backup &> $MYSQL_TMP_DIR/innobackupex-backup.log ---exec mariabackup --innobackupex --defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group=mysqld.2 --apply-log --galera-info --port=$NODE_MYPORT_2 --host=127.0.0.1 --no-timestamp $MYSQL_TMP_DIR/innobackupex_backup &> $MYSQL_TMP_DIR/innobackupex-apply.log - ---source ../galera/include/kill_galera.inc ---sleep 1 - ---connection node_1 -INSERT INTO t1 VALUES (11),(12),(13),(14),(15),(16),(17),(18),(19),(20); - ---exec rm -rf $MYSQLTEST_VARDIR/mysqld.2/data/* ---exec mariabackup --innobackupex --defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group=mysqld.2 --copy-back --port=$NODE_MYPORT_2 --host=127.0.0.1 $MYSQL_TMP_DIR/innobackupex_backup &> $MYSQL_TMP_DIR/innobackupex-restore.log - -# -# Convert the xtrabackup_galera_info into a grastate.dat file -# - ---perl - use strict; - my $xtrabackup_galera_info_file = $ENV{'MYSQL_TMP_DIR'}.'/innobackupex_backup/xtrabackup_galera_info'; - open(XTRABACKUP_GALERA_INFO, $xtrabackup_galera_info_file) or die "Can not open $xtrabackup_galera_info_file: $!"; - my $xtrabackup_galera_info = ; - my ($uuid, $seqno) = split(':', $xtrabackup_galera_info); - - my $grastate_dat_file = $ENV{'MYSQLTEST_VARDIR'}.'/mysqld.2/data/grastate.dat'; - die "grastate.dat already exists" if -e $grastate_dat_file; - - open(GRASTATE_DAT, ">$grastate_dat_file") or die "Can not write to $grastate_dat_file: $!"; - print GRASTATE_DAT "version: 2.1\n"; - print GRASTATE_DAT "uuid: $uuid\n"; - print GRASTATE_DAT "seqno: $seqno\n"; - print GRASTATE_DAT "cert_index:\n"; - exit(0); -EOF - ---source include/start_mysqld.inc ---sleep 5 - ---source include/wait_until_connected_again.inc ---let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; ---source include/wait_condition.inc - -SELECT COUNT(*) = 20 FROM t1; - -DROP TABLE t1; - ---sleep 10 - ---let $galera_connection_name = node_2a ---let $galera_server_number = 2 ---source include/galera_connect.inc ---let $node_2=node_2a - -# Restore original auto_increment_offset values. ---source ../galera/include/auto_increment_offset_restore.inc diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_xtrabackup-v2.cnf b/mysql-test/suite/galera_3nodes/t/galera_ipv6_xtrabackup-v2.cnf deleted file mode 100644 index 78fbd793aa0..00000000000 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_xtrabackup-v2.cnf +++ /dev/null @@ -1,29 +0,0 @@ -!include ../galera_3nodes.cnf - -[mysqld] -wsrep_sst_method=xtrabackup-v2 -wsrep_sst_auth="root:" -wsrep_node_address=::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' - -[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' - -[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' - -[SST] -transferfmt=@ENV.MTR_GALERA_TFMT -streamfmt=xbstream -sockopt=",pf=ip6" diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_xtrabackup-v2.opt b/mysql-test/suite/galera_3nodes/t/galera_ipv6_xtrabackup-v2.opt deleted file mode 100644 index c195dd0f35b..00000000000 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_xtrabackup-v2.opt +++ /dev/null @@ -1 +0,0 @@ ---bind-address=:: --skip-innodb-safe-truncate diff --git a/mysql-test/suite/galera_3nodes/t/galera_ipv6_xtrabackup-v2.test b/mysql-test/suite/galera_3nodes/t/galera_ipv6_xtrabackup-v2.test deleted file mode 100644 index fd7e0c50887..00000000000 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_xtrabackup-v2.test +++ /dev/null @@ -1,58 +0,0 @@ ---source include/galera_cluster.inc ---source include/check_ipv6.inc - -# Confirm that initial handshake happened over ipv6 - -SELECT VARIABLE_VALUE LIKE '%[::1]%' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_incoming_addresses'; -SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; - -# Force IST - ---connection node_2 -SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; - ---connection node_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; -INSERT INTO t1 VALUES (1); - ---connection node_2 -SET GLOBAL wsrep_provider_options='gmcast.isolate=0'; - ---let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; ---source include/wait_condition.inc - ---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; - -DROP TABLE t1; - -# Confirm that key messages around SST and IST reference IPv6 - ---connection node_1 ---let $assert_file = $MYSQLTEST_VARDIR/log/mysqld.1.err ---let $assert_only_after = CURRENT_TEST - ---let $assert_count = 2 ---let $assert_text = Streaming the backup to joiner at \[::1\] ---let $assert_select = Streaming the backup to joiner at \[::1\] ---source include/assert_grep.inc - ---let $assert_count = 1 ---let $assert_text = async IST sender starting to serve tcp://\[::1\]: ---let $assert_select = async IST sender starting to serve tcp://\[::1\]: ---source include/assert_grep.inc - ---let $assert_file = $MYSQLTEST_VARDIR/log/mysqld.2.err - ---let $assert_text = IST receiver addr using tcp://\[::1\] ---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\] ---source include/assert_grep.inc -- cgit v1.2.1 From f54295f54615274b32cd473b2070a192fcd26721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 27 Aug 2020 14:49:17 +0300 Subject: MDEV-23573 : galera_3nodes.galera_ipv6_mariabackup MTR failed: Could not open '../galera/include/have_mariabackup.inc Fix the include and add force_restart to stabilize. --- mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 863ce65b579..ae489117942 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test @@ -1,7 +1,8 @@ --source include/galera_cluster.inc --source include/check_ipv6.inc --source include/have_innodb.inc ---source ../galera/include/have_mariabackup.inc +--source include/have_mariabackup.inc +--source include/force_restart.inc # Confirm that initial handshake happened over ipv6 -- cgit v1.2.1 From 97d830565f0c1b7e4b720dcf7afed52ac8f746bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 27 Aug 2020 14:50:21 +0300 Subject: MDEV-23574 : galera_3nodes.galera_ipv6_mariabackup_section MTR failed: Could not open '../galera/include/have_mariabackup.inc' Fix the include and add force_restart to stabilize. --- .../suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result | 5 +++++ .../suite/galera_3nodes/t/galera_ipv6_mariabackup_section.test | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) 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 53e35939a79..5a844537327 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 @@ -4,15 +4,20 @@ VARIABLE_VALUE LIKE '%[::1]%' SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; VARIABLE_VALUE = 3 1 +connection node_2; SET GLOBAL wsrep_provider_options='gmcast.isolate=1'; +connection node_1; CREATE TABLE t1 (f1 INTEGER) 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 1 DROP TABLE t1; +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\]:] +connection node_2; include/assert_grep.inc [IST receiver addr using tcp://\[::1\]] include/assert_grep.inc [Prepared IST receiver, listening at: tcp://\[::1\]] 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 78fcf0873fc..2c5aae8534d 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 @@ -1,7 +1,8 @@ --source include/galera_cluster.inc --source include/check_ipv6.inc --source include/have_innodb.inc ---source ../galera/include/have_mariabackup.inc +--source include/have_mariabackup.inc +--source include/force_restart.inc # Confirm that initial handshake happened over ipv6 -- cgit v1.2.1 From 3135de4266765b5e75c2b3e6350ec0a080380e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 27 Aug 2020 14:51:06 +0300 Subject: MDEV-23576 : galera_3nodes.galera_ipv6_mysqldump MTR failed: WSREP_SST: [ERROR] rsync daemon port '16008' has been taken Add force_restart to clean up rsync daemon port. --- mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.test | 1 + 1 file changed, 1 insertion(+) 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 4a6de8abb9c..c9e08f58950 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.test +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.test @@ -1,5 +1,6 @@ --source include/galera_cluster.inc --source include/check_ipv6.inc +--source include/force_restart.inc call mtr.add_suppression("WSREP: wsrep_sst_method is set to 'mysqldump' yet mysqld bind_address is set to'"); call mtr.add_suppression("Failed to load slave replication state from table mysql.gtid_slave_pos"); -- cgit v1.2.1 From 2845ed682cc5c3a86f41711c026d47243e0c987a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 27 Aug 2020 14:52:12 +0300 Subject: MDEV-23581 : galera_3nodes.galera_ipv6_rsync MTR failed: WSREP_SST: [ERROR] rsync daemon port '16008' has been taken Add force_restart to free rsync daemon port. --- mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.test | 1 + 1 file changed, 1 insertion(+) 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 1937eb43e13..fff776d98b6 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.test +++ b/mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.test @@ -1,5 +1,6 @@ --source include/galera_cluster.inc --source include/check_ipv6.inc +--source include/force_restart.inc # Confirm that initial handshake happened over ipv6 -- cgit v1.2.1 From fcea7918de382184ab25659e4d42568d664ab61f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 27 Aug 2020 14:56:13 +0300 Subject: MDEV-23580 : galera_3nodes.galera_ipv6_rsync_section MTR failed: WSREP_SST: [ERROR] rsync daemon port '16008' has been taken Add force_restart to free rsync daemon port. --- mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync_section.test | 1 + 1 file changed, 1 insertion(+) 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 1937eb43e13..fff776d98b6 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 @@ -1,5 +1,6 @@ --source include/galera_cluster.inc --source include/check_ipv6.inc +--source include/force_restart.inc # Confirm that initial handshake happened over ipv6 -- cgit v1.2.1 From a34f93010c2f4e86f5587241d1ce111603aea466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 27 Aug 2020 14:58:55 +0300 Subject: MDEV-23587 : galera_3nodes.galera_var_dirty_reads2 MTR failed: 1047: WSREP has not yet prepared node for application use Add wait_condition to make sure insert has been replicated and after cluster restore wait until node is ready before continuing. --- mysql-test/suite/galera_3nodes/t/galera_var_dirty_reads2.test | 4 ++++ 1 file changed, 4 insertions(+) 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 e3f94a012b8..6476c4fe4fa 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 @@ -34,6 +34,9 @@ SET SESSION wsrep_sync_wait = 0; 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 @@ -111,6 +114,7 @@ SELECT COUNT(*) > 0 FROM INFORMATION_SCHEMA.PROCESSLIST; # Restore cluster SET GLOBAL wsrep_provider_options='gmcast.isolate=0'; +--source include/galera_wait_ready.inc --connection node_1 --let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -- cgit v1.2.1 From c08afc4363317f516995eca71aa0c71d9da03b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 27 Aug 2020 15:00:25 +0300 Subject: Update galera_3nodes suite global ignore list. --- mysql-test/suite/galera_3nodes/suite.pm | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/galera_3nodes/suite.pm b/mysql-test/suite/galera_3nodes/suite.pm index 4a861f3b9fa..350e4af98ff 100644 --- a/mysql-test/suite/galera_3nodes/suite.pm +++ b/mysql-test/suite/galera_3nodes/suite.pm @@ -22,7 +22,6 @@ push @::global_suppressions, qr(WSREP:.*down context.*), qr(WSREP: Failed to send state UUID:), qr(WSREP: last inactive check more than .* skipping check), - qr(WSREP: SQL statement was ineffective), qr(WSREP: Releasing seqno [0-9]* before [0-9]* was assigned.), qr|WSREP: access file\(.*gvwstate.dat\) failed\(No such file or directory\)|, qr(WSREP: Quorum: No node with complete state), @@ -36,14 +35,38 @@ push @::global_suppressions, qr(WSREP: user message in state LEAVING), qr(WSREP: .* sending install message failed: Transport endpoint is not connected), qr(WSREP: .* sending install message failed: Resource temporarily unavailable), - qr(WSREP: Sending JOIN failed: -107 \(Transport endpoint is not connected\). Will retry in new primary component.), + qr(WSREP: Maximum writeset size exceeded by .*), + qr(WSREP: transaction size exceeded.*), + qr(WSREP: RBR event .*), + qr(WSREP: Ignoring error for TO isolated action: .*), + qr(WSREP: transaction size limit .*), + qr(WSREP: rbr write fail, .*), + qr(WSREP: .*Backend not supported: foo.*), + qr(WSREP: .*Failed to initialize backend using .*), + qr(WSREP: .*Failed to open channel 'my_wsrep_cluster' at .*), + qr(WSREP: gcs connect failed: Socket type not supported), + qr(WSREP: failed to open gcomm backend connection: 110: failed to reach primary view: 110 .*), + qr(WSREP: .*Failed to open backend connection: -110 .*), + qr(WSREP: .*Failed to open channel 'my_wsrep_cluster' at .*), + qr(WSREP: gcs connect failed: Connection timed out), + qr|WSREP: wsrep::connect\(.*\) failed: 7|, + qr(WSREP: SYNC message from member .* in non-primary configuration. Ignored.), qr(WSREP: Could not find peer:), + qr(WSREP: TO isolation failed for: .*), qr|WSREP: gcs_caused\(\) returned .*|, qr|WSREP: Protocol violation. JOIN message sender .* is not in state transfer \(SYNCED\). Message ignored.|, qr|WSREP: Protocol violation. JOIN message sender .* is not in state transfer \(JOINED\). Message ignored.|, + qr|WSREP: Unsupported protocol downgrade: incremental data collection disabled. Expect abort.|, qr(WSREP: Action message in non-primary configuration from member [0-9]*), + qr(WSREP: Last Applied Action message in non-primary configuration from member [0-9]*), + qr(WSREP: discarding established .*), + qr|WSREP: .*core_handle_uuid_msg.*|, qr(WSREP: --wsrep-causal-reads=ON takes precedence over --wsrep-sync-wait=0. WSREP_SYNC_WAIT_BEFORE_READ is on), - qr(WSREP: JOIN message from member .* in non-primary configuration. Ignored.), + qr|WSREP: JOIN message from member .* in non-primary configuration. Ignored.|, + qr(WSREP: Failed to remove page file .*), + qr(WSREP: wsrep_sst_method is set to 'mysqldump' yet mysqld bind_address is set to .*), + qr|WSREP: Sending JOIN failed: -107 \(Transport endpoint is not connected\). Will retry in new primary component.|, + qr|WSREP: Trying to continue unpaused monitor|, ); bless { }; -- cgit v1.2.1 From f69cc26757733724254ee37aec5a092f520d230f Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Thu, 27 Aug 2020 17:34:12 +0530 Subject: MDEV-23596: Assertion `tab->ref.use_count' failed in join_read_key_unlock_row The issue here was that the query was using ORDER BY LIMIT optimzation where the access method was changed from EQ_REF access to an index scan (index that would resolve the ORDER BY clause). But the parameter READ_RECORD::unlock_row was not reset to rr_unlock_row, which is used when the access method is not EQ_REF access. --- mysql-test/r/order_by.result | 16 ++++++++++++++++ mysql-test/t/order_by.test | 15 +++++++++++++++ sql/sql_select.cc | 3 +++ 3 files changed, 34 insertions(+) diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result index ffb37c9309f..f7427bcd30e 100644 --- a/mysql-test/r/order_by.result +++ b/mysql-test/r/order_by.result @@ -3356,3 +3356,19 @@ SET max_sort_length= @save_max_sort_length; SET sort_buffer_size= @save_sort_buffer_size; SET max_length_for_sort_data= @save_max_length_for_sort_data; DROP TABLE t1; +# +# MDEV-23596: Assertion `tab->ref.use_count' failed in join_read_key_unlock_row +# +CREATE TABLE t1 (a INT PRIMARY KEY, b INT, KEY(b)); +INSERT INTO t1 VALUES (0, 1),(1, 2); +CREATE TABLE t2 SELECT * FROM t1; +EXPLAIN SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.b ORDER BY t1.b LIMIT 1) AS c FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 +2 DEPENDENT SUBQUERY t1 index PRIMARY b 5 NULL 1 Using where +SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.b ORDER BY t1.b LIMIT 1) AS c FROM t2; +c +1 +NULL +DROP TABLE t1,t2; +# end of 10.1 tests diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test index 3a30e0b6c76..3e614ed3316 100644 --- a/mysql-test/t/order_by.test +++ b/mysql-test/t/order_by.test @@ -2196,3 +2196,18 @@ SET max_sort_length= @save_max_sort_length; SET sort_buffer_size= @save_sort_buffer_size; SET max_length_for_sort_data= @save_max_length_for_sort_data; DROP TABLE t1; + +--echo # +--echo # MDEV-23596: Assertion `tab->ref.use_count' failed in join_read_key_unlock_row +--echo # + +CREATE TABLE t1 (a INT PRIMARY KEY, b INT, KEY(b)); +INSERT INTO t1 VALUES (0, 1),(1, 2); +CREATE TABLE t2 SELECT * FROM t1; + +EXPLAIN SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.b ORDER BY t1.b LIMIT 1) AS c FROM t2; +SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.b ORDER BY t1.b LIMIT 1) AS c FROM t2; + +DROP TABLE t1,t2; + +--echo # end of 10.1 tests diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 4c6e87e4f27..e2e87bb1a86 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -21601,6 +21601,9 @@ check_reverse_order: else if (select && select->quick) select->quick->need_sorted_output(); + tab->read_record.unlock_row= (tab->type == JT_EQ_REF) ? + join_read_key_unlock_row : rr_unlock_row; + } // QEP has been modified /* -- cgit v1.2.1 From 5843dc485bb894e5d3fde2bb6bb7f473c8f78159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 27 Aug 2020 15:00:49 +0300 Subject: Update galera and galera_3nodes disabled.def file after fixes. --- mysql-test/suite/galera/disabled.def | 1 + mysql-test/suite/galera_3nodes/disabled.def | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/mysql-test/suite/galera/disabled.def b/mysql-test/suite/galera/disabled.def index 02f1bb5eb1f..b4dd37ea7cb 100644 --- a/mysql-test/suite/galera/disabled.def +++ b/mysql-test/suite/galera/disabled.def @@ -12,6 +12,7 @@ MW-286 : MDEV-18464 Killing thread can cause mutex deadlock if done concurrently with Galera/replication victim kill MW-328A : MDEV-22666 galera.MW-328A MTR failed: "Semaphore wait has lasted > 600 seconds" and do not release port 16002 +MW-328B : MDEV-22666 galera.MW-328A MTR failed: "Semaphore wait has lasted > 600 seconds" and do not release port 16002 MW-329 : MDEV-19962 Galera test failure on MW-329 galera.galera_defaults : MDEV-21494 Galera test sporadic failure on galera.galera_defaults galera_as_slave_replication_bundle : MDEV-15785 OPTION_GTID_BEGIN is set in Gtid_log_event::do_apply_event() diff --git a/mysql-test/suite/galera_3nodes/disabled.def b/mysql-test/suite/galera_3nodes/disabled.def index 415da407cf7..c6d3ece75d1 100644 --- a/mysql-test/suite/galera_3nodes/disabled.def +++ b/mysql-test/suite/galera_3nodes/disabled.def @@ -10,12 +10,6 @@ # ############################################################################## -galera_ipv6_mariabackup : MDEV-23573 Could not open '../galera/include/have_mariabackup.inc' -galera_ipv6_mariabackup_section : MDEV-23574 Could not open '../galera/include/have_mariabackup.inc' -galera_ipv6_mysqldump : MDEV-23576 WSREP_SST: [ERROR] rsync daemon port '16008' has been taken -galera_ipv6_rsyn : MDEV-23581 WSREP_SST: [ERROR] rsync daemon port '16008' has been taken -galera_ipv6_rsync_section : MDEV-23580 WSREP_SST: [ERROR] rsync daemon port '16008' has been taken -galera_ipv6_xtrabackup-v2 : MDEV-23575 WSREP_SST: [ERROR] innobackupex not in path 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 -- cgit v1.2.1 From 482cf29e168673f68196a235aff00fc741bf71da Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Fri, 7 Aug 2020 00:00:40 -0400 Subject: MDEV-23091: perfschema Add support for OpenBSD's getthrid() to retrieve the thread id --- storage/perfschema/CMakeLists.txt | 10 ++++++++++ storage/perfschema/my_thread.h | 5 +++++ storage/perfschema/pfs_config.h.cmake | 1 + 3 files changed, 16 insertions(+) diff --git a/storage/perfschema/CMakeLists.txt b/storage/perfschema/CMakeLists.txt index c871677d0a9..a40e5ba6206 100644 --- a/storage/perfschema/CMakeLists.txt +++ b/storage/perfschema/CMakeLists.txt @@ -298,6 +298,16 @@ int main(int ac, char **av) }" HAVE_SYS_GETTID) +# Check for getthrid() +CHECK_C_SOURCE_COMPILES(" +#include +int main(int ac, char **av) +{ + unsigned long long tid = getthrid(); + return (tid != 0 ? 0 : 1); +}" +HAVE_GETTHRID) + # Check for pthread_getthreadid_np() CHECK_C_SOURCE_COMPILES(" #include diff --git a/storage/perfschema/my_thread.h b/storage/perfschema/my_thread.h index 12e01a510ed..b9f3f7775ff 100644 --- a/storage/perfschema/my_thread.h +++ b/storage/perfschema/my_thread.h @@ -67,6 +67,10 @@ static inline my_thread_os_id_t my_thread_os_id() /* FreeBSD 10.2 */ return pthread_getthreadid_np(); #else +#ifdef HAVE_GETTHRID + /* OpenBSD */ + return getthrid(); +#else #ifdef HAVE_INTEGER_PTHREAD_SELF /* Unknown platform, fallback. */ return pthread_self(); @@ -74,6 +78,7 @@ static inline my_thread_os_id_t my_thread_os_id() /* Feature not available. */ return 0; #endif /* HAVE_INTEGER_PTHREAD_SELF */ +#endif /* HAVE_GETTHRID */ #endif /* HAVE_PTHREAD_GETTHREADID_NP */ #endif /* _WIN32 */ #endif /* HAVE_SYS_GETTID */ diff --git a/storage/perfschema/pfs_config.h.cmake b/storage/perfschema/pfs_config.h.cmake index 0dc29da72d9..1b518fe3211 100644 --- a/storage/perfschema/pfs_config.h.cmake +++ b/storage/perfschema/pfs_config.h.cmake @@ -1,4 +1,5 @@ #cmakedefine HAVE_PTHREAD_THREADID_NP 1 #cmakedefine HAVE_SYS_GETTID 1 +#cmakedefine HAVE_GETTHRID 1 #cmakedefine HAVE_PTHREAD_GETTHREADID_NP 1 #cmakedefine HAVE_INTEGER_PTHREAD_SELF 1 -- cgit v1.2.1 From df07ea0b27f891c69e60b75869f474cd03232216 Mon Sep 17 00:00:00 2001 From: sjaakola Date: Thu, 27 Aug 2020 10:52:39 +0300 Subject: MDEV-23557 Galera heap-buffer-overflow in wsrep_rec_get_foreign_key This commit contains a fix and extended test case for a ASAN failure reported during galera.fk mtr testing. The reported heap buffer overflow happens in test case where a cascading foreign key constraint is defined for a column of varchar type, and galera.fk.test has such vulnerable test scenario. Troubleshoting revealed that erlier fix for MDEV-19660 has made a fix for cascading delete handling to append wsrep keys from pcur->old_rec, in row_ins_foreign_check_on_constraint(). And, the ASAN failuer comes from later scanning of this old_rec reference. The fix in this commit, moves the call for wsrep_append_foreign_key() to happen somewhat earlier, and inside ongoing mtr, and using clust_rec which is set earlier in the same mtr for both update and delete cascade operations. for wsrep key populating, it does not matter when the keys are populated, all keys just have to be appended before wsrep transaction replicates. Note that I also tried similar fix for earlier wsrep key append, but using the old implementation with pcur->old_rec (instead of clust_rec), and same ASAN failure was reported. So it appears that pcur->old_rec is not properly set, to be used for wsrep key appending. galera.galera_fk_cascade_delete test has been extended by two new test scenarios: * FK cascade on varchar column. This test case reproduces same scenario as galera.fk, and this test scenario will also trigger ASAN failure with non fixed MariaDB versions. * multi-master conflict with FK cascading. this scenario causes a conflict between a replicated FK cascading transaction and local transaction trying to modify the cascaded child table row. Local transaction should be aborted and get deadlock error. This test scenario is passing both with old MariaDB version and with this commit as well. --- .../suite/galera/r/galera_fk_cascade_delete.result | 18 ++-- .../galera/r/galera_fk_cascade_delete_debug.result | 67 +++++++++++++++ .../suite/galera/t/galera_fk_cascade_delete.test | 18 +++- .../galera/t/galera_fk_cascade_delete_debug.test | 98 ++++++++++++++++++++++ storage/innobase/row/row0ins.cc | 16 ++-- 5 files changed, 200 insertions(+), 17 deletions(-) create mode 100644 mysql-test/suite/galera/r/galera_fk_cascade_delete_debug.result create mode 100644 mysql-test/suite/galera/t/galera_fk_cascade_delete_debug.test diff --git a/mysql-test/suite/galera/r/galera_fk_cascade_delete.result b/mysql-test/suite/galera/r/galera_fk_cascade_delete.result index 73375ae55c5..a6c6504dc39 100644 --- a/mysql-test/suite/galera/r/galera_fk_cascade_delete.result +++ b/mysql-test/suite/galera/r/galera_fk_cascade_delete.result @@ -1,3 +1,8 @@ +# +# test phase with cascading foreign key through 3 tables +# +connection node_1; +set wsrep_sync_wait=0; CREATE TABLE grandparent ( id INT NOT NULL PRIMARY KEY ) ENGINE=InnoDB; @@ -19,14 +24,15 @@ INSERT INTO grandparent VALUES (1),(2); INSERT INTO parent VALUES (1,1), (2,2); INSERT INTO child VALUES (1,1), (2,2); connection node_2; +set wsrep_sync_wait=0; DELETE FROM grandparent WHERE id = 1; connection node_1; -SELECT COUNT(*) = 0 FROM parent WHERE grandparent_id = 1; -COUNT(*) = 0 -1 -SELECT COUNT(*) = 0 FROM child WHERE parent_id = 1; -COUNT(*) = 0 -1 +SELECT COUNT(*), COUNT(*) = 0 FROM parent WHERE grandparent_id = 1; +COUNT(*) COUNT(*) = 0 +0 1 +SELECT COUNT(*), COUNT(*) = 0 FROM child WHERE parent_id = 1; +COUNT(*) COUNT(*) = 0 +0 1 DROP TABLE child; DROP TABLE parent; DROP TABLE grandparent; 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 new file mode 100644 index 00000000000..89613b2856a --- /dev/null +++ b/mysql-test/suite/galera/r/galera_fk_cascade_delete_debug.result @@ -0,0 +1,67 @@ +# +# test phase with foreign key of varchar type +# +connection node_1; +CREATE TABLE parent ( +`id` varchar(36) COLLATE utf8_unicode_ci NOT NULL, +PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +CREATE TABLE child ( +`id` int NOT NULL, +`parent_id` varchar(36) COLLATE utf8_unicode_ci DEFAULT NULL, +PRIMARY KEY (`id`), +KEY `parent_id` (`parent_id`), +CONSTRAINT `ipallocations_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +INSERT INTO parent VALUES ('row one'), ('row two'); +INSERT INTO child VALUES (1,'row one'), (2,'row two'); +connection node_2; +DELETE FROM parent; +connection node_1; +SELECT COUNT(*), COUNT(*) = 0 FROM parent; +COUNT(*) COUNT(*) = 0 +0 1 +SELECT COUNT(*), COUNT(*) = 0 FROM child; +COUNT(*) COUNT(*) = 0 +0 1 +DROP TABLE child; +DROP TABLE parent; +# +# test phase with MM conflict in FK cascade +# +connection node_1; +set wsrep_retry_autocommit=0; +CREATE TABLE parent ( +id INT NOT NULL PRIMARY KEY +) ENGINE=InnoDB; +CREATE TABLE child ( +id INT NOT NULL PRIMARY KEY, +j int default 0, +parent_id INT, +FOREIGN KEY (parent_id) +REFERENCES parent(id) +ON DELETE CASCADE +) ENGINE=InnoDB; +INSERT INTO parent VALUES (1); +INSERT INTO child VALUES (1,0,1); +connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; +SET GLOBAL debug_dbug = "d,sync.wsrep_apply_cb"; +connection node_2; +DELETE FROM parent; +connection node_1a; +SET SESSION DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached"; +connection node_1; +update child set j=2;; +connection node_1a; +SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb"; +SET GLOBAL debug_dbug = ""; +SET DEBUG_SYNC = "RESET"; +connection node_1; +SELECT COUNT(*), COUNT(*) = 0 FROM parent; +COUNT(*) COUNT(*) = 0 +0 1 +SELECT COUNT(*), COUNT(*) = 0 FROM child; +COUNT(*) COUNT(*) = 0 +0 1 +DROP TABLE child; +DROP TABLE parent; diff --git a/mysql-test/suite/galera/t/galera_fk_cascade_delete.test b/mysql-test/suite/galera/t/galera_fk_cascade_delete.test index 9b79b4c30b6..6f0de0a1f4a 100644 --- a/mysql-test/suite/galera/t/galera_fk_cascade_delete.test +++ b/mysql-test/suite/galera/t/galera_fk_cascade_delete.test @@ -3,7 +3,13 @@ # --source include/galera_cluster.inc ---source include/have_innodb.inc + +--echo # +--echo # test phase with cascading foreign key through 3 tables +--echo # + +--connection node_1 +set wsrep_sync_wait=0; CREATE TABLE grandparent ( id INT NOT NULL PRIMARY KEY @@ -30,11 +36,17 @@ INSERT INTO parent VALUES (1,1), (2,2); INSERT INTO child VALUES (1,1), (2,2); --connection node_2 +set wsrep_sync_wait=0; + +--let $wait_condition = SELECT COUNT(*) = 2 FROM child; +--source include/wait_condition.inc DELETE FROM grandparent WHERE id = 1; --connection node_1 -SELECT COUNT(*) = 0 FROM parent WHERE grandparent_id = 1; -SELECT COUNT(*) = 0 FROM child WHERE parent_id = 1; +--let $wait_condition = SELECT COUNT(*) = 1 FROM child; +--source include/wait_condition.inc +SELECT COUNT(*), COUNT(*) = 0 FROM parent WHERE grandparent_id = 1; +SELECT COUNT(*), COUNT(*) = 0 FROM child WHERE parent_id = 1; DROP TABLE child; DROP TABLE parent; 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 new file mode 100644 index 00000000000..f38c028b7d6 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_fk_cascade_delete_debug.test @@ -0,0 +1,98 @@ +--source include/galera_cluster.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc + +--echo # +--echo # test phase with foreign key of varchar type +--echo # +--connection node_1 + CREATE TABLE parent ( + `id` varchar(36) COLLATE utf8_unicode_ci NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + + CREATE TABLE child ( + `id` int NOT NULL, + `parent_id` varchar(36) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `parent_id` (`parent_id`), + CONSTRAINT `ipallocations_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`) ON DELETE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + +INSERT INTO parent VALUES ('row one'), ('row two'); +INSERT INTO child VALUES (1,'row one'), (2,'row two'); + +--connection node_2 +--let $wait_condition = SELECT COUNT(*) = 2 FROM child; +--source include/wait_condition.inc +DELETE FROM parent; + +--connection node_1 +--let $wait_condition = SELECT COUNT(*) = 0 FROM child; +--source include/wait_condition.inc + +SELECT COUNT(*), COUNT(*) = 0 FROM parent; +SELECT COUNT(*), COUNT(*) = 0 FROM child; + +DROP TABLE child; +DROP TABLE parent; + +--echo # +--echo # test phase with MM conflict in FK cascade +--echo # + +--connection node_1 +set wsrep_retry_autocommit=0; +CREATE TABLE parent ( + id INT NOT NULL PRIMARY KEY +) ENGINE=InnoDB; + +CREATE TABLE child ( + id INT NOT NULL PRIMARY KEY, + j int default 0, + parent_id INT, + FOREIGN KEY (parent_id) + REFERENCES parent(id) + ON DELETE CASCADE +) ENGINE=InnoDB; + +INSERT INTO parent VALUES (1); +INSERT INTO child VALUES (1,0,1); + +# 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 +--send update child set j=2; + +--connection node_1a +# release the applier +SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb"; +SET GLOBAL debug_dbug = ""; +SET DEBUG_SYNC = "RESET"; + +--connection node_1 +--reap + +--let $wait_condition = SELECT COUNT(*) = 0 FROM child; +--source include/wait_condition.inc +SELECT COUNT(*), COUNT(*) = 0 FROM parent; +SELECT COUNT(*), COUNT(*) = 0 FROM child; + +DROP TABLE child; +DROP TABLE parent; diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 50394193a15..c0aa3655b7b 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -1402,20 +1402,20 @@ row_ins_foreign_check_on_constraint( btr_pcur_store_position(cascade->pcur, mtr); } +#ifdef WITH_WSREP + err = wsrep_append_foreign_key(trx, foreign, clust_rec, clust_index, + FALSE, WSREP_KEY_EXCLUSIVE); + if (err != DB_SUCCESS) { + ib::info() << "WSREP: foreign key append failed: " << err; + goto nonstandard_exit_func; + } +#endif /* WITH_WSREP */ mtr_commit(mtr); ut_a(cascade->pcur->rel_pos == BTR_PCUR_ON); cascade->state = UPD_NODE_UPDATE_CLUSTERED; -#ifdef WITH_WSREP - err = wsrep_append_foreign_key(trx, foreign, cascade->pcur->old_rec, clust_index, - FALSE, WSREP_KEY_EXCLUSIVE); - if (err != DB_SUCCESS) { - fprintf(stderr, - "WSREP: foreign key append failed: %d\n", err); - } else -#endif /* WITH_WSREP */ err = row_update_cascade_for_mysql(thr, cascade, foreign->foreign_table); -- cgit v1.2.1 From c14ecc750037f666ad1d39927ac0eb1ab4543506 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 25 Aug 2020 15:56:25 +0400 Subject: MDEV-23568 Improve performance of my_{time|date|datetime}_to_str() This patch improves functions my_xxx_to_str() using the idea introduced in this change in MySQL-8.0: commit 8d10f2fff6bbdea7f436b868ebb5fd811defc68a Author: Knut Anders Hatlen Date: Thu Oct 10 13:55:07 2019 +0200 Bug#30472888: IMPROVE THE PERFORMANCE OF INTEGER HANDLING IN THE TEXT PROTOCOL The new way prints 2 digits at a time and demonstrates a very impressing query time reduce: 10% to 38%, depending on the exact data type and the number of fractional digits: SELECT BENCHMARK(10*1000*1000,CONCAT(TIME'10:20:30')); SELECT BENCHMARK(10*1000*1000,CONCAT(TIME'10:20:30.123456')); SELECT BENCHMARK(10*1000*1000,CONCAT(DATE'2001-01-01')); SELECT BENCHMARK(10*1000*1000,CONCAT(TIMESTAMP'2001-01-01 10:20:30')); SELECT BENCHMARK(10*1000*1000,CONCAT(TIMESTAMP'2001-01-01 10:20:30.123456')); See MDEV for details on the benchmark results. --- sql-common/my_time.c | 173 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 149 insertions(+), 24 deletions(-) diff --git a/sql-common/my_time.c b/sql-common/my_time.c index 5c14b8071a3..563ca00d59f 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -1454,23 +1454,148 @@ void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type) /* - Helper function for datetime formatting. - Format number as string, left-padded with 0. + A formatting routine to print a 2 digit zero padded number. + It prints 2 digits at a time, which gives a performance improvement. + The idea is taken from "class TwoDigitWriter" in MySQL. + + The old implementation printed one digit at a time, using the division + and the remainder operators, which appeared to be slow. + It's cheaper to have a cached array of 2-digit numbers + in their string representation. + + Benchmark results showed a 10% to 23% time reduce for these queries: + SELECT BENCHMARK(10*1000*1000,CONCAT(TIME'10:20:30')); + SELECT BENCHMARK(10*1000*1000,CONCAT(DATE'2001-01-01')); + SELECT BENCHMARK(10*1000*1000,CONCAT(TIMESTAMP'2001-01-01 10:20:30')); + SELECT BENCHMARK(10*1000*1000,CONCAT(TIME'10:20:30.123456')); + SELECT BENCHMARK(10*1000*1000,CONCAT(TIMESTAMP'2001-01-01 10:20:30.123456')); + (depending on the exact data type and fractional precision). + + The array has extra elements for uint8 values 100..255. + This is done for safety. If the caller passes a value + outside of the expected range 0..99, it will be printed as "XX". +*/ + +static const char two_digit_numbers[512+1]= +{ + /* 0..99 */ + "00010203040506070809" + "10111213141516171819" + "20212223242526272829" + "30313233343536373839" + "40414243444546474849" + "50515253545556575859" + "60616263646566676869" + "70717273747576777879" + "80818283848586878889" + "90919293949596979899" + /* 100..199 - safety */ + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXX" + /* 200..255 - safety */ + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXXXXXXXXXX" + "XXXXXXXXXXXX" +}; + + +static inline char* fmt_number2(uint8 val, char *out) +{ + const char *src= two_digit_numbers + val * 2; + *out++= *src++; + *out++= *src++; + return out; +} - The reason to use own formatting rather than sprintf() is performance - in a - datetime benchmark it helped to reduced the datetime formatting overhead - from ~30% down to ~4%. +/* + We tried the same trick with an array of 16384 zerofill 4-digit numbers, + with 10000 elements with numbers 0000..9999, and a tail filled with "XXXX". + + Benchmark results for a RelWithDebInfo build: + + SELECT BENCHMARK(10*1000*1000,CONCAT(TIMESTAMP'2001-01-01 10:20:30.123456')); + - 0.379 sec (current) + - 0.369 sec (array) + + SELECT BENCHMARK(10*1000*1000,CONCAT(DATE'2001-01-01')); + - 0.225 sec (current) + - 0.219 sec (array) + + It demonstrated an additional 3% performance imrovement one these queries. + However, as the array size is too huge, we afraid that it will flush data + from the CPU memory cache, which under real load may affect negatively. + + Let's keep using the fmt_number4() version with division and remainder + for now. This can be revised later. We could try some smaller array, + e.g. for YEARs in the range 1970..2098 (fitting into a 256 element array). */ +/* +static inline char* fmt_number4(uint16 val, char *out) +{ + const char *src= four_digit_numbers + (val & 0x3FFF) * 4; + memcpy(out, src, 4); + return out + 4; +} +*/ + + +/* + A formatting routine to print a 4 digit zero padded number. +*/ +static inline char* fmt_number4(uint16 val, char *out) +{ + out= fmt_number2((uint8) (val / 100), out); + out= fmt_number2((uint8) (val % 100), out); + return out; +} + + +/* + A formatting routine to print a 6 digit zero padded number. +*/ +static inline char* fmt_number6(uint val, char *out) +{ + out= fmt_number2((uint8) (val / 10000), out); + val%= 10000; + out= fmt_number2((uint8) (val / 100), out); + out= fmt_number2((uint8) (val % 100), out); + return out; +} + -static char* fmt_number(uint val, char *out, uint digits) +static char* fmt_usec(uint val, char *out, uint digits) { - uint i; - for(i= 0; i < digits; i++) + switch (digits) { - out[digits-i-1]= '0' + val%10; - val/=10; + case 1: + *out++= '0' + (val % 10); + return out; + case 2: + return fmt_number2((uint8) val, out); + case 3: + *out++= '0' + (val / 100) % 10; + return fmt_number2((uint8) (val % 100), out); + case 4: + return fmt_number4((uint16) val, out); + case 5: + *out++= '0' + (val / 10000) % 10; + return fmt_number4((uint16) (val % 10000), out); + case 6: + return fmt_number6(val, out); } - return out + digits; + DBUG_ASSERT(0); + return out; } @@ -1480,13 +1605,13 @@ static int my_mmssff_to_str(const MYSQL_TIME *ltime, char *to, uint fsp) if (fsp == AUTO_SEC_PART_DIGITS) fsp= ltime->second_part ? TIME_SECOND_PART_DIGITS : 0; DBUG_ASSERT(fsp <= TIME_SECOND_PART_DIGITS); - pos= fmt_number(ltime->minute, pos, 2); + pos= fmt_number2((uint8) ltime->minute, pos); *pos++= ':'; - pos= fmt_number(ltime->second, pos, 2); + pos= fmt_number2((uint8) ltime->second, pos); if (fsp) { *pos++= '.'; - pos= fmt_number((uint)sec_part_shift(ltime->second_part, fsp), pos, fsp); + pos= fmt_usec((uint)sec_part_shift(ltime->second_part, fsp), pos, fsp); } return (int) (pos - to); } @@ -1506,7 +1631,7 @@ int my_interval_DDhhmmssff_to_str(const MYSQL_TIME *ltime, char *to, uint fsp) pos= longlong10_to_str((longlong) hour / 24, pos, 10); *pos++= ' '; } - pos= fmt_number(hour % 24, pos, 2); + pos= fmt_number2((uint8) (hour % 24), pos); *pos++= ':'; pos+= my_mmssff_to_str(ltime, pos, fsp); *pos= 0; @@ -1538,7 +1663,7 @@ int my_time_to_str(const MYSQL_TIME *l_time, char *to, uint digits) /* Need more than 2 digits for hours in string representation. */ pos= longlong10_to_str((longlong)hour, pos, 10); else - pos= fmt_number(hour, pos, 2); + pos= fmt_number2((uint8) hour, pos); *pos++= ':'; pos+= my_mmssff_to_str(l_time, pos, digits); @@ -1550,11 +1675,11 @@ int my_time_to_str(const MYSQL_TIME *l_time, char *to, uint digits) int my_date_to_str(const MYSQL_TIME *l_time, char *to) { char *pos=to; - pos= fmt_number(l_time->year, pos, 4); + pos= fmt_number4((uint16) l_time->year, pos); *pos++='-'; - pos= fmt_number(l_time->month, pos, 2); + pos= fmt_number2((uint8) l_time->month, pos); *pos++='-'; - pos= fmt_number(l_time->day, pos, 2); + pos= fmt_number2((uint8) l_time->day, pos); *pos= 0; return (int)(pos - to); } @@ -1563,13 +1688,13 @@ int my_date_to_str(const MYSQL_TIME *l_time, char *to) int my_datetime_to_str(const MYSQL_TIME *l_time, char *to, uint digits) { char *pos= to; - pos= fmt_number(l_time->year, pos, 4); + pos= fmt_number4((uint16) l_time->year, pos); *pos++='-'; - pos= fmt_number(l_time->month, pos, 2); + pos= fmt_number2((uint8) l_time->month, pos); *pos++='-'; - pos= fmt_number(l_time->day, pos, 2); + pos= fmt_number2((uint8) l_time->day, pos); *pos++=' '; - pos= fmt_number(l_time->hour, pos, 2); + pos= fmt_number2((uint8) l_time->hour, pos); *pos++= ':'; pos+= my_mmssff_to_str(l_time, pos, digits); *pos= 0; @@ -1625,7 +1750,7 @@ int my_timeval_to_str(const struct timeval *tm, char *to, uint dec) if (dec) { *pos++= '.'; - pos= fmt_number((uint) sec_part_shift(tm->tv_usec, dec), pos, dec); + pos= fmt_usec((uint) sec_part_shift(tm->tv_usec, dec), pos, dec); } *pos= '\0'; return (int) (pos - to); -- cgit v1.2.1 From 9ef36faa614528b66e0a6ba58a4c40b246658b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 28 Aug 2020 14:44:36 +0300 Subject: MDEV-23618 InnoDB lacks IA-32 CRC-32C acceleration on GCC 4 When MDEV-22669 introduced CRC-32C acceleration to IA-32, it worked around a compiler bug by disabling the acceleration on GCC 4 for IA-32 altogether, even though the compiler bug only affects -fPIC builds that are targeting IA-32. Let us extend the solution fe5dbfe723427a3606c41409626dc853f997e679 and define HAVE_CPUID_INSTRUCTION that allows us to implement a necessary and sufficient work-around of the compiler bug. --- config.h.cmake | 1 + mysys/CMakeLists.txt | 5 ++++- storage/innobase/ut/ut0crc32.cc | 14 ++------------ 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/config.h.cmake b/config.h.cmake index 0de5c2be3e0..3e41e0ac3af 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -103,6 +103,7 @@ #cmakedefine HAVE_LIBWRAP 1 #cmakedefine HAVE_SYSTEMD 1 +#cmakedefine HAVE_CPUID_INSTRUCTION 1 #cmakedefine HAVE_CLMUL_INSTRUCTION 1 #cmakedefine HAVE_CRC32_VPMSUM 1 diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index f72608aa1a9..54f78922f2b 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -58,7 +58,9 @@ IF (WIN32) my_win_popen.cc) ENDIF() -IF(NOT MSVC AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i[36]86") +IF(MSVC) + SET(HAVE_CPUID_INSTRUCTION 1 CACHE BOOL "") +ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i[36]86") #Check for CPUID and PCLMUL. GCC before version 5 would refuse to emit the #CPUID instruction for -m32 -fPIC because it would clobber the EBX register. CHECK_C_SOURCE_COMPILES(" @@ -70,6 +72,7 @@ IF(NOT MSVC AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i[36]86") }" HAVE_CLMUL_INSTRUCTION) IF(HAVE_CLMUL_INSTRUCTION) + SET(HAVE_CPUID_INSTRUCTION 1 CACHE BOOL "") SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_x86.c) ENDIF() ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64") diff --git a/storage/innobase/ut/ut0crc32.cc b/storage/innobase/ut/ut0crc32.cc index 1ddac168d95..80a0d165069 100644 --- a/storage/innobase/ut/ut0crc32.cc +++ b/storage/innobase/ut/ut0crc32.cc @@ -102,17 +102,7 @@ const char* ut_crc32_implementation = "Using POWER8 crc32 instructions"; extern "C" { uint32_t crc32c_aarch64(uint32_t crc, const unsigned char *buffer, uint64_t len); }; -# elif defined(_MSC_VER) -# define TRY_SSE4_2 -# elif defined (__GNUC__) -# ifdef __x86_64__ -# define TRY_SSE4_2 -# elif defined(__i386__) && (__GNUC__ > 4 || defined __clang__) -# define TRY_SSE4_2 -# endif -# endif - -# ifdef TRY_SSE4_2 +# elif defined HAVE_CPUID_INSTRUCTION /** return whether SSE4.2 instructions are available */ static inline bool has_sse4_2() { @@ -349,7 +339,7 @@ void ut_crc32_init() ut_crc32_implementation= crc32c_implementation; return; } -# elif defined(TRY_SSE4_2) +# elif defined HAVE_CPUID_INSTRUCTION if (has_sse4_2()) { ut_crc32_low= ut_crc32_hw; -- cgit v1.2.1 From c710c450e3a5654244fffaabcb4ba5af2dd24dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 28 Aug 2020 16:40:12 +0300 Subject: MDEV-21578 : CREATE OR REPLACE TRIGGER in Galera cluster not replicating While doing TOI buffer OR REPLACE option was not added to replicated string. --- mysql-test/suite/galera/r/galera_trigger.result | 32 ++++++++++++++++++++++ mysql-test/suite/galera/t/galera_trigger.test | 36 +++++++++++++++++++++++++ sql/wsrep_mysqld.cc | 7 ++++- 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/galera/r/galera_trigger.result create mode 100644 mysql-test/suite/galera/t/galera_trigger.test diff --git a/mysql-test/suite/galera/r/galera_trigger.result b/mysql-test/suite/galera/r/galera_trigger.result new file mode 100644 index 00000000000..112d3f39aa0 --- /dev/null +++ b/mysql-test/suite/galera/r/galera_trigger.result @@ -0,0 +1,32 @@ +CREATE TABLE IF NOT EXISTS t1 (id int(10) not null primary key) engine=innodb; +CREATE OR REPLACE TRIGGER tr1 +BEFORE INSERT ON t1 FOR EACH ROW +BEGIN +SET NEW.id = 100; +END| +INSERT INTO t1 VALUES (1); +SELECT * from t1; +id +100 +CREATE OR REPLACE TRIGGER tr1 +BEFORE INSERT ON t1 FOR EACH ROW +BEGIN +SET NEW.id = 200; +END| +connection node_2; +SET SESSION wsrep_sync_wait=15; +SELECT * FROM t1; +id +100 +INSERT INTO t1 values (2); +SELECT * FROM t1; +id +100 +200 +connection node_1; +SELECT * FROM t1; +id +100 +200 +DROP TRIGGER tr1; +DROP TABLE t1; diff --git a/mysql-test/suite/galera/t/galera_trigger.test b/mysql-test/suite/galera/t/galera_trigger.test new file mode 100644 index 00000000000..54508583f4b --- /dev/null +++ b/mysql-test/suite/galera/t/galera_trigger.test @@ -0,0 +1,36 @@ +--source include/galera_cluster.inc +# +# MDEV-21578 CREATE OR REPLACE TRIGGER in Galera cluster not replicating +# +CREATE TABLE IF NOT EXISTS t1 (id int(10) not null primary key) engine=innodb; +--delimiter | +CREATE OR REPLACE TRIGGER tr1 +BEFORE INSERT ON t1 FOR EACH ROW +BEGIN +SET NEW.id = 100; +END| +--delimiter ; + +INSERT INTO t1 VALUES (1); +SELECT * from t1; + +--delimiter | +CREATE OR REPLACE TRIGGER tr1 +BEFORE INSERT ON t1 FOR EACH ROW +BEGIN +SET NEW.id = 200; +END| +--delimiter ; + +--connection node_2 +SET SESSION wsrep_sync_wait=15; +SELECT * FROM t1; +INSERT INTO t1 values (2); +SELECT * FROM t1; + +--connection node_1 +SELECT * FROM t1; + +DROP TRIGGER tr1; +DROP TABLE t1; + diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index f95ef168a23..d392d1c2a61 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -2924,7 +2924,12 @@ static int wsrep_create_trigger_query(THD *thd, uchar** buf, size_t* buf_len) definer_host.length= 0; } - stmt_query.append(STRING_WITH_LEN("CREATE ")); + const LEX_STRING command[3]= + {{ C_STRING_WITH_LEN("CREATE ") }, + { C_STRING_WITH_LEN("ALTER ") }, + { C_STRING_WITH_LEN("CREATE OR REPLACE ") }}; + stmt_query.append(command[thd->lex->create_view_mode].str, + command[thd->lex->create_view_mode].length); append_definer(thd, &stmt_query, &definer_user, &definer_host); -- cgit v1.2.1 From 31e6c96b0449761dc15f548c28ded671d1b7219b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 31 Aug 2020 10:27:58 +0300 Subject: MDEV-20386 WITH_MSAN fails due to inline asm In commit 94d0bb4dbeb28a94d1f87fdd55f4297ff3df0157 (MDEV-20377) we replaced some inline assembler code with calls to GCC-style builtin functions. These functions would only be available if the target allows SSE4.2 instructions to be used. Hence, the cmake -DWITH_MSAN=ON build would fail unless the default x86 (IA-32) or AMD64 target was overridden. It turns out that the problem can be solved by overriding the default target architecture for specific functions with the help of GCC function attributes. ut_crc32c_8(), ut_crc32c_64(): Use the compiler-builtin intrinsic functions. For GCC before 5, the header file does not really work, and we must keep using the compiler built-in functions. For the Microsoft compiler, we will keep using because we will also need the definition of the __cpuid() function. On GCC and clang, we prefer to invoke inline assembler for that. Curiously, the inline assembler in has_sse4_2() or crc32_pclmul() is not causing any trouble for MSAN. Also, the inline assembler in WolfSSL appears to be fine now. Something might have changed between clang-8 and clang-10 (10.0.1). --- storage/innobase/ut/ut0crc32.cc | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/storage/innobase/ut/ut0crc32.cc b/storage/innobase/ut/ut0crc32.cc index 80a0d165069..0f7efb8b5b7 100644 --- a/storage/innobase/ut/ut0crc32.cc +++ b/storage/innobase/ut/ut0crc32.cc @@ -86,8 +86,17 @@ mysys/my_perf.c, contributed by Facebook under the following license. #include "ut0crc32.h" #include "my_valgrind.h" -#ifdef _MSC_VER -# include +#ifdef HAVE_CPUID_INSTRUCTION +# ifdef _MSC_VER +# include +# elif defined __GNUC__ && !defined __clang__ && __GNUC__ < 5 +/* does not really work in GCC before version 5 */ +# define _mm_crc32_u8(crc,data) __builtin_ia32_crc32qi(crc,data) +# define _mm_crc32_u32(crc,data) __builtin_ia32_crc32si(crc,data) +# define _mm_crc32_u64(crc,data) __builtin_ia32_crc32di(crc,data) +# else +# include +# endif #endif /* CRC32 hardware implementation. */ @@ -123,43 +132,25 @@ static inline bool has_sse4_2() @param crc CRC-32C checksum so far @param data data to be checksummed @return the updated CRC-32C */ +__attribute__((target("sse4.2"))) static inline ulint ut_crc32c_8(ulint crc, byte data) { -# ifdef _MSC_VER return _mm_crc32_u8(static_cast(crc), data); -# elif __has_feature(memory_sanitizer) - return __builtin_ia32_crc32qi(static_cast(crc), data); -# else - asm("crc32b %1, %0" : "+r" (crc) : "rm" (data)); - return crc; -# endif } /** Append 64 bits (8 aligned bytes) to a CRC-32C checksum @param[in] crc CRC-32C checksum so far @param[in] data 8 bytes of aligned data @return the updated CRC-32C */ +__attribute__((target("sse4.2"))) static inline ulint ut_crc32c_64(ulint crc, uint64_t data) { -# ifdef _MSC_VER -# ifdef _M_X64 +# if SIZEOF_SIZE_T > 4 return _mm_crc32_u64(crc, data); -# elif defined(_M_IX86) +# else crc= _mm_crc32_u32(crc, static_cast(data)); crc= _mm_crc32_u32(crc, static_cast(data >> 32)); return crc; -# else -# error Unsupported processor type -# endif -# elif __has_feature(memory_sanitizer) - return __builtin_ia32_crc32di(crc, data); -# elif defined __x86_64__ - asm("crc32q %1, %0" : "+r" (crc) : "rm" (data)); - return crc; -# else - asm("crc32l %1, %0" : "+r" (crc) : "rm" (static_cast(data))); - asm("crc32l %1, %0" : "+r" (crc) : "rm" (static_cast(data >> 32))); - return crc; # endif } -- cgit v1.2.1 From 9bb17ecf4352e0ba009d6afb9260d291ed70fa4c Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Mon, 31 Aug 2020 13:01:57 +0300 Subject: fix clang build FAILED: sql/CMakeFiles/sql.dir/sql_test.cc.o /home/kevgs/bin/clang++ -DHAVE_CONFIG_H -DHAVE_EVENT_SCHEDULER -DHAVE_POOL_OF_THREADS -DMYSQL_SERVER -D_FILE_OFFSET_BITS=64 -Iinclude -I../include -I../sql -Ipcre -I../pcre -I../zlib -Izlib -I../extra/yassl/include -I../extra/yassl/taocrypt/include -Isql -I../wsrep -O2 -fdiagnostics-color=always -fno-omit-frame-pointer -gsplit-dwarf -march=native -mtune=native -fPIC -fno-rtti -g -DENABLED_DEBUG_SYNC -ggdb3 -DSAFE_MUTEX -Wall -Wdeclaration-after-statement -Wextra -Wformat-security -Wno-init-self -Wno-null-conversion -Wno-unused-parameter -Wno-unused-private-field -Woverloaded-virtual -Wvla -Wwrite-strings -Werror -DHAVE_YASSL -DYASSL_PREFIX -DHAVE_OPENSSL -DMULTI_THREADED -MD -MT sql/CMakeFiles/sql.dir/sql_test.cc.o -MF sql/CMakeFiles/sql.dir/sql_test.cc.o.d -o sql/CMakeFiles/sql.dir/sql_test.cc.o -c ../sql/sql_test.cc ../sql/sql_test.cc:390:20: error: '::' and '*' tokens forming pointer to member type are separated by whitespace [-Werror,-Wcompound-token-split-by-space] Item* (List:: *dbug_list_item_elem_ptr)(int)= &List::elem; ~~^~ ../sql/sql_test.cc:391:32: error: '::' and '*' tokens forming pointer to member type are separated by whitespace [-Werror,-Wcompound-token-split-by-space] Item_equal* (List:: *dbug_list_item_equal_elem_ptr)(int)= ~~^~ ../sql/sql_test.cc:393:32: error: '::' and '*' tokens forming pointer to member type are separated by whitespace [-Werror,-Wcompound-token-split-by-space] TABLE_LIST* (List:: *dbug_list_table_list_elem_ptr)(int) = ~~^~ 3 errors generated. --- sql/sql_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/sql_test.cc b/sql/sql_test.cc index db52ce0aea1..4e68ec2ec2e 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -387,10 +387,10 @@ void print_sjm(SJ_MATERIALIZATION_INFO *sjm) /* Debugging help: force List<...>::elem function not be removed as unused. */ -Item* (List:: *dbug_list_item_elem_ptr)(int)= &List::elem; -Item_equal* (List:: *dbug_list_item_equal_elem_ptr)(int)= +Item* (List::*dbug_list_item_elem_ptr)(int)= &List::elem; +Item_equal* (List::*dbug_list_item_equal_elem_ptr)(int)= &List::elem; -TABLE_LIST* (List:: *dbug_list_table_list_elem_ptr)(int) = +TABLE_LIST* (List::*dbug_list_table_list_elem_ptr)(int) = &List::elem; #endif -- cgit v1.2.1 From 0f080dd60a9a4fbfcd9c8a2d0361c9d7f0c080aa Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Tue, 11 Aug 2020 16:37:48 +0200 Subject: MDEV-23094: Multiple calls to a Stored Procedure from another Stored Procedure crashes server Added system-SELECT to IF/WHILE/REPET/FOR for correct subqueries connecting. Added control of system/usual selects for correct error detection. --- mysql-test/main/parser.result | 89 +++++++++++++++++ mysql-test/main/parser.test | 97 ++++++++++++++++++ mysql-test/suite/compat/oracle/r/parser.result | 115 +++++++++++++++++++++ mysql-test/suite/compat/oracle/t/parser.test | 132 +++++++++++++++++++++++++ sql/sql_lex.cc | 6 +- sql/sql_lex.h | 14 ++- sql/sql_parse.cc | 1 + sql/sql_select.cc | 5 + sql/sql_union.cc | 2 + sql/sql_yacc.yy | 85 +++++++++++++--- sql/sql_yacc_ora.yy | 85 +++++++++++++--- 11 files changed, 601 insertions(+), 30 deletions(-) diff --git a/mysql-test/main/parser.result b/mysql-test/main/parser.result index 78156c842ea..49ef2073971 100644 --- a/mysql-test/main/parser.result +++ b/mysql-test/main/parser.result @@ -1908,4 +1908,93 @@ KILL ( SELECT 1 ) + LASTVAL(s); ERROR 42000: KILL does not support subqueries or stored functions KILL LASTVAL(s); ERROR 42000: KILL does not support subqueries or stored functions +# +# MDEV-23094: Multiple calls to a Stored Procedure from another +# Stored Procedure crashes server +# +create table t1 (id1 int primary key, data1 int); +create table t2 (id2 int primary key, data2 int); +create procedure p1(IN id int, IN dt int) +begin +if (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) +then +select 1; +end if; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +create procedure p1(IN id int, IN dt int) +begin +case (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) +when 1 then +select 1; +else +select 0; +end case; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +create procedure p1(IN id int, IN dt int) +begin +declare wcont int default 1; +while (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) and wcont +do +select 1; +set wcont=0; +end while; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +create procedure p1(IN id int, IN dt int) +begin +declare count int default 1; +repeat +select 1; +set count=count+1; +until (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) and +count < 3 +end repeat; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +create procedure p1(IN id int, IN dt int) +begin +for i in 1..(exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) +do +select 1; +end for; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +drop table t1,t2; # End of 10.4 tests diff --git a/mysql-test/main/parser.test b/mysql-test/main/parser.test index 608f76557e5..502bbde5ea5 100644 --- a/mysql-test/main/parser.test +++ b/mysql-test/main/parser.test @@ -1696,4 +1696,101 @@ KILL ( SELECT 1 ) + LASTVAL(s); --error ER_SUBQUERIES_NOT_SUPPORTED KILL LASTVAL(s); +--echo # +--echo # MDEV-23094: Multiple calls to a Stored Procedure from another +--echo # Stored Procedure crashes server +--echo # + +create table t1 (id1 int primary key, data1 int); +create table t2 (id2 int primary key, data2 int); + +delimiter //; +create procedure p1(IN id int, IN dt int) +begin + if (exists(select * from t1 where id1 = id and data1 = dt) or + not exists (select * from t2 where id2 = id and data2 = dt)) + then + select 1; + end if; +end // +delimiter ;// + +call p1(1,2); +call p1(1,2); + +drop procedure p1; + +delimiter //; +create procedure p1(IN id int, IN dt int) +begin +case (exists(select * from t1 where id1 = id and data1 = dt) or + not exists (select * from t2 where id2 = id and data2 = dt)) +when 1 then + select 1; +else + select 0; +end case; +end // +delimiter ;// + +call p1(1,2); +call p1(1,2); + +drop procedure p1; + +delimiter //; +create procedure p1(IN id int, IN dt int) +begin +declare wcont int default 1; +while (exists(select * from t1 where id1 = id and data1 = dt) or + not exists (select * from t2 where id2 = id and data2 = dt)) and wcont +do + select 1; + set wcont=0; +end while; +end // +delimiter ;// + +call p1(1,2); +call p1(1,2); + +drop procedure p1; + +delimiter //; +create procedure p1(IN id int, IN dt int) +begin +declare count int default 1; +repeat + select 1; + set count=count+1; +until (exists(select * from t1 where id1 = id and data1 = dt) or + not exists (select * from t2 where id2 = id and data2 = dt)) and + count < 3 +end repeat; +end // +delimiter ;// + +call p1(1,2); +call p1(1,2); + +drop procedure p1; + +delimiter //; +create procedure p1(IN id int, IN dt int) +begin +for i in 1..(exists(select * from t1 where id1 = id and data1 = dt) or + not exists (select * from t2 where id2 = id and data2 = dt)) +do + select 1; +end for; +end // +delimiter ;// + +call p1(1,2); +call p1(1,2); + +drop procedure p1; + +drop table t1,t2; + --echo # End of 10.4 tests diff --git a/mysql-test/suite/compat/oracle/r/parser.result b/mysql-test/suite/compat/oracle/r/parser.result index 0b573027c6d..2d9416d59c1 100644 --- a/mysql-test/suite/compat/oracle/r/parser.result +++ b/mysql-test/suite/compat/oracle/r/parser.result @@ -643,3 +643,118 @@ END; # # End of 10.3 tests # +# +# MDEV-21998: Server crashes in st_select_lex::add_table_to_list +# upon mix of KILL and sequences +# +KILL ( SELECT 1 ) + LASTVAL(s); +ERROR 42000: KILL does not support subqueries or stored functions +KILL LASTVAL(s); +ERROR 42000: KILL does not support subqueries or stored functions +# +# MDEV-23094: Multiple calls to a Stored Procedure from another +# Stored Procedure crashes server +# +create table t1 (id1 int primary key, data1 int); +create table t2 (id2 int primary key, data2 int); +create procedure p1(id int,dt int) as +begin +if (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) +then +select 1; +end if; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +create procedure p1(id int, dt int) as +begin +case (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) +when 1 then +select 1; +else +select 0; +end case; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +create procedure p1(id int, dt int) as +begin +declare wcont int default 1; +begin +while (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) and wcont +loop +select 1; +set wcont=0; +end loop; +end; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +create procedure p1(id int, dt int) as +begin +declare count int default 1; +begin +repeat +select 1; +set count=count+1; +until (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) and +count < 3 +end repeat; +end; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +create procedure p1(id int, dt int) as +begin +for i in 1..(exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)) +loop +select 1; +end loop; +end // +call p1(1,2); +1 +1 +call p1(1,2); +1 +1 +drop procedure p1; +set sql_mode=ORACLE; +create or replace procedure p1(id int, dt int) as +begin +while (1) +loop +exit when (exists(select * from t1 where id1 = id and data1 = dt) or +not exists (select * from t2 where id2 = id and data2 = dt)); +end loop; +end; +// +call p1(1,2); +call p1(1,2); +drop procedure p1; +drop table t1,t2; +# End of 10.4 tests diff --git a/mysql-test/suite/compat/oracle/t/parser.test b/mysql-test/suite/compat/oracle/t/parser.test index 4d558c5d153..8dabdc1b3bd 100644 --- a/mysql-test/suite/compat/oracle/t/parser.test +++ b/mysql-test/suite/compat/oracle/t/parser.test @@ -459,3 +459,135 @@ DELIMITER ;// --echo # --echo # End of 10.3 tests --echo # + + +--echo # +--echo # MDEV-21998: Server crashes in st_select_lex::add_table_to_list +--echo # upon mix of KILL and sequences +--echo # + +--error ER_SUBQUERIES_NOT_SUPPORTED +KILL ( SELECT 1 ) + LASTVAL(s); +--error ER_SUBQUERIES_NOT_SUPPORTED +KILL LASTVAL(s); + +--echo # +--echo # MDEV-23094: Multiple calls to a Stored Procedure from another +--echo # Stored Procedure crashes server +--echo # + +create table t1 (id1 int primary key, data1 int); +create table t2 (id2 int primary key, data2 int); + +delimiter //; +create procedure p1(id int,dt int) as +begin + if (exists(select * from t1 where id1 = id and data1 = dt) or + not exists (select * from t2 where id2 = id and data2 = dt)) + then + select 1; + end if; +end // +delimiter ;// + +call p1(1,2); +call p1(1,2); + +drop procedure p1; + +delimiter //; +create procedure p1(id int, dt int) as +begin +case (exists(select * from t1 where id1 = id and data1 = dt) or + not exists (select * from t2 where id2 = id and data2 = dt)) +when 1 then + select 1; +else + select 0; +end case; +end // +delimiter ;// + +call p1(1,2); +call p1(1,2); + +drop procedure p1; + +delimiter //; +create procedure p1(id int, dt int) as +begin +declare wcont int default 1; +begin + while (exists(select * from t1 where id1 = id and data1 = dt) or + not exists (select * from t2 where id2 = id and data2 = dt)) and wcont + loop + select 1; + set wcont=0; + end loop; +end; +end // +delimiter ;// + +call p1(1,2); +call p1(1,2); + +drop procedure p1; + +delimiter //; +create procedure p1(id int, dt int) as +begin +declare count int default 1; +begin + repeat + select 1; + set count=count+1; + until (exists(select * from t1 where id1 = id and data1 = dt) or + not exists (select * from t2 where id2 = id and data2 = dt)) and + count < 3 + end repeat; +end; +end // +delimiter ;// + +call p1(1,2); +call p1(1,2); + +drop procedure p1; + +delimiter //; +create procedure p1(id int, dt int) as +begin +for i in 1..(exists(select * from t1 where id1 = id and data1 = dt) or + not exists (select * from t2 where id2 = id and data2 = dt)) +loop + select 1; +end loop; +end // +delimiter ;// + +call p1(1,2); +call p1(1,2); + +drop procedure p1; + +delimiter //; +set sql_mode=ORACLE; +create or replace procedure p1(id int, dt int) as +begin + while (1) + loop + exit when (exists(select * from t1 where id1 = id and data1 = dt) or + not exists (select * from t2 where id2 = id and data2 = dt)); + end loop; +end; +// +delimiter ;// + +call p1(1,2); +call p1(1,2); + +drop procedure p1; + +drop table t1,t2; + +--echo # End of 10.4 tests diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index bb75ebd12a1..cbb1138fe4d 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -2428,6 +2428,7 @@ void st_select_lex::init_query() changed_elements= 0; first_natural_join_processing= 1; first_cond_optimization= 1; + is_service_select= 0; parsing_place= NO_MATTER; save_parsing_place= NO_MATTER; exclude_from_table_unique_test= no_wrap_view_item= FALSE; @@ -7614,7 +7615,7 @@ Item *LEX::create_item_ident_sp(THD *thd, Lex_ident_sys_st *name, return new (thd->mem_root) Item_func_sqlerrm(thd); } - if (!select_stack_head() && + if (fields_are_impossible() && (current_select->parsing_place != FOR_LOOP_BOUND || spcont->find_cursor(name, &unused_off, false) == NULL)) { @@ -8940,11 +8941,12 @@ void st_select_lex::add_statistics(SELECT_LEX_UNIT *unit) } -bool LEX::main_select_push() +bool LEX::main_select_push(bool service) { DBUG_ENTER("LEX::main_select_push"); current_select_number= 1; builtin_select.select_number= 1; + builtin_select.is_service_select= service; if (push_select(&builtin_select)) DBUG_RETURN(TRUE); DBUG_RETURN(FALSE); diff --git a/sql/sql_lex.h b/sql/sql_lex.h index ce30a630388..c8fca748b77 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1249,6 +1249,8 @@ public: bool no_wrap_view_item; /* exclude this select from check of unique_table() */ bool exclude_from_table_unique_test; + /* the select is "service-select" and can not have tables*/ + bool is_service_select; /* index in the select list of the expression currently being fixed */ int cur_pos_in_select_list; @@ -4413,7 +4415,7 @@ public: SELECT_LEX_UNIT *create_unit(SELECT_LEX*); SELECT_LEX *wrap_unit_into_derived(SELECT_LEX_UNIT *unit); SELECT_LEX *wrap_select_chain_into_derived(SELECT_LEX *sel); - bool main_select_push(); + bool main_select_push(bool service= false); bool insert_select_hack(SELECT_LEX *sel); SELECT_LEX *create_priority_nest(SELECT_LEX *first_in_nest); @@ -4530,6 +4532,16 @@ public: Lex_field_type_st *type) const; void mark_first_table_as_inserting(); + + bool fields_are_impossible() + { + // no select or it is last select with no tables (service select) + return !select_stack_head() || + (select_stack_top == 1 && + select_stack[0]->is_service_select); + } + + }; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index bf33148811e..909cb245b2e 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -8049,6 +8049,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, (alias ? alias->str : table->table.str), table, this, select_number)); + DBUG_ASSERT(!is_service_select || (table_options & TL_OPTION_SEQUENCE)); if (unlikely(!table)) DBUG_RETURN(0); // End of memory diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 7091ffc2c58..a813de0ef85 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1131,6 +1131,8 @@ JOIN::prepare(TABLE_LIST *tables_init, proc_param= proc_param_init; tables_list= tables_init; select_lex= select_lex_arg; + DBUG_PRINT("info", ("select %p (%u) = JOIN %p", + select_lex, select_lex->select_number, this)); select_lex->join= this; join_list= &select_lex->top_join_list; union_part= unit_arg->is_unit_op(); @@ -4494,6 +4496,9 @@ int JOIN::destroy() { DBUG_ENTER("JOIN::destroy"); + + DBUG_PRINT("info", ("select %p (%u) <> JOIN %p", + select_lex, select_lex->select_number, this)); select_lex->join= 0; cond_equal= 0; diff --git a/sql/sql_union.cc b/sql/sql_union.cc index e8b66bb8bd7..a487f4d4d73 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -2080,6 +2080,8 @@ bool st_select_lex::cleanup() bool error= FALSE; DBUG_ENTER("st_select_lex::cleanup()"); + DBUG_PRINT("info", ("select: %p (%u) JOIN %p", + this, select_number, join)); cleanup_order(order_list.first); cleanup_order(group_list.first); cleanup_ftfuncs(this); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 14b7a5589e1..83323e3f7e3 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2809,8 +2809,6 @@ create: { Lex->create_info.default_table_charset= NULL; Lex->create_info.used_fields= 0; - if (Lex->main_select_push()) - MYSQL_YYABORT; } opt_create_database_options { @@ -2819,7 +2817,6 @@ create: $1 | $3))) MYSQL_YYABORT; lex->name= $4; - Lex->pop_select(); //main select } | create_or_replace definer_opt opt_view_suid VIEW_SYM opt_if_not_exists table_ident @@ -3653,10 +3650,13 @@ sp_cursor_stmt: { DBUG_ASSERT(thd->free_list == NULL); Lex->sphead->reset_lex(thd, $1); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; } select { DBUG_ASSERT(Lex == $1); + Lex->pop_select(); //main select if (unlikely($1->stmt_finalize(thd)) || unlikely($1->sphead->restore_lex(thd))) MYSQL_YYABORT; @@ -4154,6 +4154,11 @@ sp_proc_stmt_statement: Lex_input_stream *lip= YYLIP; lex->sphead->reset_lex(thd); + /* + We should not push main select here, it will be done or not + done by the statement, we just provide only a new LEX for the + statement here as if it is start of parsing a new statement. + */ lex->sphead->m_tmp_query= lip->get_tok_start(); } statement @@ -4172,11 +4177,16 @@ RETURN_ALLMODES_SYM: sp_proc_stmt_return: RETURN_ALLMODES_SYM - { Lex->sphead->reset_lex(thd); } + { + Lex->sphead->reset_lex(thd); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; + } expr { LEX *lex= Lex; sp_head *sp= lex->sphead; + Lex->pop_select(); //main select if (unlikely(sp->m_handler->add_instr_freturn(thd, sp, lex->spcont, $3, lex)) || unlikely(sp->restore_lex(thd))) @@ -4193,7 +4203,16 @@ sp_proc_stmt_return: ; reset_lex_expr: - { Lex->sphead->reset_lex(thd); } expr { $$= $2; } + { + Lex->sphead->reset_lex(thd); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; + } + expr + { + Lex->pop_select(); //main select + $$= $2; + } ; sp_proc_stmt_exit_oracle: @@ -4285,6 +4304,8 @@ assignment_source_expr: { DBUG_ASSERT(thd->free_list == NULL); Lex->sphead->reset_lex(thd, $1); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; } expr { @@ -4293,6 +4314,7 @@ assignment_source_expr: $$->sp_lex_in_use= true; $$->set_item_and_free_list($3, thd->free_list); thd->free_list= NULL; + Lex->pop_select(); //min select if ($$->sphead->restore_lex(thd)) MYSQL_YYABORT; } @@ -4302,6 +4324,8 @@ for_loop_bound_expr: assignment_source_lex { Lex->sphead->reset_lex(thd, $1); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; Lex->current_select->parsing_place= FOR_LOOP_BOUND; } expr @@ -4310,6 +4334,7 @@ for_loop_bound_expr: $$= $1; $$->sp_lex_in_use= true; $$->set_item_and_free_list($3, NULL); + Lex->pop_select(); //main select if (unlikely($$->sphead->restore_lex(thd))) MYSQL_YYABORT; Lex->current_select->parsing_place= NO_MATTER; @@ -4424,7 +4449,11 @@ sp_fetch_list: ; sp_if: - { Lex->sphead->reset_lex(thd); } + { + Lex->sphead->reset_lex(thd); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; + } expr THEN_SYM { LEX *lex= Lex; @@ -4438,6 +4467,7 @@ sp_if: unlikely(sp->add_cont_backpatch(i)) || unlikely(sp->add_instr(i))) MYSQL_YYABORT; + Lex->pop_select(); //main select if (unlikely(sp->restore_lex(thd))) MYSQL_YYABORT; } @@ -4538,12 +4568,17 @@ case_stmt_specification: ; case_stmt_body: - { Lex->sphead->reset_lex(thd); /* For expr $2 */ } + { + Lex->sphead->reset_lex(thd); /* For expr $2 */ + if (Lex->main_select_push(true)) + MYSQL_YYABORT; + } expr { if (unlikely(Lex->case_stmt_action_expr($2))) MYSQL_YYABORT; + Lex->pop_select(); //main select if (Lex->sphead->restore_lex(thd)) MYSQL_YYABORT; } @@ -4567,6 +4602,8 @@ simple_when_clause: WHEN_SYM { Lex->sphead->reset_lex(thd); /* For expr $3 */ + if (Lex->main_select_push(true)) + MYSQL_YYABORT; } expr { @@ -4575,6 +4612,7 @@ simple_when_clause: LEX *lex= Lex; if (unlikely(lex->case_stmt_action_when($3, true))) MYSQL_YYABORT; + Lex->pop_select(); //main select /* For expr $3 */ if (unlikely(lex->sphead->restore_lex(thd))) MYSQL_YYABORT; @@ -4591,12 +4629,15 @@ searched_when_clause: WHEN_SYM { Lex->sphead->reset_lex(thd); /* For expr $3 */ + if (Lex->main_select_push(true)) + MYSQL_YYABORT; } expr { LEX *lex= Lex; if (unlikely(lex->case_stmt_action_when($3, false))) MYSQL_YYABORT; + Lex->pop_select(); //main select /* For expr $3 */ if (unlikely(lex->sphead->restore_lex(thd))) MYSQL_YYABORT; @@ -4695,9 +4736,15 @@ opt_sp_for_loop_direction: ; sp_for_loop_index_and_bounds: - ident sp_for_loop_bounds + ident { - if (unlikely(Lex->sp_for_loop_declarations(thd, &$$, &$1, $2))) + if (Lex->main_select_push(true)) + MYSQL_YYABORT; + } + sp_for_loop_bounds + { + Lex->pop_select(); //main select + if (unlikely(Lex->sp_for_loop_declarations(thd, &$$, &$1, $3))) MYSQL_YYABORT; } ; @@ -4743,8 +4790,11 @@ while_body: LEX *lex= Lex; if (unlikely(lex->sp_while_loop_expression(thd, $1))) MYSQL_YYABORT; + Lex->pop_select(); //main select if (lex->sphead->restore_lex(thd)) MYSQL_YYABORT; + if (lex->main_select_push(true)) + MYSQL_YYABORT; } sp_proc_stmts1 END WHILE_SYM { @@ -4755,7 +4805,11 @@ while_body: repeat_body: sp_proc_stmts1 UNTIL_SYM - { Lex->sphead->reset_lex(thd); } + { + Lex->sphead->reset_lex(thd); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; + } expr END REPEAT_SYM { LEX *lex= Lex; @@ -4766,6 +4820,7 @@ repeat_body: if (unlikely(i == NULL) || unlikely(lex->sphead->add_instr(i))) MYSQL_YYABORT; + Lex->pop_select(); //main select if (lex->sphead->restore_lex(thd)) MYSQL_YYABORT; /* We can shortcut the cont_backpatch here */ @@ -4794,6 +4849,8 @@ sp_labeled_control: if (unlikely(Lex->sp_push_loop_label(thd, &$1))) MYSQL_YYABORT; Lex->sphead->reset_lex(thd); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; } while_body pop_sp_loop_label { } @@ -4845,6 +4902,8 @@ sp_unlabeled_control: if (unlikely(Lex->sp_push_loop_empty_label(thd))) MYSQL_YYABORT; Lex->sphead->reset_lex(thd); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; } while_body { @@ -7816,7 +7875,7 @@ alter: { Lex->create_info.default_table_charset= NULL; Lex->create_info.used_fields= 0; - if (Lex->main_select_push()) + if (Lex->main_select_push(true)) MYSQL_YYABORT; } create_database_options @@ -13265,7 +13324,7 @@ do: { LEX *lex=Lex; lex->sql_command = SQLCOM_DO; - if (lex->main_select_push()) + if (lex->main_select_push(true)) MYSQL_YYABORT; mysql_init_select(lex); } @@ -16453,7 +16512,7 @@ set: SET { LEX *lex=Lex; - if (lex->main_select_push()) + if (lex->main_select_push(true)) MYSQL_YYABORT; lex->set_stmt_init(); lex->var_list.empty(); diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index 9366a7bcd9f..c8084f8109c 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -2311,8 +2311,6 @@ create: { Lex->create_info.default_table_charset= NULL; Lex->create_info.used_fields= 0; - if (Lex->main_select_push()) - MYSQL_YYABORT; } opt_create_database_options { @@ -2321,7 +2319,6 @@ create: $1 | $3))) MYSQL_YYABORT; lex->name= $4; - Lex->pop_select(); //main select } | create_or_replace definer_opt opt_view_suid VIEW_SYM opt_if_not_exists table_ident @@ -3547,10 +3544,13 @@ sp_cursor_stmt: { DBUG_ASSERT(thd->free_list == NULL); Lex->sphead->reset_lex(thd, $1); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; } select { DBUG_ASSERT(Lex == $1); + Lex->pop_select(); //main select if (unlikely($1->stmt_finalize(thd)) || unlikely($1->sphead->restore_lex(thd))) MYSQL_YYABORT; @@ -4061,6 +4061,11 @@ sp_proc_stmt_statement: Lex_input_stream *lip= YYLIP; lex->sphead->reset_lex(thd); + /* + We should not push main select here, it will be done or not + done by the statement, we just provide only new LEX for the + statement here as if it is start of parsing new statement. + */ lex->sphead->m_tmp_query= lip->get_tok_start(); } sp_statement @@ -4079,11 +4084,16 @@ RETURN_ALLMODES_SYM: sp_proc_stmt_return: RETURN_ALLMODES_SYM - { Lex->sphead->reset_lex(thd); } + { + Lex->sphead->reset_lex(thd); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; + } expr { LEX *lex= Lex; sp_head *sp= lex->sphead; + Lex->pop_select(); //main select if (unlikely(sp->m_handler->add_instr_freturn(thd, sp, lex->spcont, $3, lex)) || unlikely(sp->restore_lex(thd))) @@ -4100,9 +4110,16 @@ sp_proc_stmt_return: ; reset_lex_expr: - { Lex->sphead->reset_lex(thd); } + { + Lex->sphead->reset_lex(thd); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; + } expr - { $$= $2; } + { + $$= $2; + Lex->pop_select(); //main select + } ; sp_proc_stmt_exit_oracle: @@ -4201,6 +4218,8 @@ assignment_source_expr: { DBUG_ASSERT(thd->free_list == NULL); Lex->sphead->reset_lex(thd, $1); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; } expr { @@ -4209,6 +4228,7 @@ assignment_source_expr: $$->sp_lex_in_use= true; $$->set_item_and_free_list($3, thd->free_list); thd->free_list= NULL; + Lex->pop_select(); //main select if ($$->sphead->restore_lex(thd)) MYSQL_YYABORT; } @@ -4218,6 +4238,8 @@ for_loop_bound_expr: assignment_source_lex { Lex->sphead->reset_lex(thd, $1); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; Lex->current_select->parsing_place= FOR_LOOP_BOUND; } expr @@ -4226,6 +4248,7 @@ for_loop_bound_expr: $$= $1; $$->sp_lex_in_use= true; $$->set_item_and_free_list($3, NULL); + Lex->pop_select(); //main select if (unlikely($$->sphead->restore_lex(thd))) MYSQL_YYABORT; Lex->current_select->parsing_place= NO_MATTER; @@ -4338,7 +4361,11 @@ sp_fetch_list: ; sp_if: - { Lex->sphead->reset_lex(thd); } + { + Lex->sphead->reset_lex(thd); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; + } expr THEN_SYM { LEX *lex= Lex; @@ -4352,6 +4379,7 @@ sp_if: unlikely(sp->add_cont_backpatch(i)) || unlikely(sp->add_instr(i))) MYSQL_YYABORT; + Lex->pop_select(); //main select if (unlikely(sp->restore_lex(thd))) MYSQL_YYABORT; } @@ -4452,12 +4480,17 @@ case_stmt_specification: ; case_stmt_body: - { Lex->sphead->reset_lex(thd); /* For expr $2 */ } + { + Lex->sphead->reset_lex(thd); /* For expr $2 */ + if (Lex->main_select_push(true)) + MYSQL_YYABORT; + } expr { if (unlikely(Lex->case_stmt_action_expr($2))) MYSQL_YYABORT; + Lex->pop_select(); //main select if (Lex->sphead->restore_lex(thd)) MYSQL_YYABORT; } @@ -4481,6 +4514,8 @@ simple_when_clause: WHEN_SYM { Lex->sphead->reset_lex(thd); /* For expr $3 */ + if (Lex->main_select_push(true)) + MYSQL_YYABORT; } expr { @@ -4489,6 +4524,7 @@ simple_when_clause: LEX *lex= Lex; if (unlikely(lex->case_stmt_action_when($3, true))) MYSQL_YYABORT; + Lex->pop_select(); //main select /* For expr $3 */ if (unlikely(lex->sphead->restore_lex(thd))) MYSQL_YYABORT; @@ -4505,12 +4541,15 @@ searched_when_clause: WHEN_SYM { Lex->sphead->reset_lex(thd); /* For expr $3 */ + if (Lex->main_select_push(true)) + MYSQL_YYABORT; } expr { LEX *lex= Lex; if (unlikely(lex->case_stmt_action_when($3, false))) MYSQL_YYABORT; + Lex->pop_select(); //main select /* For expr $3 */ if (unlikely(lex->sphead->restore_lex(thd))) MYSQL_YYABORT; @@ -4699,9 +4738,15 @@ opt_sp_for_loop_direction: ; sp_for_loop_index_and_bounds: - ident_directly_assignable sp_for_loop_bounds + ident_directly_assignable { - if (unlikely(Lex->sp_for_loop_declarations(thd, &$$, &$1, $2))) + if (Lex->main_select_push(true)) + MYSQL_YYABORT; + } + sp_for_loop_bounds + { + Lex->pop_select(); //main select + if (unlikely(Lex->sp_for_loop_declarations(thd, &$$, &$1, $3))) MYSQL_YYABORT; } ; @@ -4747,8 +4792,11 @@ while_body: LEX *lex= Lex; if (unlikely(lex->sp_while_loop_expression(thd, $1))) MYSQL_YYABORT; + Lex->pop_select(); //main select if (lex->sphead->restore_lex(thd)) MYSQL_YYABORT; + if (lex->main_select_push(true)) + MYSQL_YYABORT; } sp_proc_stmts1 END LOOP_SYM { @@ -4759,7 +4807,11 @@ while_body: repeat_body: sp_proc_stmts1 UNTIL_SYM - { Lex->sphead->reset_lex(thd); } + { + Lex->sphead->reset_lex(thd); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; + } expr END REPEAT_SYM { LEX *lex= Lex; @@ -4770,6 +4822,7 @@ repeat_body: if (unlikely(i == NULL) || unlikely(lex->sphead->add_instr(i))) MYSQL_YYABORT; + Lex->pop_select(); //main select if (lex->sphead->restore_lex(thd)) MYSQL_YYABORT; /* We can shortcut the cont_backpatch here */ @@ -4798,6 +4851,8 @@ sp_labeled_control: if (unlikely(Lex->sp_push_loop_label(thd, &$1))) MYSQL_YYABORT; Lex->sphead->reset_lex(thd); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; } while_body pop_sp_loop_label { } @@ -4849,6 +4904,8 @@ sp_unlabeled_control: if (unlikely(Lex->sp_push_loop_empty_label(thd))) MYSQL_YYABORT; Lex->sphead->reset_lex(thd); + if (Lex->main_select_push(true)) + MYSQL_YYABORT; } while_body { @@ -7914,7 +7971,7 @@ alter: { Lex->create_info.default_table_charset= NULL; Lex->create_info.used_fields= 0; - if (Lex->main_select_push()) + if (Lex->main_select_push(true)) MYSQL_YYABORT; } create_database_options @@ -13372,7 +13429,7 @@ do: { LEX *lex=Lex; lex->sql_command = SQLCOM_DO; - if (lex->main_select_push()) + if (lex->main_select_push(true)) MYSQL_YYABORT; mysql_init_select(lex); } @@ -16619,7 +16676,7 @@ set: SET { LEX *lex=Lex; - if (lex->main_select_push()) + if (lex->main_select_push(true)) MYSQL_YYABORT; lex->set_stmt_init(); lex->var_list.empty(); -- cgit v1.2.1 From 6112a0f93d137b9754bc04449873311784e0edd9 Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Tue, 11 Aug 2020 21:45:09 +0300 Subject: MDEV-16372 ER_BASE64_DECODE_ERROR upon replaying binary log via mysqlbinlog --verbose (This commit is exclusively for 10.2 branch. Do not merge it to 10.3) In case of a pattern of non-STMT_END-marked Rows-log-event (A) followed by a STMT_END marked one (B) mysqlbinlog mixes up the base64 encoded rows events with their pseudo sql representation produced by the verbose option: BINLOG ' base64 encoded data for A ### verbose section for A base64 encoded data for B ### verbose section for B '/*!*/; In effect the produced BINLOG '...' query is not valid and is rejected with the error. Examples of this way malformed BINLOG could have been found in binlog_row_annotate.result that gets corrected with the patch. The issue is fixed with introduction an auxiliary IO_CACHE to hold on the verbose comments until the terminal STMT_END event is found. The new cache is emptied out after two pre-existing ones are done at that time. The correctly produced output now for the above case is as the following: BINLOG ' base64 encoded data for A base64 encoded data for B '/*!*/; ### verbose section for A ### verbose section for B Thanks to Alexey Midenkov for the problem recognition and attempt to tackle, and to Venkatesh Duggirala who produced a patch for the upstream whose idea is exploited here, as well as to MDEV-23077 reporter LukeXwang who also contributed a piece of a patch aiming at this issue. --- client/mysqlbinlog.cc | 11 ++++-- mysql-test/r/mysqlbinlog_row_minimal.result | 44 +++++++++++++++------- .../suite/binlog/r/binlog_row_annotate.result | 2 - .../binlog/t/binlog_mysqlbinlog_row_frag.test | 3 +- .../binlog_encryption/binlog_row_annotate.result | 1 - mysql-test/t/mysqlbinlog_row_minimal.test | 32 +++++++++++++++- sql/log_event.cc | 38 ++++++++----------- sql/log_event.h | 6 ++- sql/log_event_old.cc | 8 ++++ 9 files changed, 96 insertions(+), 49 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 13a92c0b581..4e28876cdf6 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -891,7 +891,8 @@ static bool print_base64(PRINT_EVENT_INFO *print_event_info, Log_event *ev) ev->print(result_file, print_event_info); return print_event_info->head_cache.error == -1 || - print_event_info->body_cache.error == -1; + print_event_info->body_cache.error == -1 || + print_event_info->tail_cache.error == -1; } @@ -962,8 +963,12 @@ static bool print_row_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, my_b_printf(body_cache, "'%s\n", print_event_info->delimiter); // flush cache - if ((copy_event_cache_to_file_and_reinit(&print_event_info->head_cache, result_file) || - copy_event_cache_to_file_and_reinit(&print_event_info->body_cache, result_file))) + if ((copy_event_cache_to_file_and_reinit(&print_event_info->head_cache, + result_file) || + copy_event_cache_to_file_and_reinit(&print_event_info->body_cache, + result_file) || + copy_event_cache_to_file_and_reinit(&print_event_info->tail_cache, + result_file))) return 1; } } diff --git a/mysql-test/r/mysqlbinlog_row_minimal.result b/mysql-test/r/mysqlbinlog_row_minimal.result index e78c3ca3a40..776c7ac5b53 100644 --- a/mysql-test/r/mysqlbinlog_row_minimal.result +++ b/mysql-test/r/mysqlbinlog_row_minimal.result @@ -319,6 +319,24 @@ ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; DROP TABLE t1,t2; +# +# MDEV-16372 ER_BASE64_DECODE_ERROR upon replaying binary log with system table +# +FLUSH BINARY LOGS; +CREATE TABLE t1 (pk INT PRIMARY KEY); +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (1), (2) ON DUPLICATE KEY UPDATE pk= pk + 10; +FLUSH BINARY LOGS; +Proof: two subsequent patterns must be found +FOUND 1 /### UPDATE `test`.`t1`/ in mysqlbinlog.sql +FOUND 2 /### INSERT INTO `test`.`t1`/ in mysqlbinlog.sql +DROP TABLE t1; +SELECT * FROM t1; +pk +2 +11 +# Cleanup +DROP TABLE t1; CREATE TABLE `t1` ( `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, `is_deleted` BIT(1) DEFAULT b'0', @@ -343,33 +361,33 @@ FLUSH BINARY LOGS; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; -# at 387 -# server id 1 end_log_pos 429 CRC32 XXX GTID 0-1-16 +# at POS +# server id 1 end_log_pos END_LOG_POS CRC32 XXX GTID D-S-N /*!100101 SET @@session.skip_parallel_replication=0*//*!*/; /*!100001 SET @@session.gtid_domain_id=0*//*!*/; /*!100001 SET @@session.server_id=1*//*!*/; -/*!100001 SET @@session.gtid_seq_no=16*//*!*/; +/*!100001 SET @@session.gtid_seq_no=21*//*!*/; BEGIN /*!*/; -# at 429 -# at 543 -# server id 1 end_log_pos 543 CRC32 XXX Annotate_rows: +# at POS +# at POS +# server id 1 end_log_pos END_LOG_POS CRC32 XXX Annotate_rows: #Q> UPDATE t1 t1 INNER JOIN t2 t2 ON t1.ref_id = t2.id #Q> SET t1.is_deleted = TRUE #Q> WHERE t1.id = -# server id 1 end_log_pos 594 CRC32 XXX Table_map: `test`.`t1` mapped to number 34 -# at 594 -# server id 1 end_log_pos 643 CRC32 XXX Update_rows: table id 34 flags: STMT_END_F +# server id 1 end_log_pos END_LOG_POS CRC32 XXX Table_map: `test`.`t1` mapped to number TID +# at POS +# server id 1 end_log_pos END_LOG_POS CRC32 XXX Update_rows: table id TID flags: STMT_END_F ### UPDATE `test`.`t1` ### WHERE ### @1=1 /* LONGINT meta=0 nullable=0 is_null=0 */ ### SET ### @2=b'1' /* BIT(1) meta=1 nullable=1 is_null=0 */ ### @3=X /* TIMESTAMP(0) meta=0 nullable=0 is_null=0 */ -# at 643 -# server id 1 end_log_pos 725 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 +# at POS +# server id 1 end_log_pos END_LOG_POS CRC32 XXX Query thread_id=TID exec_time=x error_code=0 SET TIMESTAMP=X/*!*/; -SET @@session.pseudo_thread_id=5/*!*/; +SET @@session.pseudo_thread_id=TID/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1, @@session.check_constraint_checks=1/*!*/; SET @@session.sql_mode=#/*!*/; SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; @@ -379,8 +397,6 @@ SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; COMMIT /*!*/; -# at 725 -# server id 1 end_log_pos 773 CRC32 XXX Rotate to master-bin.000004 pos: 4 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; diff --git a/mysql-test/suite/binlog/r/binlog_row_annotate.result b/mysql-test/suite/binlog/r/binlog_row_annotate.result index 2104d6b0e51..732ecdd02fd 100644 --- a/mysql-test/suite/binlog/r/binlog_row_annotate.result +++ b/mysql-test/suite/binlog/r/binlog_row_annotate.result @@ -442,7 +442,6 @@ BEGIN ### DELETE FROM `test1`.`t1` ### WHERE ### @1=3 /* INT meta=0 nullable=1 is_null=0 */ -'/*!*/; # at # #010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; @@ -1053,7 +1052,6 @@ BEGIN ### DELETE FROM `test1`.`t1` ### WHERE ### @1=3 /* INT meta=0 nullable=1 is_null=0 */ -'/*!*/; # at # #010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; diff --git a/mysql-test/suite/binlog/t/binlog_mysqlbinlog_row_frag.test b/mysql-test/suite/binlog/t/binlog_mysqlbinlog_row_frag.test index a1791d9701d..9f79deea3db 100644 --- a/mysql-test/suite/binlog/t/binlog_mysqlbinlog_row_frag.test +++ b/mysql-test/suite/binlog/t/binlog_mysqlbinlog_row_frag.test @@ -11,8 +11,7 @@ SELECT a from t into @a; FLUSH LOGS; DELETE FROM t; -# Todo: MDEV-10362 to test multi-row Rows_log_event:s in verbose mode ---exec $MYSQL_BINLOG -vv --debug-binlog-row-event-max-encoded-size=256 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +--exec $MYSQL_BINLOG --verbose --debug-binlog-row-event-max-encoded-size=256 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql --let SEARCH_PATTERN= BINLOG @binlog_fragment_0, @binlog_fragment_1 --let SEARCH_FILE= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql diff --git a/mysql-test/suite/binlog_encryption/binlog_row_annotate.result b/mysql-test/suite/binlog_encryption/binlog_row_annotate.result index 9b843dc8a6b..83903ecc18a 100644 --- a/mysql-test/suite/binlog_encryption/binlog_row_annotate.result +++ b/mysql-test/suite/binlog_encryption/binlog_row_annotate.result @@ -449,7 +449,6 @@ BEGIN ### DELETE FROM `test1`.`t1` ### WHERE ### @1=3 /* INT meta=0 nullable=1 is_null=0 */ -'/*!*/; # at # #010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; diff --git a/mysql-test/t/mysqlbinlog_row_minimal.test b/mysql-test/t/mysqlbinlog_row_minimal.test index b69aa6da14b..b399cc4ac45 100644 --- a/mysql-test/t/mysqlbinlog_row_minimal.test +++ b/mysql-test/t/mysqlbinlog_row_minimal.test @@ -33,6 +33,33 @@ FLUSH BINARY LOGS; DROP TABLE t1,t2; +--echo # +--echo # MDEV-16372 ER_BASE64_DECODE_ERROR upon replaying binary log with system table +--echo # +FLUSH BINARY LOGS; +CREATE TABLE t1 (pk INT PRIMARY KEY); +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (1), (2) ON DUPLICATE KEY UPDATE pk= pk + 10; + +--let $binlog = query_get_value(SHOW MASTER STATUS, File, 1) + +FLUSH BINARY LOGS; +--exec $MYSQL_BINLOG --verbose $datadir/$binlog > $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +--echo Proof: two subsequent patterns must be found +--let SEARCH_PATTERN= ### UPDATE `test`.`t1` +--let SEARCH_FILE= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN= ### INSERT INTO `test`.`t1` +--let SEARCH_FILE= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +--source include/search_pattern_in_file.inc + +DROP TABLE t1; +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +SELECT * FROM t1; + +--echo # Cleanup +DROP TABLE t1; +--remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql # # MDEV-14605 ON UPDATE CURRENT_TIMESTAMP fields by multi-table UPDATE are not logged with binlog_row_image=MINIMAL # @@ -64,11 +91,12 @@ UPDATE t1 t1 INNER JOIN t2 t2 ON t1.ref_id = t2.id WHERE t1.id = 1; --let $binlog = query_get_value(SHOW MASTER STATUS, File, 1) +--let $binlog_end= query_get_value(SHOW MASTER STATUS, Position, 1) FLUSH BINARY LOGS; --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR ---replace_regex /\d{6} *\d*:\d\d:\d\d// /SET TIMESTAMP=\d*/SET TIMESTAMP=X/ /exec_time=\d*/exec_time=x/ /@3=\d*/@3=X/ /CRC32 0x[0-9a-f]+/CRC32 XXX/ /@@session.sql_mode=\d+/@@session.sql_mode=#/ /collation_server=\d+/collation_server=#/ ---exec $MYSQL_BINLOG --verbose --verbose --base64-output=DECODE-ROWS $datadir/$binlog --start-position=$binlog_pos +--replace_regex /table id \d*/table id TID/ /mapped to number \d*/mapped to number TID/ /at \d*/at POS/ /end_log_pos \d*/end_log_pos END_LOG_POS/ /GTID \d*-\d*-\d*/GTID D-S-N/ /\d{6} *\d*:\d\d:\d\d// /SET TIMESTAMP=\d*/SET TIMESTAMP=X/ /exec_time=\d*/exec_time=x/ /@3=\d*/@3=X/ /CRC32 0x[0-9a-f]+/CRC32 XXX/ /@@session.sql_mode=\d+/@@session.sql_mode=#/ /collation_server=\d+/collation_server=#/ /thread_id=\d*/thread_id=TID/ +--exec $MYSQL_BINLOG --verbose --verbose --base64-output=DECODE-ROWS $datadir/$binlog --start-position=$binlog_pos --stop-position=$binlog_end DROP TABLE t1,t2; diff --git a/sql/log_event.cc b/sql/log_event.cc index 26c9cb6f9cb..e21a18273b3 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -3579,7 +3579,7 @@ void Log_event::print_base64(IO_CACHE* file, #ifdef WHEN_FLASHBACK_REVIEW_READY ev->need_flashback_review= need_flashback_review; if (print_event_info->verbose) - ev->print_verbose(file, print_event_info); + ev->print_verbose(&print_event_info->tail_cache, print_event_info); else { IO_CACHE tmp_cache; @@ -3589,18 +3589,7 @@ void Log_event::print_base64(IO_CACHE* file, } #else if (print_event_info->verbose) - { - /* - Verbose event printout can't start before encoded data - got enquoted. This is done at this point though multi-row - statement remain vulnerable. - TODO: fix MDEV-10362 to remove this workaround. - */ - if (print_event_info->base64_output_mode != - BASE64_OUTPUT_DECODE_ROWS) - my_b_printf(file, "'%s\n", print_event_info->delimiter); - ev->print_verbose(file, print_event_info); - } + ev->print_verbose(&print_event_info->tail_cache, print_event_info); #endif delete ev; } @@ -11538,11 +11527,8 @@ void copy_cache_to_string_wrapped(IO_CACHE *cache, str_tmp.length= sprintf(str_tmp.str, fmt_frag, 1); ret.append(&str_tmp); ret.append(cache, uint32(cache->end_of_file - (cache_size/2 + 1))); - if (!is_verbose) - { - str_tmp.length= sprintf(str_tmp.str, fmt_delim, delimiter); - ret.append(&str_tmp); - } + str_tmp.length= sprintf(str_tmp.str, fmt_delim, delimiter); + ret.append(&str_tmp); str_tmp.length= sprintf(str_tmp.str, "BINLOG @binlog_fragment_0, @binlog_fragment_1%s\n", delimiter); ret.append(&str_tmp); @@ -11552,11 +11538,8 @@ void copy_cache_to_string_wrapped(IO_CACHE *cache, str_tmp.length= sprintf(str_tmp.str, str_binlog); ret.append(&str_tmp); ret.append(cache, (uint32) cache->end_of_file); - if (!is_verbose) - { - str_tmp.length= sprintf(str_tmp.str, fmt_delim, delimiter); - ret.append(&str_tmp); - } + str_tmp.length= sprintf(str_tmp.str, fmt_delim, delimiter); + ret.append(&str_tmp); } to->length= ret.length(); @@ -11605,6 +11588,7 @@ void Rows_log_event::print_helper(FILE *file, { IO_CACHE *const head= &print_event_info->head_cache; IO_CACHE *const body= &print_event_info->body_cache; + IO_CACHE *const tail= &print_event_info->tail_cache; #ifdef WHEN_FLASHBACK_REVIEW_READY IO_CACHE *const sql= &print_event_info->review_sql_cache; #endif @@ -11646,6 +11630,13 @@ void Rows_log_event::print_helper(FILE *file, print_event_info->verbose); output_buf.append(&tmp_str); my_free(tmp_str.str); + if (copy_event_cache_to_string_and_reinit(tail, &tmp_str)) + { + tail->error= -1; + return; + } + output_buf.append(&tmp_str); + my_free(tmp_str.str); } } #endif @@ -14316,6 +14307,7 @@ st_print_event_info::st_print_event_info() myf const flags = MYF(MY_WME | MY_NABP); open_cached_file(&head_cache, NULL, NULL, 0, flags); open_cached_file(&body_cache, NULL, NULL, 0, flags); + open_cached_file(&tail_cache, NULL, NULL, 0, flags); #ifdef WHEN_FLASHBACK_REVIEW_READY open_cached_file(&review_sql_cache, NULL, NULL, 0, flags); #endif diff --git a/sql/log_event.h b/sql/log_event.h index 1fae201057f..3fc44a9669f 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -848,18 +848,19 @@ typedef struct st_print_event_info ~st_print_event_info() { close_cached_file(&head_cache); close_cached_file(&body_cache); + close_cached_file(&tail_cache); #ifdef WHEN_FLASHBACK_REVIEW_READY close_cached_file(&review_sql_cache); #endif } bool init_ok() /* tells if construction was successful */ - { return my_b_inited(&head_cache) && my_b_inited(&body_cache) + { return my_b_inited(&head_cache) && my_b_inited(&body_cache) && + my_b_inited(&tail_cache) #ifdef WHEN_FLASHBACK_REVIEW_READY && my_b_inited(&review_sql_cache) #endif ; } - /* Settings on how to print the events */ bool short_form; enum_base64_output_mode base64_output_mode; @@ -885,6 +886,7 @@ typedef struct st_print_event_info */ IO_CACHE head_cache; IO_CACHE body_cache; + IO_CACHE tail_cache; #ifdef WHEN_FLASHBACK_REVIEW_READY /* Storing the SQL for reviewing */ IO_CACHE review_sql_cache; diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc index b655d510bd5..2de316a4c55 100644 --- a/sql/log_event_old.cc +++ b/sql/log_event_old.cc @@ -1859,6 +1859,7 @@ void Old_rows_log_event::print_helper(FILE *file, { IO_CACHE *const head= &print_event_info->head_cache; IO_CACHE *const body= &print_event_info->body_cache; + IO_CACHE *const tail= &print_event_info->tail_cache; bool do_print_encoded= print_event_info->base64_output_mode != BASE64_OUTPUT_DECODE_ROWS && !print_event_info->short_form; @@ -1890,6 +1891,13 @@ void Old_rows_log_event::print_helper(FILE *file, print_event_info->verbose); output_buf.append(&tmp_str); my_free(tmp_str.str); + if (copy_event_cache_to_string_and_reinit(tail, &tmp_str)) + { + tail->error= -1; + return; + } + output_buf.append(&tmp_str); + my_free(tmp_str.str); } } #endif -- cgit v1.2.1 From caa35f8e25ce22d6b4f4c377970354cf582c7f41 Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Tue, 11 Aug 2020 21:45:09 +0300 Subject: MDEV-16372 ER_BASE64_DECODE_ERROR upon replaying binary log via mysqlbinlog --verbose (This commit is for 10.3 and upper branches) In case of a pattern of non-STMT_END-marked Rows-log-event (A) followed by a STMT_END marked one (B) mysqlbinlog mixes up the base64 encoded rows events with their pseudo sql representation produced by the verbose option: BINLOG ' base64 encoded data for A ### verbose section for A base64 encoded data for B ### verbose section for B '/*!*/; In effect the produced BINLOG '...' query is not valid and is rejected with the error. Examples of this way malformed BINLOG could have been found in binlog_row_annotate.result that gets corrected with the patch. The issue is fixed with introduction an auxiliary IO_CACHE to hold on the verbose comments until the terminal STMT_END event is found. The new cache is emptied out after two pre-existing ones are done at that time. The correctly produced output now for the above case is as the following: BINLOG ' base64 encoded data for A base64 encoded data for B '/*!*/; ### verbose section for A ### verbose section for B Thanks to Alexey Midenkov for the problem recognition and attempt to tackle, and to Venkatesh Duggirala who produced a patch for the upstream whose idea is exploited here, as well as to MDEV-23077 reporter LukeXwang who also contributed a piece of a patch aiming at this issue. --- client/mysqlbinlog.cc | 8 +++- mysql-test/main/mysqlbinlog_row_minimal.result | 44 +++++++++++++++------- mysql-test/main/mysqlbinlog_row_minimal.test | 32 +++++++++++++++- .../suite/binlog/r/binlog_mysqlbinlog_row.result | 4 +- .../suite/binlog/r/binlog_row_annotate.result | 2 - .../binlog/t/binlog_mysqlbinlog_row_frag.test | 3 +- .../binlog_encryption/binlog_row_annotate.result | 1 - sql/log_event.cc | 37 +++++++----------- sql/log_event.h | 2 + sql/log_event_old.cc | 6 ++- 10 files changed, 88 insertions(+), 51 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index a732a6ab8c3..1fa16015f4a 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -969,8 +969,12 @@ static bool print_row_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, my_b_printf(body_cache, "'%s\n", print_event_info->delimiter); // flush cache - if ((copy_event_cache_to_file_and_reinit(&print_event_info->head_cache, result_file) || - copy_event_cache_to_file_and_reinit(&print_event_info->body_cache, result_file))) + if ((copy_event_cache_to_file_and_reinit(&print_event_info->head_cache, + result_file) || + copy_event_cache_to_file_and_reinit(&print_event_info->body_cache, + result_file) || + copy_event_cache_to_file_and_reinit(&print_event_info->tail_cache, + result_file))) return 1; } } diff --git a/mysql-test/main/mysqlbinlog_row_minimal.result b/mysql-test/main/mysqlbinlog_row_minimal.result index 933457edc25..aeaabab623a 100644 --- a/mysql-test/main/mysqlbinlog_row_minimal.result +++ b/mysql-test/main/mysqlbinlog_row_minimal.result @@ -327,6 +327,24 @@ ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; DROP TABLE t1,t2; +# +# MDEV-16372 ER_BASE64_DECODE_ERROR upon replaying binary log with system table +# +FLUSH BINARY LOGS; +CREATE TABLE t1 (pk INT PRIMARY KEY); +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (1), (2) ON DUPLICATE KEY UPDATE pk= pk + 10; +FLUSH BINARY LOGS; +Proof: two subsequent patterns must be found +FOUND 1 /### UPDATE `test`.`t1`/ in mysqlbinlog.sql +FOUND 2 /### INSERT INTO `test`.`t1`/ in mysqlbinlog.sql +DROP TABLE t1; +SELECT * FROM t1; +pk +2 +11 +# Cleanup +DROP TABLE t1; CREATE TABLE `t1` ( `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, `is_deleted` BIT(1) DEFAULT b'0', @@ -351,23 +369,23 @@ FLUSH BINARY LOGS; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; -# at 387 -# server id 1 end_log_pos 429 CRC32 XXX GTID 0-1-16 +# at POS +# server id 1 end_log_pos END_LOG_POS CRC32 XXX GTID D-S-N /*!100101 SET @@session.skip_parallel_replication=0*//*!*/; /*!100001 SET @@session.gtid_domain_id=0*//*!*/; /*!100001 SET @@session.server_id=1*//*!*/; -/*!100001 SET @@session.gtid_seq_no=16*//*!*/; +/*!100001 SET @@session.gtid_seq_no=21*//*!*/; START TRANSACTION /*!*/; -# at 429 -# at 543 -# server id 1 end_log_pos 543 CRC32 XXX Annotate_rows: +# at POS +# at POS +# server id 1 end_log_pos END_LOG_POS CRC32 XXX Annotate_rows: #Q> UPDATE t1 t1 INNER JOIN t2 t2 ON t1.ref_id = t2.id #Q> SET t1.is_deleted = TRUE #Q> WHERE t1.id = -# server id 1 end_log_pos 594 CRC32 XXX Table_map: `test`.`t1` mapped to number 35 -# at 594 -# server id 1 end_log_pos 643 CRC32 XXX Update_rows: table id 35 flags: STMT_END_F +# server id 1 end_log_pos END_LOG_POS CRC32 XXX Table_map: `test`.`t1` mapped to number TID +# at POS +# server id 1 end_log_pos END_LOG_POS CRC32 XXX Update_rows: table id TID flags: STMT_END_F ### UPDATE `test`.`t1` ### WHERE ### @1=1 /* LONGINT meta=0 nullable=0 is_null=0 */ @@ -375,10 +393,10 @@ START TRANSACTION ### @2=b'1' /* BIT(1) meta=1 nullable=1 is_null=0 */ ### @3=X /* TIMESTAMP(0) meta=0 nullable=0 is_null=0 */ # Number of rows: 1 -# at 643 -# server id 1 end_log_pos 725 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 +# at POS +# server id 1 end_log_pos END_LOG_POS CRC32 XXX Query thread_id=TID exec_time=x error_code=0 SET TIMESTAMP=X/*!*/; -SET @@session.pseudo_thread_id=5/*!*/; +SET @@session.pseudo_thread_id=TID/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1, @@session.check_constraint_checks=1/*!*/; SET @@session.sql_mode=#/*!*/; SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; @@ -388,8 +406,6 @@ SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; COMMIT /*!*/; -# at 725 -# server id 1 end_log_pos 773 CRC32 XXX Rotate to master-bin.000004 pos: 4 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; diff --git a/mysql-test/main/mysqlbinlog_row_minimal.test b/mysql-test/main/mysqlbinlog_row_minimal.test index b69aa6da14b..b399cc4ac45 100644 --- a/mysql-test/main/mysqlbinlog_row_minimal.test +++ b/mysql-test/main/mysqlbinlog_row_minimal.test @@ -33,6 +33,33 @@ FLUSH BINARY LOGS; DROP TABLE t1,t2; +--echo # +--echo # MDEV-16372 ER_BASE64_DECODE_ERROR upon replaying binary log with system table +--echo # +FLUSH BINARY LOGS; +CREATE TABLE t1 (pk INT PRIMARY KEY); +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (1), (2) ON DUPLICATE KEY UPDATE pk= pk + 10; + +--let $binlog = query_get_value(SHOW MASTER STATUS, File, 1) + +FLUSH BINARY LOGS; +--exec $MYSQL_BINLOG --verbose $datadir/$binlog > $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +--echo Proof: two subsequent patterns must be found +--let SEARCH_PATTERN= ### UPDATE `test`.`t1` +--let SEARCH_FILE= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN= ### INSERT INTO `test`.`t1` +--let SEARCH_FILE= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +--source include/search_pattern_in_file.inc + +DROP TABLE t1; +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +SELECT * FROM t1; + +--echo # Cleanup +DROP TABLE t1; +--remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql # # MDEV-14605 ON UPDATE CURRENT_TIMESTAMP fields by multi-table UPDATE are not logged with binlog_row_image=MINIMAL # @@ -64,11 +91,12 @@ UPDATE t1 t1 INNER JOIN t2 t2 ON t1.ref_id = t2.id WHERE t1.id = 1; --let $binlog = query_get_value(SHOW MASTER STATUS, File, 1) +--let $binlog_end= query_get_value(SHOW MASTER STATUS, Position, 1) FLUSH BINARY LOGS; --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR ---replace_regex /\d{6} *\d*:\d\d:\d\d// /SET TIMESTAMP=\d*/SET TIMESTAMP=X/ /exec_time=\d*/exec_time=x/ /@3=\d*/@3=X/ /CRC32 0x[0-9a-f]+/CRC32 XXX/ /@@session.sql_mode=\d+/@@session.sql_mode=#/ /collation_server=\d+/collation_server=#/ ---exec $MYSQL_BINLOG --verbose --verbose --base64-output=DECODE-ROWS $datadir/$binlog --start-position=$binlog_pos +--replace_regex /table id \d*/table id TID/ /mapped to number \d*/mapped to number TID/ /at \d*/at POS/ /end_log_pos \d*/end_log_pos END_LOG_POS/ /GTID \d*-\d*-\d*/GTID D-S-N/ /\d{6} *\d*:\d\d:\d\d// /SET TIMESTAMP=\d*/SET TIMESTAMP=X/ /exec_time=\d*/exec_time=x/ /@3=\d*/@3=X/ /CRC32 0x[0-9a-f]+/CRC32 XXX/ /@@session.sql_mode=\d+/@@session.sql_mode=#/ /collation_server=\d+/collation_server=#/ /thread_id=\d*/thread_id=TID/ +--exec $MYSQL_BINLOG --verbose --verbose --base64-output=DECODE-ROWS $datadir/$binlog --start-position=$binlog_pos --stop-position=$binlog_end DROP TABLE t1,t2; diff --git a/mysql-test/suite/binlog/r/binlog_mysqlbinlog_row.result b/mysql-test/suite/binlog/r/binlog_mysqlbinlog_row.result index 469eb97badc..424abc92bc4 100644 --- a/mysql-test/suite/binlog/r/binlog_mysqlbinlog_row.result +++ b/mysql-test/suite/binlog/r/binlog_mysqlbinlog_row.result @@ -5356,7 +5356,5 @@ START TRANSACTION #010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Table_map: `test`.`t1dec102` mapped to number # # at # #010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Write_rows: table id # flags: STMT_END_F -### INSERT INTO `test`.`t1dec102` -### SET -### @1= + Error: Found Old DECIMAL (mysql-4.1 or earlier). Not enough metadata to display the value. diff --git a/mysql-test/suite/binlog/r/binlog_row_annotate.result b/mysql-test/suite/binlog/r/binlog_row_annotate.result index e65569853aa..04a007ffa41 100644 --- a/mysql-test/suite/binlog/r/binlog_row_annotate.result +++ b/mysql-test/suite/binlog/r/binlog_row_annotate.result @@ -449,7 +449,6 @@ START TRANSACTION ### DELETE FROM `test1`.`t1` ### WHERE ### @1=3 /* INT meta=0 nullable=1 is_null=0 */ -'/*!*/; # at # #010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; @@ -1073,7 +1072,6 @@ START TRANSACTION ### DELETE FROM `test1`.`t1` ### WHERE ### @1=3 /* INT meta=0 nullable=1 is_null=0 */ -'/*!*/; # at # #010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; diff --git a/mysql-test/suite/binlog/t/binlog_mysqlbinlog_row_frag.test b/mysql-test/suite/binlog/t/binlog_mysqlbinlog_row_frag.test index a1791d9701d..9f79deea3db 100644 --- a/mysql-test/suite/binlog/t/binlog_mysqlbinlog_row_frag.test +++ b/mysql-test/suite/binlog/t/binlog_mysqlbinlog_row_frag.test @@ -11,8 +11,7 @@ SELECT a from t into @a; FLUSH LOGS; DELETE FROM t; -# Todo: MDEV-10362 to test multi-row Rows_log_event:s in verbose mode ---exec $MYSQL_BINLOG -vv --debug-binlog-row-event-max-encoded-size=256 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +--exec $MYSQL_BINLOG --verbose --debug-binlog-row-event-max-encoded-size=256 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql --let SEARCH_PATTERN= BINLOG @binlog_fragment_0, @binlog_fragment_1 --let SEARCH_FILE= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql diff --git a/mysql-test/suite/binlog_encryption/binlog_row_annotate.result b/mysql-test/suite/binlog_encryption/binlog_row_annotate.result index 004f163f192..3940717bf0b 100644 --- a/mysql-test/suite/binlog_encryption/binlog_row_annotate.result +++ b/mysql-test/suite/binlog_encryption/binlog_row_annotate.result @@ -456,7 +456,6 @@ START TRANSACTION ### DELETE FROM `test1`.`t1` ### WHERE ### @1=3 /* INT meta=0 nullable=1 is_null=0 */ -'/*!*/; # at # #010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; diff --git a/sql/log_event.cc b/sql/log_event.cc index 4432a51b010..1e382cab55f 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -3875,7 +3875,7 @@ bool Log_event::print_base64(IO_CACHE* file, ev->need_flashback_review= need_flashback_review; if (print_event_info->verbose) { - if (ev->print_verbose(file, print_event_info)) + if (ev->print_verbose(&print_event_info->tail_cache, print_event_info)) goto err; } else @@ -3899,22 +3899,9 @@ bool Log_event::print_base64(IO_CACHE* file, } #else if (print_event_info->verbose) - { - /* - Verbose event printout can't start before encoded data - got enquoted. This is done at this point though multi-row - statement remain vulnerable. - TODO: fix MDEV-10362 to remove this workaround. - */ - if (print_event_info->base64_output_mode != - BASE64_OUTPUT_DECODE_ROWS) - my_b_printf(file, "'%s\n", print_event_info->delimiter); - error= ev->print_verbose(file, print_event_info); - } + error= ev->print_verbose(&print_event_info->tail_cache, print_event_info); else - { ev->count_row_events(print_event_info); - } #endif delete ev; if (unlikely(error)) @@ -11992,7 +11979,7 @@ bool copy_cache_to_file_wrapped(IO_CACHE *body, FILE *file, bool do_wrap, const char *delimiter, - bool is_verbose) + bool is_verbose /*TODO: remove */) { const my_off_t cache_size= my_b_tell(body); @@ -12025,8 +12012,7 @@ bool copy_cache_to_file_wrapped(IO_CACHE *body, my_fprintf(file, fmt_frag, 1); if (my_b_copy_to_file(body, file, SIZE_T_MAX)) goto err; - if (!is_verbose) - my_fprintf(file, fmt_delim, delimiter); + my_fprintf(file, fmt_delim, delimiter); my_fprintf(file, fmt_binlog2, delimiter); } @@ -12035,8 +12021,7 @@ bool copy_cache_to_file_wrapped(IO_CACHE *body, my_fprintf(file, str_binlog); if (my_b_copy_to_file(body, file, SIZE_T_MAX)) goto err; - if (!is_verbose) - my_fprintf(file, fmt_delim, delimiter); + my_fprintf(file, fmt_delim, delimiter); } reinit_io_cache(body, WRITE_CACHE, 0, FALSE, TRUE); @@ -12122,7 +12107,6 @@ bool copy_cache_to_string_wrapped(IO_CACHE *cache, goto err; str += (add_to_len= uint32(cache->end_of_file - (cache_size/2 + 1))); to->length += add_to_len; - if (!is_verbose) { str += (add_to_len= sprintf(str , fmt_delim, delimiter)); to->length += add_to_len; @@ -12138,7 +12122,6 @@ bool copy_cache_to_string_wrapped(IO_CACHE *cache, goto err; str += cache->end_of_file; to->length += (size_t)cache->end_of_file; - if (!is_verbose) to->length += sprintf(str , fmt_delim, delimiter); } @@ -12186,6 +12169,7 @@ bool Rows_log_event::print_helper(FILE *file, { IO_CACHE *const head= &print_event_info->head_cache; IO_CACHE *const body= &print_event_info->body_cache; + IO_CACHE *const tail= &print_event_info->tail_cache; #ifdef WHEN_FLASHBACK_REVIEW_READY IO_CACHE *const sql= &print_event_info->review_sql_cache; #endif @@ -12216,7 +12200,8 @@ bool Rows_log_event::print_helper(FILE *file, if (copy_event_cache_to_file_and_reinit(head, file) || copy_cache_to_file_wrapped(body, file, do_print_encoded, print_event_info->delimiter, - print_event_info->verbose)) + print_event_info->verbose) || + copy_event_cache_to_file_and_reinit(tail, file)) goto err; } else @@ -12234,6 +12219,11 @@ bool Rows_log_event::print_helper(FILE *file, return 1; output_buf.append(tmp_str.str, tmp_str.length); my_free(tmp_str.str); + if (copy_event_cache_to_string_and_reinit(tail, &tmp_str)) + return 1; + output_buf.append(tmp_str.str, tmp_str.length); + my_free(tmp_str.str); + #ifdef WHEN_FLASHBACK_REVIEW_READY if (copy_event_cache_to_string_and_reinit(sql, &tmp_str)) return 1; @@ -15056,6 +15046,7 @@ st_print_event_info::st_print_event_info() base64_output_mode=BASE64_OUTPUT_UNSPEC; open_cached_file(&head_cache, NULL, NULL, 0, flags); open_cached_file(&body_cache, NULL, NULL, 0, flags); + open_cached_file(&tail_cache, NULL, NULL, 0, flags); #ifdef WHEN_FLASHBACK_REVIEW_READY open_cached_file(&review_sql_cache, NULL, NULL, 0, flags); #endif diff --git a/sql/log_event.h b/sql/log_event.h index b9514e874e8..8a342cb5cd3 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -889,6 +889,7 @@ typedef struct st_print_event_info */ IO_CACHE head_cache; IO_CACHE body_cache; + IO_CACHE tail_cache; #ifdef WHEN_FLASHBACK_REVIEW_READY /* Storing the SQL for reviewing */ IO_CACHE review_sql_cache; @@ -899,6 +900,7 @@ typedef struct st_print_event_info ~st_print_event_info() { close_cached_file(&head_cache); close_cached_file(&body_cache); + close_cached_file(&tail_cache); #ifdef WHEN_FLASHBACK_REVIEW_READY close_cached_file(&review_sql_cache); #endif diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc index 8ec823d3d64..c71a1f39e28 100644 --- a/sql/log_event_old.cc +++ b/sql/log_event_old.cc @@ -1848,6 +1848,7 @@ bool Old_rows_log_event::print_helper(FILE *file, { IO_CACHE *const head= &print_event_info->head_cache; IO_CACHE *const body= &print_event_info->body_cache; + IO_CACHE *const tail= &print_event_info->tail_cache; bool do_print_encoded= print_event_info->base64_output_mode != BASE64_OUTPUT_DECODE_ROWS && print_event_info->base64_output_mode != BASE64_OUTPUT_NEVER && @@ -1867,8 +1868,9 @@ bool Old_rows_log_event::print_helper(FILE *file, { if (copy_event_cache_to_file_and_reinit(head, file) || copy_cache_to_file_wrapped(body, file, do_print_encoded, - print_event_info->delimiter, - print_event_info->verbose)) + print_event_info->delimiter, + print_event_info->verbose) || + copy_event_cache_to_file_and_reinit(tail, file)) goto err; } return 0; -- cgit v1.2.1 From feac078f15c0be6c0592d74d20cb65b8f5ad2f85 Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Tue, 11 Aug 2020 21:45:09 +0300 Subject: MDEV-16372 ER_BASE64_DECODE_ERROR upon replaying binary log via mysqlbinlog --verbose (This commit is exclusively for 10.1 branch, do not merge it to upper ones) In case of a pattern of non-STMT_END-marked Rows-log-event (A) followed by a STMT_END marked one (B) mysqlbinlog mixes up the base64 encoded rows events with their pseudo sql representation produced by the verbose option: BINLOG ' base64 encoded data for A ### verbose section for A base64 encoded data for B ### verbose section for B '/*!*/; In effect the produced BINLOG '...' query is not valid and is rejected with the error. Examples of this way malformed BINLOG could have been found in binlog_row_annotate.result that gets corrected with the patch. The issue is fixed with introduction an auxiliary IO_CACHE to hold on the verbose comments until the terminal STMT_END event is found. The new cache is emptied out after two pre-existing ones are done at that time. The correctly produced output now for the above case is as the following: BINLOG ' base64 encoded data for A base64 encoded data for B '/*!*/; ### verbose section for A ### verbose section for B Thanks to Alexey Midenkov for the problem recognition and attempt to tackle, Venkatesh Duggirala who produced a patch for the upstream whose idea is exploited here, as well as to MDEV-23077 reporter LukeXwang who also contributed a piece of a patch aiming at this issue. Extra: mysqlbinlog_row_minimal refined to not produce mutable numeric values into the result file. --- client/mysqlbinlog.cc | 11 ++++-- mysql-test/r/mysqlbinlog_row_minimal.result | 40 +++++++++++++++------- .../suite/binlog/r/binlog_row_annotate.result | 2 -- .../binlog/t/binlog_mysqlbinlog_row_frag.test | 2 +- .../binlog_encryption/binlog_row_annotate.result | 1 - mysql-test/t/mysqlbinlog_row_minimal.test | 34 ++++++++++++++++-- sql/log_event.cc | 11 ++++-- sql/log_event.h | 6 +++- sql/log_event_old.cc | 6 ++++ 9 files changed, 89 insertions(+), 24 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 979a8f29d12..449e4f0e8a9 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -860,7 +860,8 @@ static bool print_base64(PRINT_EVENT_INFO *print_event_info, Log_event *ev) ev->print(result_file, print_event_info); return print_event_info->head_cache.error == -1 || - print_event_info->body_cache.error == -1; + print_event_info->body_cache.error == -1 || + print_event_info->tail_cache.error == -1; } @@ -912,8 +913,12 @@ static bool print_row_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, my_b_printf(body_cache, "'%s\n", print_event_info->delimiter); // flush cache - if ((copy_event_cache_to_file_and_reinit(&print_event_info->head_cache, result_file) || - copy_event_cache_to_file_and_reinit(&print_event_info->body_cache, result_file))) + if ((copy_event_cache_to_file_and_reinit(&print_event_info->head_cache, + result_file) || + copy_event_cache_to_file_and_reinit(&print_event_info->body_cache, + result_file) || + copy_event_cache_to_file_and_reinit(&print_event_info->tail_cache, + result_file))) return 1; } } diff --git a/mysql-test/r/mysqlbinlog_row_minimal.result b/mysql-test/r/mysqlbinlog_row_minimal.result index 2e34b2885ca..a7fecc7e4bc 100644 --- a/mysql-test/r/mysqlbinlog_row_minimal.result +++ b/mysql-test/r/mysqlbinlog_row_minimal.result @@ -295,6 +295,24 @@ ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; DROP TABLE t1,t2; +# +# MDEV-16372 ER_BASE64_DECODE_ERROR upon replaying binary log with system table +# +FLUSH BINARY LOGS; +CREATE TABLE t1 (pk INT PRIMARY KEY); +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (1), (2) ON DUPLICATE KEY UPDATE pk= pk + 10; +FLUSH BINARY LOGS; +Proof: two subsequent patterns must be found +FOUND /### UPDATE `test`.`t1`/ in mysqlbinlog.sql +FOUND /### INSERT INTO `test`.`t1`/ in mysqlbinlog.sql +DROP TABLE t1; +SELECT * FROM t1; +pk +2 +11 +# Cleanup +DROP TABLE t1; CREATE TABLE `t1` ( `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, `is_deleted` BIT(1) DEFAULT b'0', @@ -319,28 +337,28 @@ FLUSH BINARY LOGS; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; -# at 368 -# server id 1 end_log_pos 406 GTID 0-1-16 +# at POS +# server id 1 end_log_pos END_LOG_POS GTID D-S-N /*!100101 SET @@session.skip_parallel_replication=0*//*!*/; /*!100001 SET @@session.gtid_domain_id=0*//*!*/; /*!100001 SET @@session.server_id=1*//*!*/; -/*!100001 SET @@session.gtid_seq_no=16*//*!*/; +/*!100001 SET @@session.gtid_seq_no=21*//*!*/; BEGIN /*!*/; -# at 406 -# server id 1 end_log_pos 453 Table_map: `test`.`t1` mapped to number 34 -# at 453 -# server id 1 end_log_pos 498 Update_rows: table id 34 flags: STMT_END_F +# at POS +# server id 1 end_log_pos END_LOG_POS Table_map: `test`.`t1` mapped to number TID +# at POS +# server id 1 end_log_pos END_LOG_POS Update_rows: table id TID flags: STMT_END_F ### UPDATE `test`.`t1` ### WHERE ### @1=1 /* LONGINT meta=0 nullable=0 is_null=0 */ ### SET ### @2=b'1' /* BIT(1) meta=1 nullable=1 is_null=0 */ ### @3=X /* TIMESTAMP(0) meta=0 nullable=0 is_null=0 */ -# at 498 -# server id 1 end_log_pos 576 Query thread_id=4 exec_time=x error_code=0 +# at POS +# server id 1 end_log_pos END_LOG_POS Query thread_id=TID exec_time=x error_code=0 SET TIMESTAMP=X/*!*/; -SET @@session.pseudo_thread_id=4/*!*/; +SET @@session.pseudo_thread_id=TID/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; SET @@session.sql_mode=1342177280/*!*/; SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; @@ -350,8 +368,6 @@ SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; COMMIT /*!*/; -# at 576 -# server id 1 end_log_pos 620 Rotate to master-bin.000004 pos: 4 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; diff --git a/mysql-test/suite/binlog/r/binlog_row_annotate.result b/mysql-test/suite/binlog/r/binlog_row_annotate.result index 6070f2da608..4e72ed8b032 100644 --- a/mysql-test/suite/binlog/r/binlog_row_annotate.result +++ b/mysql-test/suite/binlog/r/binlog_row_annotate.result @@ -449,7 +449,6 @@ BEGIN ### DELETE FROM `test1`.`t1` ### WHERE ### @1=3 /* INT meta=0 nullable=1 is_null=0 */ -'/*!*/; # at # #010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; @@ -1117,7 +1116,6 @@ BEGIN ### DELETE FROM `test1`.`t1` ### WHERE ### @1=3 /* INT meta=0 nullable=1 is_null=0 */ -'/*!*/; # at # #010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; diff --git a/mysql-test/suite/binlog/t/binlog_mysqlbinlog_row_frag.test b/mysql-test/suite/binlog/t/binlog_mysqlbinlog_row_frag.test index 40360421c6b..9f79deea3db 100644 --- a/mysql-test/suite/binlog/t/binlog_mysqlbinlog_row_frag.test +++ b/mysql-test/suite/binlog/t/binlog_mysqlbinlog_row_frag.test @@ -11,7 +11,7 @@ SELECT a from t into @a; FLUSH LOGS; DELETE FROM t; ---exec $MYSQL_BINLOG --debug-binlog-row-event-max-encoded-size=256 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +--exec $MYSQL_BINLOG --verbose --debug-binlog-row-event-max-encoded-size=256 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql --let SEARCH_PATTERN= BINLOG @binlog_fragment_0, @binlog_fragment_1 --let SEARCH_FILE= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql diff --git a/mysql-test/suite/binlog_encryption/binlog_row_annotate.result b/mysql-test/suite/binlog_encryption/binlog_row_annotate.result index 41721441a72..6485b723975 100644 --- a/mysql-test/suite/binlog_encryption/binlog_row_annotate.result +++ b/mysql-test/suite/binlog_encryption/binlog_row_annotate.result @@ -449,7 +449,6 @@ BEGIN ### DELETE FROM `test1`.`t1` ### WHERE ### @1=3 /* INT meta=0 nullable=1 is_null=0 */ -'/*!*/; # at # #010909 4:46:40 server id # end_log_pos # Query thread_id=# exec_time=# error_code=0 SET TIMESTAMP=1000000000/*!*/; diff --git a/mysql-test/t/mysqlbinlog_row_minimal.test b/mysql-test/t/mysqlbinlog_row_minimal.test index 39cae408d4e..57bae4247e1 100644 --- a/mysql-test/t/mysqlbinlog_row_minimal.test +++ b/mysql-test/t/mysqlbinlog_row_minimal.test @@ -33,6 +33,35 @@ FLUSH BINARY LOGS; DROP TABLE t1,t2; + +--echo # +--echo # MDEV-16372 ER_BASE64_DECODE_ERROR upon replaying binary log with system table +--echo # + +FLUSH BINARY LOGS; +CREATE TABLE t1 (pk INT PRIMARY KEY); +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (1), (2) ON DUPLICATE KEY UPDATE pk= pk + 10; + +--let $binlog = query_get_value(SHOW MASTER STATUS, File, 1) + +FLUSH BINARY LOGS; +--exec $MYSQL_BINLOG --verbose $datadir/$binlog > $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +--echo Proof: two subsequent patterns must be found +--let SEARCH_PATTERN= ### UPDATE `test`.`t1` +--let SEARCH_FILE= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN= ### INSERT INTO `test`.`t1` +--let SEARCH_FILE= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +--source include/search_pattern_in_file.inc + +DROP TABLE t1; +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql +SELECT * FROM t1; + +--echo # Cleanup +DROP TABLE t1; +--remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.sql # # MDEV-14605 ON UPDATE CURRENT_TIMESTAMP fields by multi-table UPDATE are not logged with binlog_row_image=MINIMAL # @@ -64,11 +93,12 @@ UPDATE t1 t1 INNER JOIN t2 t2 ON t1.ref_id = t2.id WHERE t1.id = 1; --let $binlog = query_get_value(SHOW MASTER STATUS, File, 1) +--let $binlog_end= query_get_value(SHOW MASTER STATUS, Position, 1) FLUSH BINARY LOGS; --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR ---replace_regex /\d{6} *\d*:\d\d:\d\d// /SET TIMESTAMP=\d*/SET TIMESTAMP=X/ /exec_time=\d*/exec_time=x/ /@3=\d*/@3=X/ /CRC32 0x[0-9a-f]+/CRC32 XXX/ ---exec $MYSQL_BINLOG --verbose --verbose --base64-output=DECODE-ROWS $datadir/$binlog --start-position=$binlog_pos +--replace_regex /table id \d*/table id TID/ /mapped to number \d*/mapped to number TID/ /at \d*/at POS/ /end_log_pos \d*/end_log_pos END_LOG_POS/ /GTID \d*-\d*-\d*/GTID D-S-N/ /\d{6} *\d*:\d\d:\d\d// /SET TIMESTAMP=\d*/SET TIMESTAMP=X/ /exec_time=\d*/exec_time=x/ /@3=\d*/@3=X/ /CRC32 0x[0-9a-f]+/CRC32 XXX/ /thread_id=\d*/thread_id=TID/ +--exec $MYSQL_BINLOG --verbose --verbose --base64-output=DECODE-ROWS $datadir/$binlog --start-position=$binlog_pos --stop-position=$binlog_end DROP TABLE t1,t2; diff --git a/sql/log_event.cc b/sql/log_event.cc index a1a442df43f..4d7bb1726ed 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -2865,10 +2865,10 @@ void Log_event::print_base64(IO_CACHE* file, default: break; } - + if (ev) { - ev->print_verbose(file, print_event_info); + ev->print_verbose(&print_event_info->tail_cache, print_event_info); delete ev; } } @@ -10671,6 +10671,7 @@ void Rows_log_event::print_helper(FILE *file, { IO_CACHE *const head= &print_event_info->head_cache; IO_CACHE *const body= &print_event_info->body_cache; + IO_CACHE *const tail= &print_event_info->tail_cache; bool do_print_encoded= print_event_info->base64_output_mode != BASE64_OUTPUT_DECODE_ROWS && !print_event_info->short_form; @@ -10694,6 +10695,11 @@ void Rows_log_event::print_helper(FILE *file, } copy_cache_to_file_wrapped(file, body, do_print_encoded, print_event_info->delimiter); + if (copy_event_cache_to_file_and_reinit(tail, file)) + { + tail->error= -1; + return; + } } } #endif @@ -13220,6 +13226,7 @@ st_print_event_info::st_print_event_info() myf const flags = MYF(MY_WME | MY_NABP); open_cached_file(&head_cache, NULL, NULL, 0, flags); open_cached_file(&body_cache, NULL, NULL, 0, flags); + open_cached_file(&tail_cache, NULL, NULL, 0, flags); } #endif diff --git a/sql/log_event.h b/sql/log_event.h index bdac9f2e581..58e1281c179 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -781,9 +781,12 @@ typedef struct st_print_event_info ~st_print_event_info() { close_cached_file(&head_cache); close_cached_file(&body_cache); + close_cached_file(&tail_cache); } bool init_ok() /* tells if construction was successful */ - { return my_b_inited(&head_cache) && my_b_inited(&body_cache); } + { return my_b_inited(&head_cache) && + my_b_inited(&body_cache) && + my_b_inited(&tail_cache); } /* Settings on how to print the events */ @@ -811,6 +814,7 @@ typedef struct st_print_event_info */ IO_CACHE head_cache; IO_CACHE body_cache; + IO_CACHE tail_cache; } PRINT_EVENT_INFO; #endif diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc index 0a4d7227dfb..8f4f6c296c4 100644 --- a/sql/log_event_old.cc +++ b/sql/log_event_old.cc @@ -1856,6 +1856,7 @@ void Old_rows_log_event::print_helper(FILE *file, { IO_CACHE *const head= &print_event_info->head_cache; IO_CACHE *const body= &print_event_info->body_cache; + IO_CACHE *const tail= &print_event_info->tail_cache; bool do_print_encoded= print_event_info->base64_output_mode != BASE64_OUTPUT_DECODE_ROWS && !print_event_info->short_form; @@ -1879,6 +1880,11 @@ void Old_rows_log_event::print_helper(FILE *file, } copy_cache_to_file_wrapped(file, body, do_print_encoded, print_event_info->delimiter); + if (copy_event_cache_to_file_and_reinit(tail, file)) + { + tail->error= -1; + return; + } } } #endif -- cgit v1.2.1 From a3d66090c789dfd9f31a63187ef2cf7a85df9c1b Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Fri, 21 Aug 2020 20:05:02 +1000 Subject: MDEV-18366 Crash on SELECT on a table with indexed virtual columns The problem was in improper error handling behavior in `row_upd_build_difference_binary`: `innobase_free_row_for_vcol` wasn't called. To eliminate this problem in all potential places, a refactoring has been made: * class ib_vcol_row is added. It owns VCOL_STORAGE and heap and maintains it in RAII manner * all innobase_allocate_row_for_vcol/innobase_free_row_for_vcol pairs are substituted with ib_vcol_row usage * row_merge_buf_add is only left untouched because it doesn't own vheap passed as an argument * innobase_allocate_row_for_vcol does not allocate VCOL_STORAGE anymore and accepts it as an argument -- this reduces a number of memory allocations * move rec_printer out of `#ifndef DBUG_OFF` and mark it cold --- .../suite/gcol/r/innodb_virtual_index.result | 3 + mysql-test/suite/gcol/t/innodb_virtual_index.test | 3 +- storage/innobase/handler/ha_innodb.cc | 95 ++++++++++------------ storage/innobase/include/rem0rec.h | 8 +- storage/innobase/include/row0mysql.h | 36 +++++++- storage/innobase/row/row0ins.cc | 47 ++++------- storage/innobase/row/row0merge.cc | 22 ++--- storage/innobase/row/row0sel.cc | 34 ++------ storage/innobase/row/row0upd.cc | 41 ++-------- storage/innobase/row/row0vers.cc | 21 +---- 10 files changed, 135 insertions(+), 175 deletions(-) diff --git a/mysql-test/suite/gcol/r/innodb_virtual_index.result b/mysql-test/suite/gcol/r/innodb_virtual_index.result index cd079544ed0..20311a21136 100644 --- a/mysql-test/suite/gcol/r/innodb_virtual_index.result +++ b/mysql-test/suite/gcol/r/innodb_virtual_index.result @@ -259,6 +259,9 @@ ERROR 22007: Incorrect date value: '20190132' for column `test`.`t1`.`vb` at row SELECT * FROM t1; a b vb ROLLBACK; +SELECT * FROM t1; +a b vb +1 20190132 0000-00-00 CHECK TABLE t1; Table Op Msg_type Msg_text test.t1 check status OK diff --git a/mysql-test/suite/gcol/t/innodb_virtual_index.test b/mysql-test/suite/gcol/t/innodb_virtual_index.test index c2f9cd78fe2..353841840dc 100644 --- a/mysql-test/suite/gcol/t/innodb_virtual_index.test +++ b/mysql-test/suite/gcol/t/innodb_virtual_index.test @@ -278,7 +278,6 @@ DELETE FROM t1; INSERT INTO t1 (a,b) VALUES(1,20190123); SELECT * FROM t1; ROLLBACK; -# MDEV-18366 FIXME: fix the crash and enable this -# SELECT * FROM t1; +SELECT * FROM t1; CHECK TABLE t1; DROP TABLE t1; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 3ab1e9c7cc2..d396c71da5f 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -21820,64 +21820,53 @@ innobase_get_field_from_update_vector( Allocate a heap and record for calculating virtual fields Used mainly for virtual fields in indexes -@param[in] thd MariaDB THD -@param[in] index Index in use -@param[out] heap Heap that holds temporary row -@param[in,out] table MariaDB table -@param[out] record Pointer to allocated MariaDB record -@param[out] storage Internal storage for blobs etc - -@retval false on success -@retval true on malloc failure or failed to open the maria table +@param[in] thd MariaDB THD +@param[in] index Index in use +@param[out] heap Heap that holds temporary row +@param[in,out] table MariaDB table +@param[out] record Pointer to allocated MariaDB record +@param[out] storage Internal storage for blobs etc + +@retval true on success +@retval false on malloc failure or failed to open the maria table for purge thread. */ -bool innobase_allocate_row_for_vcol( - THD * thd, - dict_index_t* index, - mem_heap_t** heap, - TABLE** table, - byte** record, - VCOL_STORAGE** storage) -{ - TABLE *maria_table; - String *blob_value_storage; - if (!*table) - *table= innodb_find_table_for_vc(thd, index->table); - - /* For purge thread, there is a possiblity that table could have - dropped, corrupted or unaccessible. */ - if (!*table) - return true; - maria_table= *table; - if (!*heap && !(*heap= mem_heap_create(srv_page_size))) - { - *storage= 0; - return TRUE; - } - *record= static_cast(mem_heap_alloc(*heap, - maria_table->s->reclength)); - *storage= static_cast - (mem_heap_alloc(*heap, sizeof(**storage))); - blob_value_storage= static_cast - (mem_heap_alloc(*heap, - maria_table->s->virtual_not_stored_blob_fields * - sizeof(String))); - if (!*record || !*storage || !blob_value_storage) - { - *storage= 0; - return TRUE; - } - (*storage)->maria_table= maria_table; - (*storage)->innobase_record= *record; - (*storage)->maria_record= maria_table->field[0]->record_ptr(); - (*storage)->blob_value_storage= blob_value_storage; +bool innobase_allocate_row_for_vcol(THD *thd, dict_index_t *index, + mem_heap_t **heap, TABLE **table, + VCOL_STORAGE *storage) +{ + TABLE *maria_table; + String *blob_value_storage; + if (!*table) + *table = innodb_find_table_for_vc(thd, index->table); + + /* For purge thread, there is a possiblity that table could have + dropped, corrupted or unaccessible. */ + if (!*table) + return false; + maria_table = *table; + if (!*heap && !(*heap = mem_heap_create(srv_page_size))) + return false; - maria_table->move_fields(maria_table->field, *record, - (*storage)->maria_record); - maria_table->remember_blob_values(blob_value_storage); + uchar *record = static_cast(mem_heap_alloc(*heap, + maria_table->s->reclength)); - return FALSE; + size_t len = maria_table->s->virtual_not_stored_blob_fields * sizeof(String); + blob_value_storage = static_cast(mem_heap_alloc(*heap, len)); + + if (!record || !blob_value_storage) + return false; + + storage->maria_table = maria_table; + storage->innobase_record = record; + storage->maria_record = maria_table->field[0]->record_ptr(); + storage->blob_value_storage = blob_value_storage; + + maria_table->move_fields(maria_table->field, record, storage->maria_record); + maria_table->remember_blob_values(blob_value_storage); + + return true; } diff --git a/storage/innobase/include/rem0rec.h b/storage/innobase/include/rem0rec.h index 728944d4373..81a09afa3d8 100644 --- a/storage/innobase/include/rem0rec.h +++ b/storage/innobase/include/rem0rec.h @@ -1076,16 +1076,17 @@ struct rec_offsets_print @param[in,out] o output stream @param[in] r record to display @return the output stream */ +ATTRIBUTE_COLD std::ostream& operator<<(std::ostream& o, const rec_offsets_print& r); -# ifndef DBUG_OFF /** Pretty-printer of records and tuples */ class rec_printer : public std::ostringstream { public: /** Construct a pretty-printed record. @param rec record with header @param offsets rec_get_offsets(rec, ...) */ + ATTRIBUTE_COLD rec_printer(const rec_t* rec, const rec_offs* offsets) : std::ostringstream () @@ -1099,6 +1100,7 @@ public: @param rec record, possibly lacking header @param info rec_get_info_bits(rec) @param offsets rec_get_offsets(rec, ...) */ + ATTRIBUTE_COLD rec_printer(const rec_t* rec, ulint info, const rec_offs* offsets) : std::ostringstream () @@ -1108,6 +1110,7 @@ public: /** Construct a pretty-printed tuple. @param tuple data tuple */ + ATTRIBUTE_COLD rec_printer(const dtuple_t* tuple) : std::ostringstream () @@ -1118,6 +1121,7 @@ public: /** Construct a pretty-printed tuple. @param field array of data tuple fields @param n number of fields */ + ATTRIBUTE_COLD rec_printer(const dfield_t* field, ulint n) : std::ostringstream () @@ -1134,7 +1138,7 @@ private: /** Assignment operator */ rec_printer& operator=(const rec_printer& other); }; -# endif /* !DBUG_OFF */ + # ifdef UNIV_DEBUG /** Read the DB_TRX_ID of a clustered index record. diff --git a/storage/innobase/include/row0mysql.h b/storage/innobase/include/row0mysql.h index 60f53221c9a..3b177ac1a24 100644 --- a/storage/innobase/include/row0mysql.h +++ b/storage/innobase/include/row0mysql.h @@ -814,6 +814,8 @@ struct VCOL_STORAGE byte *innobase_record; byte *maria_record; String *blob_value_storage; + VCOL_STORAGE(): maria_table(NULL), innobase_record(NULL), + maria_record(NULL), blob_value_storage(NULL) {} }; /** @@ -836,12 +838,42 @@ bool innobase_allocate_row_for_vcol( dict_index_t* index, mem_heap_t** heap, TABLE** table, - byte** record, - VCOL_STORAGE** storage); + VCOL_STORAGE* storage); /** Free memory allocated by innobase_allocate_row_for_vcol() */ void innobase_free_row_for_vcol(VCOL_STORAGE *storage); +class ib_vcol_row +{ + VCOL_STORAGE storage; +public: + mem_heap_t *heap; + + ib_vcol_row(mem_heap_t *heap) : heap(heap) {} + + byte *record(THD *thd, dict_index_t *index, TABLE **table) + { + if (!storage.innobase_record) + { + bool ok = innobase_allocate_row_for_vcol(thd, index, &heap, table, + &storage); + if (!ok) + return NULL; + } + return storage.innobase_record; + }; + + ~ib_vcol_row() + { + if (heap) + { + if (storage.innobase_record) + innobase_free_row_for_vcol(&storage); + mem_heap_free(heap); + } + } +}; + /** Get the computed value by supplying the base column values. @param[in,out] row the data row @param[in] col virtual column diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index c0aa3655b7b..b8c8a73842f 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -916,16 +916,15 @@ row_ins_invalidate_query_cache( @param[in] index clustered index of child table @param[in] node parent update node @param[in] foreign foreign key information -@param[out] err error code. */ +@return error code. */ static -void +dberr_t row_ins_foreign_fill_virtual( upd_node_t* cascade, const rec_t* rec, dict_index_t* index, upd_node_t* node, - dict_foreign_t* foreign, - dberr_t* err) + dict_foreign_t* foreign) { THD* thd = current_thd; row_ext_t* ext; @@ -934,10 +933,7 @@ row_ins_foreign_fill_virtual( const rec_offs* offsets = rec_get_offsets(rec, index, offsets_, true, ULINT_UNDEFINED, &cascade->heap); - mem_heap_t* v_heap = NULL; TABLE* mysql_table= NULL; - VCOL_STORAGE* vcol_storage= NULL; - byte* record; upd_t* update = cascade->update; ulint n_v_fld = index->table->n_v_def; ulint n_diff; @@ -957,12 +953,10 @@ row_ins_foreign_fill_virtual( innobase_init_vc_templ(index->table); } - if (innobase_allocate_row_for_vcol(thd, index, &v_heap, - &mysql_table, - &record, &vcol_storage)) { - if (v_heap) mem_heap_free(v_heap); - *err = DB_OUT_OF_MEMORY; - goto func_exit; + ib_vcol_row vc(NULL); + uchar *record = vc.record(thd, index, &mysql_table); + if (!record) { + return DB_OUT_OF_MEMORY; } for (ulint i = 0; i < n_v_fld; i++) { @@ -978,12 +972,11 @@ row_ins_foreign_fill_virtual( dfield_t* vfield = innobase_get_computed_value( update->old_vrow, col, index, - &v_heap, update->heap, NULL, thd, mysql_table, + &vc.heap, update->heap, NULL, thd, mysql_table, record, NULL, NULL, NULL); if (vfield == NULL) { - *err = DB_COMPUTE_VALUE_FAILED; - goto func_exit; + return DB_COMPUTE_VALUE_FAILED; } upd_field = upd_get_nth_field(update, n_diff); @@ -1008,13 +1001,12 @@ row_ins_foreign_fill_virtual( dfield_t* new_vfield = innobase_get_computed_value( update->old_vrow, col, index, - &v_heap, update->heap, NULL, thd, + &vc.heap, update->heap, NULL, thd, mysql_table, record, NULL, node->update, foreign); if (new_vfield == NULL) { - *err = DB_COMPUTE_VALUE_FAILED; - goto func_exit; + return DB_COMPUTE_VALUE_FAILED; } dfield_copy(&(upd_field->new_val), new_vfield); @@ -1024,14 +1016,7 @@ row_ins_foreign_fill_virtual( } update->n_fields = n_diff; - *err = DB_SUCCESS; - -func_exit: - if (v_heap) { - if (vcol_storage) - innobase_free_row_for_vcol(vcol_storage); - mem_heap_free(v_heap); - } + return DB_SUCCESS; } #ifdef WITH_WSREP @@ -1312,9 +1297,9 @@ row_ins_foreign_check_on_constraint( if (foreign->v_cols != NULL && foreign->v_cols->size() > 0) { - row_ins_foreign_fill_virtual( + err = row_ins_foreign_fill_virtual( cascade, clust_rec, clust_index, - node, foreign, &err); + node, foreign); if (err != DB_SUCCESS) { goto nonstandard_exit_func; @@ -1351,9 +1336,9 @@ row_ins_foreign_check_on_constraint( node, foreign, tmp_heap, trx); if (foreign->v_cols && !foreign->v_cols->empty()) { - row_ins_foreign_fill_virtual( + err = row_ins_foreign_fill_virtual( cascade, clust_rec, clust_index, - node, foreign, &err); + node, foreign); if (err != DB_SUCCESS) { goto nonstandard_exit_func; diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index 3a6d8cea4a8..a07ac220419 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -520,8 +520,7 @@ row_merge_buf_add( ulint bucket = 0; doc_id_t write_doc_id; ulint n_row_added = 0; - VCOL_STORAGE* vcol_storage= 0; - byte* record; + VCOL_STORAGE vcol_storage; DBUG_ENTER("row_merge_buf_add"); if (buf->n_tuples >= buf->max_tuples) { @@ -594,8 +593,11 @@ row_merge_buf_add( dict_index_t* clust_index = dict_table_get_first_index(new_table); - if (!vcol_storage && - innobase_allocate_row_for_vcol(trx->mysql_thd, clust_index, v_heap, &my_table, &record, &vcol_storage)) { + if (!vcol_storage.innobase_record && + !innobase_allocate_row_for_vcol( + trx->mysql_thd, clust_index, + v_heap, &my_table, + &vcol_storage)) { *err = DB_OUT_OF_MEMORY; goto error; } @@ -603,8 +605,8 @@ row_merge_buf_add( row_field = innobase_get_computed_value( row, v_col, clust_index, v_heap, NULL, ifield, trx->mysql_thd, - my_table, record, old_table, NULL, - NULL); + my_table, vcol_storage.innobase_record, + old_table, NULL, NULL); if (row_field == NULL) { *err = DB_COMPUTE_VALUE_FAILED; @@ -846,13 +848,13 @@ row_merge_buf_add( } end: - if (vcol_storage) - innobase_free_row_for_vcol(vcol_storage); + if (vcol_storage.innobase_record) + innobase_free_row_for_vcol(&vcol_storage); DBUG_RETURN(n_row_added); error: - if (vcol_storage) - innobase_free_row_for_vcol(vcol_storage); + if (vcol_storage.innobase_record) + innobase_free_row_for_vcol(&vcol_storage); DBUG_RETURN(0); } diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index 9340d5060d9..bb15625f748 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -176,9 +176,6 @@ row_sel_sec_rec_is_for_clust_rec( rec_offs sec_offsets_[REC_OFFS_SMALL_SIZE]; rec_offs* clust_offs = clust_offsets_; rec_offs* sec_offs = sec_offsets_; - ibool is_equal = TRUE; - VCOL_STORAGE* vcol_storage= 0; - byte* record; rec_offs_init(clust_offsets_); rec_offs_init(sec_offsets_); @@ -197,6 +194,7 @@ row_sel_sec_rec_is_for_clust_rec( } heap = mem_heap_create(256); + ib_vcol_row vc(heap); clust_offs = rec_get_offsets(clust_rec, clust_index, clust_offs, true, ULINT_UNDEFINED, &heap); @@ -225,16 +223,9 @@ row_sel_sec_rec_is_for_clust_rec( dfield_t* vfield; row_ext_t* ext; - if (!vcol_storage) - { - TABLE *mysql_table= thr->prebuilt->m_mysql_table; - innobase_allocate_row_for_vcol(thr_get_trx(thr)->mysql_thd, - clust_index, - &heap, - &mysql_table, - &record, - &vcol_storage); - } + byte *record = vc.record(thr_get_trx(thr)->mysql_thd, + clust_index, + &thr->prebuilt->m_mysql_table); v_col = reinterpret_cast(col); @@ -284,7 +275,7 @@ row_sel_sec_rec_is_for_clust_rec( sec_field, sec_len, ifield->prefix_len, clust_index->table)) { - goto inequal; + return FALSE; } continue; @@ -320,28 +311,19 @@ row_sel_sec_rec_is_for_clust_rec( rtr_read_mbr(sec_field, &sec_mbr); if (!MBR_EQUAL_CMP(&sec_mbr, &tmp_mbr)) { - is_equal = FALSE; - goto func_exit; + return FALSE; } } else { if (0 != cmp_data_data(col->mtype, col->prtype, clust_field, len, sec_field, sec_len)) { -inequal: - is_equal = FALSE; - goto func_exit; + return FALSE; } } } -func_exit: - if (UNIV_LIKELY_NULL(heap)) { - if (UNIV_LIKELY_NULL(vcol_storage)) - innobase_free_row_for_vcol(vcol_storage); - mem_heap_free(heap); - } - return(is_equal); + return TRUE; } /*********************************************************************//** diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index 6d210cfd6bb..acc7c02abf2 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -1116,10 +1116,6 @@ row_upd_build_difference_binary( for purge/mvcc purpose) */ if (n_v_fld > 0) { row_ext_t* ext; - mem_heap_t* v_heap = NULL; - byte* record; - VCOL_STORAGE* vcol_storage; - THD* thd; if (trx == NULL) { @@ -1130,9 +1126,8 @@ row_upd_build_difference_binary( ut_ad(!update->old_vrow); - innobase_allocate_row_for_vcol(thd, index, &v_heap, - &mysql_table, - &record, &vcol_storage); + ib_vcol_row vc(NULL); + uchar *record = vc.record(thd, index, &mysql_table); for (i = 0; i < n_v_fld; i++) { const dict_v_col_t* col @@ -1150,10 +1145,9 @@ row_upd_build_difference_binary( dfield_t* vfield = innobase_get_computed_value( update->old_vrow, col, index, - &v_heap, heap, NULL, thd, mysql_table, record, + &vc.heap, heap, NULL, thd, mysql_table, record, NULL, NULL, NULL); if (vfield == NULL) { - if (v_heap) mem_heap_free(v_heap); *error = DB_COMPUTE_VALUE_FAILED; return(NULL); } @@ -1182,12 +1176,6 @@ row_upd_build_difference_binary( } } - - if (v_heap) { - if (vcol_storage) - innobase_free_row_for_vcol(vcol_storage); - mem_heap_free(v_heap); - } } update->n_fields = n_diff; @@ -2122,14 +2110,8 @@ row_upd_store_v_row( THD* thd, TABLE* mysql_table) { - mem_heap_t* heap = NULL; dict_index_t* index = dict_table_get_first_index(node->table); - byte* record= 0; - VCOL_STORAGE *vcol_storage= 0; - - if (!update) - innobase_allocate_row_for_vcol(thd, index, &heap, &mysql_table, - &record, &vcol_storage); + ib_vcol_row vc(NULL); for (ulint col_no = 0; col_no < dict_table_get_n_v_cols(node->table); col_no++) { @@ -2179,24 +2161,19 @@ row_upd_store_v_row( dfield_dup(dfield, node->heap); } } else { + uchar *record = vc.record(thd, index, + &mysql_table); /* Need to compute, this happens when deleting row */ innobase_get_computed_value( node->row, col, index, - &heap, node->heap, NULL, - thd, mysql_table, record, NULL, - NULL, NULL); + &vc.heap, node->heap, + NULL, thd, mysql_table, + record, NULL, NULL, NULL); } } } } - - if (heap) { - if (vcol_storage) - innobase_free_row_for_vcol(vcol_storage); - mem_heap_free(heap); - } - } /** Stores to the heap the row on which the node->pcur is positioned. diff --git a/storage/innobase/row/row0vers.cc b/storage/innobase/row/row0vers.cc index 77bbb1b3459..047027e4950 100644 --- a/storage/innobase/row/row0vers.cc +++ b/storage/innobase/row/row0vers.cc @@ -455,11 +455,8 @@ row_vers_build_clust_v_col( mem_heap_t* heap, purge_vcol_info_t* vcol_info) { - mem_heap_t* local_heap = NULL; - VCOL_STORAGE *vcol_storage= NULL; THD* thd= current_thd; TABLE* maria_table= 0; - byte* record= 0; ut_ad(dict_index_has_virtual(index)); ut_ad(index->table == clust_index->table); @@ -469,15 +466,12 @@ row_vers_build_clust_v_col( maria_table = vcol_info->table(); } - innobase_allocate_row_for_vcol(thd, index, - &local_heap, - &maria_table, - &record, - &vcol_storage); + ib_vcol_row vc(NULL); + byte *record = vc.record(thd, index, &maria_table); if (vcol_info && !vcol_info->table()) { vcol_info->set_table(maria_table); - goto func_exit; + return; } for (ulint i = 0; i < dict_index_get_n_fields(index); i++) { @@ -491,18 +485,11 @@ row_vers_build_clust_v_col( ind_field->col); innobase_get_computed_value( - row, col, clust_index, &local_heap, + row, col, clust_index, &vc.heap, heap, NULL, thd, maria_table, record, NULL, NULL, NULL); } } - -func_exit: - if (local_heap) { - if (vcol_storage) - innobase_free_row_for_vcol(vcol_storage); - mem_heap_free(local_heap); - } } /** Build latest virtual column data from undo log -- cgit v1.2.1 From 97db6c15ea3e83a21df137c222dbd5a40fbe7c82 Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Tue, 11 Aug 2020 00:38:32 +1000 Subject: MDEV-20618 Assertion failed in row_upd_sec_index_entry Add a proper error handling of innobase_get_computed_value results in row_upd_store_row/row_upd_store_v_row. Also add an assertion in row_vers_build_clust_v_col to fail during row purge. Add one more assertion in row_sel_sec_rec_is_for_clust_rec for possible future catches. --- mysql-test/suite/gcol/inc/gcol_keys.inc | 62 ++++++++++++++++++++++++ mysql-test/suite/gcol/r/gcol_keys_innodb.result | 50 +++++++++++++++++++ mysql-test/suite/gcol/r/gcol_keys_myisam.result | 50 +++++++++++++++++++ mysql-test/suite/vcol/r/vcol_misc.result | 6 +-- mysql-test/suite/vcol/t/vcol_misc.test | 2 + sql/sql_insert.cc | 6 +-- storage/innobase/handler/ha_innodb.cc | 15 +++--- storage/innobase/include/row0mysql.h | 6 +++ storage/innobase/row/row0sel.cc | 64 +++++++++++++++---------- storage/innobase/row/row0upd.cc | 50 +++++++++++++------ storage/innobase/row/row0vers.cc | 28 ++++++++--- 11 files changed, 280 insertions(+), 59 deletions(-) diff --git a/mysql-test/suite/gcol/inc/gcol_keys.inc b/mysql-test/suite/gcol/inc/gcol_keys.inc index 97c9e41b5e8..475ab96e56f 100644 --- a/mysql-test/suite/gcol/inc/gcol_keys.inc +++ b/mysql-test/suite/gcol/inc/gcol_keys.inc @@ -747,4 +747,66 @@ ANALYZE TABLE t1, t2; --eval $query DROP TABLE t1, t2; +if($support_virtual_index) +{ +--echo # +--echo # MDEV-20618 Assertion `btr_validate_index(index, 0, false)' failed +--echo # in row_upd_sec_index_entry +--echo # +CREATE TABLE t1 (A BIT(15), VA BIT(10) GENERATED ALWAYS AS (A),PK INT, + PRIMARY KEY (PK), UNIQUE KEY (VA)); + +INSERT IGNORE INTO t1 VALUES ( '\r1','a',1); +--error ER_DATA_TOO_LONG +REPLACE INTO t1 (PK) VALUES (1); + +DROP TABLE t1; + +--echo # +--echo # MDEV-17890 Record in index was not found on update, server crash in +--echo # row_upd_build_difference_binary or +--echo # Assertion `0' failed in row_upd_sec_index_entry +--echo # +CREATE TABLE t1 ( + pk BIGINT AUTO_INCREMENT, + b BIT(15), + v BIT(10) AS (b) VIRTUAL, + PRIMARY KEY(pk), + UNIQUE(v) +); + +INSERT IGNORE INTO t1 (b) VALUES (b'101110001110100'),(b'011101'); +SELECT pk, b INTO OUTFILE 'load.data' FROM t1; +--error ER_DATA_TOO_LONG +LOAD DATA INFILE 'load.data' REPLACE INTO TABLE t1 (pk, b); + +--let $datadir= `SELECT @@datadir` +--remove_file $datadir/test/load.data +DROP TABLE t1; + +--echo # +--echo # MDEV-17834 Server crashes in row_upd_build_difference_binary +--echo # on LOAD DATA into table with indexed virtual column --echo # +CREATE TABLE t1 ( + pk INT, + i TINYINT, + ts TIMESTAMP NULL, + vi TINYINT AS (i+1) PERSISTENT, + vts TIMESTAMP(5) AS (ts) VIRTUAL, + PRIMARY KEY(pk), + UNIQUE(vts) +); + +INSERT IGNORE INTO t1 (pk,i) VALUES (1,127); + +--write_file $MYSQLTEST_VARDIR/tmp/load.data +1 4 2019-01-01 00:00:00 +EOF +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--error ER_WARN_DATA_OUT_OF_RANGE +eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/load.data' REPLACE INTO TABLE t1 (pk,i,ts); + +--remove_file $MYSQLTEST_VARDIR/tmp/load.data +DROP TABLE t1; +} diff --git a/mysql-test/suite/gcol/r/gcol_keys_innodb.result b/mysql-test/suite/gcol/r/gcol_keys_innodb.result index 04ba512aad9..ae2843dd2ec 100644 --- a/mysql-test/suite/gcol/r/gcol_keys_innodb.result +++ b/mysql-test/suite/gcol/r/gcol_keys_innodb.result @@ -825,6 +825,56 @@ a1 a2 b 0 NULL 1 DROP TABLE t1, t2; # +# MDEV-20618 Assertion `btr_validate_index(index, 0, false)' failed +# in row_upd_sec_index_entry +# +CREATE TABLE t1 (A BIT(15), VA BIT(10) GENERATED ALWAYS AS (A),PK INT, +PRIMARY KEY (PK), UNIQUE KEY (VA)); +INSERT IGNORE INTO t1 VALUES ( '\r1','a',1); +Warnings: +Warning 1906 The value specified for generated column 'VA' in table 't1' has been ignored +Warning 1264 Out of range value for column 'VA' at row 1 +REPLACE INTO t1 (PK) VALUES (1); +ERROR 22001: Data too long for column 'VA' at row 1 +DROP TABLE t1; +# +# MDEV-17890 Record in index was not found on update, server crash in +# row_upd_build_difference_binary or +# Assertion `0' failed in row_upd_sec_index_entry +# +CREATE TABLE t1 ( +pk BIGINT AUTO_INCREMENT, +b BIT(15), +v BIT(10) AS (b) VIRTUAL, +PRIMARY KEY(pk), +UNIQUE(v) +); +INSERT IGNORE INTO t1 (b) VALUES (b'101110001110100'),(b'011101'); +Warnings: +Warning 1264 Out of range value for column 'v' at row 1 +SELECT pk, b INTO OUTFILE 'load.data' FROM t1; +LOAD DATA INFILE 'load.data' REPLACE INTO TABLE t1 (pk, b); +ERROR 22001: Data too long for column 'v' at row 1 +DROP TABLE t1; +# +# MDEV-17834 Server crashes in row_upd_build_difference_binary +# on LOAD DATA into table with indexed virtual column +# +CREATE TABLE t1 ( +pk INT, +i TINYINT, +ts TIMESTAMP NULL, +vi TINYINT AS (i+1) PERSISTENT, +vts TIMESTAMP(5) AS (ts) VIRTUAL, +PRIMARY KEY(pk), +UNIQUE(vts) +); +INSERT IGNORE INTO t1 (pk,i) VALUES (1,127); +Warnings: +Warning 1264 Out of range value for column 'vi' at row 1 +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/load.data' REPLACE INTO TABLE t1 (pk,i,ts); +ERROR 22003: Out of range value for column 'vi' at row 1 +DROP TABLE t1; # # BUG#21365158 WL8149:ASSERTION `!TABLE || (!TABLE->WRITE_SET # diff --git a/mysql-test/suite/gcol/r/gcol_keys_myisam.result b/mysql-test/suite/gcol/r/gcol_keys_myisam.result index dcbba1f70c1..a91a77aedf3 100644 --- a/mysql-test/suite/gcol/r/gcol_keys_myisam.result +++ b/mysql-test/suite/gcol/r/gcol_keys_myisam.result @@ -827,6 +827,56 @@ a1 a2 b 0 NULL 1 DROP TABLE t1, t2; # +# MDEV-20618 Assertion `btr_validate_index(index, 0, false)' failed +# in row_upd_sec_index_entry +# +CREATE TABLE t1 (A BIT(15), VA BIT(10) GENERATED ALWAYS AS (A),PK INT, +PRIMARY KEY (PK), UNIQUE KEY (VA)); +INSERT IGNORE INTO t1 VALUES ( '\r1','a',1); +Warnings: +Warning 1906 The value specified for generated column 'VA' in table 't1' has been ignored +Warning 1264 Out of range value for column 'VA' at row 1 +REPLACE INTO t1 (PK) VALUES (1); +ERROR 22001: Data too long for column 'VA' at row 1 +DROP TABLE t1; +# +# MDEV-17890 Record in index was not found on update, server crash in +# row_upd_build_difference_binary or +# Assertion `0' failed in row_upd_sec_index_entry +# +CREATE TABLE t1 ( +pk BIGINT AUTO_INCREMENT, +b BIT(15), +v BIT(10) AS (b) VIRTUAL, +PRIMARY KEY(pk), +UNIQUE(v) +); +INSERT IGNORE INTO t1 (b) VALUES (b'101110001110100'),(b'011101'); +Warnings: +Warning 1264 Out of range value for column 'v' at row 1 +SELECT pk, b INTO OUTFILE 'load.data' FROM t1; +LOAD DATA INFILE 'load.data' REPLACE INTO TABLE t1 (pk, b); +ERROR 22001: Data too long for column 'v' at row 1 +DROP TABLE t1; +# +# MDEV-17834 Server crashes in row_upd_build_difference_binary +# on LOAD DATA into table with indexed virtual column +# +CREATE TABLE t1 ( +pk INT, +i TINYINT, +ts TIMESTAMP NULL, +vi TINYINT AS (i+1) PERSISTENT, +vts TIMESTAMP(5) AS (ts) VIRTUAL, +PRIMARY KEY(pk), +UNIQUE(vts) +); +INSERT IGNORE INTO t1 (pk,i) VALUES (1,127); +Warnings: +Warning 1264 Out of range value for column 'vi' at row 1 +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/load.data' REPLACE INTO TABLE t1 (pk,i,ts); +ERROR 22003: Out of range value for column 'vi' at row 1 +DROP TABLE t1; DROP VIEW IF EXISTS v1,v2; DROP TABLE IF EXISTS t1,t2,t3; DROP PROCEDURE IF EXISTS p1; diff --git a/mysql-test/suite/vcol/r/vcol_misc.result b/mysql-test/suite/vcol/r/vcol_misc.result index a9b5bc29018..6c4975f2178 100644 --- a/mysql-test/suite/vcol/r/vcol_misc.result +++ b/mysql-test/suite/vcol/r/vcol_misc.result @@ -456,8 +456,7 @@ select pk, col_bit+0, vcol_bit+0 from t1; pk col_bit+0 vcol_bit+0 99 10000 1023 REPLACE LOW_PRIORITY INTO `t1` (`pk`) VALUES (99); -Warnings: -Warning 1264 Out of range value for column 'vcol_bit' at row 1 +ERROR 22001: Data too long for column 'vcol_bit' at row 1 drop table t1; # # MDEV-17837 REPLACE on table with virtual_field can cause crash in set_ok_status() @@ -476,8 +475,7 @@ INSERT IGNORE INTO t1 (pk,i) VALUES (1,127); Warnings: Warning 1264 Out of range value for column 'vi' at row 1 REPLACE INTO t1 (pk,i) VALUES (1,2); -Warnings: -Warning 1264 Out of range value for column 'vi' at row 1 +ERROR 22003: Out of range value for column 'vi' at row 1 DROP TABLE t1; SET @sql_mode=@old_sql_mode; # diff --git a/mysql-test/suite/vcol/t/vcol_misc.test b/mysql-test/suite/vcol/t/vcol_misc.test index 73b23c78977..07f96f4e0b8 100644 --- a/mysql-test/suite/vcol/t/vcol_misc.test +++ b/mysql-test/suite/vcol/t/vcol_misc.test @@ -431,6 +431,7 @@ replace INTO `t1` (`pk`,col_bit) VALUES (99,1000); select pk, col_bit+0, vcol_bit+0 from t1; replace INTO `t1` (`pk`,col_bit) VALUES (99,10000); select pk, col_bit+0, vcol_bit+0 from t1; +--error ER_DATA_TOO_LONG REPLACE LOW_PRIORITY INTO `t1` (`pk`) VALUES (99); drop table t1; @@ -451,6 +452,7 @@ CREATE TABLE t1 ( INSERT INTO t1 (pk,i) VALUES (1,1); TRUNCATE TABLE t1; INSERT IGNORE INTO t1 (pk,i) VALUES (1,127); +--error ER_WARN_DATA_OUT_OF_RANGE REPLACE INTO t1 (pk,i) VALUES (1,2); DROP TABLE t1; SET @sql_mode=@old_sql_mode; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index ec784bc6df4..0c50a251d26 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1748,15 +1748,13 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) } if (table->vfield) { - my_bool abort_on_warning= thd->abort_on_warning; /* We have not yet called update_virtual_fields(VOL_UPDATE_FOR_READ) in handler methods for the just read row in record[1]. */ table->move_fields(table->field, table->record[1], table->record[0]); - thd->abort_on_warning= 0; - table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_REPLACE); - thd->abort_on_warning= abort_on_warning; + if (table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_REPLACE)) + goto err; table->move_fields(table->field, table->record[0], table->record[1]); } if (info->handle_duplicates == DUP_UPDATE) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index d396c71da5f..3b404928cf4 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -103,6 +103,7 @@ this program; if not, write to the Free Software Foundation, Inc., #include "srv0mon.h" #include "srv0srv.h" #include "srv0start.h" +#include "rem0rec.h" #ifdef UNIV_DEBUG #include "trx0purge.h" #endif /* UNIV_DEBUG */ @@ -21881,6 +21882,13 @@ void innobase_free_row_for_vcol(VCOL_STORAGE *storage) } +void innobase_report_computed_value_failed(dtuple_t *row) +{ + ib::error() << "Compute virtual column values failed for " + << rec_printer(row).str(); +} + + /** Get the computed value by supplying the base column values. @param[in,out] row the data row @param[in] col virtual column @@ -22008,13 +22016,6 @@ innobase_get_computed_value( dbug_tmp_restore_column_map(mysql_table->write_set, old_write_set); if (ret != 0) { - // FIXME: Why this error message is macro-hidden? -#ifdef INNODB_VIRTUAL_DEBUG - ib::warn() << "Compute virtual column values failed "; - fputs("InnoDB: Cannot compute value for following record ", - stderr); - dtuple_print(stderr, row); -#endif /* INNODB_VIRTUAL_DEBUG */ DBUG_RETURN(NULL); } diff --git a/storage/innobase/include/row0mysql.h b/storage/innobase/include/row0mysql.h index 3b177ac1a24..d5cdd4a3f17 100644 --- a/storage/innobase/include/row0mysql.h +++ b/storage/innobase/include/row0mysql.h @@ -874,6 +874,12 @@ public: } }; +/** Report virtual value computation failure in ib::error +@param[in] row the data row +*/ +ATTRIBUTE_COLD +void innobase_report_computed_value_failed(dtuple_t *row); + /** Get the computed value by supplying the base column values. @param[in,out] row the data row @param[in] col virtual column diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index bb15625f748..7fd0210dbab 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -154,11 +154,15 @@ fields are compared with collation! must be protected by a page s-latch @param[in] clust_index clustered index @param[in] thr query thread -@return TRUE if the secondary record is equal to the corresponding -fields in the clustered record, when compared with collation; -FALSE if not equal or if the clustered record has been marked for deletion */ +@retval DB_COMPUTE_VALUE_FAILED in case of virtual column value computation + failure. +@retval DB_SUCCESS_LOCKED_REC if the secondary record is equal to the + corresponding fields in the clustered record, when compared with + collation; +@retval DB_SUCCESS if not equal or if the clustered record has been marked + for deletion */ static -ibool +dberr_t row_sel_sec_rec_is_for_clust_rec( const rec_t* sec_rec, dict_index_t* sec_index, @@ -190,7 +194,7 @@ row_sel_sec_rec_is_for_clust_rec( it is not visible in the read view. Besides, if there are any externally stored columns, some of them may have already been purged. */ - return(FALSE); + return DB_SUCCESS; } heap = mem_heap_create(256); @@ -242,6 +246,10 @@ row_sel_sec_rec_is_for_clust_rec( thr->prebuilt->m_mysql_table, record, NULL, NULL, NULL); + if (vfield == NULL) { + innobase_report_computed_value_failed(row); + return DB_COMPUTE_VALUE_FAILED; + } clust_len = vfield->len; clust_field = static_cast(vfield->data); } else { @@ -275,7 +283,7 @@ row_sel_sec_rec_is_for_clust_rec( sec_field, sec_len, ifield->prefix_len, clust_index->table)) { - return FALSE; + return DB_SUCCESS; } continue; @@ -311,19 +319,19 @@ row_sel_sec_rec_is_for_clust_rec( rtr_read_mbr(sec_field, &sec_mbr); if (!MBR_EQUAL_CMP(&sec_mbr, &tmp_mbr)) { - return FALSE; + return DB_SUCCESS; } } else { if (0 != cmp_data_data(col->mtype, col->prtype, clust_field, len, sec_field, sec_len)) { - return FALSE; + return DB_SUCCESS; } } } - return TRUE; + return DB_SUCCESS_LOCKED_REC; } /*********************************************************************//** @@ -890,7 +898,7 @@ row_sel_get_clust_rec( dict_index_t* index; rec_t* clust_rec; rec_t* old_vers; - dberr_t err; + dberr_t err = DB_SUCCESS; mem_heap_t* heap = NULL; rec_offs offsets_[REC_OFFS_NORMAL_SIZE]; rec_offs* offsets = offsets_; @@ -932,7 +940,7 @@ row_sel_get_clust_rec( clustered index record did not exist in the read view of trx. */ - goto func_exit; + goto err_exit; } offsets = rec_get_offsets(clust_rec, index, offsets, true, @@ -997,7 +1005,7 @@ row_sel_get_clust_rec( clust_rec = old_vers; if (clust_rec == NULL) { - goto func_exit; + goto err_exit; } } @@ -1014,13 +1022,14 @@ row_sel_get_clust_rec( visit through secondary index records that would not really exist in our snapshot. */ - if ((old_vers - || rec_get_deleted_flag(rec, dict_table_is_comp( - plan->table))) - && !row_sel_sec_rec_is_for_clust_rec(rec, plan->index, - clust_rec, index, - thr)) { - goto func_exit; + if (old_vers || rec_get_deleted_flag(rec, dict_table_is_comp( + plan->table))) { + err = row_sel_sec_rec_is_for_clust_rec(rec, + plan->index, clust_rec, + index, thr); + if (err != DB_SUCCESS_LOCKED_REC) { + goto err_exit; + } } } @@ -1033,7 +1042,6 @@ row_sel_get_clust_rec( row_sel_fetch_columns(index, clust_rec, offsets, UT_LIST_GET_FIRST(plan->columns)); *out_rec = clust_rec; -func_exit: err = DB_SUCCESS; err_exit: if (UNIV_LIKELY_NULL(heap)) { @@ -3565,10 +3573,18 @@ Row_sel_get_clust_rec_for_mysql::operator()( || trx->isolation_level <= TRX_ISO_READ_UNCOMMITTED || dict_index_is_spatial(sec_index) || rec_get_deleted_flag(rec, dict_table_is_comp( - sec_index->table))) - && !row_sel_sec_rec_is_for_clust_rec( - rec, sec_index, clust_rec, clust_index, thr)) { - clust_rec = NULL; + sec_index->table)))) { + err = row_sel_sec_rec_is_for_clust_rec(rec, sec_index, + clust_rec, clust_index, thr); + switch (err) { + case DB_SUCCESS: + clust_rec = NULL; + break; + case DB_SUCCESS_LOCKED_REC: + break; + default: + goto err_exit; + } } err = DB_SUCCESS; diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index acc7c02abf2..10156c7d3ab 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -2101,9 +2101,11 @@ row_upd_eval_new_vals( @param[in,out] node row update node @param[in] update an update vector if it is update @param[in] thd mysql thread handle -@param[in,out] mysql_table mysql table object */ +@param[in,out] mysql_table mysql table object +@return true if success + false if virtual column value computation fails. */ static -void +bool row_upd_store_v_row( upd_node_t* node, const upd_t* update, @@ -2165,24 +2167,33 @@ row_upd_store_v_row( &mysql_table); /* Need to compute, this happens when deleting row */ - innobase_get_computed_value( - node->row, col, index, - &vc.heap, node->heap, - NULL, thd, mysql_table, - record, NULL, NULL, NULL); + dfield_t* vfield = + innobase_get_computed_value( + node->row, col, index, + &vc.heap, node->heap, + NULL, thd, mysql_table, + record, NULL, NULL, + NULL); + if (vfield == NULL) { + return false; + } } } } } + + return true; } /** Stores to the heap the row on which the node->pcur is positioned. @param[in] node row update node @param[in] thd mysql thread handle @param[in,out] mysql_table NULL, or mysql table object when - user thread invokes dml */ + user thread invokes dml +@return false if virtual column value computation fails + true otherwise. */ static -void +bool row_upd_store_row( upd_node_t* node, THD* thd, @@ -2226,8 +2237,12 @@ row_upd_store_row( NULL, NULL, NULL, ext, node->heap); if (node->table->n_v_cols) { - row_upd_store_v_row(node, node->is_delete ? NULL : node->update, + bool ok = row_upd_store_v_row(node, + node->is_delete ? NULL : node->update, thd, mysql_table); + if (!ok) { + return false; + } } if (node->is_delete) { @@ -2242,6 +2257,7 @@ row_upd_store_row( if (UNIV_LIKELY_NULL(heap)) { mem_heap_free(heap); } + return true; } /***********************************************************//** @@ -2957,9 +2973,12 @@ row_upd_del_mark_clust_rec( /* Store row because we have to build also the secondary index entries */ - row_upd_store_row(node, trx->mysql_thd, + if (!row_upd_store_row(node, trx->mysql_thd, thr->prebuilt && thr->prebuilt->table == node->table - ? thr->prebuilt->m_mysql_table : NULL); + ? thr->prebuilt->m_mysql_table : NULL)) { + err = DB_COMPUTE_VALUE_FAILED; + return err; + } /* Mark the clustered index record deleted; we do not have to check locks, because we assume that we have an x-lock on the record */ @@ -3168,8 +3187,11 @@ row_upd_clust_step( goto exit_func; } - row_upd_store_row(node, trx->mysql_thd, - thr->prebuilt ? thr->prebuilt->m_mysql_table : NULL); + if(!row_upd_store_row(node, trx->mysql_thd, + thr->prebuilt ? thr->prebuilt->m_mysql_table : NULL)) { + err = DB_COMPUTE_VALUE_FAILED; + goto exit_func; + } if (row_upd_changes_ord_field_binary(index, node->update, thr, node->row, node->ext)) { diff --git a/storage/innobase/row/row0vers.cc b/storage/innobase/row/row0vers.cc index 047027e4950..2d8704764d1 100644 --- a/storage/innobase/row/row0vers.cc +++ b/storage/innobase/row/row0vers.cc @@ -445,9 +445,11 @@ row_vers_must_preserve_del_marked( @param[in] clust_index clustered index @param[in] index the secondary index @param[in] heap heap used to build virtual dtuple -@param[in,out] vcol_info virtual column information. */ +@param[in,out] vcol_info virtual column information. +@return true in case of success + false if virtual column computation fails */ static -void +bool row_vers_build_clust_v_col( dtuple_t* row, dict_index_t* clust_index, @@ -471,7 +473,8 @@ row_vers_build_clust_v_col( if (vcol_info && !vcol_info->table()) { vcol_info->set_table(maria_table); - return; + // wait for second fetch + return true; } for (ulint i = 0; i < dict_index_get_n_fields(index); i++) { @@ -484,12 +487,18 @@ row_vers_build_clust_v_col( col = reinterpret_cast( ind_field->col); - innobase_get_computed_value( + dfield_t *vfield = innobase_get_computed_value( row, col, clust_index, &vc.heap, heap, NULL, thd, maria_table, record, NULL, NULL, NULL); + if (vfield == NULL) { + innobase_report_computed_value_failed(row); + ut_ad(0); + return false; + } } } + return true; } /** Build latest virtual column data from undo log @@ -826,8 +835,11 @@ row_vers_build_cur_vrow( mtr->commit(); } - row_vers_build_clust_v_col( + bool res = row_vers_build_clust_v_col( row, clust_index, index, heap, vcol_info); + if (!res) { + return NULL; + } if (vcol_info != NULL && vcol_info->is_first_fetch()) { return NULL; @@ -948,10 +960,14 @@ row_vers_old_has_index_entry( mtr->commit(); } - row_vers_build_clust_v_col( + bool res = row_vers_build_clust_v_col( row, clust_index, index, heap, vcol_info); + if (!res) { + goto unsafe_to_purge; + } + if (vcol_info && vcol_info->is_first_fetch()) { goto unsafe_to_purge; } -- cgit v1.2.1 From c34cb165881e18234543b12bae9e2f96548ba7d3 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 1 Sep 2020 11:34:03 +0200 Subject: fix compiler error on clang-cl --- strings/ctype.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strings/ctype.c b/strings/ctype.c index c9977824176..46951c3ae1f 100644 --- a/strings/ctype.c +++ b/strings/ctype.c @@ -921,7 +921,7 @@ my_string_metadata_get(MY_STRING_METADATA *metadata, /* Check repertoire: detect pure ascii strings */ -uint +my_repertoire_t my_string_repertoire(CHARSET_INFO *cs, const char *str, size_t length) { if (cs->mbminlen == 1 && !(cs->state & MY_CS_NONASCII)) @@ -948,7 +948,7 @@ my_string_repertoire(CHARSET_INFO *cs, const char *str, size_t length) /* Returns repertoire for charset */ -uint my_charset_repertoire(CHARSET_INFO *cs) +my_repertoire_t my_charset_repertoire(CHARSET_INFO *cs) { return cs->state & MY_CS_PUREASCII ? MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30; -- cgit v1.2.1 From 94e9dc95d4bebf711f001e16bbb53fd8d6a58b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 1 Sep 2020 15:52:36 +0300 Subject: MDEV-23600 Division by 0 in row_search_with_covering_prefix The InnoDB index fields store bytes, not characters. Remove some unnecessary conversions from characters to bytes. This also fixes MDEV-20422 and the wrong-result bug MDEV-12486. --- ..._prefix_index_cluster_optimization.combinations | 5 + .../innodb_prefix_index_cluster_optimization.inc | 1 + mysql-test/r/fast_prefix_index_fetch_innodb.result | 57 ++- mysql-test/r/innodb_ext_key,off.rdiff | 295 ++++++++++++++ mysql-test/r/innodb_ext_key.result | 422 --------------------- mysql-test/t/fast_prefix_index_fetch_innodb.test | 52 ++- mysql-test/t/innodb_ext_key.combinations | 5 + mysql-test/t/innodb_ext_key.test | 222 +---------- storage/innobase/row/row0sel.cc | 31 +- storage/xtradb/row/row0sel.cc | 32 +- 10 files changed, 439 insertions(+), 683 deletions(-) create mode 100644 mysql-test/include/innodb_prefix_index_cluster_optimization.combinations create mode 100644 mysql-test/include/innodb_prefix_index_cluster_optimization.inc create mode 100644 mysql-test/r/innodb_ext_key,off.rdiff create mode 100644 mysql-test/t/innodb_ext_key.combinations diff --git a/mysql-test/include/innodb_prefix_index_cluster_optimization.combinations b/mysql-test/include/innodb_prefix_index_cluster_optimization.combinations new file mode 100644 index 00000000000..ad82f82aa9d --- /dev/null +++ b/mysql-test/include/innodb_prefix_index_cluster_optimization.combinations @@ -0,0 +1,5 @@ +[covering] +innodb_prefix_index_cluster_optimization=on + +[unoptimized] +innodb_prefix_index_cluster_optimization=off diff --git a/mysql-test/include/innodb_prefix_index_cluster_optimization.inc b/mysql-test/include/innodb_prefix_index_cluster_optimization.inc new file mode 100644 index 00000000000..c841fece702 --- /dev/null +++ b/mysql-test/include/innodb_prefix_index_cluster_optimization.inc @@ -0,0 +1 @@ +--source include/have_innodb.inc diff --git a/mysql-test/r/fast_prefix_index_fetch_innodb.result b/mysql-test/r/fast_prefix_index_fetch_innodb.result index c6d96389b08..885ee000c28 100644 --- a/mysql-test/r/fast_prefix_index_fetch_innodb.result +++ b/mysql-test/r/fast_prefix_index_fetch_innodb.result @@ -1,4 +1,4 @@ -drop table if exists prefixinno; +SET @save_opt= @@GLOBAL.innodb_prefix_index_cluster_optimization; set global innodb_prefix_index_cluster_optimization = ON; show variables like 'innodb_prefix_index_cluster_optimization'; Variable_name Value @@ -346,10 +346,10 @@ f1 🐱🌑 select @cluster_lookups; @cluster_lookups -2 +1 select @cluster_lookups_avoided; @cluster_lookups_avoided -0 +1 # Eligible - record length is shorter than prefix length SELECT f1 FROM t1 FORCE INDEX (`f1`) WHERE f1 like '🌑%'; f1 @@ -366,10 +366,10 @@ f1 🌒 select @cluster_lookups; @cluster_lookups -1 +0 select @cluster_lookups_avoided; @cluster_lookups_avoided -1 +2 DROP TABLE t1; CREATE TABLE t1( col1 INT, @@ -398,4 +398,49 @@ select @cluster_lookups_avoided; @cluster_lookups_avoided 0 DROP TABLE t1; -set global innodb_prefix_index_cluster_optimization = OFF; +# +# MDEV-23600 Division by 0 in row_search_with_covering_prefix() +# +CREATE TABLE t(c POINT UNIQUE) ENGINE=InnoDB; +INSERT t SET c=POINT(1,1); +SELECT * FROM t WHERE c > (SELECT MAX(c) FROM t); +c +DROP TABLE t; +# +# MDEV-12486 Wrong results with innodb_prefix_index_cluster_optimization +# +CREATE TABLE wp_blogs ( +blog_id bigint(20) NOT NULL auto_increment, +site_id bigint(20) NOT NULL default '0', +domain varchar(200) NOT NULL default '', +path varchar(100) NOT NULL default '', +registered datetime NOT NULL default '0000-00-00 00:00:00', +last_updated datetime NOT NULL default '0000-00-00 00:00:00', +public tinyint(2) NOT NULL default '1', +archived tinyint(2) NOT NULL default '0', +mature tinyint(2) NOT NULL default '0', +spam tinyint(2) NOT NULL default '0', +deleted tinyint(2) NOT NULL default '0', +lang_id int(11) NOT NULL default '0', +PRIMARY KEY (blog_id), +KEY domain (domain(50),path(5)), +KEY lang_id (lang_id) +) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; +INSERT INTO wp_blogs (domain, path) VALUES +('domain.no', '/fondsinvesteringer/'), ('domain.no', '/'), +('foo', 'bar'), ('bar', 'foo'), ('foo', 'foo'), ('bar', 'bar'), +('foo', 'foobar'), ('bar', 'foobar'), ('foobar', 'foobar'); +SET GLOBAL innodb_prefix_index_cluster_optimization=off; +SELECT blog_id FROM wp_blogs WHERE domain IN ('domain.no') +AND path IN ( '/fondsinvesteringer/', '/' ); +blog_id +2 +1 +SET GLOBAL innodb_prefix_index_cluster_optimization=on; +SELECT blog_id FROM wp_blogs WHERE domain IN ('domain.no') +AND path IN ( '/fondsinvesteringer/', '/' ); +blog_id +2 +1 +DROP TABLE wp_blogs; +SET GLOBAL innodb_prefix_index_cluster_optimization = @save_opt; diff --git a/mysql-test/r/innodb_ext_key,off.rdiff b/mysql-test/r/innodb_ext_key,off.rdiff new file mode 100644 index 00000000000..47ca1e6849a --- /dev/null +++ b/mysql-test/r/innodb_ext_key,off.rdiff @@ -0,0 +1,295 @@ +@@ -4,7 +4,7 @@ + explain + select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 8 const,const 1 Using index ++1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 const 5 Using where + flush status; + select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; + count(*) +@@ -14,7 +14,7 @@ + Handler_read_first 0 + Handler_read_key 1 + Handler_read_last 0 +-Handler_read_next 1 ++Handler_read_next 5 + Handler_read_prev 0 + Handler_read_retry 0 + Handler_read_rnd 0 +@@ -45,7 +45,7 @@ + select count(*) from lineitem + where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 8 NULL 1 Using where; Using index ++1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; Using index + flush status; + select count(*) from lineitem + where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000; +@@ -56,7 +56,7 @@ + Handler_read_first 0 + Handler_read_key 1 + Handler_read_last 0 +-Handler_read_next 1 ++Handler_read_next 6 + Handler_read_prev 0 + Handler_read_retry 0 + Handler_read_rnd 0 +@@ -66,7 +66,7 @@ + select l_orderkey, l_linenumber from lineitem + where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 8 NULL 3 Using where; Using index ++1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; Using index + flush status; + select l_orderkey, l_linenumber from lineitem + where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; +@@ -79,7 +79,7 @@ + Handler_read_first 0 + Handler_read_key 1 + Handler_read_last 0 +-Handler_read_next 3 ++Handler_read_next 6 + Handler_read_prev 0 + Handler_read_retry 0 + Handler_read_rnd 0 +@@ -88,7 +88,7 @@ + explain + select min(l_orderkey) from lineitem where l_shipdate='1992-07-01'; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away ++1 SIMPLE lineitem ref i_l_shipdate i_l_shipdate 4 const 6 Using index + flush status; + select min(l_orderkey) from lineitem where l_shipdate='1992-07-01'; + min(l_orderkey) +@@ -98,7 +98,7 @@ + Handler_read_first 0 + Handler_read_key 1 + Handler_read_last 0 +-Handler_read_next 0 ++Handler_read_next 6 + Handler_read_prev 0 + Handler_read_retry 0 + Handler_read_rnd 0 +@@ -108,7 +108,7 @@ + select min(l_orderkey) from lineitem + where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away ++1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; Using index + flush status; + select min(l_orderkey) from lineitem + where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; +@@ -119,7 +119,7 @@ + Handler_read_first 0 + Handler_read_key 1 + Handler_read_last 0 +-Handler_read_next 0 ++Handler_read_next 6 + Handler_read_prev 0 + Handler_read_retry 0 + Handler_read_rnd 0 +@@ -129,7 +129,7 @@ + select max(l_linenumber) from lineitem + where l_shipdate='1992-07-01' and l_orderkey=130; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away ++1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 const 5 Using where + flush status; + select max(l_linenumber) from lineitem + where l_shipdate='1992-07-01' and l_orderkey=130; +@@ -140,7 +140,7 @@ + Handler_read_first 0 + Handler_read_key 1 + Handler_read_last 0 +-Handler_read_next 0 ++Handler_read_next 5 + Handler_read_prev 0 + Handler_read_retry 0 + Handler_read_rnd 0 +@@ -152,7 +152,7 @@ + where l_shipdate='1992-07-01' and l_orderkey=130 + or l_receiptdate='1992-07-01' and l_orderkey=5603; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE lineitem index_merge i_l_shipdate,i_l_receiptdate i_l_shipdate,i_l_receiptdate 8,8 NULL 2 Using union(i_l_shipdate,i_l_receiptdate); Using where ++1 SIMPLE lineitem index_merge i_l_shipdate,i_l_receiptdate i_l_shipdate,i_l_receiptdate 4,4 NULL 9 Using union(i_l_shipdate,i_l_receiptdate); Using where + flush status; + select l_orderkey, l_linenumber + from lineitem use index (i_l_shipdate, i_l_receiptdate) +@@ -166,10 +166,10 @@ + Handler_read_first 0 + Handler_read_key 2 + Handler_read_last 0 +-Handler_read_next 2 ++Handler_read_next 9 + Handler_read_prev 0 + Handler_read_retry 0 +-Handler_read_rnd 2 ++Handler_read_rnd 9 + Handler_read_rnd_deleted 0 + Handler_read_rnd_next 0 + explain +@@ -178,7 +178,7 @@ + where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000 + or l_receiptdate='1992-07-01' and l_orderkey between 5001 and 6000; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE lineitem index_merge i_l_shipdate,i_l_receiptdate i_l_shipdate,i_l_receiptdate 8,8 NULL 3 Using sort_union(i_l_shipdate,i_l_receiptdate); Using where ++1 SIMPLE lineitem index_merge i_l_shipdate,i_l_receiptdate i_l_shipdate,i_l_receiptdate 4,4 NULL 9 Using union(i_l_shipdate,i_l_receiptdate); Using where + flush status; + select l_orderkey, l_linenumber + from lineitem use index (i_l_shipdate, i_l_receiptdate) +@@ -193,10 +193,10 @@ + Handler_read_first 0 + Handler_read_key 2 + Handler_read_last 0 +-Handler_read_next 3 ++Handler_read_next 9 + Handler_read_prev 0 + Handler_read_retry 0 +-Handler_read_rnd 3 ++Handler_read_rnd 9 + Handler_read_rnd_deleted 0 + Handler_read_rnd_next 0 + explain +@@ -204,7 +204,7 @@ + where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000 + or l_receiptdate='1992-07-01' and l_orderkey between 5001 and 6000; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE lineitem index_merge PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate,i_l_receiptdate 8,8 NULL 3 Using sort_union(i_l_shipdate,i_l_receiptdate); Using where ++1 SIMPLE lineitem index_merge PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate,PRIMARY,i_l_receiptdate,PRIMARY 4,4,4,4 NULL 2 Using union(intersect(i_l_shipdate,PRIMARY),intersect(i_l_receiptdate,PRIMARY)); Using where + flush status; + select l_orderkey, l_linenumber from lineitem + where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000 +@@ -218,7 +218,7 @@ + Handler_read_first 0 + Handler_read_key 2 + Handler_read_last 0 +-Handler_read_next 3 ++Handler_read_next 9 + Handler_read_prev 0 + Handler_read_retry 0 + Handler_read_rnd 3 +@@ -228,7 +228,7 @@ + select max(l_orderkey) from lineitem + where l_partkey between 1 and 10 group by l_partkey; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE lineitem range i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 NULL # Using where; Using index for group-by ++1 SIMPLE lineitem range i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 NULL # Using where; Using index + flush status; + select max(l_orderkey) from lineitem + where l_partkey between 1 and 10 group by l_partkey; +@@ -246,9 +246,9 @@ + show status like 'handler_read%'; + Variable_name Value + Handler_read_first 0 +-Handler_read_key 21 +-Handler_read_last 1 +-Handler_read_next 0 ++Handler_read_key 1 ++Handler_read_last 0 ++Handler_read_next 294 + Handler_read_prev 0 + Handler_read_retry 0 + Handler_read_rnd 0 +@@ -258,7 +258,7 @@ + select max(l_orderkey) from lineitem + where l_suppkey in (1,4) group by l_suppkey; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE lineitem range i_l_suppkey i_l_suppkey 5 NULL # Using where; Using index for group-by ++1 SIMPLE lineitem range i_l_suppkey i_l_suppkey 5 NULL # Using where; Using index + flush status; + select max(l_orderkey) from lineitem + where l_suppkey in (1,4) group by l_suppkey; +@@ -268,9 +268,9 @@ + show status like 'handler_read%'; + Variable_name Value + Handler_read_first 0 +-Handler_read_key 6 +-Handler_read_last 1 +-Handler_read_next 0 ++Handler_read_key 2 ++Handler_read_last 0 ++Handler_read_next 1230 + Handler_read_prev 0 + Handler_read_retry 0 + Handler_read_rnd 0 +@@ -286,7 +286,7 @@ + id select_type table type possible_keys key key_len ref rows Extra + 1 SIMPLE part range i_p_retailprice i_p_retailprice 9 NULL # Using where; Using index + 1 SIMPLE orders ref PRIMARY,i_o_orderdate i_o_orderdate 4 const # Using index +-1 SIMPLE lineitem ref i_l_partkey i_l_partkey 9 dbt3_s001.part.p_partkey,dbt3_s001.orders.o_orderkey # Using index ++1 SIMPLE lineitem ref i_l_partkey i_l_partkey 5 dbt3_s001.part.p_partkey # Using where; Using index + flush status; + select o_orderkey, p_partkey + from part use index (i_p_retailprice), +@@ -300,7 +300,7 @@ + Handler_read_first 0 + Handler_read_key 3 + Handler_read_last 0 +-Handler_read_next 3 ++Handler_read_next 26 + Handler_read_prev 0 + Handler_read_retry 0 + Handler_read_rnd 0 +@@ -317,8 +317,8 @@ + select * from t0, part ignore index (primary) + where p_partkey=t0.a and p_size=1; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE t0 ALL NULL NULL NULL NULL 5 Using where +-1 SIMPLE part eq_ref i_p_size i_p_size 9 const,dbt3_s001.t0.a 1 ++1 SIMPLE t0 ALL NULL NULL NULL NULL 5 ++1 SIMPLE part ref i_p_size i_p_size 5 const 5 Using index condition + select * from t0, part ignore index (primary) + where p_partkey=t0.a and p_size=1; + a p_partkey p_name p_mfgr p_brand p_type p_size p_container p_retailprice p_comment +@@ -495,7 +495,7 @@ + select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a and t3.pk1=t1.a; + id select_type table type possible_keys key key_len ref rows Extra + 1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where +-1 SIMPLE t3 ref PRIMARY,col1 col1 12 test.t1.a,test.t1.a,test.t1.a # Using index ++1 SIMPLE t3 ref PRIMARY,col1 col1 8 test.t1.a,test.t1.a # Using where; Using index + drop table t1,t2,t3; + # + # Bug mdev-4340: performance regression with extended_keys=on +@@ -705,13 +705,13 @@ + select * from t1 force index(index_date_updated) + where index_date_updated= 10 and index_id < 800; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE t1 range index_date_updated index_date_updated 13 NULL # Using index condition ++1 SIMPLE t1 ref index_date_updated index_date_updated 5 const # Using index condition + # This used to work from the start: + explain + select * from t2 force index(index_date_updated) + where index_date_updated= 10 and index_id < 800; + id select_type table type possible_keys key key_len ref rows Extra +-1 SIMPLE t2 range index_date_updated index_date_updated 13 NULL # Using index condition ++1 SIMPLE t2 ref index_date_updated index_date_updated 5 const # Using index condition + drop table t0,t1,t2; + # + # MDEV-11196: Error:Run-Time Check Failure #2 - Stack around the variable 'key_buff' +@@ -746,11 +746,12 @@ + "select_id": 1, + "table": { + "table_name": "t1", +- "access_type": "range", ++ "access_type": "ref", + "possible_keys": ["f2"], + "key": "f2", +- "key_length": "3070", +- "used_key_parts": ["f2", "pk1"], ++ "key_length": "3066", ++ "used_key_parts": ["f2"], ++ "ref": ["const"], + "rows": 1, + "filtered": 100, + "index_condition": "t1.pk1 <= 5 and t1.pk2 <= 5 and t1.f2 = 'abc'", +@@ -779,8 +780,8 @@ + "access_type": "range", + "possible_keys": ["k1"], + "key": "k1", +- "key_length": "3011", +- "used_key_parts": ["pk1", "f2", "pk2"], ++ "key_length": "3007", ++ "used_key_parts": ["pk1", "f2"], + "rows": 1, + "filtered": 100, + "index_condition": "t1.f2 <= 5 and t1.pk2 <= 5 and t1.pk1 = 'abc'", diff --git a/mysql-test/r/innodb_ext_key.result b/mysql-test/r/innodb_ext_key.result index e02b78cad15..233b359157b 100644 --- a/mysql-test/r/innodb_ext_key.result +++ b/mysql-test/r/innodb_ext_key.result @@ -1,30 +1,6 @@ -DROP TABLE IF EXISTS t1,t2,t3,t4; -DROP DATABASE IF EXISTS dbt3_s001; SET SESSION STORAGE_ENGINE='InnoDB'; CREATE DATABASE dbt3_s001; use dbt3_s001; -set @save_ext_key_optimizer_switch=@@optimizer_switch; -set optimizer_switch='extended_keys=off'; -explain -select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 const 5 Using where -flush status; -select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; -count(*) -1 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 1 -Handler_read_last 0 -Handler_read_next 5 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 0 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=on'; explain select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; id select_type table type possible_keys key key_len ref rows Extra @@ -44,29 +20,6 @@ Handler_read_retry 0 Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=off'; -explain -select count(*) from lineitem -where l_orderkey=130 and l_linenumber=2 and l_shipdate='1992-07-01'; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem const PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 8 const,const 1 -flush status; -select count(*) from lineitem -where l_orderkey=130 and l_linenumber=2 and l_shipdate='1992-07-01'; -count(*) -1 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 1 -Handler_read_last 0 -Handler_read_next 0 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 0 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=on'; explain select count(*) from lineitem where l_orderkey=130 and l_linenumber=2 and l_shipdate='1992-07-01'; @@ -88,29 +41,6 @@ Handler_read_retry 0 Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=off'; -explain -select count(*) from lineitem -where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; Using index -flush status; -select count(*) from lineitem -where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000; -count(*) -1 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 1 -Handler_read_last 0 -Handler_read_next 6 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 0 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=on'; explain select count(*) from lineitem where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000; @@ -132,31 +62,6 @@ Handler_read_retry 0 Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=off'; -explain -select l_orderkey, l_linenumber from lineitem -where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; Using index -flush status; -select l_orderkey, l_linenumber from lineitem -where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; -l_orderkey l_linenumber -1088 3 -1217 1 -1221 3 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 1 -Handler_read_last 0 -Handler_read_next 6 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 0 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=on'; explain select l_orderkey, l_linenumber from lineitem where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; @@ -180,27 +85,6 @@ Handler_read_retry 0 Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=off'; -explain -select min(l_orderkey) from lineitem where l_shipdate='1992-07-01'; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem ref i_l_shipdate i_l_shipdate 4 const 6 Using index -flush status; -select min(l_orderkey) from lineitem where l_shipdate='1992-07-01'; -min(l_orderkey) -130 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 1 -Handler_read_last 0 -Handler_read_next 6 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 0 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=on'; explain select min(l_orderkey) from lineitem where l_shipdate='1992-07-01'; id select_type table type possible_keys key key_len ref rows Extra @@ -220,29 +104,6 @@ Handler_read_retry 0 Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=off'; -explain -select min(l_orderkey) from lineitem -where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; Using index -flush status; -select min(l_orderkey) from lineitem -where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; -min(l_orderkey) -1088 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 1 -Handler_read_last 0 -Handler_read_next 6 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 0 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=on'; explain select min(l_orderkey) from lineitem where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; @@ -264,29 +125,6 @@ Handler_read_retry 0 Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=off'; -explain -select max(l_linenumber) from lineitem -where l_shipdate='1992-07-01' and l_orderkey=130; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 const 5 Using where -flush status; -select max(l_linenumber) from lineitem -where l_shipdate='1992-07-01' and l_orderkey=130; -max(l_linenumber) -2 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 1 -Handler_read_last 0 -Handler_read_next 5 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 0 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=on'; explain select max(l_linenumber) from lineitem where l_shipdate='1992-07-01' and l_orderkey=130; @@ -308,34 +146,6 @@ Handler_read_retry 0 Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=off'; -explain -select l_orderkey, l_linenumber -from lineitem use index (i_l_shipdate, i_l_receiptdate) -where l_shipdate='1992-07-01' and l_orderkey=130 -or l_receiptdate='1992-07-01' and l_orderkey=5603; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem index_merge i_l_shipdate,i_l_receiptdate i_l_shipdate,i_l_receiptdate 4,4 NULL 9 Using union(i_l_shipdate,i_l_receiptdate); Using where -flush status; -select l_orderkey, l_linenumber -from lineitem use index (i_l_shipdate, i_l_receiptdate) -where l_shipdate='1992-07-01' and l_orderkey=130 -or l_receiptdate='1992-07-01' and l_orderkey=5603; -l_orderkey l_linenumber -130 2 -5603 2 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 2 -Handler_read_last 0 -Handler_read_next 9 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 9 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=on'; explain select l_orderkey, l_linenumber from lineitem use index (i_l_shipdate, i_l_receiptdate) @@ -362,35 +172,6 @@ Handler_read_retry 0 Handler_read_rnd 2 Handler_read_rnd_deleted 0 Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=off'; -explain -select l_orderkey, l_linenumber -from lineitem use index (i_l_shipdate, i_l_receiptdate) -where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000 -or l_receiptdate='1992-07-01' and l_orderkey between 5001 and 6000; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem index_merge i_l_shipdate,i_l_receiptdate i_l_shipdate,i_l_receiptdate 4,4 NULL 9 Using union(i_l_shipdate,i_l_receiptdate); Using where -flush status; -select l_orderkey, l_linenumber -from lineitem use index (i_l_shipdate, i_l_receiptdate) -where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000 -or l_receiptdate='1992-07-01' and l_orderkey between 5001 and 6000; -l_orderkey l_linenumber -130 2 -5603 2 -5959 3 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 2 -Handler_read_last 0 -Handler_read_next 9 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 9 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=on'; explain select l_orderkey, l_linenumber from lineitem use index (i_l_shipdate, i_l_receiptdate) @@ -418,33 +199,6 @@ Handler_read_retry 0 Handler_read_rnd 3 Handler_read_rnd_deleted 0 Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=off'; -explain -select l_orderkey, l_linenumber from lineitem -where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000 -or l_receiptdate='1992-07-01' and l_orderkey between 5001 and 6000; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem index_merge PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate,PRIMARY,i_l_receiptdate,PRIMARY 4,4,4,4 NULL 2 Using union(intersect(i_l_shipdate,PRIMARY),intersect(i_l_receiptdate,PRIMARY)); Using where -flush status; -select l_orderkey, l_linenumber from lineitem -where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000 -or l_receiptdate='1992-07-01' and l_orderkey between 5001 and 6000; -l_orderkey l_linenumber -130 2 -5603 2 -5959 3 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 2 -Handler_read_last 0 -Handler_read_next 9 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 3 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=on'; explain select l_orderkey, l_linenumber from lineitem where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000 @@ -470,38 +224,6 @@ Handler_read_retry 0 Handler_read_rnd 3 Handler_read_rnd_deleted 0 Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=off'; -explain -select max(l_orderkey) from lineitem -where l_partkey between 1 and 10 group by l_partkey; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem range i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 NULL # Using where; Using index -flush status; -select max(l_orderkey) from lineitem -where l_partkey between 1 and 10 group by l_partkey; -max(l_orderkey) -5984 -5957 -5892 -5856 -5959 -5957 -5794 -5894 -5859 -5632 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 1 -Handler_read_last 0 -Handler_read_next 294 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 0 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=on'; explain select max(l_orderkey) from lineitem where l_partkey between 1 and 10 group by l_partkey; @@ -532,30 +254,6 @@ Handler_read_retry 0 Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=off'; -explain -select max(l_orderkey) from lineitem -where l_suppkey in (1,4) group by l_suppkey; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem range i_l_suppkey i_l_suppkey 5 NULL # Using where; Using index -flush status; -select max(l_orderkey) from lineitem -where l_suppkey in (1,4) group by l_suppkey; -max(l_orderkey) -5988 -5984 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 2 -Handler_read_last 0 -Handler_read_next 1230 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 0 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=on'; explain select max(l_orderkey) from lineitem where l_suppkey in (1,4) group by l_suppkey; @@ -579,37 +277,6 @@ Handler_read_rnd 0 Handler_read_rnd_deleted 0 Handler_read_rnd_next 0 create index i_p_retailprice on part(p_retailprice); -set optimizer_switch='extended_keys=off'; -explain -select o_orderkey, p_partkey -from part use index (i_p_retailprice), -lineitem use index (i_l_partkey), orders -where p_retailprice > 1100 and o_orderdate='1997-01-01' -and o_orderkey=l_orderkey and p_partkey=l_partkey; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE part range i_p_retailprice i_p_retailprice 9 NULL # Using where; Using index -1 SIMPLE orders ref PRIMARY,i_o_orderdate i_o_orderdate 4 const # Using index -1 SIMPLE lineitem ref i_l_partkey i_l_partkey 5 dbt3_s001.part.p_partkey # Using where; Using index -flush status; -select o_orderkey, p_partkey -from part use index (i_p_retailprice), -lineitem use index (i_l_partkey), orders -where p_retailprice > 1100 and o_orderdate='1997-01-01' -and o_orderkey=l_orderkey and p_partkey=l_partkey; -o_orderkey p_partkey -5895 200 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 3 -Handler_read_last 0 -Handler_read_next 26 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 0 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 0 -set optimizer_switch='extended_keys=on'; explain select o_orderkey, p_partkey from part use index (i_p_retailprice), @@ -646,7 +313,6 @@ Handler_read_rnd_next 0 create table t0 (a int); insert into t0 values (1), (2), (3), (4), (5); create index i_p_size on part(p_size); -set optimizer_switch='extended_keys=on'; explain select * from t0, part ignore index (primary) where p_partkey=t0.a and p_size=1; @@ -667,7 +333,6 @@ use test; # set @save_optimizer_switch=@@optimizer_switch; SET optimizer_switch='materialization=on,semijoin=on'; -SET optimizer_switch='extended_keys=on'; CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; INSERT INTO t1 VALUES (1,1), (2,2); SELECT * FROM t1 WHERE 2 IN (SELECT MAX(s1.a) FROM t1 AS s1, t1 AS s2); @@ -688,9 +353,7 @@ set optimizer_switch=@save_optimizer_switch; # + extended_keys = on # (valgrinf complains fixed by the patch for bug #914560) # -set @save_optimizer_switch=@@optimizer_switch; SET optimizer_switch = 'derived_with_keys=on'; -SET optimizer_switch = 'extended_keys=on'; CREATE TABLE t1 (a varchar(1)) ENGINE=MyISAM; INSERT INTO t1 VALUES ('j'), ('v'); CREATE TABLE t2 (b varchar(1)) ENGINE=MyISAM; @@ -720,21 +383,6 @@ c int NOT NULL PRIMARY KEY INSERT INTO t2 VALUES (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (24); -set @save_optimizer_switch=@@optimizer_switch; -SET optimizer_switch = 'extended_keys=off'; -EXPLAIN -SELECT a FROM t1 AS t, t2 -WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); -id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t index a,b b 7 NULL 10 Using index -1 PRIMARY t1 ref b b 3 test.t.b 2 Using index -1 PRIMARY t2 index NULL PRIMARY 4 NULL 11 Using index; FirstMatch(t) -1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t.a 1 Using index -SELECT a FROM t1 AS t, t2 -WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); -a -24 -SET optimizer_switch = 'extended_keys=on'; EXPLAIN SELECT a FROM t1 AS t, t2 WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); @@ -747,7 +395,6 @@ SELECT a FROM t1 AS t, t2 WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); a 24 -set optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2; # # LP Bug #923236: hash join + extended_keys = on @@ -756,12 +403,10 @@ CREATE TABLE t1 (a int) ENGINE=MyISAM; CREATE TABLE t2 (b int) ENGINE=MyISAM; INSERT INTO t1 (a) VALUES (4), (6); INSERT INTO t2 (b) VALUES (0), (8); -set @save_optimizer_switch=@@optimizer_switch; set @save_join_cache_level=@@join_cache_level; SET join_cache_level=3; SET optimizer_switch='join_cache_hashed=on'; SET optimizer_switch='join_cache_bka=on'; -SET optimizer_switch='extended_keys=on'; EXPLAIN SELECT * FROM t1, t2 WHERE b=a; id select_type table type possible_keys key key_len ref rows Extra @@ -786,26 +431,16 @@ UNIQUE KEY uq (c2,c3), KEY c3 (c3), KEY c4 (c4) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; -set @save_optimizer_switch=@@optimizer_switch; -set session optimizer_switch='extended_keys=off'; -INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar') -ON DUPLICATE KEY UPDATE c4 = VALUES(c4); INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar') ON DUPLICATE KEY UPDATE c4 = VALUES(c4); -DELETE FROM t1; -set session optimizer_switch='extended_keys=on'; INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar') ON DUPLICATE KEY UPDATE c4 = VALUES(c4); -INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar') -ON DUPLICATE KEY UPDATE c4 = VALUES(c4); -set optimizer_switch=@save_optimizer_switch; DROP TABLE t1; # # Bug mdev-4220: using ref instead of eq_ref # with extended_keys=on # (performance regression introduced in the patch for mdev-3851) # -set @save_optimizer_switch=@@optimizer_switch; create table t1 (a int not null) engine=innodb; insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t2 ( @@ -815,29 +450,6 @@ insert into t2 select A.a + 10 * B.a, A.a + 10 * B.a, A.a + 10 * B.a from t1 A, t1 B; -set optimizer_switch='extended_keys=off'; -explain -select * from t1, t2 where t2.a=t1.a and t2.b < 2; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 10 -1 SIMPLE t2 eq_ref a a 4 test.t1.a 1 Using where -flush status; -select * from t1, t2 where t2.a=t1.a and t2.b < 2; -a pk a b -0 0 0 0 -1 1 1 1 -show status like 'handler_read%'; -Variable_name Value -Handler_read_first 0 -Handler_read_key 10 -Handler_read_last 0 -Handler_read_next 0 -Handler_read_prev 0 -Handler_read_retry 0 -Handler_read_rnd 0 -Handler_read_rnd_deleted 0 -Handler_read_rnd_next 11 -set optimizer_switch='extended_keys=on'; explain select * from t1, t2 where t2.a=t1.a and t2.b < 2; id select_type table type possible_keys key key_len ref rows Extra @@ -874,18 +486,6 @@ analyze table t1,t3; Table Op Msg_type Msg_text test.t1 analyze status OK test.t3 analyze status OK -set optimizer_switch='extended_keys=off'; -explain -select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where -1 SIMPLE t3 ref col1 col1 8 test.t1.a,test.t1.a # Using index -explain -select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a and t3.pk1=t1.a; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where -1 SIMPLE t3 ref PRIMARY,col1 col1 8 test.t1.a,test.t1.a # Using where; Using index -set optimizer_switch='extended_keys=on'; explain select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a; id select_type table type possible_keys key key_len ref rows Extra @@ -900,7 +500,6 @@ drop table t1,t2,t3; # # Bug mdev-4340: performance regression with extended_keys=on # -set @save_optimizer_switch=@@optimizer_switch; CREATE TABLE t1 ( page_id int(8) unsigned NOT NULL AUTO_INCREMENT, page_namespace int(11) NOT NULL DEFAULT '0', @@ -1000,16 +599,6 @@ INSERT INTO t3 VALUES (89,'text-8008',''),(90,'text-9008',''),(91,'text-9',''),(92,'text-1009',''), (93,'text-2009',''),(94,'text-3009',''),(95,'text-4009',''),(96,'text-5009',''), (97,'text-6009',''),(98,'text-7009',''),(99,'text-8009',''),(100,'text-9009',''); -set optimizer_switch='extended_keys=off'; -EXPLAIN -SELECT * FROM t1, t2 IGNORE INDEX (PRIMARY), t3 -WHERE page_id=rev_page AND rev_text_id=old_id AND page_namespace=4 AND page_title='Sandbox' -ORDER BY rev_timestamp ASC LIMIT 10; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 const PRIMARY,name_title name_title 261 const,const 1 -1 SIMPLE t2 ref page_timestamp page_timestamp 4 const 10 Using where -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.rev_text_id 1 -set optimizer_switch='extended_keys=on'; EXPLAIN SELECT * FROM t1, t2 IGNORE INDEX (PRIMARY), t3 WHERE page_id=rev_page AND rev_text_id=old_id AND page_namespace=4 AND page_title='Sandbox' @@ -1027,7 +616,6 @@ create table t1 (a bigint not null unique auto_increment, b varchar(10), primary create table t2 (a bigint not null unique auto_increment, b varchar(10), primary key (a), key (b(2))) engine = innodb default character set utf8; insert into t1 (b) values (null), (null), (null); insert into t2 (b) values (null), (null), (null); -set optimizer_switch='extended_keys=on'; explain select a from t1 where b is null order by a desc limit 2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index b PRIMARY 8 NULL 3 Using where @@ -1042,14 +630,6 @@ select a from t2 where b is null order by a desc limit 2; a 3 2 -set optimizer_switch='extended_keys=off'; -explain select a from t2 where b is null order by a desc limit 2; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range b b 9 NULL 3 Using where; Using filesort -select a from t2 where b is null order by a desc limit 2; -a -3 -2 explain select a from t2 where b is null order by a desc; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 index b PRIMARY 8 NULL 3 Using where @@ -1067,7 +647,6 @@ a 2 1 drop table t1, t2; -set optimizer_switch=@save_optimizer_switch; # # MDEV-10325: Queries examines all rows of a tables when it should not # @@ -1213,7 +792,6 @@ EXPLAIN } } drop table t1; -set optimizer_switch=@save_ext_key_optimizer_switch; set global innodb_file_format = @save_innodb_file_format; set global innodb_large_prefix = @save_innodb_large_prefix; SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/t/fast_prefix_index_fetch_innodb.test b/mysql-test/t/fast_prefix_index_fetch_innodb.test index c3b3440d82d..7112f14bbd5 100644 --- a/mysql-test/t/fast_prefix_index_fetch_innodb.test +++ b/mysql-test/t/fast_prefix_index_fetch_innodb.test @@ -1,9 +1,6 @@ -- source include/have_innodb.inc ---disable_warnings -drop table if exists prefixinno; ---enable_warnings - +SET @save_opt= @@GLOBAL.innodb_prefix_index_cluster_optimization; set global innodb_prefix_index_cluster_optimization = ON; show variables like 'innodb_prefix_index_cluster_optimization'; @@ -665,4 +662,49 @@ select @cluster_lookups; select @cluster_lookups_avoided; DROP TABLE t1; -set global innodb_prefix_index_cluster_optimization = OFF; + +--echo # +--echo # MDEV-23600 Division by 0 in row_search_with_covering_prefix() +--echo # +CREATE TABLE t(c POINT UNIQUE) ENGINE=InnoDB; +INSERT t SET c=POINT(1,1); +SELECT * FROM t WHERE c > (SELECT MAX(c) FROM t); +DROP TABLE t; + +--echo # +--echo # MDEV-12486 Wrong results with innodb_prefix_index_cluster_optimization +--echo # +CREATE TABLE wp_blogs ( + blog_id bigint(20) NOT NULL auto_increment, + site_id bigint(20) NOT NULL default '0', + domain varchar(200) NOT NULL default '', + path varchar(100) NOT NULL default '', + registered datetime NOT NULL default '0000-00-00 00:00:00', + last_updated datetime NOT NULL default '0000-00-00 00:00:00', + public tinyint(2) NOT NULL default '1', + archived tinyint(2) NOT NULL default '0', + mature tinyint(2) NOT NULL default '0', + spam tinyint(2) NOT NULL default '0', + deleted tinyint(2) NOT NULL default '0', + lang_id int(11) NOT NULL default '0', + PRIMARY KEY (blog_id), + KEY domain (domain(50),path(5)), + KEY lang_id (lang_id) +) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; + +INSERT INTO wp_blogs (domain, path) VALUES +('domain.no', '/fondsinvesteringer/'), ('domain.no', '/'), +('foo', 'bar'), ('bar', 'foo'), ('foo', 'foo'), ('bar', 'bar'), +('foo', 'foobar'), ('bar', 'foobar'), ('foobar', 'foobar'); + +SET GLOBAL innodb_prefix_index_cluster_optimization=off; +SELECT blog_id FROM wp_blogs WHERE domain IN ('domain.no') +AND path IN ( '/fondsinvesteringer/', '/' ); + +SET GLOBAL innodb_prefix_index_cluster_optimization=on; +SELECT blog_id FROM wp_blogs WHERE domain IN ('domain.no') +AND path IN ( '/fondsinvesteringer/', '/' ); + +DROP TABLE wp_blogs; + +SET GLOBAL innodb_prefix_index_cluster_optimization = @save_opt; diff --git a/mysql-test/t/innodb_ext_key.combinations b/mysql-test/t/innodb_ext_key.combinations new file mode 100644 index 00000000000..6ad97eaf75b --- /dev/null +++ b/mysql-test/t/innodb_ext_key.combinations @@ -0,0 +1,5 @@ +[on] +optimizer_switch=extended_keys=on + +[off] +optimizer_switch=extended_keys=off diff --git a/mysql-test/t/innodb_ext_key.test b/mysql-test/t/innodb_ext_key.test index bec4462df08..c936e4b5170 100644 --- a/mysql-test/t/innodb_ext_key.test +++ b/mysql-test/t/innodb_ext_key.test @@ -1,9 +1,4 @@ ---source include/have_innodb.inc - ---disable_warnings -DROP TABLE IF EXISTS t1,t2,t3,t4; -DROP DATABASE IF EXISTS dbt3_s001; ---enable_warnings +--source include/innodb_prefix_index_cluster_optimization.inc SET SESSION STORAGE_ENGINE='InnoDB'; @@ -19,32 +14,12 @@ use dbt3_s001; --enable_result_log --enable_query_log -set @save_ext_key_optimizer_switch=@@optimizer_switch; - -set optimizer_switch='extended_keys=off'; explain select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; flush status; select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; show status like 'handler_read%'; -set optimizer_switch='extended_keys=on'; -explain -select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; -flush status; -select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=off'; -explain -select count(*) from lineitem - where l_orderkey=130 and l_linenumber=2 and l_shipdate='1992-07-01'; -flush status; -select count(*) from lineitem - where l_orderkey=130 and l_linenumber=2 and l_shipdate='1992-07-01'; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=on'; explain select count(*) from lineitem where l_orderkey=130 and l_linenumber=2 and l_shipdate='1992-07-01'; @@ -53,16 +28,6 @@ select count(*) from lineitem where l_orderkey=130 and l_linenumber=2 and l_shipdate='1992-07-01'; show status like 'handler_read%'; -set optimizer_switch='extended_keys=off'; -explain -select count(*) from lineitem - where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000; -flush status; -select count(*) from lineitem - where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=on'; explain select count(*) from lineitem where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000; @@ -71,16 +36,6 @@ select count(*) from lineitem where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000; show status like 'handler_read%'; -set optimizer_switch='extended_keys=off'; -explain -select l_orderkey, l_linenumber from lineitem - where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; -flush status; -select l_orderkey, l_linenumber from lineitem - where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=on'; explain select l_orderkey, l_linenumber from lineitem where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; @@ -89,21 +44,12 @@ select l_orderkey, l_linenumber from lineitem where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; show status like 'handler_read%'; -set optimizer_switch='extended_keys=off'; explain select min(l_orderkey) from lineitem where l_shipdate='1992-07-01'; flush status; select min(l_orderkey) from lineitem where l_shipdate='1992-07-01'; show status like 'handler_read%'; -set optimizer_switch='extended_keys=on'; -explain -select min(l_orderkey) from lineitem where l_shipdate='1992-07-01'; -flush status; -select min(l_orderkey) from lineitem where l_shipdate='1992-07-01'; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=off'; explain select min(l_orderkey) from lineitem where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; @@ -112,25 +58,6 @@ select min(l_orderkey) from lineitem where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; show status like 'handler_read%'; -set optimizer_switch='extended_keys=on'; -explain -select min(l_orderkey) from lineitem - where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; -flush status; -select min(l_orderkey) from lineitem - where l_shipdate='1992-07-01' and l_orderkey between 1001 and 2000; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=off'; -explain -select max(l_linenumber) from lineitem - where l_shipdate='1992-07-01' and l_orderkey=130; -flush status; -select max(l_linenumber) from lineitem - where l_shipdate='1992-07-01' and l_orderkey=130; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=on'; explain select max(l_linenumber) from lineitem where l_shipdate='1992-07-01' and l_orderkey=130; @@ -139,7 +66,6 @@ select max(l_linenumber) from lineitem where l_shipdate='1992-07-01' and l_orderkey=130; show status like 'handler_read%'; -set optimizer_switch='extended_keys=off'; explain select l_orderkey, l_linenumber from lineitem use index (i_l_shipdate, i_l_receiptdate) @@ -152,20 +78,6 @@ select l_orderkey, l_linenumber or l_receiptdate='1992-07-01' and l_orderkey=5603; show status like 'handler_read%'; -set optimizer_switch='extended_keys=on'; -explain -select l_orderkey, l_linenumber - from lineitem use index (i_l_shipdate, i_l_receiptdate) - where l_shipdate='1992-07-01' and l_orderkey=130 - or l_receiptdate='1992-07-01' and l_orderkey=5603; -flush status; -select l_orderkey, l_linenumber - from lineitem use index (i_l_shipdate, i_l_receiptdate) - where l_shipdate='1992-07-01' and l_orderkey=130 - or l_receiptdate='1992-07-01' and l_orderkey=5603; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=off'; explain select l_orderkey, l_linenumber from lineitem use index (i_l_shipdate, i_l_receiptdate) @@ -178,20 +90,6 @@ select l_orderkey, l_linenumber or l_receiptdate='1992-07-01' and l_orderkey between 5001 and 6000; show status like 'handler_read%'; -set optimizer_switch='extended_keys=on'; -explain -select l_orderkey, l_linenumber - from lineitem use index (i_l_shipdate, i_l_receiptdate) - where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000 - or l_receiptdate='1992-07-01' and l_orderkey between 5001 and 6000; -flush status; -select l_orderkey, l_linenumber - from lineitem use index (i_l_shipdate, i_l_receiptdate) - where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000 - or l_receiptdate='1992-07-01' and l_orderkey between 5001 and 6000; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=off'; explain select l_orderkey, l_linenumber from lineitem where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000 @@ -202,28 +100,6 @@ select l_orderkey, l_linenumber from lineitem or l_receiptdate='1992-07-01' and l_orderkey between 5001 and 6000; show status like 'handler_read%'; -set optimizer_switch='extended_keys=on'; -explain -select l_orderkey, l_linenumber from lineitem - where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000 - or l_receiptdate='1992-07-01' and l_orderkey between 5001 and 6000; -flush status; -select l_orderkey, l_linenumber from lineitem - where l_shipdate='1992-07-01' and l_orderkey between 1 and 1000 - or l_receiptdate='1992-07-01' and l_orderkey between 5001 and 6000; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=off'; ---replace_column 9 # -explain -select max(l_orderkey) from lineitem - where l_partkey between 1 and 10 group by l_partkey; -flush status; -select max(l_orderkey) from lineitem - where l_partkey between 1 and 10 group by l_partkey; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=on'; --replace_column 9 # explain select max(l_orderkey) from lineitem @@ -233,17 +109,6 @@ select max(l_orderkey) from lineitem where l_partkey between 1 and 10 group by l_partkey; show status like 'handler_read%'; -set optimizer_switch='extended_keys=off'; ---replace_column 9 # -explain -select max(l_orderkey) from lineitem - where l_suppkey in (1,4) group by l_suppkey; -flush status; -select max(l_orderkey) from lineitem - where l_suppkey in (1,4) group by l_suppkey; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=on'; --replace_column 9 # explain select max(l_orderkey) from lineitem @@ -255,23 +120,6 @@ show status like 'handler_read%'; create index i_p_retailprice on part(p_retailprice); -set optimizer_switch='extended_keys=off'; ---replace_column 9 # -explain -select o_orderkey, p_partkey - from part use index (i_p_retailprice), - lineitem use index (i_l_partkey), orders - where p_retailprice > 1100 and o_orderdate='1997-01-01' - and o_orderkey=l_orderkey and p_partkey=l_partkey; -flush status; -select o_orderkey, p_partkey - from part use index (i_p_retailprice), - lineitem use index (i_l_partkey), orders - where p_retailprice > 1100 and o_orderdate='1997-01-01' - and o_orderkey=l_orderkey and p_partkey=l_partkey; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=on'; --replace_column 9 # explain select o_orderkey, p_partkey @@ -296,8 +144,6 @@ create table t0 (a int); insert into t0 values (1), (2), (3), (4), (5); create index i_p_size on part(p_size); -set optimizer_switch='extended_keys=on'; - explain select * from t0, part ignore index (primary) where p_partkey=t0.a and p_size=1; @@ -320,7 +166,6 @@ use test; set @save_optimizer_switch=@@optimizer_switch; SET optimizer_switch='materialization=on,semijoin=on'; -SET optimizer_switch='extended_keys=on'; CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; INSERT INTO t1 VALUES (1,1), (2,2); @@ -339,10 +184,7 @@ set optimizer_switch=@save_optimizer_switch; --echo # (valgrinf complains fixed by the patch for bug #914560) --echo # -set @save_optimizer_switch=@@optimizer_switch; - SET optimizer_switch = 'derived_with_keys=on'; -SET optimizer_switch = 'extended_keys=on'; CREATE TABLE t1 (a varchar(1)) ENGINE=MyISAM; INSERT INTO t1 VALUES ('j'), ('v'); @@ -382,24 +224,12 @@ INSERT INTO t2 VALUES (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (24); -set @save_optimizer_switch=@@optimizer_switch; - -SET optimizer_switch = 'extended_keys=off'; -EXPLAIN -SELECT a FROM t1 AS t, t2 - WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); -SELECT a FROM t1 AS t, t2 - WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); - -SET optimizer_switch = 'extended_keys=on'; EXPLAIN SELECT a FROM t1 AS t, t2 WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); SELECT a FROM t1 AS t, t2 WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); -set optimizer_switch=@save_optimizer_switch; - DROP TABLE t1,t2; --echo # @@ -413,13 +243,11 @@ CREATE TABLE t2 (b int) ENGINE=MyISAM; INSERT INTO t1 (a) VALUES (4), (6); INSERT INTO t2 (b) VALUES (0), (8); -set @save_optimizer_switch=@@optimizer_switch; set @save_join_cache_level=@@join_cache_level; SET join_cache_level=3; SET optimizer_switch='join_cache_hashed=on'; SET optimizer_switch='join_cache_bka=on'; -SET optimizer_switch='extended_keys=on'; EXPLAIN SELECT * FROM t1, t2 WHERE b=a; @@ -448,24 +276,11 @@ KEY c4 (c4) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; -set @save_optimizer_switch=@@optimizer_switch; - -set session optimizer_switch='extended_keys=off'; -INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar') - ON DUPLICATE KEY UPDATE c4 = VALUES(c4); -INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar') - ON DUPLICATE KEY UPDATE c4 = VALUES(c4); - -DELETE FROM t1; - -set session optimizer_switch='extended_keys=on'; INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar') ON DUPLICATE KEY UPDATE c4 = VALUES(c4); INSERT INTO t1 (c2, c3, c4) VALUES (58291525, 2580, 'foobar') ON DUPLICATE KEY UPDATE c4 = VALUES(c4); -set optimizer_switch=@save_optimizer_switch; - DROP TABLE t1; --echo # @@ -474,8 +289,6 @@ DROP TABLE t1; --echo # (performance regression introduced in the patch for mdev-3851) --echo # -set @save_optimizer_switch=@@optimizer_switch; - create table t1 (a int not null) engine=innodb; insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); @@ -489,14 +302,6 @@ select A.a + 10 * B.a, A.a + 10 * B.a, A.a + 10 * B.a from t1 A, t1 B; -set optimizer_switch='extended_keys=off'; -explain -select * from t1, t2 where t2.a=t1.a and t2.b < 2; -flush status; -select * from t1, t2 where t2.a=t1.a and t2.b < 2; -show status like 'handler_read%'; - -set optimizer_switch='extended_keys=on'; explain select * from t1, t2 where t2.a=t1.a and t2.b < 2; flush status; @@ -522,15 +327,6 @@ alter table t3 add primary key (pk1, pk2); alter table t3 add key (col1, col2); analyze table t1,t3; -set optimizer_switch='extended_keys=off'; ---replace_column 9 # -explain -select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a; ---replace_column 9 # -explain -select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a and t3.pk1=t1.a; - -set optimizer_switch='extended_keys=on'; --replace_column 9 # explain select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a; @@ -544,8 +340,6 @@ drop table t1,t2,t3; --echo # Bug mdev-4340: performance regression with extended_keys=on --echo # -set @save_optimizer_switch=@@optimizer_switch; - CREATE TABLE t1 ( page_id int(8) unsigned NOT NULL AUTO_INCREMENT, page_namespace int(11) NOT NULL DEFAULT '0', @@ -649,13 +443,6 @@ INSERT INTO t3 VALUES (97,'text-6009',''),(98,'text-7009',''),(99,'text-8009',''),(100,'text-9009',''); -set optimizer_switch='extended_keys=off'; -EXPLAIN -SELECT * FROM t1, t2 IGNORE INDEX (PRIMARY), t3 - WHERE page_id=rev_page AND rev_text_id=old_id AND page_namespace=4 AND page_title='Sandbox' -ORDER BY rev_timestamp ASC LIMIT 10; - -set optimizer_switch='extended_keys=on'; EXPLAIN SELECT * FROM t1, t2 IGNORE INDEX (PRIMARY), t3 WHERE page_id=rev_page AND rev_text_id=old_id AND page_namespace=4 AND page_title='Sandbox' @@ -674,14 +461,10 @@ create table t2 (a bigint not null unique auto_increment, b varchar(10), primary insert into t1 (b) values (null), (null), (null); insert into t2 (b) values (null), (null), (null); -set optimizer_switch='extended_keys=on'; explain select a from t1 where b is null order by a desc limit 2; select a from t1 where b is null order by a desc limit 2; explain select a from t2 where b is null order by a desc limit 2; select a from t2 where b is null order by a desc limit 2; -set optimizer_switch='extended_keys=off'; -explain select a from t2 where b is null order by a desc limit 2; -select a from t2 where b is null order by a desc limit 2; explain select a from t2 where b is null order by a desc; select a from t2 where b is null order by a desc; @@ -691,8 +474,6 @@ select a from t2 where b is null order by a desc,a,a; drop table t1, t2; -set optimizer_switch=@save_optimizer_switch; - --echo # --echo # MDEV-10325: Queries examines all rows of a tables when it should not --echo # @@ -828,7 +609,6 @@ explain format= json select * from t1 force index(k1) where f2 <= 5 and pk2 <=5 and pk1 = 'abc' and f1 <= '3'; drop table t1; -set optimizer_switch=@save_ext_key_optimizer_switch; set global innodb_file_format = @save_innodb_file_format; set global innodb_large_prefix = @save_innodb_large_prefix; SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index 936b0eccfb7..f45702157c8 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -2,7 +2,7 @@ Copyright (c) 1997, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. -Copyright (c) 2015, 2018, MariaDB Corporation. +Copyright (c) 2015, 2020, MariaDB Corporation. Portions of this file contain modifications contributed and copyrighted by Google, Inc. Those modifications are gratefully acknowledged and are described @@ -3723,9 +3723,16 @@ bool row_search_with_covering_prefix( return false; } + /* We can avoid a clustered index lookup if + all of the following hold: + (1) all columns are in the secondary index + (2) all values for columns that are prefix-only + indexes are shorter than the prefix size + This optimization can avoid many IOs for certain schemas. */ for (ulint i = 0; i < prebuilt->n_template; i++) { mysql_row_templ_t* templ = prebuilt->mysql_template + i; ulint j = templ->rec_prefix_field_no; + ut_ad(!templ->mbminlen == !templ->mbmaxlen); /** Condition (1) : is the field in the index. */ if (j == ULINT_UNDEFINED) { @@ -3735,33 +3742,29 @@ bool row_search_with_covering_prefix( /** Condition (2): If this is a prefix index then row's value size shorter than prefix length. */ - if (!templ->rec_field_is_prefix) { + if (!templ->rec_field_is_prefix + || rec_offs_nth_sql_null(offsets, j)) { continue; } - ulint rec_size = rec_offs_nth_size(offsets, j); const dict_field_t* field = dict_index_get_nth_field(index, j); - ulint max_chars = field->prefix_len / templ->mbmaxlen; - ut_a(field->prefix_len > 0); - - if (rec_size < max_chars) { - /* Record in bytes shorter than the index - prefix length in char. */ + if (!field->prefix_len) { continue; } - if (rec_size * templ->mbminlen >= field->prefix_len) { + const ulint rec_size = rec_offs_nth_size(offsets, j); + + if (rec_size >= field->prefix_len) { /* Shortest representation string by the byte length of the record is longer than the maximum possible index prefix. */ return false; } - size_t num_chars = rec_field_len_in_chars( - field->col, j, rec, offsets); - - if (num_chars >= max_chars) { + if (templ->mbminlen != templ->mbmaxlen + && rec_field_len_in_chars(field->col, j, rec, offsets) + >= field->prefix_len / templ->mbmaxlen) { /* No of chars to store the record exceeds the index prefix character length. */ return false; diff --git a/storage/xtradb/row/row0sel.cc b/storage/xtradb/row/row0sel.cc index c9c7f1dd9c1..a968fc83243 100644 --- a/storage/xtradb/row/row0sel.cc +++ b/storage/xtradb/row/row0sel.cc @@ -2,7 +2,7 @@ Copyright (c) 1997, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. -Copyright (c) 2015, 2018, MariaDB Corporation. +Copyright (c) 2015, 2020, MariaDB Corporation. Portions of this file contain modifications contributed and copyrighted by Google, Inc. Those modifications are gratefully acknowledged and are described @@ -3740,9 +3740,16 @@ bool row_search_with_covering_prefix( return false; } + /* We can avoid a clustered index lookup if + all of the following hold: + (1) all columns are in the secondary index + (2) all values for columns that are prefix-only + indexes are shorter than the prefix size + This optimization can avoid many IOs for certain schemas. */ for (ulint i = 0; i < prebuilt->n_template; i++) { mysql_row_templ_t* templ = prebuilt->mysql_template + i; ulint j = templ->rec_prefix_field_no; + ut_ad(!templ->mbminlen == !templ->mbmaxlen); /** Condition (1) : is the field in the index. */ if (j == ULINT_UNDEFINED) { @@ -3752,34 +3759,29 @@ bool row_search_with_covering_prefix( /** Condition (2): If this is a prefix index then row's value size shorter than prefix length. */ - if (!templ->rec_field_is_prefix) { + if (!templ->rec_field_is_prefix + || rec_offs_nth_sql_null(offsets, j)) { continue; } - ulint rec_size = rec_offs_nth_size(offsets, j); const dict_field_t* field = dict_index_get_nth_field(index, j); - ulint max_chars = field->prefix_len / templ->mbmaxlen; - ut_a(field->prefix_len > 0); - - if (rec_size < max_chars) { - /* Record in bytes shorter than the index - prefix length in char. */ + if (!field->prefix_len) { continue; } - if (rec_size * templ->mbminlen >= field->prefix_len) { + const ulint rec_size = rec_offs_nth_size(offsets, j); + + if (rec_size >= field->prefix_len) { /* Shortest representation string by the byte length of the record is longer than the maximum possible index prefix. */ return false; } - - size_t num_chars = rec_field_len_in_chars( - field->col, j, rec, offsets); - - if (num_chars >= max_chars) { + if (templ->mbminlen != templ->mbmaxlen + && rec_field_len_in_chars(field->col, j, rec, offsets) + >= field->prefix_len / templ->mbmaxlen) { /* No of chars to store the record exceeds the index prefix character length. */ return false; -- cgit v1.2.1 From 4a165f37114eafc0cced25dfea80b3f3bccc2fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 31 Aug 2020 16:48:28 +0300 Subject: Fix GCC 10.2.0 -Og -Wmaybe-uninitialized --- sql/opt_range.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 6a5f1c9f750..e933d2af355 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -7555,13 +7555,15 @@ SEL_TREE *Item_bool_func::get_full_func_mm_tree(RANGE_OPT_PARAM *param, table_map param_comp= ~(param->prev_tables | param->read_tables | param->current_table); #ifdef HAVE_SPATIAL - Field::geometry_type sav_geom_type; - const bool geometry= field_item->field->type() == MYSQL_TYPE_GEOMETRY; - if (geometry) + Field::geometry_type sav_geom_type= Field::GEOM_GEOMETRY, *geom_type= + field_item->field->type() == MYSQL_TYPE_GEOMETRY + ? &(static_cast(field_item->field))->geom_type + : NULL; + if (geom_type) { - sav_geom_type= ((Field_geom*) field_item->field)->geom_type; + sav_geom_type= *geom_type; /* We have to be able to store all sorts of spatial features here */ - ((Field_geom*) field_item->field)->geom_type= Field::GEOM_GEOMETRY; + *geom_type= Field::GEOM_GEOMETRY; } #endif /*HAVE_SPATIAL*/ @@ -7592,9 +7594,9 @@ SEL_TREE *Item_bool_func::get_full_func_mm_tree(RANGE_OPT_PARAM *param, } #ifdef HAVE_SPATIAL - if (geometry) + if (geom_type) { - ((Field_geom*) field_item->field)->geom_type= sav_geom_type; + *geom_type= sav_geom_type; } #endif /*HAVE_SPATIAL*/ DBUG_RETURN(ftree); -- cgit v1.2.1 From ebafe5a2367478413bd582487c9afc18ccd7f4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 31 Aug 2020 17:20:03 +0300 Subject: Cleanup: Avoid repeated calls to dict_col_t::is_virtual() --- storage/innobase/handler/ha_innodb.cc | 9 ++++----- storage/innobase/row/row0merge.cc | 30 ++++++++++++------------------ 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 3b404928cf4..e171b6a99b3 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -5775,14 +5775,13 @@ innobase_vcol_build_templ( mysql_row_templ_t* templ, ulint col_no) { - if (dict_col_is_virtual(col)) { - templ->is_virtual = true; - templ->col_no = col_no; + templ->col_no = col_no; + templ->is_virtual = col->is_virtual(); + + if (templ->is_virtual) { templ->clust_rec_field_no = ULINT_UNDEFINED; templ->rec_field_no = col->ind; } else { - templ->is_virtual = false; - templ->col_no = col_no; templ->clust_rec_field_no = dict_col_get_clust_pos( col, clust_index); ut_a(templ->clust_rec_field_no != ULINT_UNDEFINED); diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index a07ac220419..6571a7fbfec 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -554,23 +554,16 @@ row_merge_buf_add( for (i = 0; i < n_fields; i++, field++, ifield++) { ulint len; - const dict_col_t* col; - ulint col_no; ulint fixed_len; const dfield_t* row_field; - - col = ifield->col; - const dict_v_col_t* v_col = NULL; - if (dict_col_is_virtual(col)) { - v_col = reinterpret_cast(col); - } - - col_no = dict_col_get_no(col); + const dict_col_t* const col = ifield->col; + const dict_v_col_t* const v_col = col->is_virtual() + ? reinterpret_cast(col) + : NULL; /* Process the Doc ID column */ - if (*doc_id > 0 - && col_no == index->table->fts->doc_col - && !dict_col_is_virtual(col)) { + if (!v_col && *doc_id + && col->ind == index->table->fts->doc_col) { fts_write_doc_id((byte*) &write_doc_id, *doc_id); /* Note: field->data now points to a value on the @@ -589,7 +582,7 @@ row_merge_buf_add( field->type.len = ifield->col->len; } else { /* Use callback to get the virtual column value */ - if (dict_col_is_virtual(col)) { + if (v_col) { dict_index_t* clust_index = dict_table_get_first_index(new_table); @@ -614,7 +607,8 @@ row_merge_buf_add( } dfield_copy(field, row_field); } else { - row_field = dtuple_get_nth_field(row, col_no); + row_field = dtuple_get_nth_field(row, + col->ind); dfield_copy(field, row_field); } @@ -720,7 +714,7 @@ row_merge_buf_add( } else if (!ext) { } else if (dict_index_is_clust(index)) { /* Flag externally stored fields. */ - const byte* buf = row_ext_lookup(ext, col_no, + const byte* buf = row_ext_lookup(ext, col->ind, &len); if (UNIV_LIKELY_NULL(buf)) { ut_a(buf != field_ref_zero); @@ -731,9 +725,9 @@ row_merge_buf_add( len = dfield_get_len(field); } } - } else if (!dict_col_is_virtual(col)) { + } else if (!v_col) { /* Only non-virtual column are stored externally */ - const byte* buf = row_ext_lookup(ext, col_no, + const byte* buf = row_ext_lookup(ext, col->ind, &len); if (UNIV_LIKELY_NULL(buf)) { ut_a(buf != field_ref_zero); -- cgit v1.2.1 From 0af6e525212f81c2da8185817c6ca2e7c3ac036a Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 1 Sep 2020 21:12:01 +1000 Subject: travis: osx build time out storing cache. Ensure not Cellar --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 51897563235..bc3b948af77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,6 @@ cache: timeout: 500 apt: true ccache: true - directories: - - /usr/local/Cellar # Fails do to permission error: https://github.com/travis-ci/travis-ci/issues/8092 addons: apt: -- cgit v1.2.1 From 594aad7b0607b752c3815d2c31370a63006d4542 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 1 Sep 2020 21:12:01 +1000 Subject: travis: osx build time out storing cache. Ensure not Cellar --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a430ff14640..25159e30191 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,8 +20,6 @@ cache: timeout: 500 apt: true ccache: true - directories: - - /usr/local/Cellar # Fails do to permission error: https://github.com/travis-ci/travis-ci/issues/8092 env: matrix: -- cgit v1.2.1 From 56ae0adee35c1bc053711a8579857e6b0301eb80 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Wed, 2 Sep 2020 11:23:18 +1000 Subject: travis: update osx to xcode12u in attempt to solve openssl build failure --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 25159e30191..809a08fd6a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ language: cpp os: - linux - osx -osx_image: xcode10.1 +osx_image: xcode12u compiler: - gcc - clang -- cgit v1.2.1 From 054f96ecff111c0925edba5657a69611cb243643 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Wed, 2 Sep 2020 12:54:14 +1000 Subject: innodb: osx build failure fix Build failure was: storage/innobase/os/os0proc.cc:144:3: error: use of undeclared identifier 'MEM_UNDEFINED' MEM_UNDEFINED(ptr, size); Assumed to be introduced in MDEV-20377 commit: c36834c8324974f26770d64192898f4f45d9f772 --- storage/innobase/os/os0proc.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/innobase/os/os0proc.cc b/storage/innobase/os/os0proc.cc index 508a13de2ca..71cb88ae372 100644 --- a/storage/innobase/os/os0proc.cc +++ b/storage/innobase/os/os0proc.cc @@ -29,6 +29,7 @@ Created 9/30/1995 Heikki Tuuri #ifdef HAVE_LINUX_LARGE_PAGES # include "mysqld.h" #endif +#include "my_valgrind.h" /* FreeBSD for example has only MAP_ANON, Linux has MAP_ANONYMOUS and MAP_ANON but MAP_ANON is marked as deprecated */ -- cgit v1.2.1 From cd36bc01a5f1c1cd126cdd0668c6049cc78be40a Mon Sep 17 00:00:00 2001 From: Sujatha Date: Wed, 26 Aug 2020 16:25:28 +0530 Subject: MDEV-23534: SIGSEGV in sf_malloc_usable_size/my_free on SET GLOBAL REPLICATE_DO_TABLE Backporting fixes for: MDEV-22317: SIGSEGV in my_free/delete_dynamic in optimized builds (ARIA) Backported following commits from: 10.5.3 commit 77e1b0c39771f47bb2602530b8d1e584ac1d3731 -- Post push fix. commit 2e6b21be4a8d0bf094da288cadff866f1bb38062 MDEV-22059: MSAN report at replicate_ignore_table_grant Backported following commits from: 10.5.4 commit 840fb495ce2c0c00b20f2a9ba44b6fcc20c56118 --- .../suite/rpl/r/rpl_filter_tables_dynamic.result | 2 + .../rpl/r/rpl_filter_wild_tables_dynamic.result | 2 + .../suite/rpl/t/rpl_filter_tables_dynamic.test | 2 + .../rpl/t/rpl_filter_wild_tables_dynamic.test | 2 + sql/rpl_filter.cc | 52 ++++++++++++++++------ 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_filter_tables_dynamic.result b/mysql-test/suite/rpl/r/rpl_filter_tables_dynamic.result index 5a746c88458..9709e24fbde 100644 --- a/mysql-test/suite/rpl/r/rpl_filter_tables_dynamic.result +++ b/mysql-test/suite/rpl/r/rpl_filter_tables_dynamic.result @@ -5,6 +5,8 @@ ERROR HY000: This operation cannot be performed as you have a running slave ''; SET @@GLOBAL.replicate_ignore_table="test.t4,test.t5,test.t6"; ERROR HY000: This operation cannot be performed as you have a running slave ''; run STOP SLAVE '' first include/stop_slave.inc +SET @@GLOBAL.replicate_do_table=""; +SET @@GLOBAL.replicate_ignore_table=""; SET @@GLOBAL.replicate_do_table="test.t1,test.t2,test.t3"; SET @@GLOBAL.replicate_ignore_table="test.t4,test.t5,test.t6"; include/start_slave.inc diff --git a/mysql-test/suite/rpl/r/rpl_filter_wild_tables_dynamic.result b/mysql-test/suite/rpl/r/rpl_filter_wild_tables_dynamic.result index 19d8e513e6f..338f4b3bbcf 100644 --- a/mysql-test/suite/rpl/r/rpl_filter_wild_tables_dynamic.result +++ b/mysql-test/suite/rpl/r/rpl_filter_wild_tables_dynamic.result @@ -5,6 +5,8 @@ ERROR HY000: This operation cannot be performed as you have a running slave ''; SET @@GLOBAL.replicate_wild_ignore_table="test.b%"; ERROR HY000: This operation cannot be performed as you have a running slave ''; run STOP SLAVE '' first include/stop_slave.inc +SET @@GLOBAL.replicate_wild_do_table=""; +SET @@GLOBAL.replicate_wild_ignore_table=""; SET @@GLOBAL.replicate_wild_do_table="test.a%"; SET @@GLOBAL.replicate_wild_ignore_table="test.b%"; include/start_slave.inc diff --git a/mysql-test/suite/rpl/t/rpl_filter_tables_dynamic.test b/mysql-test/suite/rpl/t/rpl_filter_tables_dynamic.test index 97ecc167356..ebededc36b3 100644 --- a/mysql-test/suite/rpl/t/rpl_filter_tables_dynamic.test +++ b/mysql-test/suite/rpl/t/rpl_filter_tables_dynamic.test @@ -51,6 +51,8 @@ SET @@GLOBAL.replicate_ignore_table="test.t4,test.t5,test.t6"; connection slave; source include/stop_slave.inc; +SET @@GLOBAL.replicate_do_table=""; +SET @@GLOBAL.replicate_ignore_table=""; SET @@GLOBAL.replicate_do_table="test.t1,test.t2,test.t3"; SET @@GLOBAL.replicate_ignore_table="test.t4,test.t5,test.t6"; source include/start_slave.inc; diff --git a/mysql-test/suite/rpl/t/rpl_filter_wild_tables_dynamic.test b/mysql-test/suite/rpl/t/rpl_filter_wild_tables_dynamic.test index c822c81f270..09db91aa4d3 100644 --- a/mysql-test/suite/rpl/t/rpl_filter_wild_tables_dynamic.test +++ b/mysql-test/suite/rpl/t/rpl_filter_wild_tables_dynamic.test @@ -13,6 +13,8 @@ SET @@GLOBAL.replicate_wild_ignore_table="test.b%"; connection slave; source include/stop_slave.inc; +SET @@GLOBAL.replicate_wild_do_table=""; +SET @@GLOBAL.replicate_wild_ignore_table=""; SET @@GLOBAL.replicate_wild_do_table="test.a%"; SET @@GLOBAL.replicate_wild_ignore_table="test.b%"; source include/start_slave.inc; diff --git a/sql/rpl_filter.cc b/sql/rpl_filter.cc index 366902c1f26..0d5d9ffeea8 100644 --- a/sql/rpl_filter.cc +++ b/sql/rpl_filter.cc @@ -349,14 +349,20 @@ Rpl_filter::set_do_table(const char* table_spec) int status; if (do_table_inited) - my_hash_reset(&do_table); + { + my_hash_free(&do_table); + do_table_inited= 0; + } status= parse_filter_rule(table_spec, &Rpl_filter::add_do_table); - if (!do_table.records) + if (do_table_inited && status) { - my_hash_free(&do_table); - do_table_inited= 0; + if (!do_table.records) + { + my_hash_free(&do_table); + do_table_inited= 0; + } } return status; @@ -369,14 +375,20 @@ Rpl_filter::set_ignore_table(const char* table_spec) int status; if (ignore_table_inited) - my_hash_reset(&ignore_table); + { + my_hash_free(&ignore_table); + ignore_table_inited= 0; + } status= parse_filter_rule(table_spec, &Rpl_filter::add_ignore_table); - if (!ignore_table.records) + if (ignore_table_inited && status) { - my_hash_free(&ignore_table); - ignore_table_inited= 0; + if (!ignore_table.records) + { + my_hash_free(&ignore_table); + ignore_table_inited= 0; + } } return status; @@ -411,14 +423,20 @@ Rpl_filter::set_wild_do_table(const char* table_spec) int status; if (wild_do_table_inited) + { free_string_array(&wild_do_table); + wild_do_table_inited= 0; + } status= parse_filter_rule(table_spec, &Rpl_filter::add_wild_do_table); - if (!wild_do_table.elements) + if (wild_do_table_inited && status) { - delete_dynamic(&wild_do_table); - wild_do_table_inited= 0; + if (!wild_do_table.elements) + { + delete_dynamic(&wild_do_table); + wild_do_table_inited= 0; + } } return status; @@ -431,14 +449,20 @@ Rpl_filter::set_wild_ignore_table(const char* table_spec) int status; if (wild_ignore_table_inited) + { free_string_array(&wild_ignore_table); + wild_ignore_table_inited= 0; + } status= parse_filter_rule(table_spec, &Rpl_filter::add_wild_ignore_table); - if (!wild_ignore_table.elements) + if (wild_ignore_table_inited && status) { - delete_dynamic(&wild_ignore_table); - wild_ignore_table_inited= 0; + if (!wild_ignore_table.elements) + { + delete_dynamic(&wild_ignore_table); + wild_ignore_table_inited= 0; + } } return status; -- cgit v1.2.1 From 837bbbafc535d14ea102ced983349fd29b84f782 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Wed, 2 Sep 2020 16:15:02 +0530 Subject: MDEV-23470 InnoDB: Failing assertion: cmp < 0 in row_ins_check_foreign_constraint During insertion of clustered index, InnoDB does the check for foreign key constraints. Problem is that it uses the clustered index entry to search indexes of referenced tables and it could lead to unexpected result when there is no foreign index. Solution: ======== Rebuild the tuple based on foreign column names before searching it on reference index when there is no foreign index. --- mysql-test/suite/innodb/r/foreign-keys.result | 16 ++++++ mysql-test/suite/innodb/t/foreign-keys.test | 19 +++++++ storage/innobase/row/row0ins.cc | 74 +++++++++++++++++++++++---- 3 files changed, 100 insertions(+), 9 deletions(-) diff --git a/mysql-test/suite/innodb/r/foreign-keys.result b/mysql-test/suite/innodb/r/foreign-keys.result index 5cbbb5298de..05e68b0c3db 100644 --- a/mysql-test/suite/innodb/r/foreign-keys.result +++ b/mysql-test/suite/innodb/r/foreign-keys.result @@ -220,3 +220,19 @@ drop table t1,t2; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails drop table t1,t2; ERROR 42S02: Unknown table 'test.t2' +# +# MDEV-23470 InnoDB: Failing assertion: cmp < 0 in +# row_ins_check_foreign_constraint +# +CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY, f2 INT NOT NULL)ENGINE=InnoDB; +CREATE TABLE t2(f1 VARCHAR(100), f2 INT NOT NULL, +INDEX(f2))ENGINE=InnoDB; +INSERT INTO t1 VALUES(99, 2); +ALTER TABLE t2 ADD FOREIGN KEY(f2) REFERENCES t1(f1); +SET FOREIGN_KEY_CHECKS=0; +DROP INDEX f2 ON t2; +SET FOREIGN_KEY_CHECKS=1; +INSERT INTO t2 VALUES('G', 3); +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)) +DROP TABLE t2, t1; +SET FOREIGN_KEY_CHECKS=DEFAULT; diff --git a/mysql-test/suite/innodb/t/foreign-keys.test b/mysql-test/suite/innodb/t/foreign-keys.test index 58a71d11a6a..53fbe8d00dc 100644 --- a/mysql-test/suite/innodb/t/foreign-keys.test +++ b/mysql-test/suite/innodb/t/foreign-keys.test @@ -250,3 +250,22 @@ show create table t2; drop table t1,t2; --error ER_BAD_TABLE_ERROR drop table t1,t2; + +--echo # +--echo # MDEV-23470 InnoDB: Failing assertion: cmp < 0 in +--echo # row_ins_check_foreign_constraint +--echo # +CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY, f2 INT NOT NULL)ENGINE=InnoDB; +CREATE TABLE t2(f1 VARCHAR(100), f2 INT NOT NULL, + INDEX(f2))ENGINE=InnoDB; + +INSERT INTO t1 VALUES(99, 2); +ALTER TABLE t2 ADD FOREIGN KEY(f2) REFERENCES t1(f1); + +SET FOREIGN_KEY_CHECKS=0; +DROP INDEX f2 ON t2; +SET FOREIGN_KEY_CHECKS=1; +--error ER_NO_REFERENCED_ROW_2 +INSERT INTO t2 VALUES('G', 3); +DROP TABLE t2, t1; +SET FOREIGN_KEY_CHECKS=DEFAULT; diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index b8c8a73842f..af6d2f5fa83 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -1905,6 +1905,39 @@ exit_func: DBUG_RETURN(err); } +/** Sets the values of the dtuple fields in ref_entry from the values of +foreign columns in entry. +@param[in] foreign foreign key constraint +@param[in] index clustered index +@param[in] entry tuple of clustered index +@param[in] ref_entry tuple of foreign columns +@return true if all foreign key fields present in clustered index */ +static +bool row_ins_foreign_index_entry(dict_foreign_t *foreign, + const dict_index_t *index, + const dtuple_t *entry, + dtuple_t *ref_entry) +{ + for (ulint i= 0; i < foreign->n_fields; i++) + { + for (ulint j= 0; j < index->n_fields; j++) + { + const char *col_name= dict_table_get_col_name( + index->table, dict_index_get_nth_col_no(index, j)); + if (0 == innobase_strcasecmp(col_name, foreign->foreign_col_names[i])) + { + dfield_copy(&ref_entry->fields[i], &entry->fields[j]); + goto got_match; + } + } + return false; +got_match: + continue; + } + + return true; +} + /***************************************************************//** Checks if foreign key constraints fail for an index entry. If index is not mentioned in any constraint, this function does nothing, @@ -1923,9 +1956,10 @@ row_ins_check_foreign_constraints( que_thr_t* thr) /*!< in: query thread */ { dict_foreign_t* foreign; - dberr_t err; + dberr_t err = DB_SUCCESS; trx_t* trx; ibool got_s_lock = FALSE; + mem_heap_t* heap = NULL; DBUG_ASSERT(index->is_primary() == pk); @@ -1935,13 +1969,36 @@ row_ins_check_foreign_constraints( "foreign_constraint_check_for_ins"); for (dict_foreign_set::iterator it = table->foreign_set.begin(); - it != table->foreign_set.end(); + err == DB_SUCCESS && it != table->foreign_set.end(); ++it) { foreign = *it; if (foreign->foreign_index == index || (pk && !foreign->foreign_index)) { + + dtuple_t* ref_tuple = entry; + if (UNIV_UNLIKELY(!foreign->foreign_index)) { + /* Change primary key entry to + foreign key index entry */ + if (!heap) { + heap = mem_heap_create(1000); + } else { + mem_heap_empty(heap); + } + + ref_tuple = dtuple_create( + heap, foreign->n_fields); + dtuple_set_n_fields_cmp( + ref_tuple, foreign->n_fields); + if (!row_ins_foreign_index_entry( + foreign, index, entry, ref_tuple)) { + err = DB_NO_REFERENCED_ROW; + break; + } + + } + dict_table_t* ref_table = NULL; dict_table_t* referenced_table = foreign->referenced_table; @@ -1971,7 +2028,7 @@ row_ins_check_foreign_constraints( table from being dropped while the check is running. */ err = row_ins_check_foreign_constraint( - TRUE, foreign, table, entry, thr); + TRUE, foreign, table, ref_tuple, thr); if (referenced_table) { my_atomic_addlint( @@ -1986,15 +2043,14 @@ row_ins_check_foreign_constraints( if (ref_table != NULL) { dict_table_close(ref_table, FALSE, FALSE); } - - if (err != DB_SUCCESS) { - - return(err); - } } } - return(DB_SUCCESS); + if (UNIV_LIKELY_NULL(heap)) { + mem_heap_free(heap); + } + + return err; } /***************************************************************//** -- cgit v1.2.1 From 9aea50616c2d8e067e5ce3efb1152e81877bf931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 2 Sep 2020 14:57:48 +0300 Subject: Increase mariabackup SST initial timeout to avoid timeouts. --- scripts/wsrep_sst_mariabackup.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/wsrep_sst_mariabackup.sh b/scripts/wsrep_sst_mariabackup.sh index 86378cb699c..ef2a3b66de8 100644 --- a/scripts/wsrep_sst_mariabackup.sh +++ b/scripts/wsrep_sst_mariabackup.sh @@ -1,6 +1,6 @@ #!/bin/bash -ue # Copyright (C) 2013 Percona Inc -# Copyright (C) 2017-2019 MariaDB +# Copyright (C) 2017-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 @@ -363,7 +363,7 @@ read_cnf() iopts=$(parse_cnf sst inno-backup-opts "") iapts=$(parse_cnf sst inno-apply-opts "") impts=$(parse_cnf sst inno-move-opts "") - stimeout=$(parse_cnf sst sst-initial-timeout 100) + stimeout=$(parse_cnf sst sst-initial-timeout 300) ssyslog=$(parse_cnf sst sst-syslog 0) ssystag=$(parse_cnf mysqld_safe syslog-tag "${SST_SYSLOG_TAG:-}") ssystag+="-" @@ -624,7 +624,8 @@ recv_joiner() popd 1>/dev/null if [[ ${RC[0]} -eq 124 ]];then - wsrep_log_error "Possible timeout in receving first data from donor in gtid stage" + wsrep_log_error "Possible timeout in receiving first data from " + "donor in gtid stage: exit codes: ${RC[@]}" exit 32 fi -- cgit v1.2.1 From 48ab5a4997b073f98d8d521045f14a4ec211ed1b Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Sat, 29 Aug 2020 11:24:13 +0400 Subject: Part2: MDEV-23568 Improve performance of my_{time|date|datetime}_to_str() As an additional improvement, let's store string representations of the numbers using an array uint16[256] instead of char[512]. This allows to use int2store(), which copies two bytes at a time on x86, instead of copying the two bytes with digits one-by-one. This change gives an additional 7% to 26% query time reduce for: SELECT BENCHMARK(10*1000*1000,CONCAT(TIME'10:20:30')); SELECT BENCHMARK(10*1000*1000,CONCAT(TIME'10:20:30.123456')); SELECT BENCHMARK(10*1000*1000,CONCAT(DATE'2001-01-01')); SELECT BENCHMARK(10*1000*1000,CONCAT(TIMESTAMP'2001-01-01 10:20:30')); SELECT BENCHMARK(10*1000*1000,CONCAT(TIMESTAMP'2001-01-01 10:20:30.123456')); The total time reduce (part1 + part2) is now between 15% to 38% for these queries. --- sql-common/my_time.c | 85 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/sql-common/my_time.c b/sql-common/my_time.c index 563ca00d59f..96674723b34 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -1471,55 +1471,68 @@ void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type) SELECT BENCHMARK(10*1000*1000,CONCAT(TIMESTAMP'2001-01-01 10:20:30.123456')); (depending on the exact data type and fractional precision). - The array has extra elements for uint8 values 100..255. + The array has extra elements for values 100..255. This is done for safety. If the caller passes a value - outside of the expected range 0..99, it will be printed as "XX". -*/ + outside of the expected range 0..99, the value will be printed as "XX". + + Part2: + + As an additional improvement over "class TwoDigitWriter", we store + the string representations of the numbers in an array uint16[256] + instead of char[512]. This allows to copy data using int2store(), + which copies two bytes at a time on x86 and gives an additional + 7% to 26% time reduce over copying the two bytes separately. + + The total time reduce is 15% to 38% on the above queries. -static const char two_digit_numbers[512+1]= + The bytes in the following array are swapped: + e.g. 0x3130 in two_digit_numbers[1] means the following: + - 0x31 is '1' (the left byte, the right digit) + - 0x30 is '0' (the right byte, the left digit) + int2store() puts the lower byte first, so the output string becomes '01'. +*/ +static const uint16 two_digit_numbers[256]= { /* 0..99 */ - "00010203040506070809" - "10111213141516171819" - "20212223242526272829" - "30313233343536373839" - "40414243444546474849" - "50515253545556575859" - "60616263646566676869" - "70717273747576777879" - "80818283848586878889" - "90919293949596979899" + 0x3030,0x3130,0x3230,0x3330,0x3430,0x3530,0x3630,0x3730,0x3830,0x3930, + 0x3031,0x3131,0x3231,0x3331,0x3431,0x3531,0x3631,0x3731,0x3831,0x3931, + 0x3032,0x3132,0x3232,0x3332,0x3432,0x3532,0x3632,0x3732,0x3832,0x3932, + 0x3033,0x3133,0x3233,0x3333,0x3433,0x3533,0x3633,0x3733,0x3833,0x3933, + 0x3034,0x3134,0x3234,0x3334,0x3434,0x3534,0x3634,0x3734,0x3834,0x3934, + 0x3035,0x3135,0x3235,0x3335,0x3435,0x3535,0x3635,0x3735,0x3835,0x3935, + 0x3036,0x3136,0x3236,0x3336,0x3436,0x3536,0x3636,0x3736,0x3836,0x3936, + 0x3037,0x3137,0x3237,0x3337,0x3437,0x3537,0x3637,0x3737,0x3837,0x3937, + 0x3038,0x3138,0x3238,0x3338,0x3438,0x3538,0x3638,0x3738,0x3838,0x3938, + 0x3039,0x3139,0x3239,0x3339,0x3439,0x3539,0x3639,0x3739,0x3839,0x3939, /* 100..199 - safety */ - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXX" + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, /* 200..255 - safety */ - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXXXXXXXXXX" - "XXXXXXXXXXXX" + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, + 0x5858,0x5858,0x5858,0x5858,0x5858,0x5858, }; - static inline char* fmt_number2(uint8 val, char *out) { - const char *src= two_digit_numbers + val * 2; - *out++= *src++; - *out++= *src++; - return out; + int2store(out, two_digit_numbers[val]); + return out + 2; } + /* - We tried the same trick with an array of 16384 zerofill 4-digit numbers, + We tried the same trick with a char array of 16384 zerofill 4-digit numbers, with 10000 elements with numbers 0000..9999, and a tail filled with "XXXX". Benchmark results for a RelWithDebInfo build: -- cgit v1.2.1 From a256070e7d94fdd1d63a4823c638ff5c76ca9c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 3 Sep 2020 08:41:47 +0300 Subject: MDEV-7110 follow-up fix: Do not pass NULL as nonnull parameter Passing a null pointer to the "%s" argument of a printf-like function is undefined behaviour. In the GNU libc implementation of the printf() family of functions, it happens to work. GCC 10.2.0 would diagnose this with -Wformat-overflow -Og. In -fsanitize=undefined (WITH_UBSAN=ON) builds, a runtime error would be generated. In some other builds, GCC 8 or later might infer that the parameter is nonnull and optimize away further checks whether the parameter is null, leading to SIGSEGV. --- sql/mysqld.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 6a5162e2f03..8d00b5af948 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3974,7 +3974,8 @@ rpl_make_log_name(const char *opt, const char *ext) { DBUG_ENTER("rpl_make_log_name"); - DBUG_PRINT("enter", ("opt: %s, def: %s, ext: %s", opt, def, ext)); + DBUG_PRINT("enter", ("opt: %s, def: %s, ext: %s", opt ? opt : "(null)", + def, ext)); char buff[FN_REFLEN]; const char *base= opt ? opt : def; unsigned int options= -- cgit v1.2.1 From 94a520ddbe39ae97de1135d98699cf2674e6b77e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 3 Sep 2020 09:05:56 +0300 Subject: MDEV-22387: Do not pass null pointer to some memcpy() Passing a null pointer to a nonnull argument is not only undefined behaviour, but it also grants the compiler the permission to optimize away further checks whether the pointer is null. GCC -O2 at least starting with version 8 may do that, potentially causing SIGSEGV. These problems were caught in a WITH_UBSAN=ON build with the Bug#7024 test in main.view. --- mysys/mf_iocache.c | 8 +++++--- mysys/my_alloc.c | 4 +++- sql/debug_sync.cc | 4 +++- sql/net_serv.cc | 5 +++-- sql/sql_string.h | 5 +++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c index 1245a622262..11f7bbd81b4 100644 --- a/mysys/mf_iocache.c +++ b/mysys/mf_iocache.c @@ -1,6 +1,6 @@ /* Copyright (c) 2000, 2011, Oracle and/or its affiliates - Copyright (c) 2010, 2015, MariaDB + Copyright (c) 2010, 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 @@ -703,7 +703,8 @@ int _my_b_cache_read(IO_CACHE *info, uchar *Buffer, size_t Count) info->read_pos=info->buffer+Count; info->read_end=info->buffer+length; info->pos_in_file=pos_in_file; - memcpy(Buffer, info->buffer, Count); + if (Count) + memcpy(Buffer, info->buffer, Count); DBUG_RETURN(0); } @@ -1206,7 +1207,8 @@ static int _my_b_cache_read_r(IO_CACHE *cache, uchar *Buffer, size_t Count) DBUG_RETURN(1); } cnt= (len > Count) ? Count : len; - memcpy(Buffer, cache->read_pos, cnt); + if (cnt) + memcpy(Buffer, cache->read_pos, cnt); Count -= cnt; Buffer+= cnt; left_length+= cnt; diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c index 3b614cb4c15..5bfcb455b8a 100644 --- a/mysys/my_alloc.c +++ b/mysys/my_alloc.c @@ -1,5 +1,6 @@ /* Copyright (c) 2000, 2010, Oracle and/or its affiliates + Copyright (c) 2010, 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 @@ -449,7 +450,8 @@ char *strmake_root(MEM_ROOT *root, const char *str, size_t len) char *pos; if ((pos=alloc_root(root,len+1))) { - memcpy(pos,str,len); + if (len) + memcpy(pos,str,len); pos[len]=0; } return pos; diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc index 591ce5800a8..79f3a241907 100644 --- a/sql/debug_sync.cc +++ b/sql/debug_sync.cc @@ -1,4 +1,5 @@ /* Copyright (c) 2009, 2013, Oracle and/or its affiliates. + Copyright (c) 2013, 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 @@ -319,7 +320,8 @@ static char *debug_sync_bmove_len(char *to, char *to_end, DBUG_ASSERT(to_end); DBUG_ASSERT(!length || from); set_if_smaller(length, (size_t) (to_end - to)); - memcpy(to, from, length); + if (length) + memcpy(to, from, length); return (to + length); } diff --git a/sql/net_serv.cc b/sql/net_serv.cc index ea5e4353c83..22eee6297c9 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2016, Oracle and/or its affiliates. - Copyright (c) 2012, 2017, MariaDB Corporation + Copyright (c) 2012, 2020, MariaDB Corporation. 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 @@ -577,7 +577,8 @@ net_write_buff(NET *net, const uchar *packet, ulong len) return net_real_write(net, packet, len) ? 1 : 0; /* Send out rest of the blocks as full sized blocks */ } - memcpy((char*) net->write_pos,packet,len); + if (len) + memcpy((char*) net->write_pos,packet,len); net->write_pos+= len; return 0; } diff --git a/sql/sql_string.h b/sql/sql_string.h index 6fd3d7a10db..fe756fe1cdf 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -3,7 +3,7 @@ /* Copyright (c) 2000, 2013, Oracle and/or its affiliates. - Copyright (c) 2008, 2013, Monty Program Ab. + Copyright (c) 2008, 2020, MariaDB Corporation. 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 @@ -512,7 +512,8 @@ public: } void q_append(const char *data, uint32 data_len) { - memcpy(Ptr + str_length, data, data_len); + if (data_len) + memcpy(Ptr + str_length, data, data_len); str_length += data_len; } -- cgit v1.2.1 From f0a57acb492c4b034213d37c1fb5943850619f5a Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 3 Sep 2020 11:31:06 +0400 Subject: 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 *); -- cgit v1.2.1 From 33ae1616e01b564d03c507769564d37c582783cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Thu, 3 Sep 2020 14:10:42 +0300 Subject: MDEV-21578 : CREATE OR REPLACE TRIGGER in Galera cluster not replicating In 10.3 OR REPLACE trigger option is part of create_info. --- sql/wsrep_mysqld.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index 20f2cd99edd..de234770788 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -2900,11 +2900,14 @@ static int wsrep_create_trigger_query(THD *thd, uchar** buf, size_t* buf_len) definer_host.length= 0; } - const LEX_CSTRING command[3]= + const LEX_CSTRING command[2]= {{ C_STRING_WITH_LEN("CREATE ") }, - { C_STRING_WITH_LEN("ALTER ") }, { C_STRING_WITH_LEN("CREATE OR REPLACE ") }}; - stmt_query.append(command[thd->lex->create_view->mode]); + + if (thd->lex->create_info.or_replace()) + stmt_query.append(command[1]); + else + stmt_query.append(command[0]); append_definer(thd, &stmt_query, &definer_user, &definer_host); -- cgit v1.2.1 From a7dd7c899356b2d3a7f79e6ebba5d854ed63ae9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 3 Sep 2020 14:49:11 +0300 Subject: MDEV-23651 InnoDB: Failing assertion: !space->referenced() commit de942c9f618b590a01a7960c171d7e50e435708f (MDEV-15983) introduced a race condition that we inadequately fixed in commit 93b69825adf5e55601ba44b4c89ec36ce62f8112 (MDEV-16169). Because fil_space_t::release() or fil_space_t::acquire() are not protected by fil_system.mutex like their predecessors, it is possible that stop_new_ops was set between the time a thread checked fil_space_t::is_stopping() and invoked fil_space_t::acquire(). In an execution trace, this happened in fil_system_t::keyrotate_next(), causing an assertion failure in fil_delete_tablespace() in the other thread that seeked to stop new operations. We fix this bug by merging the flag fil_space_t::stop_new_ops and the reference count fil_space_t::n_pending_ops into a single word that is only being accessed by atomic memory operations. fil_space_t::set_stopping(): Accessor for changing the state of the former stop_new_ops flag. fil_space_t::acquire(): Return whether the acquisition succeeded. It would fail between set_stopping(true) and set_stopping(false). --- storage/innobase/fil/fil0crypt.cc | 39 +++++----- storage/innobase/fil/fil0fil.cc | 51 ++++--------- storage/innobase/handler/i_s.cc | 6 +- storage/innobase/include/fil0fil.h | 144 +++++++++++++++++++++++-------------- storage/innobase/trx/trx0purge.cc | 6 +- 5 files changed, 128 insertions(+), 118 deletions(-) diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc index 4f80b7e409f..c9663837fa6 100644 --- a/storage/innobase/fil/fil0crypt.cc +++ b/storage/innobase/fil/fil0crypt.cc @@ -1418,12 +1418,15 @@ inline fil_space_t *fil_system_t::keyrotate_next(fil_space_t *space, } } - if (it == end) - return NULL; + while (it != end) + { + space= &*it; + if (space->acquire()) + return space; + while (++it != end && (!UT_LIST_GET_LEN(it->chain) || it->is_stopping())); + } - space= &*it; - space->acquire(); - return space; + return NULL; } /** Return the next tablespace. @@ -1445,12 +1448,14 @@ static fil_space_t *fil_space_next(fil_space_t *space, bool recheck, space= UT_LIST_GET_FIRST(fil_system.space_list); /* We can trust that space is not NULL because at least the system tablespace is always present and loaded first. */ - space->acquire(); + if (!space->acquire()) + goto next; } else { /* Move on to the next fil_space_t */ space->release(); +next: space= UT_LIST_GET_NEXT(space_list, space); /* Skip abnormal tablespaces or those that are being created by @@ -1460,8 +1465,8 @@ static fil_space_t *fil_space_next(fil_space_t *space, bool recheck, space->is_stopping() || space->purpose != FIL_TYPE_TABLESPACE)) space= UT_LIST_GET_NEXT(space_list, space); - if (space) - space->acquire(); + if (space && !space->acquire()) + goto next; } mutex_exit(&fil_system.mutex); @@ -2330,31 +2335,27 @@ static void fil_crypt_rotation_list_fill() space = UT_LIST_GET_NEXT(space_list, space)) { if (space->purpose != FIL_TYPE_TABLESPACE || space->is_in_rotation_list - || space->is_stopping() - || UT_LIST_GET_LEN(space->chain) == 0) { + || UT_LIST_GET_LEN(space->chain) == 0 + || !space->acquire()) { continue; } /* Ensure that crypt_data has been initialized. */ if (!space->size) { - /* Protect the tablespace while we may - release fil_system.mutex. */ - ut_d(space->acquire()); ut_d(const fil_space_t* s=) fil_system.read_page0(space->id); ut_ad(!s || s == space); - ut_d(space->release()); if (!space->size) { /* Page 0 was not loaded. Skip this tablespace. */ - continue; + goto next; } } /* Skip ENCRYPTION!=DEFAULT tablespaces. */ if (space->crypt_data && !space->crypt_data->is_default_encryption()) { - continue; + goto next; } if (srv_encrypt_tables) { @@ -2362,19 +2363,21 @@ static void fil_crypt_rotation_list_fill() innodb_encrypt_tables!=OFF */ if (space->crypt_data && space->crypt_data->min_key_version) { - continue; + goto next; } } else { /* Skip unencrypted tablespaces if innodb_encrypt_tables=OFF */ if (!space->crypt_data || !space->crypt_data->min_key_version) { - continue; + goto next; } } fil_system.rotation_list.push_back(*space); space->is_in_rotation_list = true; +next: + space->release(); } } diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 73208d4dddc..f354f7905bb 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -763,8 +763,7 @@ fil_try_to_close_file_in_LRU( static void fil_flush_low(fil_space_t* space, bool metadata = false) { ut_ad(mutex_own(&fil_system.mutex)); - ut_ad(space); - ut_ad(!space->stop_new_ops); + ut_ad(!space->is_stopping()); if (fil_buffering_disabled(space)) { @@ -1934,10 +1933,8 @@ fil_space_acquire_low(ulint id, bool silent) ib::warn() << "Trying to access missing" " tablespace " << id; } - } else if (space->is_stopping()) { + } else if (!space->acquire()) { space = NULL; - } else { - space->acquire(); } mutex_exit(&fil_system.mutex); @@ -2254,14 +2251,14 @@ fil_check_pending_ops(const fil_space_t* space, ulint count) { ut_ad(mutex_own(&fil_system.mutex)); - if (space == NULL) { + if (!space) { return 0; } - if (ulint n_pending_ops = my_atomic_loadlint(&space->n_pending_ops)) { + if (uint32_t n_pending_ops = space->referenced()) { - /* Give a warning every 10 second, starting after 1 second */ - if ((count % 500) == 50) { + /* Give a warning every 10 second, starting after 1 second */ + if ((count % 500) == 50) { ib::warn() << "Trying to close/delete/truncate" " tablespace '" << space->name << "' but there are " << n_pending_ops @@ -2347,14 +2344,13 @@ fil_check_pending_operations( fil_space_t* sp = fil_space_get_by_id(id); if (sp) { - sp->stop_new_ops = true; - if (sp->crypt_data) { - sp->acquire(); + if (sp->crypt_data && sp->acquire()) { mutex_exit(&fil_system.mutex); fil_space_crypt_close_tablespace(sp); mutex_enter(&fil_system.mutex); sp->release(); } + sp->set_stopping(true); } /* Check for pending operations. */ @@ -2875,7 +2871,7 @@ fil_rename_tablespace( multiple datafiles per tablespace. */ ut_a(UT_LIST_GET_LEN(space->chain) == 1); node = UT_LIST_GET_FIRST(space->chain); - space->n_pending_ops++; + ut_a(space->acquire()); mutex_exit(&fil_system.mutex); @@ -2897,8 +2893,7 @@ fil_rename_tablespace( /* log_sys.mutex is above fil_system.mutex in the latching order */ ut_ad(log_mutex_own()); mutex_enter(&fil_system.mutex); - ut_ad(space->n_pending_ops); - space->n_pending_ops--; + space->release(); ut_ad(space->name == old_space_name); ut_ad(node->name == old_file_name); bool success; @@ -4204,7 +4199,7 @@ fil_io( if (space == NULL || (req_type.is_read() && !sync - && space->stop_new_ops + && space->is_stopping() && !space->is_being_truncated)) { mutex_exit(&fil_system.mutex); @@ -4844,7 +4839,7 @@ fil_space_validate_for_mtr_commit( fil_space_acquire() before mtr_start() and fil_space_t::release() after mtr_commit(). This is why n_pending_ops should not be zero if stop_new_ops is set. */ - ut_ad(!space->stop_new_ops + ut_ad(!space->is_stopping() || space->is_being_truncated /* fil_truncate_prepare() */ || space->referenced()); } @@ -5070,7 +5065,7 @@ truncate_t::truncate( err = DB_ERROR; } - space->stop_new_ops = false; + space->set_stopping(false); /* If we opened the file in this function, close it. */ if (!already_open) { @@ -5171,26 +5166,6 @@ fil_space_get_block_size(const fil_space_t* space, unsigned offset) return block_size; } -/*******************************************************************//** -Returns the table space by a given id, NULL if not found. */ -fil_space_t* -fil_space_found_by_id( -/*==================*/ - ulint id) /*!< in: space id */ -{ - fil_space_t* space = NULL; - mutex_enter(&fil_system.mutex); - space = fil_space_get_by_id(id); - - /* Not found if space is being deleted */ - if (space && space->stop_new_ops) { - space = NULL; - } - - mutex_exit(&fil_system.mutex); - return space; -} - /** Get should we punch hole to tablespace. @param[in] node File node diff --git a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc index 9da81f96e88..d3e951ce5a0 100644 --- a/storage/innobase/handler/i_s.cc +++ b/storage/innobase/handler/i_s.cc @@ -8579,8 +8579,7 @@ i_s_tablespaces_encryption_fill_table( for (fil_space_t* space = UT_LIST_GET_FIRST(fil_system.space_list); space; space = UT_LIST_GET_NEXT(space_list, space)) { if (space->purpose == FIL_TYPE_TABLESPACE - && !space->is_stopping()) { - space->acquire(); + && space->acquire()) { mutex_exit(&fil_system.mutex); if (int err = i_s_dict_fill_tablespaces_encryption( thd, space, tables->table)) { @@ -8842,8 +8841,7 @@ i_s_tablespaces_scrubbing_fill_table( for (fil_space_t* space = UT_LIST_GET_FIRST(fil_system.space_list); space; space = UT_LIST_GET_NEXT(space_list, space)) { if (space->purpose == FIL_TYPE_TABLESPACE - && !space->is_stopping()) { - space->acquire(); + && space->acquire()) { mutex_exit(&fil_system.mutex); if (int err = i_s_dict_fill_tablespaces_scrubbing( thd, space, tables->table)) { diff --git a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h index 0a1d78230c7..898caf1a813 100644 --- a/storage/innobase/include/fil0fil.h +++ b/storage/innobase/include/fil0fil.h @@ -93,18 +93,6 @@ struct fil_space_t : ilist_node, /** Log sequence number of the latest MLOG_INDEX_LOAD record that was found while parsing the redo log */ lsn_t enable_lsn; - bool stop_new_ops; - /*!< we set this true when we start - deleting a single-table tablespace. - When this is set following new ops - are not allowed: - * read IO request - * ibuf merge - * file flush - Note that we can still possibly have - new write operations because we don't - check this flag when doing flush - batches. */ /** whether undo tablespace truncation is in progress */ bool is_being_truncated; #ifdef UNIV_DEBUG @@ -142,14 +130,24 @@ struct fil_space_t : ilist_node, ulint n_pending_flushes; /*!< this is positive when flushing the tablespace to disk; dropping of the tablespace is forbidden if this is positive */ - /** Number of pending buffer pool operations accessing the tablespace - without holding a table lock or dict_operation_lock S-latch - that would prevent the table (and tablespace) from being - dropped. An example is change buffer merge. - The tablespace cannot be dropped while this is nonzero, - or while fil_node_t::n_pending is nonzero. - Protected by fil_system.mutex and my_atomic_loadlint() and friends. */ - ulint n_pending_ops; +private: + /** Number of pending buffer pool operations accessing the + tablespace without holding a table lock or dict_operation_lock + S-latch that would prevent the table (and tablespace) from being + dropped. An example is change buffer merge. + + The tablespace cannot be dropped while this is nonzero, or while + fil_node_t::n_pending is nonzero. + + The most significant bit contains the STOP_NEW_OPS flag. + + Protected by my_atomic. */ + uint32_t n_pending_ops; + + /** Flag in n_pending_ops that indicates that the tablespace is being + deleted, and no further operations should be performed */ + static const uint32_t STOP_NEW_OPS= 1U << 31; +public: /** Number of pending block read or write operations (when a write is imminent or a read has recently completed). The tablespace object cannot be freed while this is nonzero, @@ -183,9 +181,6 @@ struct fil_space_t : ilist_node, ulint magic_n;/*!< FIL_SPACE_MAGIC_N */ - /** @return whether the tablespace is about to be dropped */ - bool is_stopping() const { return stop_new_ops; } - /** Clamp a page number for batched I/O, such as read-ahead. @param offset page number limit @return offset clamped to the tablespace size */ @@ -267,39 +262,78 @@ struct fil_space_t : ilist_node, /** Close each file. Only invoked on fil_system.temp_space. */ void close(); - /** Acquire a tablespace reference. */ - void acquire() { my_atomic_addlint(&n_pending_ops, 1); } - /** Release a tablespace reference. - @return whether this was the last reference */ - bool release() - { - ulint n = my_atomic_addlint(&n_pending_ops, ulint(-1)); - ut_ad(n); - return n == 1; - } - /** @return whether references are being held */ - bool referenced() { return my_atomic_loadlint(&n_pending_ops); } - /** @return whether references are being held */ - bool referenced() const - { - return const_cast(this)->referenced(); - } + /** @return whether the tablespace is about to be dropped or is referenced */ + uint32_t is_stopping_or_referenced() + { + return my_atomic_load32(&n_pending_ops); + } - /** Acquire a tablespace reference for I/O. */ - void acquire_for_io() { my_atomic_addlint(&n_pending_ios, 1); } - /** Release a tablespace reference for I/O. */ - void release_for_io() - { - ut_ad(pending_io()); - my_atomic_addlint(&n_pending_ios, ulint(-1)); - } - /** @return whether I/O is pending */ - bool pending_io() { return my_atomic_loadlint(&n_pending_ios); } - /** @return whether I/O is pending */ - bool pending_io() const - { - return const_cast(this)->pending_io(); - } + /** @return whether the tablespace is about to be dropped or is referenced */ + uint32_t is_stopping_or_referenced() const + { + return const_cast(this)->is_stopping_or_referenced(); + } + + /** @return whether the tablespace is about to be dropped */ + bool is_stopping() const + { + return is_stopping_or_referenced() & STOP_NEW_OPS; + } + + /** @return number of references being held */ + uint32_t referenced() const + { + return is_stopping_or_referenced() & ~STOP_NEW_OPS; + } + + /** Note that operations on the tablespace must stop or can resume */ + void set_stopping(bool stopping) + { + /* Note: starting with 10.4 this should be std::atomic::fetch_xor() */ + uint32_t n= stopping ? 0 : STOP_NEW_OPS; + while (!my_atomic_cas32_strong_explicit(&n_pending_ops, &n, + n ^ STOP_NEW_OPS, + MY_MEMORY_ORDER_ACQUIRE, + MY_MEMORY_ORDER_RELAXED)) + ut_ad(!(n & STOP_NEW_OPS) == stopping); + } + + MY_ATTRIBUTE((warn_unused_result)) + /** @return whether a tablespace reference was successfully acquired */ + bool acquire() + { + uint32_t n= 0; + while (!my_atomic_cas32_strong_explicit(&n_pending_ops, &n, n + 1, + MY_MEMORY_ORDER_ACQUIRE, + MY_MEMORY_ORDER_RELAXED)) + if (UNIV_UNLIKELY(n & STOP_NEW_OPS)) + return false; + return true; + } + /** Release a tablespace reference. + @return whether this was the last reference */ + bool release() + { + uint32_t n= my_atomic_add32(&n_pending_ops, uint32_t(-1)); + ut_ad(n & ~STOP_NEW_OPS); + return (n & ~STOP_NEW_OPS) == 1; + } + + /** Acquire a tablespace reference for I/O. */ + void acquire_for_io() { my_atomic_addlint(&n_pending_ios, 1); } + /** Release a tablespace reference for I/O. */ + void release_for_io() + { + ut_d(ulint n=) my_atomic_addlint(&n_pending_ios, ulint(-1)); + ut_ad(n); + } + /** @return whether I/O is pending */ + bool pending_io() { return my_atomic_loadlint(&n_pending_ios); } + /** @return whether I/O is pending */ + bool pending_io() const + { + return const_cast(this)->pending_io(); + } }; /** Value of fil_space_t::magic_n */ diff --git a/storage/innobase/trx/trx0purge.cc b/storage/innobase/trx/trx0purge.cc index 279ba21d4db..02a524d6850 100644 --- a/storage/innobase/trx/trx0purge.cc +++ b/storage/innobase/trx/trx0purge.cc @@ -1030,13 +1030,13 @@ not_found: /* This is only executed by the srv_purge_coordinator_thread. */ export_vars.innodb_undo_truncations++; - /* TODO: PUNCH_HOLE the garbage (with write-ahead logging) */ + /* In MDEV-8319 (10.5) we will PUNCH_HOLE the garbage + (with write-ahead logging). */ mutex_enter(&fil_system.mutex); - ut_ad(space->stop_new_ops); ut_ad(space->is_being_truncated); - space->stop_new_ops = false; space->is_being_truncated = false; + space->set_stopping(false); mutex_exit(&fil_system.mutex); if (purge_sys.rseg != NULL -- cgit v1.2.1 From b795adcff72a84421576748646e2446e3ef24202 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Thu, 3 Sep 2020 15:37:04 +0300 Subject: Make rowid_filter_innodb test stable It was failing on mac-1012-bintar. --- mysql-test/main/rowid_filter.result | 6 ++++++ mysql-test/main/rowid_filter.test | 1 + mysql-test/main/rowid_filter_innodb.result | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/mysql-test/main/rowid_filter.result b/mysql-test/main/rowid_filter.result index a5223666fb4..b0cc5496a4d 100644 --- a/mysql-test/main/rowid_filter.result +++ b/mysql-test/main/rowid_filter.result @@ -2139,6 +2139,12 @@ A.a+1000*B.a + 10000, 'filler-data-filler-data' from t11 A, t10 B; +analyze table t1 persistent for all; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze Warning Engine-independent statistics are not collected for column 'el_index' +test.t1 analyze Warning Engine-independent statistics are not collected for column 'filler' +test.t1 analyze status Table is already up to date # This must not use rowid_filter with key=el_index|el_index_60: explain select * from t1 diff --git a/mysql-test/main/rowid_filter.test b/mysql-test/main/rowid_filter.test index c47710e65b8..ed1227d3770 100644 --- a/mysql-test/main/rowid_filter.test +++ b/mysql-test/main/rowid_filter.test @@ -377,6 +377,7 @@ select 'filler-data-filler-data' from t11 A, t10 B; +analyze table t1 persistent for all; --echo # This must not use rowid_filter with key=el_index|el_index_60: explain diff --git a/mysql-test/main/rowid_filter_innodb.result b/mysql-test/main/rowid_filter_innodb.result index 05d97b746a7..b2971cc2aa3 100644 --- a/mysql-test/main/rowid_filter_innodb.result +++ b/mysql-test/main/rowid_filter_innodb.result @@ -2068,6 +2068,12 @@ A.a+1000*B.a + 10000, 'filler-data-filler-data' from t11 A, t10 B; +analyze table t1 persistent for all; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze Warning Engine-independent statistics are not collected for column 'el_index' +test.t1 analyze Warning Engine-independent statistics are not collected for column 'filler' +test.t1 analyze status OK # This must not use rowid_filter with key=el_index|el_index_60: explain select * from t1 -- cgit v1.2.1 From 938db04898ee9029421f5251751239255dd81c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 3 Sep 2020 16:40:28 +0300 Subject: Cleanup: Remove os0proc.* --- extra/mariabackup/write_filt.cc | 1 - storage/innobase/CMakeLists.txt | 2 -- storage/innobase/include/buf0buf.h | 1 - storage/innobase/include/os0proc.h | 50 -------------------------------------- storage/innobase/include/ut0new.h | 7 ++++-- storage/innobase/os/os0proc.cc | 45 ---------------------------------- storage/innobase/pars/lexyy.cc | 1 - storage/innobase/pars/pars0lex.l | 1 - storage/innobase/srv/srv0srv.cc | 1 - storage/innobase/srv/srv0start.cc | 4 +-- storage/innobase/trx/trx0trx.cc | 1 - storage/innobase/ut/ut0new.cc | 4 +++ 12 files changed, 11 insertions(+), 107 deletions(-) delete mode 100644 storage/innobase/include/os0proc.h delete mode 100644 storage/innobase/os/os0proc.cc diff --git a/extra/mariabackup/write_filt.cc b/extra/mariabackup/write_filt.cc index 8c4d2345f91..d8910699d16 100644 --- a/extra/mariabackup/write_filt.cc +++ b/extra/mariabackup/write_filt.cc @@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA #include "write_filt.h" #include "fil_cur.h" #include "xtrabackup.h" -#include /************************************************************************ Write-through page write filter. */ diff --git a/storage/innobase/CMakeLists.txt b/storage/innobase/CMakeLists.txt index 0547674a4dd..30409902e38 100644 --- a/storage/innobase/CMakeLists.txt +++ b/storage/innobase/CMakeLists.txt @@ -190,7 +190,6 @@ SET(INNOBASE_SOURCES include/os0event.h include/os0file.h include/os0file.ic - include/os0proc.h include/os0thread.h include/page0cur.h include/page0cur.ic @@ -296,7 +295,6 @@ SET(INNOBASE_SOURCES mem/mem0mem.cc mtr/mtr0mtr.cc os/os0file.cc - os/os0proc.cc os/os0event.cc os/os0thread.cc page/page0cur.cc diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index 20bf8d5b24b..fa873fe8741 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -40,7 +40,6 @@ Created 11/5/1995 Heikki Tuuri #include "ut0byte.h" #include "page0types.h" #include "ut0rbt.h" -#include "os0proc.h" #include "log0log.h" #include "srv0srv.h" #include diff --git a/storage/innobase/include/os0proc.h b/storage/innobase/include/os0proc.h deleted file mode 100644 index 2a507e013fe..00000000000 --- a/storage/innobase/include/os0proc.h +++ /dev/null @@ -1,50 +0,0 @@ -/***************************************************************************** - -Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2019, MariaDB Corporation. - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA - -*****************************************************************************/ - -/**************************************************//** -@file include/os0proc.h -The interface to the operating system -process control primitives - -Created 9/30/1995 Heikki Tuuri -*******************************************************/ - -#ifndef os0proc_h -#define os0proc_h - -#include "univ.i" - -#ifdef UNIV_LINUX -#include -#include -#endif - -typedef void* os_process_t; -typedef unsigned long int os_process_id_t; - -/** The total amount of memory currently allocated from the operating -system with allocate_large(). */ -extern Atomic_counter os_total_large_mem_allocated; - -/** Converts the current process id to a number. -@return process id as a number */ -ulint -os_proc_get_number(void); - -#endif diff --git a/storage/innobase/include/ut0new.h b/storage/innobase/include/ut0new.h index 87249062a83..e8469db9dc3 100644 --- a/storage/innobase/include/ut0new.h +++ b/storage/innobase/include/ut0new.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2014, 2015, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2019, MariaDB Corporation. +Copyright (c) 2017, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -137,7 +137,6 @@ InnoDB: #include "mysql/psi/psi_memory.h" /* PSI_memory_key, PSI_memory_info */ #include "os0thread.h" /* os_thread_sleep() */ -#include "os0proc.h" /* os_total_large_mem_allocated */ #include "ut0ut.h" /* ut_strcmp_functor, ut_basename_noext() */ #define OUT_OF_MEMORY_MSG \ @@ -145,6 +144,10 @@ InnoDB: " operating system. Note that on most 32-bit computers the process" \ " memory space is limited to 2 GB or 4 GB." +/** The total amount of memory currently allocated from the operating +system with allocate_large() */ +extern Atomic_counter os_total_large_mem_allocated; + /** Maximum number of retries to allocate memory. */ extern const size_t alloc_max_retries; diff --git a/storage/innobase/os/os0proc.cc b/storage/innobase/os/os0proc.cc deleted file mode 100644 index 819e16f2302..00000000000 --- a/storage/innobase/os/os0proc.cc +++ /dev/null @@ -1,45 +0,0 @@ -/***************************************************************************** - -Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2019, 2020, MariaDB Corporation. - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA - -*****************************************************************************/ - -/**************************************************//** -@file os/os0proc.cc -The interface to the operating system -process control primitives - -Created 9/30/1995 Heikki Tuuri -*******************************************************/ - -#include "univ.i" - -/** The total amount of memory currently allocated from the operating -system with allocacte_large(). */ -Atomic_counter os_total_large_mem_allocated; - -/** Converts the current process id to a number. -@return process id as a number */ -ulint -os_proc_get_number(void) -/*====================*/ -{ -#ifdef _WIN32 - return(static_cast(GetCurrentProcessId())); -#else - return(static_cast(getpid())); -#endif -} diff --git a/storage/innobase/pars/lexyy.cc b/storage/innobase/pars/lexyy.cc index ab49aab953b..e57a28ce7f1 100644 --- a/storage/innobase/pars/lexyy.cc +++ b/storage/innobase/pars/lexyy.cc @@ -816,7 +816,6 @@ Created 12/14/1997 Heikki Tuuri #include "pars0grm.h" #include "pars0sym.h" #include "mem0mem.h" -#include "os0proc.h" #define malloc(A) ut_malloc_nokey(A) #define free(A) ut_free(A) diff --git a/storage/innobase/pars/pars0lex.l b/storage/innobase/pars/pars0lex.l index 64a3dc0c461..1ddc5132da1 100644 --- a/storage/innobase/pars/pars0lex.l +++ b/storage/innobase/pars/pars0lex.l @@ -58,7 +58,6 @@ Created 12/14/1997 Heikki Tuuri #include "pars0grm.h" #include "pars0sym.h" #include "mem0mem.h" -#include "os0proc.h" #define malloc(A) ut_malloc_nokey(A) #define free(A) ut_free(A) diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index ceb9245f659..236ca2080b7 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -55,7 +55,6 @@ Created 10/8/1995 Heikki Tuuri #include "lock0lock.h" #include "log0recv.h" #include "mem0mem.h" -#include "os0proc.h" #include "pars0pars.h" #include "que0que.h" #include "row0mysql.h" diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 85fc90a8e0c..3badbbdef73 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -76,7 +76,6 @@ Created 2/16/1996 Heikki Tuuri #include "btr0defragment.h" #include "mysql/service_wsrep.h" /* wsrep_recovery */ #include "trx0rseg.h" -#include "os0proc.h" #include "buf0flu.h" #include "buf0rea.h" #include "dict0boot.h" @@ -1241,7 +1240,8 @@ dberr_t srv_start(bool create_new_db) sprintf(srv_monitor_file_name, "%s/innodb_status." ULINTPF, fil_path_to_mysql_datadir, - os_proc_get_number()); + static_cast + (IF_WIN(GetCurrentProcessId(), getpid()))); srv_monitor_file = my_fopen(srv_monitor_file_name, O_RDWR|O_TRUNC|O_CREAT, diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc index d1f6a66f09b..074667a22f9 100644 --- a/storage/innobase/trx/trx0trx.cc +++ b/storage/innobase/trx/trx0trx.cc @@ -35,7 +35,6 @@ Created 3/26/1996 Heikki Tuuri #include "btr0sea.h" #include "lock0lock.h" #include "log0log.h" -#include "os0proc.h" #include "que0que.h" #include "srv0mon.h" #include "srv0srv.h" diff --git a/storage/innobase/ut/ut0new.cc b/storage/innobase/ut/ut0new.cc index c4cf8364806..5e00a4ca0ea 100644 --- a/storage/innobase/ut/ut0new.cc +++ b/storage/innobase/ut/ut0new.cc @@ -26,6 +26,10 @@ Created May 26, 2014 Vasil Dimov #include "univ.i" #include +/** The total amount of memory currently allocated from the operating +system with allocate_large(). */ +Atomic_counter os_total_large_mem_allocated; + /** Maximum number of retries to allocate memory. */ const size_t alloc_max_retries = 60; -- cgit v1.2.1 From d63fcbc2f07bb51ea4a5424361deef319da9bd39 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Thu, 3 Sep 2020 15:26:55 +0000 Subject: MDEV-23661: RocksDB produces "missing initializer for member" warnings Add -Wno-missing-field-initializers for MyRocks and gcc version below 5.0 --- storage/rocksdb/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/storage/rocksdb/CMakeLists.txt b/storage/rocksdb/CMakeLists.txt index 506dead7a6e..a82794e9f07 100644 --- a/storage/rocksdb/CMakeLists.txt +++ b/storage/rocksdb/CMakeLists.txt @@ -54,6 +54,9 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU") SKIP_ROCKSDB_PLUGIN("${OLD_COMPILER_MSG}") ENDIF() SET(CXX11_FLAGS "-std=c++11") + IF (GCC_VERSION VERSION_LESS 5.0) + SET(CXX11_FLAGS "-Wno-missing-field-initializers") + ENDIF() ELSEIF (CMAKE_CXX_COMPILER_ID MATCHES "Clang") IF ((CMAKE_CXX_COMPILER_VERSION AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3) OR (CLANG_VERSION_STRING AND CLANG_VERSION_STRING VERSION_LESS 3.3)) -- cgit v1.2.1 From 24f510bba4f0c3236aa5a8c96c209eb71317f4fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 4 Sep 2020 10:31:41 +0300 Subject: MDEV-23633 MY_RELAX_CPU performs unnecessary compare-and-swap on ARM This follows up MDEV-14374, which was filed against MariaDB Server 10.3. Back then, on a 48-core Qualcomm Centriq 2400, the performance of delay loops for spinloops was tested both with and without the dummy compare-and-swap operation, and it was decided to keep the dummy operation. On target architectures where nothing special is available (other than x86 (IA-32, AMD64) or POWER), we perform a dummy compare-and-swap operation. This is contrary to the idea of the x86 PAUSE instruction and the __ppc_get_timebase(), which aim to keep the memory bus idle for a while, to allow other cores to better execute code while a spinloop is waiting for something to be changed. On MariaDB Server 10.4 and another implementation of the ARMv8 ISA, omitting the dummy compare-and-swap improved performance by up to 12%. So, let us avoid the dummy compare-and-swap on ARM. For now, we are retaining the dummy compare-and-swap on other ISAs (such as SPARC, MIPS, S390x, RISC-V) because we do not have any performance data for them. --- include/my_cpu.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/my_cpu.h b/include/my_cpu.h index b7d7008a8e3..0b51d3ef90f 100644 --- a/include/my_cpu.h +++ b/include/my_cpu.h @@ -53,6 +53,7 @@ #ifdef _WIN32 #elif defined HAVE_PAUSE_INSTRUCTION #elif defined(_ARCH_PWR8) +#elif defined __GNUC__ && (defined __arm__ || defined __aarch64__) #else # include "my_atomic.h" #endif @@ -80,6 +81,9 @@ static inline void MY_RELAX_CPU(void) #endif #elif defined(_ARCH_PWR8) __ppc_get_timebase(); +#elif defined __GNUC__ && (defined __arm__ || defined __aarch64__) + /* Mainly, prevent the compiler from optimizing away delay loops */ + __asm__ __volatile__ ("":::"memory") #else int32 var, oldval = 0; my_atomic_cas32_strong_explicit(&var, &oldval, 1, MY_MEMORY_ORDER_RELAXED, -- cgit v1.2.1 From b0c194cab4ba0d8618080756d3af592a6d84fe7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 4 Sep 2020 11:40:17 +0300 Subject: MDEV-23633 fixup: Add missing semicolon --- include/my_cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/my_cpu.h b/include/my_cpu.h index 0b51d3ef90f..57f2bf814d4 100644 --- a/include/my_cpu.h +++ b/include/my_cpu.h @@ -83,7 +83,7 @@ static inline void MY_RELAX_CPU(void) __ppc_get_timebase(); #elif defined __GNUC__ && (defined __arm__ || defined __aarch64__) /* Mainly, prevent the compiler from optimizing away delay loops */ - __asm__ __volatile__ ("":::"memory") + __asm__ __volatile__ ("":::"memory"); #else int32 var, oldval = 0; my_atomic_cas32_strong_explicit(&var, &oldval, 1, MY_MEMORY_ORDER_RELAXED, -- cgit v1.2.1 From 8c2909a2a4629f542a52b12cc41bcbf6c36fc588 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 4 Sep 2020 09:12:27 +0000 Subject: Fix a typo in the previous cset --- storage/rocksdb/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/rocksdb/CMakeLists.txt b/storage/rocksdb/CMakeLists.txt index a82794e9f07..f9384848243 100644 --- a/storage/rocksdb/CMakeLists.txt +++ b/storage/rocksdb/CMakeLists.txt @@ -55,7 +55,7 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU") ENDIF() SET(CXX11_FLAGS "-std=c++11") IF (GCC_VERSION VERSION_LESS 5.0) - SET(CXX11_FLAGS "-Wno-missing-field-initializers") + SET(CXX11_FLAGS "-std=c++11 -Wno-missing-field-initializers") ENDIF() ELSEIF (CMAKE_CXX_COMPILER_ID MATCHES "Clang") IF ((CMAKE_CXX_COMPILER_VERSION AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3) OR -- cgit v1.2.1 From c029d4562322d8c792f96717e0fb7f18d2379b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 4 Sep 2020 12:07:46 +0300 Subject: MDEV-23600 follow-up: uninitialized rec_field_is_prefix build_template_field(): Initialize templ->rec_field_is_prefix also for indexes on virtual columns. This was caught on 10.5 by MemorySanitizer as use-of-uninitialized-value in row_search_with_covering_prefix() when running the test main.fast_prefix_index_fetch_innodb. --- storage/innobase/handler/ha_innodb.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index e171b6a99b3..2493a11b554 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -7455,6 +7455,8 @@ build_template_field( #ifdef HAVE_valgrind_or_MSAN MEM_UNDEFINED(templ, sizeof *templ); #endif /* HAVE_valgrind_or_MSAN */ + templ->rec_field_is_prefix = FALSE; + templ->rec_prefix_field_no = ULINT_UNDEFINED; templ->is_virtual = !field->stored_in_db(); if (!templ->is_virtual) { @@ -7516,8 +7518,6 @@ build_template_field( << " query " << innobase_get_stmt_unsafe(current_thd, &size); } - templ->rec_field_is_prefix = FALSE; - templ->rec_prefix_field_no = ULINT_UNDEFINED; if (dict_index_is_clust(index)) { templ->rec_field_no = templ->clust_rec_field_no; @@ -7535,7 +7535,6 @@ build_template_field( DBUG_ASSERT(!ha_innobase::omits_virtual_cols(*table->s)); col = &dict_table_get_nth_v_col(index->table, v_no)->m_col; templ->clust_rec_field_no = v_no; - templ->rec_prefix_field_no = ULINT_UNDEFINED; if (dict_index_is_clust(index)) { templ->rec_field_no = templ->clust_rec_field_no; -- cgit v1.2.1 From 1a3ce7e77c61c4e8e95825dde5d706de95ffb0e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 4 Sep 2020 12:17:35 +0300 Subject: MDEV-23651: Fix the Windows build In the Microsoft environment, my_atomic requires int32. --- storage/innobase/include/fil0fil.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h index 898caf1a813..6a184fe6f94 100644 --- a/storage/innobase/include/fil0fil.h +++ b/storage/innobase/include/fil0fil.h @@ -142,11 +142,11 @@ private: The most significant bit contains the STOP_NEW_OPS flag. Protected by my_atomic. */ - uint32_t n_pending_ops; + int32 n_pending_ops; /** Flag in n_pending_ops that indicates that the tablespace is being deleted, and no further operations should be performed */ - static const uint32_t STOP_NEW_OPS= 1U << 31; + static const int32 STOP_NEW_OPS= 1 << 31; public: /** Number of pending block read or write operations (when a write is imminent or a read has recently completed). @@ -263,13 +263,13 @@ public: void close(); /** @return whether the tablespace is about to be dropped or is referenced */ - uint32_t is_stopping_or_referenced() + int32 is_stopping_or_referenced() { return my_atomic_load32(&n_pending_ops); } /** @return whether the tablespace is about to be dropped or is referenced */ - uint32_t is_stopping_or_referenced() const + int32 is_stopping_or_referenced() const { return const_cast(this)->is_stopping_or_referenced(); } @@ -281,7 +281,7 @@ public: } /** @return number of references being held */ - uint32_t referenced() const + int32 referenced() const { return is_stopping_or_referenced() & ~STOP_NEW_OPS; } @@ -290,7 +290,7 @@ public: void set_stopping(bool stopping) { /* Note: starting with 10.4 this should be std::atomic::fetch_xor() */ - uint32_t n= stopping ? 0 : STOP_NEW_OPS; + int32 n= stopping ? 0 : STOP_NEW_OPS; while (!my_atomic_cas32_strong_explicit(&n_pending_ops, &n, n ^ STOP_NEW_OPS, MY_MEMORY_ORDER_ACQUIRE, @@ -302,7 +302,7 @@ public: /** @return whether a tablespace reference was successfully acquired */ bool acquire() { - uint32_t n= 0; + int32 n= 0; while (!my_atomic_cas32_strong_explicit(&n_pending_ops, &n, n + 1, MY_MEMORY_ORDER_ACQUIRE, MY_MEMORY_ORDER_RELAXED)) @@ -314,7 +314,7 @@ public: @return whether this was the last reference */ bool release() { - uint32_t n= my_atomic_add32(&n_pending_ops, uint32_t(-1)); + int32 n= my_atomic_add32(&n_pending_ops, -1); ut_ad(n & ~STOP_NEW_OPS); return (n & ~STOP_NEW_OPS) == 1; } -- cgit v1.2.1 From 3ee2422624ffb3d7ffefff8db7ef9398816299bc Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Fri, 4 Sep 2020 17:40:51 +0800 Subject: 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; } -- cgit v1.2.1 From d25f806d73d9984f0c9f2a346dcebb01a0eaa109 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Fri, 4 Sep 2020 14:33:13 +0200 Subject: MDEV-22749 Implement portable PCLMUL accelerated crc32() with Intel intrinsics Removed some inine assembly, replaced by code from https://github.com/intel/soft-crc Also,replace GCC inline assembly for cpuid in ut0crc32 with __cpuid, to fix "PIC register clobbered by 'ebx' in 'asm'. This enables fast CRC32C on 32bit Intel processors with GCC. --- mysys/CMakeLists.txt | 27 +- mysys/crc32/crc32_x86.c | 810 ++++++++++++++++------------------------ storage/innobase/ut/ut0crc32.cc | 23 +- 3 files changed, 340 insertions(+), 520 deletions(-) diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index 54f78922f2b..099ba63c8e7 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -60,20 +60,21 @@ ENDIF() IF(MSVC) SET(HAVE_CPUID_INSTRUCTION 1 CACHE BOOL "") -ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i[36]86") - #Check for CPUID and PCLMUL. GCC before version 5 would refuse to emit the - #CPUID instruction for -m32 -fPIC because it would clobber the EBX register. - CHECK_C_SOURCE_COMPILES(" - int main() - { - asm volatile (\"cpuid\" : : \"a\"(1) : \"ebx\"); - asm volatile (\"pclmulqdq \\$0x00, %%xmm1, %%xmm0\":::\"cc\"); - return 0; - }" HAVE_CLMUL_INSTRUCTION) - - IF(HAVE_CLMUL_INSTRUCTION) - SET(HAVE_CPUID_INSTRUCTION 1 CACHE BOOL "") + SET(HAVE_CLMUL_INSTRUCTION 1 CACHE BOOL "") + SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_x86.c) + IF(CLANG_CL) + SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.c PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul") + ENDIF() +ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i386|i686") + SET(HAVE_CPUID_INSTRUCTION 1 CACHE BOOL "") + MY_CHECK_C_COMPILER_FLAG(-msse4.2) + MY_CHECK_C_COMPILER_FLAG(-mpclmul) + CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H) + CHECK_INCLUDE_FILE(x86intrin.h HAVE_X86INTRIN_H) + IF(have_C__msse4.2 AND have_C__mpclmul AND HAVE_CPUID_H AND HAVE_X86INTRIN_H) + SET(HAVE_CLMUL_INSTRUCTION 1 CACHE BOOL "") SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_x86.c) + SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.c PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul") ENDIF() ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64") IF(CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) diff --git a/mysys/crc32/crc32_x86.c b/mysys/crc32/crc32_x86.c index 608ba3927c7..48c930e762e 100644 --- a/mysys/crc32/crc32_x86.c +++ b/mysys/crc32/crc32_x86.c @@ -1,542 +1,358 @@ -/****************************************************** -Copyright (c) 2017 Percona LLC and/or its affiliates. +/* Copyright (c) 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 + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* + Implementation of CRC32 (Ethernet) uing Intel PCLMULQDQ + Ported from Intels work, see https://github.com/intel/soft-crc +*/ + +/******************************************************************************* + Copyright (c) 2009-2018, Intel Corporation + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ -CRC32 using Intel's PCLMUL instruction. -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; version 2 of the License. +#include +#include -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +#include +#include +#include +#include +#include -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA +#if defined(__GNUC__) +#include +#include +#elif defined(_MSC_VER) +#include +#else +#error "unknown compiler" +#endif -*******************************************************/ +static int has_sse42_and_pclmul(uint32_t recx) +{ + /* 1 << 20 is SSE42, 1 << 1 is PCLMULQDQ */ +#define bits_SSE42_AND_PCLMUL (1 << 20 | 1 << 1) + return (recx & bits_SSE42_AND_PCLMUL) == bits_SSE42_AND_PCLMUL; +} -/* crc-intel-pclmul.c - Intel PCLMUL accelerated CRC implementation - * Copyright (C) 2016 Jussi Kivilinna +#ifdef __GNUC__ +int crc32_pclmul_enabled(void) +{ + uint32_t reax= 0, rebx= 0, recx= 0, redx= 0; + __cpuid(1, reax, rebx, recx, redx); + return has_sse42_and_pclmul(recx); +} +#elif defined(_MSC_VER) +int crc32_pclmul_enabled(void) +{ + int regs[4]; + __cpuid(regs, 1); + return has_sse42_and_pclmul(regs[2]); +} +#endif + +/** + * @brief Shifts left 128 bit register by specified number of bytes * - * This file is part of Libgcrypt. + * @param reg 128 bit value + * @param num number of bytes to shift left \a reg by (0-16) * - * Libgcrypt is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. + * @return \a reg << (\a num * 8) + */ +static inline __m128i xmm_shift_left(__m128i reg, const unsigned int num) +{ + static const MY_ALIGNED(16) uint8_t crc_xmm_shift_tab[48]= { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + + const __m128i *p= (const __m128i *) (crc_xmm_shift_tab + 16 - num); + + return _mm_shuffle_epi8(reg, _mm_loadu_si128(p)); +} + +struct crcr_pclmulqdq_ctx +{ + uint64_t rk1; + uint64_t rk2; + uint64_t rk5; + uint64_t rk6; + uint64_t rk7; + uint64_t rk8; +}; + +/** + * @brief Performs one folding round * - * Libgcrypt is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. + * Logically function operates as follows: + * DATA = READ_NEXT_16BYTES(); + * F1 = LSB8(FOLD) + * F2 = MSB8(FOLD) + * T1 = CLMUL(F1, RK1) + * T2 = CLMUL(F2, RK2) + * FOLD = XOR(T1, T2, DATA) * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA + * @param data_block 16 byte data block + * @param precomp precomputed rk1 constanst + * @param fold running 16 byte folded data * + * @return New 16 byte folded data */ +static inline __m128i crcr32_folding_round(const __m128i data_block, + const __m128i precomp, const __m128i fold) +{ + __m128i tmp0= _mm_clmulepi64_si128(fold, precomp, 0x01); + __m128i tmp1= _mm_clmulepi64_si128(fold, precomp, 0x10); -#include + return _mm_xor_si128(tmp1, _mm_xor_si128(data_block, tmp0)); +} -#include -#include -#include -#include +/** + * @brief Performs reduction from 128 bits to 64 bits + * + * @param data128 128 bits data to be reduced + * @param precomp rk5 and rk6 precomputed constants + * + * @return data reduced to 64 bits + */ +static inline __m128i crcr32_reduce_128_to_64(__m128i data128, const __m128i precomp) +{ + __m128i tmp0, tmp1, tmp2; -# define U64_C(c) (c ## UL) + /* 64b fold */ + tmp0= _mm_clmulepi64_si128(data128, precomp, 0x00); + tmp1= _mm_srli_si128(data128, 8); + tmp0= _mm_xor_si128(tmp0, tmp1); -typedef uint32_t u32; -typedef uint16_t u16; -typedef uint64_t u64; -#ifndef byte -typedef uint8_t byte; -#endif + /* 32b fold */ + tmp2= _mm_slli_si128(tmp0, 4); + tmp1= _mm_clmulepi64_si128(tmp2, precomp, 0x10); -# define _gcry_bswap32 __builtin_bswap32 + return _mm_xor_si128(tmp1, tmp0); +} -#if defined(_GCRY_GCC_VERSION) && _GCRY_GCC_VERSION >= 40400 /* 4.4 */ -/* Prevent compiler from issuing SSE instructions between asm blocks. */ -# pragma GCC target("no-sse") -#endif +/** + * @brief Performs Barret's reduction from 64 bits to 32 bits + * + * @param data64 64 bits data to be reduced + * @param precomp rk7 precomputed constant + * + * @return data reduced to 32 bits + */ +static inline uint32_t crcr32_reduce_64_to_32(__m128i data64, const __m128i precomp) +{ + static const MY_ALIGNED(16) uint32_t mask1[4]= { + 0xffffffff, 0xffffffff, 0x00000000, 0x00000000}; + static const MY_ALIGNED(16) uint32_t mask2[4]= { + 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff}; + __m128i tmp0, tmp1, tmp2; + + tmp0= _mm_and_si128(data64, _mm_load_si128((__m128i *) mask2)); + tmp1= _mm_clmulepi64_si128(tmp0, precomp, 0x00); + tmp1= _mm_xor_si128(tmp1, tmp0); + tmp1= _mm_and_si128(tmp1, _mm_load_si128((__m128i *) mask1)); -#define ALIGNED_16 __attribute__ ((aligned (16))) + tmp2= _mm_clmulepi64_si128(tmp1, precomp, 0x10); + tmp2= _mm_xor_si128(tmp2, tmp1); + tmp2= _mm_xor_si128(tmp2, tmp0); + return _mm_extract_epi32(tmp2, 2); +} -struct u16_unaligned_s +/** + * @brief Calculates reflected 32-bit CRC for given \a data block + * by applying folding and reduction methods. + * + * Algorithm operates on 32 bit CRCs. + * Polynomials and initial values may need to be promoted to + * 32 bits where required. + * + * @param crc initial CRC value (32 bit value) + * @param data pointer to data block + * @param data_len length of \a data block in bytes + * @param params pointer to PCLMULQDQ CRC calculation context + * + * @return CRC for given \a data block (32 bits wide). + */ +static inline uint32_t crcr32_calc_pclmulqdq(const uint8_t *data, uint32_t data_len, + uint32_t crc, + const struct crcr_pclmulqdq_ctx *params) { - u16 a; -} __attribute__((packed, aligned (1), may_alias)); + __m128i temp, fold, k; + uint32_t n; + DBUG_ASSERT(data); + DBUG_ASSERT(params); -/* Constants structure for generic reflected/non-reflected CRC32 CLMUL - * functions. */ -struct crc32_consts_s -{ - /* k: { x^(32*17), x^(32*15), x^(32*5), x^(32*3), x^(32*2), 0 } mod P(x) */ - u64 k[6]; - /* my_p: { floor(x^64 / P(x)), P(x) } */ - u64 my_p[2]; -}; + if (unlikely(data_len == 0)) + return crc; + /** + * Get CRC init value + */ + temp= _mm_insert_epi32(_mm_setzero_si128(), crc, 0); -/* CLMUL constants for CRC32 and CRC32RFC1510. */ -static const struct crc32_consts_s crc32_consts ALIGNED_16 = -{ - { /* k[6] = reverse_33bits( x^(32*y) mod P(x) ) */ - U64_C(0x154442bd4), U64_C(0x1c6e41596), /* y = { 17, 15 } */ - U64_C(0x1751997d0), U64_C(0x0ccaa009e), /* y = { 5, 3 } */ - U64_C(0x163cd6124), 0 /* y = 2 */ - }, - { /* my_p[2] = reverse_33bits ( { floor(x^64 / P(x)), P(x) } ) */ - U64_C(0x1f7011641), U64_C(0x1db710641) - } -}; + /** + * ------------------------------------------------- + * Folding all data into single 16 byte data block + * Assumes: \a fold holds first 16 bytes of data + */ -/* Common constants for CRC32 algorithms. */ -static const byte crc32_refl_shuf_shift[3 * 16] ALIGNED_16 = - { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - }; -static const byte crc32_partial_fold_input_mask[16 + 16] ALIGNED_16 = + if (unlikely(data_len < 32)) { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - }; -static const u64 crc32_merge9to15_shuf[15 - 9 + 1][2] ALIGNED_16 = - { - { U64_C(0x0706050403020100), U64_C(0xffffffffffffff0f) }, /* 9 */ - { U64_C(0x0706050403020100), U64_C(0xffffffffffff0f0e) }, - { U64_C(0x0706050403020100), U64_C(0xffffffffff0f0e0d) }, - { U64_C(0x0706050403020100), U64_C(0xffffffff0f0e0d0c) }, - { U64_C(0x0706050403020100), U64_C(0xffffff0f0e0d0c0b) }, - { U64_C(0x0706050403020100), U64_C(0xffff0f0e0d0c0b0a) }, - { U64_C(0x0706050403020100), U64_C(0xff0f0e0d0c0b0a09) }, /* 15 */ - }; -static const u64 crc32_merge5to7_shuf[7 - 5 + 1][2] ALIGNED_16 = - { - { U64_C(0xffffff0703020100), U64_C(0xffffffffffffffff) }, /* 5 */ - { U64_C(0xffff070603020100), U64_C(0xffffffffffffffff) }, - { U64_C(0xff07060503020100), U64_C(0xffffffffffffffff) }, /* 7 */ - }; - -/* PCLMUL functions for reflected CRC32. */ -static inline void -crc32_reflected_bulk (u32 *pcrc, const byte *inbuf, size_t inlen, - const struct crc32_consts_s *consts) -{ - if (inlen >= 8 * 16) + if (unlikely(data_len == 16)) { - asm volatile ("movd %[crc], %%xmm4\n\t" - "movdqu %[inbuf_0], %%xmm0\n\t" - "movdqu %[inbuf_1], %%xmm1\n\t" - "movdqu %[inbuf_2], %%xmm2\n\t" - "movdqu %[inbuf_3], %%xmm3\n\t" - "pxor %%xmm4, %%xmm0\n\t" - : - : [inbuf_0] "m" (inbuf[0 * 16]), - [inbuf_1] "m" (inbuf[1 * 16]), - [inbuf_2] "m" (inbuf[2 * 16]), - [inbuf_3] "m" (inbuf[3 * 16]), - [crc] "m" (*pcrc) - ); - - inbuf += 4 * 16; - inlen -= 4 * 16; - - asm volatile ("movdqa %[k1k2], %%xmm4\n\t" - : - : [k1k2] "m" (consts->k[1 - 1]) - ); - - /* Fold by 4. */ - while (inlen >= 4 * 16) - { - asm volatile ("movdqu %[inbuf_0], %%xmm5\n\t" - "movdqa %%xmm0, %%xmm6\n\t" - "pclmulqdq $0x00, %%xmm4, %%xmm0\n\t" - "pclmulqdq $0x11, %%xmm4, %%xmm6\n\t" - "pxor %%xmm5, %%xmm0\n\t" - "pxor %%xmm6, %%xmm0\n\t" - - "movdqu %[inbuf_1], %%xmm5\n\t" - "movdqa %%xmm1, %%xmm6\n\t" - "pclmulqdq $0x00, %%xmm4, %%xmm1\n\t" - "pclmulqdq $0x11, %%xmm4, %%xmm6\n\t" - "pxor %%xmm5, %%xmm1\n\t" - "pxor %%xmm6, %%xmm1\n\t" - - "movdqu %[inbuf_2], %%xmm5\n\t" - "movdqa %%xmm2, %%xmm6\n\t" - "pclmulqdq $0x00, %%xmm4, %%xmm2\n\t" - "pclmulqdq $0x11, %%xmm4, %%xmm6\n\t" - "pxor %%xmm5, %%xmm2\n\t" - "pxor %%xmm6, %%xmm2\n\t" - - "movdqu %[inbuf_3], %%xmm5\n\t" - "movdqa %%xmm3, %%xmm6\n\t" - "pclmulqdq $0x00, %%xmm4, %%xmm3\n\t" - "pclmulqdq $0x11, %%xmm4, %%xmm6\n\t" - "pxor %%xmm5, %%xmm3\n\t" - "pxor %%xmm6, %%xmm3\n\t" - : - : [inbuf_0] "m" (inbuf[0 * 16]), - [inbuf_1] "m" (inbuf[1 * 16]), - [inbuf_2] "m" (inbuf[2 * 16]), - [inbuf_3] "m" (inbuf[3 * 16]) - ); - - inbuf += 4 * 16; - inlen -= 4 * 16; - } - - asm volatile ("movdqa %[k3k4], %%xmm6\n\t" - "movdqa %[my_p], %%xmm5\n\t" - : - : [k3k4] "m" (consts->k[3 - 1]), - [my_p] "m" (consts->my_p[0]) - ); - - /* Fold 4 to 1. */ - - asm volatile ("movdqa %%xmm0, %%xmm4\n\t" - "pclmulqdq $0x00, %%xmm6, %%xmm0\n\t" - "pclmulqdq $0x11, %%xmm6, %%xmm4\n\t" - "pxor %%xmm1, %%xmm0\n\t" - "pxor %%xmm4, %%xmm0\n\t" - - "movdqa %%xmm0, %%xmm4\n\t" - "pclmulqdq $0x00, %%xmm6, %%xmm0\n\t" - "pclmulqdq $0x11, %%xmm6, %%xmm4\n\t" - "pxor %%xmm2, %%xmm0\n\t" - "pxor %%xmm4, %%xmm0\n\t" - - "movdqa %%xmm0, %%xmm4\n\t" - "pclmulqdq $0x00, %%xmm6, %%xmm0\n\t" - "pclmulqdq $0x11, %%xmm6, %%xmm4\n\t" - "pxor %%xmm3, %%xmm0\n\t" - "pxor %%xmm4, %%xmm0\n\t" - : - : - ); + /* 16 bytes */ + fold= _mm_loadu_si128((__m128i *) data); + fold= _mm_xor_si128(fold, temp); + goto reduction_128_64; } - else + if (unlikely(data_len < 16)) { - asm volatile ("movd %[crc], %%xmm1\n\t" - "movdqu %[inbuf], %%xmm0\n\t" - "movdqa %[k3k4], %%xmm6\n\t" - "pxor %%xmm1, %%xmm0\n\t" - "movdqa %[my_p], %%xmm5\n\t" - : - : [inbuf] "m" (*inbuf), - [crc] "m" (*pcrc), - [k3k4] "m" (consts->k[3 - 1]), - [my_p] "m" (consts->my_p[0]) - ); - - inbuf += 16; - inlen -= 16; + /* 0 to 15 bytes */ + MY_ALIGNED(16) uint8_t buffer[16]; + + memset(buffer, 0, sizeof(buffer)); + memcpy(buffer, data, data_len); + + fold= _mm_load_si128((__m128i *) buffer); + fold= _mm_xor_si128(fold, temp); + if ((data_len < 4)) + { + fold= xmm_shift_left(fold, 8 - data_len); + goto barret_reduction; + } + fold= xmm_shift_left(fold, 16 - data_len); + goto reduction_128_64; } + /* 17 to 31 bytes */ + fold= _mm_loadu_si128((__m128i *) data); + fold= _mm_xor_si128(fold, temp); + n= 16; + k= _mm_load_si128((__m128i *) (¶ms->rk1)); + goto partial_bytes; + } - /* Fold by 1. */ - if (inlen >= 16) - { - while (inlen >= 16) - { - /* Load next block to XMM2. Fold XMM0 to XMM0:XMM1. */ - asm volatile ("movdqu %[inbuf], %%xmm2\n\t" - "movdqa %%xmm0, %%xmm1\n\t" - "pclmulqdq $0x00, %%xmm6, %%xmm0\n\t" - "pclmulqdq $0x11, %%xmm6, %%xmm1\n\t" - "pxor %%xmm2, %%xmm0\n\t" - "pxor %%xmm1, %%xmm0\n\t" - : - : [inbuf] "m" (*inbuf) - ); - - inbuf += 16; - inlen -= 16; - } - } + /** + * At least 32 bytes in the buffer + */ + + /** + * Apply CRC initial value + */ + fold= _mm_loadu_si128((const __m128i *) data); + fold= _mm_xor_si128(fold, temp); + + /** + * Main folding loop + * - the last 16 bytes is processed separately + */ + k= _mm_load_si128((__m128i *) (¶ms->rk1)); + for (n= 16; (n + 16) <= data_len; n+= 16) + { + temp= _mm_loadu_si128((__m128i *) &data[n]); + fold= crcr32_folding_round(temp, k, fold); + } - /* Partial fold. */ - if (inlen) - { - /* Load last input and add padding zeros. */ - asm volatile ("movdqu %[shr_shuf], %%xmm3\n\t" - "movdqu %[shl_shuf], %%xmm4\n\t" - "movdqu %[mask], %%xmm2\n\t" - - "movdqa %%xmm0, %%xmm1\n\t" - "pshufb %%xmm4, %%xmm0\n\t" - "movdqu %[inbuf], %%xmm4\n\t" - "pshufb %%xmm3, %%xmm1\n\t" - "pand %%xmm4, %%xmm2\n\t" - "por %%xmm1, %%xmm2\n\t" - - "movdqa %%xmm0, %%xmm1\n\t" - "pclmulqdq $0x00, %%xmm6, %%xmm0\n\t" - "pclmulqdq $0x11, %%xmm6, %%xmm1\n\t" - "pxor %%xmm2, %%xmm0\n\t" - "pxor %%xmm1, %%xmm0\n\t" - : - : [inbuf] "m" (*(inbuf - 16 + inlen)), - [mask] "m" (crc32_partial_fold_input_mask[inlen]), - [shl_shuf] "m" (crc32_refl_shuf_shift[inlen]), - [shr_shuf] "m" (crc32_refl_shuf_shift[inlen + 16]) - ); - - inbuf += inlen; - inlen -= inlen; - } +partial_bytes: + if (likely(n < data_len)) + { + static const MY_ALIGNED(16) uint32_t mask3[4]= {0x80808080, 0x80808080, + 0x80808080, 0x80808080}; + static const MY_ALIGNED(16) uint8_t shf_table[32]= { + 0x00, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, + 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; + __m128i last16, a, b; - /* Final fold. */ - asm volatile (/* reduce 128-bits to 96-bits */ - "movdqa %%xmm0, %%xmm1\n\t" - "pclmulqdq $0x10, %%xmm6, %%xmm0\n\t" - "psrldq $8, %%xmm1\n\t" - "pxor %%xmm1, %%xmm0\n\t" - - /* reduce 96-bits to 64-bits */ - "pshufd $0xfc, %%xmm0, %%xmm1\n\t" /* [00][00][00][x] */ - "pshufd $0xf9, %%xmm0, %%xmm0\n\t" /* [00][00][x>>64][x>>32] */ - "pclmulqdq $0x00, %[k5], %%xmm1\n\t" /* [00][00][xx][xx] */ - "pxor %%xmm1, %%xmm0\n\t" /* top 64-bit are zero */ - - /* barrett reduction */ - "pshufd $0xf3, %%xmm0, %%xmm1\n\t" /* [00][00][x>>32][00] */ - "pslldq $4, %%xmm0\n\t" /* [??][x>>32][??][??] */ - "pclmulqdq $0x00, %%xmm5, %%xmm1\n\t" /* [00][xx][xx][00] */ - "pclmulqdq $0x10, %%xmm5, %%xmm1\n\t" /* [00][xx][xx][00] */ - "pxor %%xmm1, %%xmm0\n\t" - - /* store CRC */ - "pextrd $2, %%xmm0, %[out]\n\t" - : [out] "=m" (*pcrc) - : [k5] "m" (consts->k[5 - 1]) - ); -} + last16= _mm_loadu_si128((const __m128i *) &data[data_len - 16]); -static inline void -crc32_reflected_less_than_16 (u32 *pcrc, const byte *inbuf, size_t inlen, - const struct crc32_consts_s *consts) -{ - if (inlen < 4) - { - u32 crc = *pcrc; - u32 data; - - asm volatile ("movdqa %[my_p], %%xmm5\n\t" - : - : [my_p] "m" (consts->my_p[0]) - ); - - if (inlen == 1) - { - data = inbuf[0]; - data ^= crc; - data <<= 24; - crc >>= 8; - } - else if (inlen == 2) - { - data = ((const struct u16_unaligned_s *)inbuf)->a; - data ^= crc; - data <<= 16; - crc >>= 16; - } - else - { - data = ((const struct u16_unaligned_s *)inbuf)->a; - data |= ((u32) inbuf[2]) << 16; - data ^= crc; - data <<= 8; - crc >>= 24; - } - - /* Barrett reduction */ - asm volatile ("movd %[in], %%xmm0\n\t" - "movd %[crc], %%xmm1\n\t" - - "pclmulqdq $0x00, %%xmm5, %%xmm0\n\t" /* [00][00][xx][xx] */ - "psllq $32, %%xmm1\n\t" - "pshufd $0xfc, %%xmm0, %%xmm0\n\t" /* [00][00][00][x] */ - "pclmulqdq $0x10, %%xmm5, %%xmm0\n\t" /* [00][00][xx][xx] */ - "pxor %%xmm1, %%xmm0\n\t" - - "pextrd $1, %%xmm0, %[out]\n\t" - : [out] "=m" (*pcrc) - : [in] "rm" (data), - [crc] "rm" (crc) - ); - } - else if (inlen == 4) - { - /* Barrett reduction */ - asm volatile ("movd %[crc], %%xmm1\n\t" - "movd %[in], %%xmm0\n\t" - "movdqa %[my_p], %%xmm5\n\t" - "pxor %%xmm1, %%xmm0\n\t" - - "pclmulqdq $0x00, %%xmm5, %%xmm0\n\t" /* [00][00][xx][xx] */ - "pshufd $0xfc, %%xmm0, %%xmm0\n\t" /* [00][00][00][x] */ - "pclmulqdq $0x10, %%xmm5, %%xmm0\n\t" /* [00][00][xx][xx] */ - - "pextrd $1, %%xmm0, %[out]\n\t" - : [out] "=m" (*pcrc) - : [in] "m" (*inbuf), - [crc] "m" (*pcrc), - [my_p] "m" (consts->my_p[0]) - ); - } - else - { - asm volatile ("movdqu %[shuf], %%xmm4\n\t" - "movd %[crc], %%xmm1\n\t" - "movdqa %[my_p], %%xmm5\n\t" - "movdqa %[k3k4], %%xmm6\n\t" - : - : [shuf] "m" (crc32_refl_shuf_shift[inlen]), - [crc] "m" (*pcrc), - [my_p] "m" (consts->my_p[0]), - [k3k4] "m" (consts->k[3 - 1]) - ); - - if (inlen >= 8) - { - asm volatile ("movq %[inbuf], %%xmm0\n\t" - : - : [inbuf] "m" (*inbuf) - ); - if (inlen > 8) - { - asm volatile (/*"pinsrq $1, %[inbuf_tail], %%xmm0\n\t"*/ - "movq %[inbuf_tail], %%xmm2\n\t" - "punpcklqdq %%xmm2, %%xmm0\n\t" - "pshufb %[merge_shuf], %%xmm0\n\t" - : - : [inbuf_tail] "m" (inbuf[inlen - 8]), - [merge_shuf] "m" - (*crc32_merge9to15_shuf[inlen - 9]) - ); - } - } - else - { - asm volatile ("movd %[inbuf], %%xmm0\n\t" - "pinsrd $1, %[inbuf_tail], %%xmm0\n\t" - "pshufb %[merge_shuf], %%xmm0\n\t" - : - : [inbuf] "m" (*inbuf), - [inbuf_tail] "m" (inbuf[inlen - 4]), - [merge_shuf] "m" - (*crc32_merge5to7_shuf[inlen - 5]) - ); - } - - /* Final fold. */ - asm volatile ("pxor %%xmm1, %%xmm0\n\t" - "pshufb %%xmm4, %%xmm0\n\t" - - /* reduce 128-bits to 96-bits */ - "movdqa %%xmm0, %%xmm1\n\t" - "pclmulqdq $0x10, %%xmm6, %%xmm0\n\t" - "psrldq $8, %%xmm1\n\t" - "pxor %%xmm1, %%xmm0\n\t" /* top 32-bit are zero */ - - /* reduce 96-bits to 64-bits */ - "pshufd $0xfc, %%xmm0, %%xmm1\n\t" /* [00][00][00][x] */ - "pshufd $0xf9, %%xmm0, %%xmm0\n\t" /* [00][00][x>>64][x>>32] */ - "pclmulqdq $0x00, %[k5], %%xmm1\n\t" /* [00][00][xx][xx] */ - "pxor %%xmm1, %%xmm0\n\t" /* top 64-bit are zero */ - - /* barrett reduction */ - "pshufd $0xf3, %%xmm0, %%xmm1\n\t" /* [00][00][x>>32][00] */ - "pslldq $4, %%xmm0\n\t" /* [??][x>>32][??][??] */ - "pclmulqdq $0x00, %%xmm5, %%xmm1\n\t" /* [00][xx][xx][00] */ - "pclmulqdq $0x10, %%xmm5, %%xmm1\n\t" /* [00][xx][xx][00] */ - "pxor %%xmm1, %%xmm0\n\t" - - /* store CRC */ - "pextrd $2, %%xmm0, %[out]\n\t" - : [out] "=m" (*pcrc) - : [k5] "m" (consts->k[5 - 1]) - ); - } -} + temp= _mm_loadu_si128((const __m128i *) &shf_table[data_len & 15]); + a= _mm_shuffle_epi8(fold, temp); -void -crc32_intel_pclmul (u32 *pcrc, const byte *inbuf, size_t inlen) -{ - const struct crc32_consts_s *consts = &crc32_consts; -#if defined(__x86_64__) && defined(__WIN64__) - char win64tmp[2 * 16]; - - /* XMM6-XMM7 need to be restored after use. */ - asm volatile ("movdqu %%xmm6, 0*16(%0)\n\t" - "movdqu %%xmm7, 1*16(%0)\n\t" - : - : "r" (win64tmp) - : "memory"); -#endif + temp= _mm_xor_si128(temp, _mm_load_si128((const __m128i *) mask3)); + b= _mm_shuffle_epi8(fold, temp); + b= _mm_blendv_epi8(b, last16, temp); - if (!inlen) - return; - - if (inlen >= 16) - crc32_reflected_bulk(pcrc, inbuf, inlen, consts); - else - crc32_reflected_less_than_16(pcrc, inbuf, inlen, consts); - -#if defined(__x86_64__) && defined(__WIN64__) - /* Restore used registers. */ - asm volatile("movdqu 0*16(%0), %%xmm6\n\t" - "movdqu 1*16(%0), %%xmm7\n\t" - : - : "r" (win64tmp) - : "memory"); -#endif -} + /* k = rk1 & rk2 */ + temp= _mm_clmulepi64_si128(a, k, 0x01); + fold= _mm_clmulepi64_si128(a, k, 0x10); -#ifdef __GNUC__ -int crc32_pclmul_enabled(void) -{ - int eax, ecx; - /* We assume that the CPUID instruction and its parameter 1 are available. - We do not support any precursors of the Intel 80486. */ - asm("cpuid" : "=a"(eax), "=c"(ecx) : "0"(1) : "ebx", "edx"); - return !(~ecx & (1 << 19 | 1 << 1)); -} -#elif 0 /* defined _MSC_VER */ /* FIXME: implement the pclmul interface */ -#include -int crc32_pclmul_enabled(void) -{ - /* We assume that the CPUID instruction and its parameter 1 are available. - We do not support any precursors of the Intel 80486. */ - int regs[4]; - __cpuid(regs, 1); - return !(~regs[2] & (1 << 19 | 1 << 1)); -} -#else -int crc32_pclmul_enabled(void) -{ - return 0; + fold= _mm_xor_si128(fold, temp); + fold= _mm_xor_si128(fold, b); + } + + /** + * ------------------------------------------------- + * Reduction 128 -> 32 + * Assumes: \a fold holds 128bit folded data + */ +reduction_128_64: + k= _mm_load_si128((__m128i *) (¶ms->rk5)); + fold= crcr32_reduce_128_to_64(fold, k); + +barret_reduction: + k= _mm_load_si128((__m128i *) (¶ms->rk7)); + n= crcr32_reduce_64_to_32(fold, k); + return n; } -#endif +static const MY_ALIGNED(16) struct crcr_pclmulqdq_ctx ether_crc32_clmul= { + 0xccaa009e, /**< rk1 */ + 0x1751997d0, /**< rk2 */ + 0xccaa009e, /**< rk5 */ + 0x163cd6124, /**< rk6 */ + 0x1f7011640, /**< rk7 */ + 0x1db710641 /**< rk8 */ +}; + +/** + * @brief Calculates Ethernet CRC32 using PCLMULQDQ method. + * + * @param data pointer to data block to calculate CRC for + * @param data_len size of data block + * + * @return New CRC value + */ unsigned int crc32_pclmul(unsigned int crc32, const void *buf, size_t len) { - crc32= ~crc32; - crc32_intel_pclmul(&crc32, buf, len); - return ~crc32; + return ~crcr32_calc_pclmulqdq(buf, (uint32_t)len, ~crc32, ðer_crc32_clmul); } diff --git a/storage/innobase/ut/ut0crc32.cc b/storage/innobase/ut/ut0crc32.cc index 0f7efb8b5b7..c83bb19ad76 100644 --- a/storage/innobase/ut/ut0crc32.cc +++ b/storage/innobase/ut/ut0crc32.cc @@ -89,14 +89,17 @@ mysys/my_perf.c, contributed by Facebook under the following license. #ifdef HAVE_CPUID_INSTRUCTION # ifdef _MSC_VER # include -# elif defined __GNUC__ && !defined __clang__ && __GNUC__ < 5 -/* does not really work in GCC before version 5 */ -# define _mm_crc32_u8(crc,data) __builtin_ia32_crc32qi(crc,data) -# define _mm_crc32_u32(crc,data) __builtin_ia32_crc32si(crc,data) -# define _mm_crc32_u64(crc,data) __builtin_ia32_crc32di(crc,data) # else -# include -# endif +# include +# if defined __GNUC__ && !defined __clang__ && __GNUC__ < 5 +/* does not really work in GCC before version 5 */ +# define _mm_crc32_u8(crc,data) __builtin_ia32_crc32qi(crc,data) +# define _mm_crc32_u32(crc,data) __builtin_ia32_crc32si(crc,data) +# define _mm_crc32_u64(crc,data) __builtin_ia32_crc32di(crc,data) +# else +# include +# endif +# endif #endif /* CRC32 hardware implementation. */ @@ -122,9 +125,9 @@ static inline bool has_sse4_2() __cpuid(data, 1); return !!(data[2] & 1 << 20); # else - uint32_t eax, ecx; - asm("cpuid" : "=a"(eax), "=c"(ecx) : "a"(1) : "ebx", "edx"); - return !!(ecx & 1 << 20); + uint32_t reax = 0, rebx = 0, recx = 0, redx = 0; + __cpuid(1, reax, rebx, recx, redx); + return !!(recx & 1 << 20); # endif } -- cgit v1.2.1 From 2cc9e456933051506acfe20cda5b4fbf9c85c81c Mon Sep 17 00:00:00 2001 From: Kentoku SHIBA Date: Fri, 4 Sep 2020 22:10:57 +0900 Subject: 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 | 871 +++++++++++++++++++++------------ storage/spider/spd_db_mysql.cc | 677 +++++++++++++++++++++++-- storage/spider/spd_db_oracle.cc | 496 ++++++++++--------- storage/spider/spd_group_by_handler.cc | 15 + storage/spider/spd_include.h | 4 + storage/spider/spd_table.cc | 7 + 8 files changed, 1673 insertions(+), 598 deletions(-) diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 366554855d0..7b6bfafefc7 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -2106,6 +2106,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); @@ -2113,6 +2114,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)) @@ -2134,11 +2140,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); @@ -2174,6 +2184,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); @@ -2201,6 +2213,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) @@ -2603,6 +2617,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); @@ -2610,6 +2625,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)) @@ -2628,11 +2648,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); @@ -2668,6 +2692,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); @@ -2695,6 +2721,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) @@ -3074,6 +3102,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); @@ -3082,6 +3111,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)) @@ -3100,11 +3134,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); @@ -3140,6 +3178,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); @@ -3167,6 +3207,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) @@ -3463,6 +3505,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); @@ -3471,6 +3514,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)) @@ -3489,11 +3537,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); @@ -3529,6 +3581,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); @@ -3556,6 +3610,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) @@ -3912,6 +3968,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); @@ -3919,6 +3976,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)) @@ -3937,11 +3999,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); @@ -3977,6 +4043,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); @@ -4004,6 +4072,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) @@ -4604,6 +4674,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); @@ -4612,6 +4683,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)) @@ -4636,11 +4712,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); @@ -4677,6 +4757,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); @@ -4706,6 +4788,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) @@ -5415,6 +5499,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); @@ -5423,6 +5508,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)) @@ -5448,11 +5538,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); @@ -5495,6 +5589,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); @@ -5531,6 +5627,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); @@ -5558,6 +5656,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) @@ -6076,6 +6176,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); @@ -6084,6 +6185,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)) @@ -6108,11 +6214,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); @@ -6149,6 +6259,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); @@ -6178,6 +6290,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) @@ -6882,6 +6996,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); @@ -6890,6 +7005,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)) @@ -6915,11 +7035,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); @@ -6962,6 +7086,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); @@ -6998,6 +7124,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); @@ -7025,6 +7153,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) @@ -7557,6 +7687,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); @@ -7565,6 +7696,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)) @@ -7574,11 +7710,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); @@ -7614,6 +7754,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); @@ -7641,6 +7783,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) @@ -8174,6 +8318,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)) { @@ -8183,6 +8328,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( @@ -8192,10 +8343,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); @@ -8231,6 +8386,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); @@ -8258,6 +8415,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) @@ -11269,9 +11428,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 */ @@ -11289,6 +11451,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); @@ -13080,6 +13244,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)) { @@ -13089,6 +13254,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( @@ -13098,10 +13269,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); @@ -13139,6 +13314,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); @@ -13165,6 +13342,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 404d3b6754e..4b7ece6f265 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -3230,6 +3230,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); @@ -3270,6 +3271,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 @@ -3347,6 +3350,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); @@ -3357,11 +3362,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; @@ -3425,12 +3433,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 88371d85d5a..048df727778 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -214,22 +214,13 @@ int spider_db_ping_internal( ) { int error_num; DBUG_ENTER("spider_db_ping_internal"); - 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); if (conn->server_lost || conn->queued_connect) { if ((error_num = spider_db_connect(share, conn, all_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; @@ -242,11 +233,7 @@ int spider_db_ping_internal( { 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())) @@ -254,20 +241,12 @@ int spider_db_ping_internal( 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); } @@ -322,6 +301,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) { @@ -637,7 +617,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 @@ -645,25 +624,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", @@ -690,6 +662,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); } } @@ -705,6 +678,7 @@ int spider_db_before_query( } } conn->in_before_query = FALSE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(0); } @@ -717,6 +691,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) { @@ -759,6 +734,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) { @@ -773,6 +749,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); } @@ -794,6 +771,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); } @@ -806,6 +784,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); } @@ -831,6 +810,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); } @@ -852,6 +832,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); } @@ -868,6 +849,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); } @@ -877,6 +859,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); } @@ -899,6 +882,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); } @@ -907,6 +891,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); } @@ -929,33 +914,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 ( @@ -971,13 +948,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); @@ -987,12 +961,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) } @@ -1022,19 +990,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] @@ -1067,8 +1027,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] && @@ -1093,10 +1051,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); } @@ -1110,15 +1064,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); @@ -1156,6 +1111,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); @@ -1203,6 +1160,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); @@ -1230,6 +1189,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); @@ -3979,6 +3940,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); } @@ -3995,6 +3957,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); } @@ -4026,6 +3989,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); } @@ -4070,6 +4034,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); } @@ -4110,6 +4075,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); } @@ -4138,6 +4104,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); } @@ -4145,6 +4112,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); } @@ -4188,6 +4156,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); } @@ -4212,6 +4181,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); } @@ -4223,6 +4193,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); } @@ -4458,6 +4429,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); } @@ -4483,6 +4455,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); } @@ -4493,6 +4466,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); } @@ -4523,13 +4497,6 @@ int spider_db_store_result_for_reuse_cursor( { my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(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); - } -*/ DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); } if (!result_list->current) @@ -4540,13 +4507,6 @@ int spider_db_store_result_for_reuse_cursor( spider_malloc(spider_current_trx, 4, sizeof(*result_list->first), MYF(MY_WME | MY_ZEROFILL))) ) { -/* - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } -*/ DBUG_RETURN(HA_ERR_OUT_OF_MEM); } TMP_TABLE_PARAM *tmp_tbl_prm = (TMP_TABLE_PARAM *) @@ -4573,13 +4533,6 @@ int spider_db_store_result_for_reuse_cursor( spider_malloc(spider_current_trx, 5, sizeof(*result_list->last), MYF(MY_WME | MY_ZEROFILL))) ) { -/* - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } -*/ DBUG_RETURN(HA_ERR_OUT_OF_MEM); } TMP_TABLE_PARAM *tmp_tbl_prm = (TMP_TABLE_PARAM *) @@ -4609,13 +4562,6 @@ int spider_db_store_result_for_reuse_cursor( spider_malloc(spider_current_trx, 6, sizeof(*result_list->last), MYF(MY_WME | MY_ZEROFILL))) ) { -/* - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } -*/ DBUG_RETURN(HA_ERR_OUT_OF_MEM); } TMP_TABLE_PARAM *tmp_tbl_prm = (TMP_TABLE_PARAM *) @@ -4641,13 +4587,6 @@ int spider_db_store_result_for_reuse_cursor( } current->result = current->prev->result; current->result->set_limit(result_list->limit_num); -/* - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } -*/ current->record_num = current->result->num_rows(); current->dbton_id = current->result->dbton_id; result_list->record_num += current->record_num; @@ -4687,13 +4626,6 @@ int spider_db_store_result_for_reuse_cursor( current->result->set_limit(result_list->limit_num); current->prev->result = NULL; result_list->limit_num -= current->prev->record_num; -/* - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } -*/ } else { if (spider_bit_is_set(spider->db_request_phase, link_idx)) { @@ -4704,13 +4636,6 @@ int spider_db_store_result_for_reuse_cursor( DBUG_PRINT("info", ("spider conn[%p]->quick_target=%p", conn, spider)); conn->quick_target = spider; spider->quick_targets[link_idx] = spider; -/* - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } -*/ } current->dbton_id = current->result->dbton_id; SPIDER_DB_ROW *row; @@ -5003,15 +4928,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); @@ -5240,6 +5165,7 @@ int spider_db_seek_next( link_idx = link_idx_holder->link_idx; 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); @@ -5248,6 +5174,11 @@ int spider_db_seek_next( if ((error_num = dbton_handler->set_sql_for_exec(sql_type, link_idx))) { + 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_PRINT("info",("spider error_num 6=%d", error_num)); DBUG_RETURN(error_num); } @@ -5273,10 +5204,14 @@ int spider_db_seek_next( pthread_mutex_unlock(&conn->bg_conn_mutex); } else { 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); @@ -5297,6 +5232,8 @@ int spider_db_seek_next( result_list->quick_mode, &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); @@ -5309,6 +5246,8 @@ int spider_db_seek_next( DBUG_RETURN(error_num); } spider->connection_ids[link_idx] = 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 (fields->is_first_link_ok_chain(link_idx_chain)) @@ -5351,6 +5290,7 @@ int spider_db_seek_next( } 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); @@ -5359,6 +5299,11 @@ int spider_db_seek_next( 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_PRINT("info",("spider error_num 6=%d", error_num)); DBUG_RETURN(error_num); } @@ -5384,10 +5329,14 @@ int spider_db_seek_next( pthread_mutex_unlock(&conn->bg_conn_mutex); } else { 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); @@ -5424,6 +5373,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); @@ -5452,6 +5403,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) @@ -5497,6 +5450,8 @@ int spider_db_seek_next( #endif } 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))) { @@ -5623,6 +5578,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); @@ -5630,6 +5586,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)) @@ -5655,10 +5616,14 @@ int spider_db_seek_last( pthread_mutex_unlock(&conn->bg_conn_mutex); } else { 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); @@ -5695,6 +5660,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); @@ -5722,6 +5689,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) @@ -5844,6 +5813,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); @@ -5851,6 +5821,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)) @@ -5860,10 +5835,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); @@ -5900,6 +5879,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); @@ -5927,6 +5908,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) @@ -6644,8 +6627,6 @@ int spider_db_bulk_insert( #endif SPIDER_SHARE *share = spider->share; THD *thd = spider->wide_handler->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) @@ -6701,61 +6682,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] @@ -6795,15 +6765,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 && @@ -6830,8 +6797,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 (!insert_info && copy_info) { insert_info = @@ -6874,11 +6843,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; @@ -6887,14 +6853,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) @@ -6916,15 +6880,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(); @@ -6934,25 +6895,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 } @@ -6996,8 +6953,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, @@ -7005,6 +6965,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) @@ -7055,9 +7017,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 && @@ -7084,6 +7049,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); @@ -7211,6 +7178,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)) { @@ -7220,6 +7188,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( @@ -7230,7 +7204,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 { @@ -7296,6 +7274,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)) { @@ -7305,14 +7284,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); @@ -7325,7 +7304,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) @@ -7350,6 +7333,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)) { @@ -7359,6 +7343,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( @@ -7369,7 +7359,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); } } } @@ -7437,6 +7431,7 @@ int spider_db_update( #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 conn->ignore_dup_key = spider->wide_handler->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)) { @@ -7446,6 +7441,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( @@ -7455,10 +7456,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); @@ -7495,6 +7500,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); @@ -7534,6 +7541,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); @@ -7549,6 +7558,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); @@ -7579,6 +7590,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); @@ -7769,6 +7782,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); @@ -7776,6 +7790,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)) @@ -7791,10 +7810,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); @@ -7834,6 +7857,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); @@ -7907,6 +7932,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); @@ -7915,11 +7942,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); } @@ -8032,6 +8061,7 @@ int spider_db_direct_update( conn = spider->conns[roop_count]; sql_type = SPIDER_SQL_TYPE_UPDATE_SQL; 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); @@ -8039,6 +8069,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)) @@ -8054,10 +8089,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); @@ -8098,6 +8137,8 @@ int spider_db_direct_update( (error_num != HA_ERR_FOUND_DUPP_KEY || !spider->wide_handler->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); @@ -8135,11 +8176,13 @@ int spider_db_direct_update( DBUG_PRINT("info", ("spider found_rows = %llu", *found_rows)); counted = TRUE; } + DBUG_ASSERT(conn->mta_conn_mutex_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); } @@ -8181,8 +8224,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, @@ -8234,6 +8280,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); @@ -8242,6 +8290,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); @@ -8298,6 +8348,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)) { @@ -8307,6 +8358,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( @@ -8315,9 +8372,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))) @@ -8430,6 +8505,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); @@ -8437,6 +8513,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)) @@ -8452,10 +8533,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); @@ -8492,6 +8577,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); @@ -8518,6 +8605,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) @@ -8655,6 +8744,7 @@ int spider_db_direct_delete( conn = spider->conns[roop_count]; sql_type = SPIDER_SQL_TYPE_DELETE_SQL; 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); @@ -8662,6 +8752,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)) @@ -8677,10 +8772,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); @@ -8717,6 +8816,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); @@ -8743,6 +8844,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 (!counted) @@ -8791,6 +8894,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)) { @@ -8800,6 +8904,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( @@ -8809,6 +8919,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, @@ -8832,6 +8944,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); @@ -8861,6 +8975,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); @@ -8897,6 +9013,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); @@ -8924,6 +9042,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); @@ -8952,6 +9072,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); @@ -10825,7 +10947,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)) @@ -10848,9 +10977,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); @@ -10869,8 +10995,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) { @@ -11082,12 +11206,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) @@ -11117,21 +11243,15 @@ 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 ( #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) direct_sql->access_mode == 0 && #endif spider_dbton[conn->dbton_id].db_util->database_has_default_value() ) { - 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() || @@ -11140,8 +11260,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) || @@ -11155,7 +11273,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); @@ -11165,12 +11282,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); } } DBUG_RETURN(0); @@ -11182,25 +11293,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) || @@ -11215,17 +11318,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 @@ -11291,13 +11387,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); @@ -11313,6 +11414,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); @@ -11359,13 +11462,18 @@ int spider_db_udf_ping_table( my_afree(sql_buf); 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); @@ -11384,6 +11492,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); @@ -11393,6 +11503,8 @@ int spider_db_udf_ping_table( my_afree(sql_buf); 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); @@ -11613,13 +11725,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); @@ -11631,6 +11748,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); @@ -11646,6 +11765,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; my_afree(sql_buf); @@ -11659,9 +11780,18 @@ 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); + my_afree(sql_buf); + DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) { my_afree(sql_buf); DBUG_RETURN(error_num); @@ -11670,6 +11800,8 @@ int spider_db_udf_ping_table_mon_next( my_afree(sql_buf); 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); @@ -11756,8 +11888,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; @@ -11767,8 +11913,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 { @@ -11788,8 +11947,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; @@ -11802,11 +11975,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; } } @@ -11814,11 +11999,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, @@ -11847,6 +12044,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; @@ -11862,6 +12063,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; @@ -11888,6 +12093,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; @@ -11905,6 +12114,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; @@ -11917,12 +12130,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; @@ -11943,6 +12164,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)); @@ -11950,6 +12177,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); } @@ -11992,9 +12223,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, @@ -12004,6 +12238,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); @@ -12012,6 +12248,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); @@ -12152,8 +12390,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) @@ -12168,16 +12404,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; @@ -12227,11 +12461,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; @@ -12370,23 +12599,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); } @@ -12436,6 +12663,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; @@ -12475,24 +12703,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) { @@ -12500,7 +12723,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->wide_handler->trx->thd, @@ -12527,24 +12758,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); } diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 1337717dcad..0df67e4fb22 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -2306,10 +2306,6 @@ int spider_db_mbase::print_warnings( db_conn->warning_count #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, @@ -2327,18 +2323,10 @@ int spider_db_mbase::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_RETURN(0); } /* 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) { @@ -2373,11 +2361,6 @@ int spider_db_mbase::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); -*/ } } } @@ -2593,14 +2576,31 @@ int spider_db_mbase::consistent_snapshot( ) { DBUG_ENTER("spider_db_mbase::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); @@ -2618,16 +2618,18 @@ int spider_db_mbase::start_transaction( ) { DBUG_ENTER("spider_db_mbase::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); } @@ -2636,14 +2638,31 @@ int spider_db_mbase::commit( ) { DBUG_ENTER("spider_db_mbase::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); @@ -2656,6 +2675,13 @@ int spider_db_mbase::rollback( int error_num; DBUG_ENTER("spider_db_mbase::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, @@ -2672,12 +2698,18 @@ int spider_db_mbase::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); @@ -2714,14 +2746,31 @@ int spider_db_mbase::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); @@ -2740,14 +2789,31 @@ int spider_db_mbase::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); @@ -2766,14 +2832,31 @@ int spider_db_mbase::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); @@ -2792,14 +2875,31 @@ int spider_db_mbase::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); @@ -2821,50 +2921,118 @@ int spider_db_mbase::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; @@ -2889,25 +3057,59 @@ int spider_db_mbase::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); } @@ -2929,25 +3131,59 @@ int spider_db_mbase::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); } @@ -2979,14 +3215,31 @@ int spider_db_mbase::set_wait_timeout( DBUG_RETURN(HA_ERR_OUT_OF_MEM); sql_str.q_append(SPIDER_SQL_WAIT_TIMEOUT_STR, SPIDER_SQL_WAIT_TIMEOUT_LEN); sql_str.q_append(timeout_str, timeout_str_length); + 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); @@ -3027,14 +3280,31 @@ int spider_db_mbase::set_sql_mode( } } 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); @@ -3064,14 +3334,31 @@ int spider_db_mbase::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); @@ -3115,6 +3402,14 @@ int spider_db_mbase::set_loop_check( sql_str.q_append(lcptr->merged_value.str, lcptr->merged_value.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(), @@ -3122,8 +3417,16 @@ int spider_db_mbase::set_loop_check( -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); @@ -3181,9 +3484,12 @@ int spider_db_mbase::exec_simple_sql_with_result( ) { int error_num; DBUG_ENTER("spider_db_mbase::exec_simple_sql_with_result"); + 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; spider_conn_set_timeout_from_share(conn, all_link_idx, trx->thd, @@ -3209,6 +3515,8 @@ int spider_db_mbase::exec_simple_sql_with_result( if ((error_num = spider_db_ping_internal(share, conn, all_link_idx, 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; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -3219,6 +3527,8 @@ int spider_db_mbase::exec_simple_sql_with_result( if ((error_num = spider_db_set_names_internal(trx, share, conn, all_link_idx, 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; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -3235,12 +3545,16 @@ int spider_db_mbase::exec_simple_sql_with_result( -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_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); @@ -3251,18 +3565,29 @@ int spider_db_mbase::exec_simple_sql_with_result( } if (!(*res = store_result(NULL, NULL, &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); @@ -8142,6 +8467,14 @@ int spider_mbase_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; @@ -8156,14 +8489,15 @@ int spider_mbase_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 ( @@ -8180,6 +8514,8 @@ int spider_mbase_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); @@ -8199,6 +8535,8 @@ int spider_mbase_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); @@ -8207,6 +8545,8 @@ int spider_mbase_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); @@ -8219,6 +8559,8 @@ int spider_mbase_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); @@ -8235,6 +8577,8 @@ int spider_mbase_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); @@ -8247,6 +8591,8 @@ int spider_mbase_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); @@ -8255,6 +8601,8 @@ int spider_mbase_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); @@ -8267,6 +8615,8 @@ int spider_mbase_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); @@ -8278,6 +8628,8 @@ int spider_mbase_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); @@ -8290,6 +8642,8 @@ int spider_mbase_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); @@ -8298,6 +8652,8 @@ int spider_mbase_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); @@ -8310,6 +8666,8 @@ int spider_mbase_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); @@ -8318,6 +8676,8 @@ int spider_mbase_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); @@ -14003,9 +14363,12 @@ int spider_mbase_handler::show_table_status( 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; conn->disable_connect_retry = TRUE; @@ -14032,6 +14395,8 @@ int spider_mbase_handler::show_table_status( if ((error_num = spider_db_ping(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -14041,6 +14406,8 @@ int spider_mbase_handler::show_table_status( if ((error_num = spider_db_set_names(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -14058,12 +14425,16 @@ int spider_mbase_handler::show_table_status( &spider->need_mons[link_idx]) ) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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 { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -14080,6 +14451,8 @@ int spider_mbase_handler::show_table_status( if (spider_param_dry_access()) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -14089,9 +14462,17 @@ int spider_mbase_handler::show_table_status( if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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, @@ -14103,6 +14484,8 @@ int spider_mbase_handler::show_table_status( } } conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -14138,9 +14521,12 @@ int spider_mbase_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; conn->disable_connect_retry = TRUE; @@ -14167,6 +14553,8 @@ int spider_mbase_handler::show_table_status( if ((error_num = spider_db_ping(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -14176,6 +14564,8 @@ int spider_mbase_handler::show_table_status( if ((error_num = spider_db_set_names(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -14193,12 +14583,16 @@ int spider_mbase_handler::show_table_status( &spider->need_mons[link_idx]) ) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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 { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -14215,6 +14609,8 @@ int spider_mbase_handler::show_table_status( if (spider_param_dry_access()) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -14224,6 +14620,8 @@ int spider_mbase_handler::show_table_status( if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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))) @@ -14232,6 +14630,8 @@ int spider_mbase_handler::show_table_status( DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -14312,9 +14712,12 @@ int spider_mbase_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, @@ -14339,6 +14742,8 @@ int spider_mbase_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); @@ -14347,6 +14752,8 @@ int spider_mbase_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); @@ -14363,11 +14770,15 @@ int spider_mbase_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); @@ -14385,6 +14796,8 @@ int spider_mbase_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); @@ -14393,6 +14806,8 @@ int spider_mbase_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); @@ -14447,9 +14862,12 @@ int spider_mbase_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, @@ -14474,6 +14892,8 @@ int spider_mbase_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); @@ -14482,6 +14902,8 @@ int spider_mbase_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); @@ -14498,11 +14920,15 @@ int spider_mbase_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); @@ -14520,6 +14946,8 @@ int spider_mbase_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); @@ -14528,6 +14956,8 @@ int spider_mbase_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); @@ -14637,9 +15067,12 @@ int spider_mbase_handler::simple_action( DBUG_ASSERT(0); 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, @@ -14664,6 +15097,8 @@ int spider_mbase_handler::simple_action( /* 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); @@ -14673,6 +15108,8 @@ int spider_mbase_handler::simple_action( } 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); @@ -14690,12 +15127,16 @@ int spider_mbase_handler::simple_action( -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); @@ -14712,18 +15153,29 @@ int spider_mbase_handler::simple_action( 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); @@ -14809,9 +15261,12 @@ ha_rows spider_mbase_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, @@ -14838,6 +15293,8 @@ ha_rows spider_mbase_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); @@ -14848,6 +15305,8 @@ ha_rows spider_mbase_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); @@ -14867,6 +15326,8 @@ ha_rows spider_mbase_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); @@ -14876,6 +15337,8 @@ ha_rows spider_mbase_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); @@ -14895,6 +15358,8 @@ ha_rows spider_mbase_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); @@ -14902,6 +15367,8 @@ ha_rows spider_mbase_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); @@ -14909,6 +15376,8 @@ ha_rows spider_mbase_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); @@ -14941,13 +15410,18 @@ int spider_mbase_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); @@ -14964,10 +15438,14 @@ int spider_mbase_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); @@ -15003,14 +15481,31 @@ int spider_mbase_handler::unlock_tables( spider_conn_set_timeout_from_share(conn, link_idx, spider->wide_handler->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); } @@ -15033,13 +15528,18 @@ int spider_mbase_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); @@ -15056,11 +15556,15 @@ int spider_mbase_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); @@ -15083,13 +15587,18 @@ int spider_mbase_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); @@ -15106,11 +15615,15 @@ int spider_mbase_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); @@ -15134,13 +15647,18 @@ int spider_mbase_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); @@ -15157,11 +15675,15 @@ int spider_mbase_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); @@ -15185,13 +15707,18 @@ int spider_mbase_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); @@ -15208,11 +15735,15 @@ int spider_mbase_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); @@ -15235,13 +15766,18 @@ int spider_mbase_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); @@ -15258,11 +15794,15 @@ int spider_mbase_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); @@ -15285,13 +15825,18 @@ int spider_mbase_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); @@ -15308,11 +15853,15 @@ int spider_mbase_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); @@ -15339,6 +15888,14 @@ int spider_mbase_handler::flush_tables( spider_conn_set_timeout_from_share(conn, link_idx, spider->wide_handler->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(), @@ -15346,9 +15903,17 @@ int spider_mbase_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); @@ -15365,6 +15930,14 @@ int spider_mbase_handler::flush_logs( spider_conn_set_timeout_from_share(conn, link_idx, spider->wide_handler->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, @@ -15372,9 +15945,17 @@ int spider_mbase_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 7cc32316f68..e2a7e5941c1 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -1817,16 +1817,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); } @@ -2015,14 +2017,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; @@ -2033,14 +2052,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; @@ -2070,14 +2106,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 { @@ -2086,14 +2139,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); } @@ -11135,114 +11205,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->wide_handler->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->wide_handler->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->wide_handler->trx->spider_thread_id; - request_key.query_id = spider->wide_handler->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->stat.records) share->stat.records = 10000; share->stat.mean_rec_length = 65535; @@ -11253,9 +11215,12 @@ int spider_oracle_handler::show_table_status( share->stat.update_time = (time_t) 0; share->stat.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, @@ -11280,6 +11245,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); @@ -11288,6 +11255,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); @@ -11304,11 +11273,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); @@ -11324,6 +11297,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))) @@ -11331,6 +11306,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); @@ -11378,107 +11355,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->wide_handler->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->wide_handler->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->wide_handler->trx->spider_thread_id; - request_key.query_id = spider->wide_handler->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++) @@ -11490,19 +11366,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, @@ -11527,6 +11397,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); @@ -11535,6 +11407,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); @@ -11551,11 +11425,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); @@ -11573,6 +11451,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); @@ -11581,6 +11461,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); @@ -11626,9 +11508,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, @@ -11653,6 +11538,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); @@ -11662,6 +11549,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); @@ -11679,12 +11568,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); @@ -11701,18 +11594,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); @@ -11745,9 +11649,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, @@ -11772,6 +11679,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); @@ -11781,6 +11690,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); @@ -11798,12 +11709,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); @@ -11820,18 +11735,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); @@ -11941,9 +11867,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, @@ -11970,6 +11899,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); @@ -11980,6 +11911,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); @@ -11999,6 +11932,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); @@ -12008,6 +11943,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); @@ -12027,6 +11964,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); @@ -12034,6 +11973,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); @@ -12041,6 +11982,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); @@ -12074,13 +12017,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); @@ -12097,10 +12045,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); @@ -12146,13 +12098,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); @@ -12169,11 +12126,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); @@ -12196,13 +12157,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); @@ -12219,11 +12185,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); @@ -12247,13 +12217,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); @@ -12270,11 +12245,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); @@ -12298,13 +12277,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); @@ -12321,11 +12305,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); @@ -12348,13 +12336,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); @@ -12371,11 +12364,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); @@ -12398,13 +12395,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); @@ -12421,11 +12423,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); @@ -12452,6 +12458,14 @@ int spider_oracle_handler::flush_tables( spider_conn_set_timeout_from_share(conn, link_idx, spider->wide_handler->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(), @@ -12459,9 +12473,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); @@ -12478,6 +12500,14 @@ int spider_oracle_handler::flush_logs( spider_conn_set_timeout_from_share(conn, link_idx, spider->wide_handler->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, @@ -12485,9 +12515,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_group_by_handler.cc b/storage/spider/spd_group_by_handler.cc index d4ff18d129f..30d81b5a4ae 100644 --- a/storage/spider/spd_group_by_handler.cc +++ b/storage/spider/spd_group_by_handler.cc @@ -1411,6 +1411,7 @@ int spider_group_by_handler::init_scan() } } else { #endif + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_SELECT_SQL)) { @@ -1421,6 +1422,12 @@ int spider_group_by_handler::init_scan() dbton_hdl->set_sql_for_exec(SPIDER_SQL_TYPE_SELECT_SQL, link_idx, link_idx_chain))) { + 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( @@ -1430,11 +1437,15 @@ int spider_group_by_handler::init_scan() 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); @@ -1459,6 +1470,8 @@ int spider_group_by_handler::init_scan() spider->result_list.quick_mode, &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); @@ -1475,6 +1488,8 @@ int spider_group_by_handler::init_scan() DBUG_RETURN(error_num); } spider->connection_ids[link_idx] = 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 (fields->is_first_link_ok_chain(link_idx_chain)) diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index d339c63911d..bf6c415b745 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -19,6 +19,8 @@ #if MYSQL_VERSION_ID < 50500 #define spider_my_free(A,B) my_free(A,B) +#define pthread_mutex_assert_owner(A) +#define pthread_mutex_assert_not_owner(A) #else #define spider_my_free(A,B) my_free(A) #ifdef pthread_mutex_t @@ -41,6 +43,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 1664b4a1bf5..415f3be7b6c 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -6698,13 +6698,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); @@ -6717,6 +6722,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); -- cgit v1.2.1 From 9b688471274868ff94115fd6e4255ee01befedad Mon Sep 17 00:00:00 2001 From: Kentoku SHIBA Date: Fri, 4 Sep 2020 22:10:57 +0900 Subject: 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 | 823 ++++++++++++++++++++++----------- storage/spider/spd_db_mysql.cc | 661 ++++++++++++++++++++++++-- storage/spider/spd_db_oracle.cc | 492 +++++++++++--------- storage/spider/spd_group_by_handler.cc | 15 + storage/spider/spd_include.h | 4 + storage/spider/spd_table.cc | 7 + 8 files changed, 1658 insertions(+), 545 deletions(-) diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 1f4439161b2..b2600859b88 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -2333,6 +2333,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); @@ -2340,6 +2341,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)) @@ -2361,11 +2367,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); @@ -2401,6 +2411,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); @@ -2428,6 +2440,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) @@ -2829,6 +2843,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); @@ -2836,6 +2851,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)) @@ -2854,11 +2874,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); @@ -2894,6 +2918,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); @@ -2921,6 +2947,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) @@ -3299,6 +3327,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); @@ -3307,6 +3336,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)) @@ -3325,11 +3359,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); @@ -3365,6 +3403,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); @@ -3392,6 +3432,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) @@ -3687,6 +3729,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); @@ -3695,6 +3738,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)) @@ -3713,11 +3761,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); @@ -3753,6 +3805,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); @@ -3780,6 +3834,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) @@ -4135,6 +4191,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); @@ -4142,6 +4199,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)) @@ -4160,11 +4222,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); @@ -4200,6 +4266,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); @@ -4227,6 +4295,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) @@ -4824,6 +4894,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); @@ -4832,6 +4903,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)) @@ -4856,11 +4932,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); @@ -4897,6 +4977,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); @@ -4926,6 +5008,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) @@ -5634,6 +5718,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); @@ -5642,6 +5727,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)) @@ -5667,11 +5757,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); @@ -5714,6 +5808,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); @@ -5750,6 +5846,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); @@ -5777,6 +5875,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) @@ -6294,6 +6394,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); @@ -6302,6 +6403,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)) @@ -6326,11 +6432,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); @@ -6367,6 +6477,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); @@ -6396,6 +6508,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) @@ -7099,6 +7213,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); @@ -7107,6 +7222,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)) @@ -7132,11 +7252,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); @@ -7179,6 +7303,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); @@ -7215,6 +7341,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); @@ -7242,6 +7370,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) @@ -7765,6 +7895,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); @@ -7773,6 +7904,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)) @@ -7782,11 +7918,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); @@ -7822,6 +7962,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); @@ -7849,6 +7991,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) @@ -8381,6 +8525,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)) { @@ -8390,6 +8535,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( @@ -8399,10 +8550,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); @@ -8437,6 +8592,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); @@ -8464,6 +8621,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) @@ -11300,9 +11459,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 */ @@ -11320,6 +11482,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); @@ -13136,6 +13300,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)) { @@ -13145,6 +13310,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( @@ -13154,10 +13325,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); @@ -13195,6 +13370,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); @@ -13221,6 +13398,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 03afdfd68f8..1e973493ba8 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -2628,6 +2628,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); @@ -2668,6 +2669,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 @@ -2745,6 +2748,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); @@ -2755,11 +2760,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; @@ -2823,12 +2831,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 08d2591a07e..6d2afc1fd55 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -214,22 +214,13 @@ int spider_db_ping_internal( ) { int error_num; DBUG_ENTER("spider_db_ping_internal"); - 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); if (conn->server_lost || conn->queued_connect) { if ((error_num = spider_db_connect(share, conn, all_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; @@ -242,11 +233,7 @@ int spider_db_ping_internal( { 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())) @@ -254,20 +241,12 @@ int spider_db_ping_internal( 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); } @@ -322,6 +301,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) { @@ -616,7 +596,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 @@ -624,25 +603,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", @@ -669,6 +641,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); } } @@ -684,6 +657,7 @@ int spider_db_before_query( } } conn->in_before_query = FALSE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(0); } @@ -696,6 +670,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) { @@ -738,6 +713,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) { @@ -752,6 +728,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); } @@ -773,6 +750,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); } @@ -785,6 +763,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); } @@ -810,6 +789,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); } @@ -831,6 +811,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); } @@ -847,6 +828,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); } @@ -856,6 +838,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); } @@ -878,6 +861,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); } @@ -886,6 +870,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); } @@ -908,33 +893,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 ( @@ -949,13 +926,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); @@ -965,12 +939,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) } @@ -999,19 +967,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] @@ -1043,8 +1003,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] && @@ -1069,10 +1027,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); } @@ -1086,15 +1040,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); @@ -1131,6 +1086,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); @@ -1178,6 +1135,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); @@ -1205,6 +1164,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); @@ -3952,6 +3913,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); } @@ -3968,6 +3930,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); } @@ -3999,6 +3962,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); } @@ -4042,6 +4006,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); } @@ -4081,6 +4046,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); } @@ -4109,6 +4075,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); } @@ -4116,6 +4083,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); } @@ -4159,6 +4127,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); } @@ -4182,6 +4151,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); } @@ -4193,6 +4163,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); } @@ -4423,6 +4394,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); } @@ -4448,6 +4420,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); } @@ -4458,6 +4431,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); } @@ -4543,15 +4517,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); @@ -4780,6 +4754,7 @@ int spider_db_seek_next( link_idx = link_idx_holder->link_idx; 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); @@ -4788,6 +4763,11 @@ int spider_db_seek_next( if ((error_num = dbton_handler->set_sql_for_exec(sql_type, link_idx))) { + 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_PRINT("info",("spider error_num 6=%d", error_num)); DBUG_RETURN(error_num); } @@ -4797,10 +4777,14 @@ int spider_db_seek_next( 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); @@ -4821,6 +4805,8 @@ int spider_db_seek_next( result_list->quick_mode, &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); @@ -4833,6 +4819,8 @@ int spider_db_seek_next( DBUG_RETURN(error_num); } spider->connection_ids[link_idx] = 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 (fields->is_first_link_ok_chain(link_idx_chain)) @@ -4874,6 +4862,7 @@ int spider_db_seek_next( } 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); @@ -4882,6 +4871,11 @@ int spider_db_seek_next( 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_PRINT("info",("spider error_num 6=%d", error_num)); DBUG_RETURN(error_num); } @@ -4891,10 +4885,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); @@ -4931,6 +4929,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); @@ -4959,6 +4959,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) @@ -5003,6 +5005,8 @@ int spider_db_seek_next( #endif } 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))) { @@ -5129,6 +5133,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); @@ -5136,6 +5141,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)) @@ -5145,10 +5155,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); @@ -5184,6 +5198,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); @@ -5211,6 +5227,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) @@ -5332,6 +5350,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); @@ -5339,6 +5358,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)) @@ -5348,10 +5372,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); @@ -5387,6 +5415,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); @@ -5414,6 +5444,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) @@ -6124,8 +6156,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) @@ -6181,61 +6211,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] @@ -6274,15 +6293,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 && @@ -6309,8 +6325,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 (!insert_info && copy_info) { insert_info = @@ -6351,11 +6369,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; @@ -6364,14 +6379,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) @@ -6393,15 +6406,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(); @@ -6411,25 +6421,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 } @@ -6473,8 +6479,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, @@ -6482,6 +6491,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) @@ -6530,9 +6541,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 && @@ -6559,6 +6573,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); @@ -6686,6 +6702,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)) { @@ -6695,6 +6712,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( @@ -6705,7 +6728,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 { @@ -6771,6 +6798,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)) { @@ -6780,14 +6808,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); @@ -6800,7 +6828,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) @@ -6825,6 +6857,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)) { @@ -6834,6 +6867,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( @@ -6844,7 +6883,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); } } } @@ -6912,6 +6955,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)) { @@ -6921,6 +6965,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( @@ -6930,10 +6980,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); @@ -6969,6 +7023,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); @@ -7008,6 +7064,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); @@ -7022,6 +7080,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); @@ -7052,6 +7112,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); @@ -7242,6 +7304,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); @@ -7249,6 +7312,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)) @@ -7264,10 +7332,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); @@ -7306,6 +7378,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); @@ -7377,6 +7451,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); @@ -7385,11 +7461,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); } @@ -7502,6 +7580,7 @@ int spider_db_direct_update( conn = spider->conns[roop_count]; sql_type = SPIDER_SQL_TYPE_UPDATE_SQL; 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); @@ -7509,6 +7588,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)) @@ -7524,10 +7608,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); @@ -7566,6 +7654,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); @@ -7603,11 +7693,13 @@ int spider_db_direct_update( DBUG_PRINT("info", ("spider found_rows = %llu", *found_rows)); counted = TRUE; } + DBUG_ASSERT(conn->mta_conn_mutex_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); } @@ -7649,8 +7741,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, @@ -7700,6 +7795,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); @@ -7708,6 +7805,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); @@ -7764,6 +7863,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)) { @@ -7773,6 +7873,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( @@ -7781,9 +7887,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))) @@ -7896,6 +8020,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); @@ -7903,6 +8028,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)) @@ -7918,10 +8048,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); @@ -7957,6 +8091,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); @@ -7983,6 +8119,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) @@ -8118,6 +8256,7 @@ int spider_db_direct_delete( conn = spider->conns[roop_count]; sql_type = SPIDER_SQL_TYPE_DELETE_SQL; 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); @@ -8125,6 +8264,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)) @@ -8140,10 +8284,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); @@ -8179,6 +8327,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); @@ -8205,6 +8355,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 (!counted) @@ -8253,6 +8405,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)) { @@ -8262,6 +8415,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( @@ -8271,6 +8430,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, @@ -8293,6 +8454,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); @@ -8322,6 +8485,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); @@ -8357,6 +8522,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); @@ -8384,6 +8551,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); @@ -8412,6 +8581,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); @@ -10257,7 +10428,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)) @@ -10280,9 +10458,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); @@ -10301,8 +10476,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) { @@ -10514,12 +10687,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) @@ -10549,19 +10724,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() || @@ -10570,8 +10739,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) || @@ -10585,7 +10752,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); @@ -10595,12 +10761,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) } @@ -10614,25 +10774,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) || @@ -10647,17 +10799,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 @@ -10721,13 +10866,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); @@ -10743,6 +10893,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); @@ -10789,13 +10941,18 @@ int spider_db_udf_ping_table( my_afree(sql_buf); 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); @@ -10814,6 +10971,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); @@ -10823,6 +10982,8 @@ int spider_db_udf_ping_table( my_afree(sql_buf); 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); @@ -11028,13 +11189,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); @@ -11046,6 +11212,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); @@ -11061,6 +11229,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; my_afree(sql_buf); @@ -11074,9 +11244,18 @@ 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); + my_afree(sql_buf); + DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) { my_afree(sql_buf); DBUG_RETURN(error_num); @@ -11085,6 +11264,8 @@ int spider_db_udf_ping_table_mon_next( my_afree(sql_buf); 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); @@ -11171,8 +11352,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; @@ -11182,8 +11377,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 { @@ -11203,8 +11411,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; @@ -11217,11 +11439,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; } } @@ -11229,11 +11463,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, @@ -11262,6 +11508,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; @@ -11277,6 +11527,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; @@ -11303,6 +11557,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; @@ -11320,6 +11578,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; @@ -11332,12 +11594,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; @@ -11358,6 +11628,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)); @@ -11365,6 +11641,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); } @@ -11407,9 +11687,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, @@ -11419,6 +11702,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); @@ -11427,6 +11712,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); @@ -11567,8 +11854,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) @@ -11583,16 +11868,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; @@ -11641,11 +11924,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; @@ -11781,23 +12059,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); } @@ -11847,6 +12123,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; @@ -11885,24 +12162,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) { @@ -11910,7 +12182,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); @@ -11936,24 +12216,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); } @@ -11990,3 +12268,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 db610262c2b..420f14f9919 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -2292,10 +2292,6 @@ void spider_db_mbase::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, @@ -2313,18 +2309,10 @@ void spider_db_mbase::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) { @@ -2343,11 +2331,6 @@ void spider_db_mbase::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); -*/ } } } @@ -2562,14 +2545,31 @@ int spider_db_mbase::consistent_snapshot( ) { DBUG_ENTER("spider_db_mbase::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); @@ -2587,16 +2587,18 @@ int spider_db_mbase::start_transaction( ) { DBUG_ENTER("spider_db_mbase::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); } @@ -2605,14 +2607,31 @@ int spider_db_mbase::commit( ) { DBUG_ENTER("spider_db_mbase::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); @@ -2625,6 +2644,13 @@ int spider_db_mbase::rollback( int error_num; DBUG_ENTER("spider_db_mbase::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, @@ -2641,12 +2667,18 @@ int spider_db_mbase::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); @@ -2683,14 +2715,31 @@ int spider_db_mbase::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); @@ -2709,14 +2758,31 @@ int spider_db_mbase::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); @@ -2735,14 +2801,31 @@ int spider_db_mbase::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); @@ -2761,14 +2844,31 @@ int spider_db_mbase::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); @@ -2790,50 +2890,118 @@ int spider_db_mbase::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; @@ -2858,25 +3026,59 @@ int spider_db_mbase::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); } @@ -2898,25 +3100,59 @@ int spider_db_mbase::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); } @@ -2948,14 +3184,31 @@ int spider_db_mbase::set_wait_timeout( DBUG_RETURN(HA_ERR_OUT_OF_MEM); sql_str.q_append(SPIDER_SQL_WAIT_TIMEOUT_STR, SPIDER_SQL_WAIT_TIMEOUT_LEN); sql_str.q_append(timeout_str, timeout_str_length); + 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); @@ -2996,14 +3249,31 @@ int spider_db_mbase::set_sql_mode( } } 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); @@ -3033,14 +3303,31 @@ int spider_db_mbase::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); @@ -3057,9 +3344,12 @@ int spider_db_mbase::exec_simple_sql_with_result( ) { int error_num; DBUG_ENTER("spider_db_mbase::exec_simple_sql_with_result"); + 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; spider_conn_set_timeout_from_share(conn, all_link_idx, trx->thd, @@ -3085,6 +3375,8 @@ int spider_db_mbase::exec_simple_sql_with_result( if ((error_num = spider_db_ping_internal(share, conn, all_link_idx, 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; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -3095,6 +3387,8 @@ int spider_db_mbase::exec_simple_sql_with_result( if ((error_num = spider_db_set_names_internal(trx, share, conn, all_link_idx, 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; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -3111,12 +3405,16 @@ int spider_db_mbase::exec_simple_sql_with_result( -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_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); @@ -3127,18 +3425,29 @@ int spider_db_mbase::exec_simple_sql_with_result( } if (!(*res = store_result(NULL, NULL, &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); @@ -7968,6 +8277,14 @@ int spider_mbase_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; @@ -7980,14 +8297,15 @@ int spider_mbase_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 ( @@ -8004,6 +8322,8 @@ int spider_mbase_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); @@ -8023,6 +8343,8 @@ int spider_mbase_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); @@ -8031,6 +8353,8 @@ int spider_mbase_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); @@ -8043,6 +8367,8 @@ int spider_mbase_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); @@ -8059,6 +8385,8 @@ int spider_mbase_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); @@ -8071,6 +8399,8 @@ int spider_mbase_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); @@ -8079,6 +8409,8 @@ int spider_mbase_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); @@ -8091,6 +8423,8 @@ int spider_mbase_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); @@ -8102,6 +8436,8 @@ int spider_mbase_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); @@ -8114,6 +8450,8 @@ int spider_mbase_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); @@ -8122,6 +8460,8 @@ int spider_mbase_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); @@ -8134,6 +8474,8 @@ int spider_mbase_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); @@ -8142,6 +8484,8 @@ int spider_mbase_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); @@ -13580,9 +13924,12 @@ int spider_mbase_handler::show_table_status( 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; conn->disable_connect_retry = TRUE; @@ -13608,6 +13955,8 @@ int spider_mbase_handler::show_table_status( if ((error_num = spider_db_ping(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -13617,6 +13966,8 @@ int spider_mbase_handler::show_table_status( if ((error_num = spider_db_set_names(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -13633,12 +13984,16 @@ int spider_mbase_handler::show_table_status( &spider->need_mons[link_idx]) ) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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 { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -13655,6 +14010,8 @@ int spider_mbase_handler::show_table_status( if (spider_param_dry_access()) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -13664,9 +14021,17 @@ int spider_mbase_handler::show_table_status( if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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, @@ -13678,6 +14043,8 @@ int spider_mbase_handler::show_table_status( } } conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -13713,9 +14080,12 @@ int spider_mbase_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; conn->disable_connect_retry = TRUE; @@ -13741,6 +14111,8 @@ int spider_mbase_handler::show_table_status( if ((error_num = spider_db_ping(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -13750,6 +14122,8 @@ int spider_mbase_handler::show_table_status( if ((error_num = spider_db_set_names(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -13766,12 +14140,16 @@ int spider_mbase_handler::show_table_status( &spider->need_mons[link_idx]) ) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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 { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -13788,6 +14166,8 @@ int spider_mbase_handler::show_table_status( if (spider_param_dry_access()) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -13797,6 +14177,8 @@ int spider_mbase_handler::show_table_status( if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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))) @@ -13805,6 +14187,8 @@ int spider_mbase_handler::show_table_status( DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -13881,9 +14265,12 @@ int spider_mbase_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, @@ -13907,6 +14294,8 @@ int spider_mbase_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); @@ -13915,6 +14304,8 @@ int spider_mbase_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); @@ -13930,11 +14321,15 @@ int spider_mbase_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); @@ -13952,6 +14347,8 @@ int spider_mbase_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); @@ -13960,6 +14357,8 @@ int spider_mbase_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); @@ -14014,9 +14413,12 @@ int spider_mbase_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, @@ -14040,6 +14442,8 @@ int spider_mbase_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); @@ -14048,6 +14452,8 @@ int spider_mbase_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); @@ -14063,11 +14469,15 @@ int spider_mbase_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); @@ -14085,6 +14495,8 @@ int spider_mbase_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); @@ -14093,6 +14505,8 @@ int spider_mbase_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); @@ -14202,9 +14616,12 @@ int spider_mbase_handler::simple_action( DBUG_ASSERT(0); 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, @@ -14228,6 +14645,8 @@ int spider_mbase_handler::simple_action( /* 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); @@ -14237,6 +14656,8 @@ int spider_mbase_handler::simple_action( } 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); @@ -14253,12 +14674,16 @@ int spider_mbase_handler::simple_action( -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); @@ -14275,18 +14700,29 @@ int spider_mbase_handler::simple_action( 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); @@ -14372,9 +14808,12 @@ ha_rows spider_mbase_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, @@ -14400,6 +14839,8 @@ ha_rows spider_mbase_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); @@ -14410,6 +14851,8 @@ ha_rows spider_mbase_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); @@ -14428,6 +14871,8 @@ ha_rows spider_mbase_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); @@ -14437,6 +14882,8 @@ ha_rows spider_mbase_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); @@ -14456,6 +14903,8 @@ ha_rows spider_mbase_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); @@ -14463,6 +14912,8 @@ ha_rows spider_mbase_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); @@ -14470,6 +14921,8 @@ ha_rows spider_mbase_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); @@ -14502,13 +14955,18 @@ int spider_mbase_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); @@ -14524,10 +14982,14 @@ int spider_mbase_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); @@ -14562,14 +15024,31 @@ int spider_mbase_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); } @@ -14592,13 +15071,18 @@ int spider_mbase_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); @@ -14614,11 +15098,15 @@ int spider_mbase_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); @@ -14641,13 +15129,18 @@ int spider_mbase_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); @@ -14663,11 +15156,15 @@ int spider_mbase_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); @@ -14691,13 +15188,18 @@ int spider_mbase_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); @@ -14713,11 +15215,15 @@ int spider_mbase_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); @@ -14741,13 +15247,18 @@ int spider_mbase_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); @@ -14763,11 +15274,15 @@ int spider_mbase_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); @@ -14790,13 +15305,18 @@ int spider_mbase_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); @@ -14812,11 +15332,15 @@ int spider_mbase_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); @@ -14839,13 +15363,18 @@ int spider_mbase_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); @@ -14861,11 +15390,15 @@ int spider_mbase_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); @@ -14891,6 +15424,14 @@ int spider_mbase_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(), @@ -14898,9 +15439,17 @@ int spider_mbase_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); @@ -14916,6 +15465,14 @@ int spider_mbase_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, @@ -14923,9 +15480,17 @@ int spider_mbase_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 6df105e9898..b7561ccb96e 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -1812,16 +1812,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); } @@ -2010,14 +2012,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; @@ -2028,14 +2047,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; @@ -2065,14 +2101,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 { @@ -2081,14 +2134,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); } @@ -11123,112 +11193,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->stat.records) share->stat.records = 10000; share->stat.mean_rec_length = 65535; @@ -11239,9 +11203,12 @@ int spider_oracle_handler::show_table_status( share->stat.update_time = (time_t) 0; share->stat.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, @@ -11265,6 +11232,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); @@ -11273,6 +11242,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); @@ -11288,11 +11259,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); @@ -11308,6 +11283,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))) @@ -11315,6 +11292,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); @@ -11362,105 +11341,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++) @@ -11472,19 +11352,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, @@ -11508,6 +11382,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); @@ -11516,6 +11392,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); @@ -11531,11 +11409,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); @@ -11553,6 +11435,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); @@ -11561,6 +11445,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); @@ -11606,9 +11492,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, @@ -11632,6 +11521,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); @@ -11641,6 +11532,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); @@ -11657,12 +11550,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); @@ -11679,18 +11576,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); @@ -11723,9 +11631,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, @@ -11749,6 +11660,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); @@ -11758,6 +11671,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); @@ -11774,12 +11689,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); @@ -11796,18 +11715,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); @@ -11917,9 +11847,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, @@ -11945,6 +11878,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); @@ -11955,6 +11890,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); @@ -11973,6 +11910,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); @@ -11982,6 +11921,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); @@ -12001,6 +11942,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); @@ -12008,6 +11951,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); @@ -12015,6 +11960,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); @@ -12048,13 +11995,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); @@ -12070,10 +12022,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); @@ -12119,13 +12075,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); @@ -12141,11 +12102,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); @@ -12168,13 +12133,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); @@ -12190,11 +12160,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); @@ -12218,13 +12192,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); @@ -12240,11 +12219,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); @@ -12268,13 +12251,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); @@ -12290,11 +12278,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); @@ -12317,13 +12309,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); @@ -12339,11 +12336,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); @@ -12366,13 +12367,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); @@ -12388,11 +12394,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); @@ -12418,6 +12428,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(), @@ -12425,9 +12443,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); @@ -12443,6 +12469,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, @@ -12450,9 +12484,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_group_by_handler.cc b/storage/spider/spd_group_by_handler.cc index caa974bf8ee..de041897239 100644 --- a/storage/spider/spd_group_by_handler.cc +++ b/storage/spider/spd_group_by_handler.cc @@ -1410,6 +1410,7 @@ int spider_group_by_handler::init_scan() } } else { #endif + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_SELECT_SQL)) { @@ -1420,6 +1421,12 @@ int spider_group_by_handler::init_scan() dbton_hdl->set_sql_for_exec(SPIDER_SQL_TYPE_SELECT_SQL, link_idx, link_idx_chain))) { + 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( @@ -1429,11 +1436,15 @@ int spider_group_by_handler::init_scan() 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); @@ -1458,6 +1469,8 @@ int spider_group_by_handler::init_scan() spider->result_list.quick_mode, &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); @@ -1474,6 +1487,8 @@ int spider_group_by_handler::init_scan() DBUG_RETURN(error_num); } spider->connection_ids[link_idx] = 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 (fields->is_first_link_ok_chain(link_idx_chain)) diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index 2249d3e699c..95064fa4c72 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -19,6 +19,8 @@ #if MYSQL_VERSION_ID < 50500 #define spider_my_free(A,B) my_free(A,B) +#define pthread_mutex_assert_owner(A) +#define pthread_mutex_assert_not_owner(A) #else #define spider_my_free(A,B) my_free(A) #ifdef pthread_mutex_t @@ -41,6 +43,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 88effd38717..fd0ece10c1b 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -6383,13 +6383,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); @@ -6402,6 +6407,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); -- cgit v1.2.1 From e976f461d8c0e11a12453fa96f732a447b84420c Mon Sep 17 00:00:00 2001 From: Kentoku SHIBA Date: Fri, 4 Sep 2020 22:10:57 +0900 Subject: 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 | 823 ++++++++++++++++++++++----------- storage/spider/spd_db_mysql.cc | 623 +++++++++++++++++++++++-- storage/spider/spd_db_oracle.cc | 492 +++++++++++--------- storage/spider/spd_group_by_handler.cc | 15 + storage/spider/spd_include.h | 4 + storage/spider/spd_table.cc | 7 + 8 files changed, 1622 insertions(+), 543 deletions(-) diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 967d2c6e5de..2b993fa7e9c 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -2331,6 +2331,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); @@ -2338,6 +2339,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)) @@ -2359,11 +2365,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); @@ -2399,6 +2409,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); @@ -2426,6 +2438,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) @@ -2827,6 +2841,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); @@ -2834,6 +2849,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)) @@ -2852,11 +2872,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); @@ -2892,6 +2916,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); @@ -2919,6 +2945,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) @@ -3297,6 +3325,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); @@ -3305,6 +3334,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)) @@ -3323,11 +3357,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); @@ -3363,6 +3401,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); @@ -3390,6 +3430,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) @@ -3685,6 +3727,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); @@ -3693,6 +3736,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)) @@ -3711,11 +3759,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); @@ -3751,6 +3803,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); @@ -3778,6 +3832,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) @@ -4133,6 +4189,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); @@ -4140,6 +4197,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)) @@ -4158,11 +4220,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); @@ -4198,6 +4264,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); @@ -4225,6 +4293,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) @@ -4763,6 +4833,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); @@ -4771,6 +4842,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)) @@ -4795,11 +4871,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); @@ -4836,6 +4916,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); @@ -4865,6 +4947,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) @@ -5560,6 +5644,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); @@ -5568,6 +5653,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)) @@ -5593,11 +5683,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); @@ -5640,6 +5734,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); @@ -5676,6 +5772,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); @@ -5703,6 +5801,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) @@ -6212,6 +6312,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); @@ -6220,6 +6321,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)) @@ -6244,11 +6350,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); @@ -6285,6 +6395,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); @@ -6314,6 +6426,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) @@ -7013,6 +7127,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); @@ -7021,6 +7136,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)) @@ -7046,11 +7166,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); @@ -7093,6 +7217,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); @@ -7129,6 +7255,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); @@ -7156,6 +7284,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) @@ -7675,6 +7805,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); @@ -7683,6 +7814,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)) @@ -7692,11 +7828,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); @@ -7732,6 +7872,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); @@ -7759,6 +7901,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) @@ -8291,6 +8435,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)) { @@ -8300,6 +8445,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( @@ -8309,10 +8460,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); @@ -8347,6 +8502,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); @@ -8374,6 +8531,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) @@ -11135,9 +11294,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 */ @@ -11155,6 +11317,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); @@ -12970,6 +13134,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)) { @@ -12979,6 +13144,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( @@ -12988,10 +13159,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); @@ -13029,6 +13204,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); @@ -13055,6 +13232,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 4a8de844ca9..e7e48b40add 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -2594,6 +2594,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); @@ -2634,6 +2635,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 @@ -2711,6 +2714,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); @@ -2721,11 +2726,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; @@ -2789,12 +2797,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 bf576f2359e..e87321f896d 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -213,22 +213,13 @@ int spider_db_ping_internal( ) { int error_num; DBUG_ENTER("spider_db_ping_internal"); - 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); if (conn->server_lost || conn->queued_connect) { if ((error_num = spider_db_connect(share, conn, all_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; @@ -241,11 +232,7 @@ int spider_db_ping_internal( { 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())) @@ -253,20 +240,12 @@ int spider_db_ping_internal( 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); } @@ -321,6 +300,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) { @@ -569,7 +549,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 @@ -577,25 +556,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", @@ -622,6 +594,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); } } @@ -637,6 +610,7 @@ int spider_db_before_query( } } conn->in_before_query = FALSE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(0); } @@ -649,6 +623,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) { @@ -691,6 +666,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) { @@ -705,6 +681,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); } @@ -726,6 +703,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); } @@ -738,6 +716,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); } @@ -763,6 +742,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); } @@ -784,6 +764,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); } @@ -800,6 +781,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); } @@ -809,6 +791,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); } @@ -831,6 +814,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); } @@ -839,6 +823,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); } @@ -861,33 +846,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 ( @@ -902,13 +879,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); @@ -918,12 +892,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) } @@ -952,19 +920,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] @@ -996,8 +956,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] && @@ -1022,10 +980,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); } @@ -1039,15 +993,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); @@ -1084,6 +1039,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); @@ -1131,6 +1088,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); @@ -1158,6 +1117,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); @@ -3751,6 +3712,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); } @@ -3767,6 +3729,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); } @@ -3798,6 +3761,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); } @@ -3841,6 +3805,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); } @@ -3880,6 +3845,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); } @@ -3908,6 +3874,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); } @@ -3915,6 +3882,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); } @@ -3958,6 +3926,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); } @@ -3981,6 +3950,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); } @@ -3992,6 +3962,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); } @@ -4222,6 +4193,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); } @@ -4247,6 +4219,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); } @@ -4257,6 +4230,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); } @@ -4342,15 +4316,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); @@ -4579,6 +4553,7 @@ int spider_db_seek_next( link_idx = link_idx_holder->link_idx; 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); @@ -4587,6 +4562,11 @@ int spider_db_seek_next( if ((error_num = dbton_handler->set_sql_for_exec(sql_type, link_idx))) { + 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_PRINT("info",("spider error_num 6=%d", error_num)); DBUG_RETURN(error_num); } @@ -4596,10 +4576,14 @@ int spider_db_seek_next( 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); @@ -4620,6 +4604,8 @@ int spider_db_seek_next( result_list->quick_mode, &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); @@ -4632,6 +4618,8 @@ int spider_db_seek_next( DBUG_RETURN(error_num); } spider->connection_ids[link_idx] = 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 (fields->is_first_link_ok_chain(link_idx_chain)) @@ -4673,6 +4661,7 @@ int spider_db_seek_next( } 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); @@ -4681,6 +4670,11 @@ int spider_db_seek_next( 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_PRINT("info",("spider error_num 6=%d", error_num)); DBUG_RETURN(error_num); } @@ -4690,10 +4684,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); @@ -4730,6 +4728,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); @@ -4758,6 +4758,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) @@ -4802,6 +4804,8 @@ int spider_db_seek_next( #endif } 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))) { @@ -4928,6 +4932,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); @@ -4935,6 +4940,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)) @@ -4944,10 +4954,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); @@ -4983,6 +4997,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); @@ -5010,6 +5026,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) @@ -5131,6 +5149,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); @@ -5138,6 +5157,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)) @@ -5147,10 +5171,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); @@ -5186,6 +5214,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); @@ -5213,6 +5243,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) @@ -5886,8 +5918,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) @@ -5942,61 +5972,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] @@ -6035,15 +6054,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 && @@ -6070,8 +6086,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) { @@ -6107,11 +6125,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; @@ -6120,14 +6135,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) @@ -6149,15 +6162,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(); @@ -6167,25 +6177,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 } @@ -6229,8 +6235,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, @@ -6238,6 +6247,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) @@ -6286,9 +6297,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 && @@ -6315,6 +6329,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); @@ -6442,6 +6458,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)) { @@ -6451,6 +6468,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( @@ -6461,7 +6484,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 { @@ -6527,6 +6554,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)) { @@ -6536,14 +6564,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); @@ -6556,7 +6584,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) @@ -6581,6 +6613,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)) { @@ -6590,6 +6623,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( @@ -6600,7 +6639,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); } } } @@ -6668,6 +6711,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)) { @@ -6677,6 +6721,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( @@ -6686,10 +6736,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); @@ -6725,6 +6779,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); @@ -6764,6 +6820,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); @@ -6778,6 +6836,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); @@ -6808,6 +6868,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); @@ -6997,6 +7059,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); @@ -7004,6 +7067,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)) @@ -7019,10 +7087,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); @@ -7061,6 +7133,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); @@ -7128,6 +7202,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); @@ -7136,11 +7212,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); } @@ -7252,6 +7330,7 @@ int spider_db_direct_update( conn = spider->conns[roop_count]; sql_type = SPIDER_SQL_TYPE_UPDATE_SQL; 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); @@ -7259,6 +7338,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)) @@ -7274,10 +7358,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); @@ -7316,6 +7404,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); @@ -7351,11 +7441,13 @@ int spider_db_direct_update( DBUG_PRINT("info", ("spider update_rows = %llu", *update_rows)); counted = TRUE; } + DBUG_ASSERT(conn->mta_conn_mutex_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); } @@ -7396,8 +7488,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, @@ -7443,6 +7538,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); @@ -7451,6 +7548,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); @@ -7507,6 +7606,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)) { @@ -7516,6 +7616,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( @@ -7524,9 +7630,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))) @@ -7639,6 +7763,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); @@ -7646,6 +7771,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)) @@ -7661,10 +7791,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); @@ -7700,6 +7834,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); @@ -7726,6 +7862,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) @@ -7861,6 +7999,7 @@ int spider_db_direct_delete( conn = spider->conns[roop_count]; sql_type = SPIDER_SQL_TYPE_DELETE_SQL; 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); @@ -7868,6 +8007,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)) @@ -7883,10 +8027,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); @@ -7922,6 +8070,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); @@ -7948,6 +8098,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 (!counted) @@ -7996,6 +8148,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)) { @@ -8005,6 +8158,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( @@ -8014,6 +8173,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, @@ -8036,6 +8197,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); @@ -8065,6 +8228,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); @@ -8100,6 +8265,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); @@ -8127,6 +8294,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); @@ -8155,6 +8324,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); @@ -9940,7 +10111,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)) @@ -9963,9 +10141,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); @@ -9984,8 +10159,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) { @@ -10197,12 +10370,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) @@ -10232,19 +10407,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() || @@ -10253,8 +10422,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) || @@ -10268,7 +10435,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); @@ -10278,12 +10444,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) } @@ -10297,25 +10457,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) || @@ -10330,17 +10482,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 @@ -10404,13 +10549,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); @@ -10426,6 +10576,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); @@ -10472,13 +10624,18 @@ int spider_db_udf_ping_table( my_afree(sql_buf); 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); @@ -10497,6 +10654,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); @@ -10506,6 +10665,8 @@ int spider_db_udf_ping_table( my_afree(sql_buf); 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); @@ -10711,13 +10872,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); @@ -10729,6 +10895,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); @@ -10744,6 +10912,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; my_afree(sql_buf); @@ -10757,9 +10927,18 @@ 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); + my_afree(sql_buf); + DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) { my_afree(sql_buf); DBUG_RETURN(error_num); @@ -10768,6 +10947,8 @@ int spider_db_udf_ping_table_mon_next( my_afree(sql_buf); 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); @@ -10854,8 +11035,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; @@ -10865,8 +11060,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 { @@ -10886,8 +11094,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; @@ -10900,11 +11122,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; } } @@ -10912,11 +11146,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, @@ -10945,6 +11191,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; @@ -10960,6 +11210,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; @@ -10986,6 +11240,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; @@ -11003,6 +11261,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; @@ -11015,12 +11277,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; @@ -11041,6 +11311,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)); @@ -11048,6 +11324,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); } @@ -11090,9 +11370,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, @@ -11102,6 +11385,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); @@ -11110,6 +11395,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); @@ -11250,8 +11537,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) @@ -11266,16 +11551,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; @@ -11324,11 +11607,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; @@ -11464,23 +11742,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); } @@ -11530,6 +11806,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; @@ -11568,24 +11845,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) { @@ -11593,7 +11865,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); @@ -11619,24 +11899,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); } @@ -11673,3 +11951,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 6ee4be4c7cc..128cd494e7f 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -2185,10 +2185,6 @@ void spider_db_mbase::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, @@ -2206,18 +2202,10 @@ void spider_db_mbase::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) { @@ -2236,11 +2224,6 @@ void spider_db_mbase::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); -*/ } } } @@ -2380,14 +2363,31 @@ int spider_db_mbase::consistent_snapshot( ) { DBUG_ENTER("spider_db_mbase::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); @@ -2405,16 +2405,18 @@ int spider_db_mbase::start_transaction( ) { DBUG_ENTER("spider_db_mbase::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); } @@ -2423,14 +2425,31 @@ int spider_db_mbase::commit( ) { DBUG_ENTER("spider_db_mbase::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); @@ -2443,6 +2462,13 @@ int spider_db_mbase::rollback( int error_num; DBUG_ENTER("spider_db_mbase::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, @@ -2459,12 +2485,18 @@ int spider_db_mbase::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); @@ -2501,14 +2533,31 @@ int spider_db_mbase::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); @@ -2527,14 +2576,31 @@ int spider_db_mbase::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); @@ -2553,14 +2619,31 @@ int spider_db_mbase::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); @@ -2579,14 +2662,31 @@ int spider_db_mbase::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); @@ -2608,50 +2708,118 @@ int spider_db_mbase::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; @@ -2676,25 +2844,59 @@ int spider_db_mbase::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); } @@ -2716,25 +2918,59 @@ int spider_db_mbase::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); } @@ -2765,14 +3001,31 @@ int spider_db_mbase::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); @@ -2789,9 +3042,12 @@ int spider_db_mbase::exec_simple_sql_with_result( ) { int error_num; DBUG_ENTER("spider_db_mbase::exec_simple_sql_with_result"); + 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; spider_conn_set_timeout_from_share(conn, all_link_idx, trx->thd, @@ -2817,6 +3073,8 @@ int spider_db_mbase::exec_simple_sql_with_result( if ((error_num = spider_db_ping_internal(share, conn, all_link_idx, 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; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -2827,6 +3085,8 @@ int spider_db_mbase::exec_simple_sql_with_result( if ((error_num = spider_db_set_names_internal(trx, share, conn, all_link_idx, 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; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -2843,12 +3103,16 @@ int spider_db_mbase::exec_simple_sql_with_result( -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_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); @@ -2859,18 +3123,29 @@ int spider_db_mbase::exec_simple_sql_with_result( } if (!(*res = store_result(NULL, NULL, &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); @@ -6507,6 +6782,14 @@ int spider_mbase_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; @@ -6519,14 +6802,15 @@ int spider_mbase_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 ( @@ -6543,6 +6827,8 @@ int spider_mbase_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); @@ -6562,6 +6848,8 @@ int spider_mbase_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); @@ -6570,6 +6858,8 @@ int spider_mbase_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); @@ -6582,6 +6872,8 @@ int spider_mbase_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); @@ -6598,6 +6890,8 @@ int spider_mbase_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); @@ -6610,6 +6904,8 @@ int spider_mbase_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); @@ -6618,6 +6914,8 @@ int spider_mbase_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); @@ -6630,6 +6928,8 @@ int spider_mbase_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); @@ -6641,6 +6941,8 @@ int spider_mbase_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); @@ -6653,6 +6955,8 @@ int spider_mbase_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); @@ -6661,6 +6965,8 @@ int spider_mbase_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); @@ -6673,6 +6979,8 @@ int spider_mbase_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); @@ -6681,6 +6989,8 @@ int spider_mbase_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); @@ -12076,9 +12386,12 @@ int spider_mbase_handler::show_table_status( 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; conn->disable_connect_retry = TRUE; @@ -12104,6 +12417,8 @@ int spider_mbase_handler::show_table_status( if ((error_num = spider_db_ping(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -12113,6 +12428,8 @@ int spider_mbase_handler::show_table_status( if ((error_num = spider_db_set_names(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -12129,12 +12446,16 @@ int spider_mbase_handler::show_table_status( &spider->need_mons[link_idx]) ) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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 { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -12151,6 +12472,8 @@ int spider_mbase_handler::show_table_status( if (spider_param_dry_access()) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -12160,9 +12483,17 @@ int spider_mbase_handler::show_table_status( if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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, @@ -12174,6 +12505,8 @@ int spider_mbase_handler::show_table_status( } } conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -12216,9 +12549,12 @@ int spider_mbase_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; conn->disable_connect_retry = TRUE; @@ -12244,6 +12580,8 @@ int spider_mbase_handler::show_table_status( if ((error_num = spider_db_ping(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -12253,6 +12591,8 @@ int spider_mbase_handler::show_table_status( if ((error_num = spider_db_set_names(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -12269,12 +12609,16 @@ int spider_mbase_handler::show_table_status( &spider->need_mons[link_idx]) ) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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 { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -12291,6 +12635,8 @@ int spider_mbase_handler::show_table_status( if (spider_param_dry_access()) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -12300,6 +12646,8 @@ int spider_mbase_handler::show_table_status( if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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))) @@ -12308,6 +12656,8 @@ int spider_mbase_handler::show_table_status( DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -12391,9 +12741,12 @@ int spider_mbase_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, @@ -12417,6 +12770,8 @@ int spider_mbase_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); @@ -12425,6 +12780,8 @@ int spider_mbase_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); @@ -12440,11 +12797,15 @@ int spider_mbase_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); @@ -12462,6 +12823,8 @@ int spider_mbase_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); @@ -12470,6 +12833,8 @@ int spider_mbase_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); @@ -12524,9 +12889,12 @@ int spider_mbase_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, @@ -12550,6 +12918,8 @@ int spider_mbase_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); @@ -12558,6 +12928,8 @@ int spider_mbase_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); @@ -12573,11 +12945,15 @@ int spider_mbase_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); @@ -12595,6 +12971,8 @@ int spider_mbase_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); @@ -12603,6 +12981,8 @@ int spider_mbase_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); @@ -12669,9 +13049,12 @@ int spider_mbase_handler::show_records( SPIDER_SHARE *share = spider->share; uint pos = spider->conn_link_idx[link_idx]; DBUG_ENTER("spider_mbase_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, @@ -12695,6 +13078,8 @@ int spider_mbase_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); @@ -12704,6 +13089,8 @@ int spider_mbase_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); @@ -12720,12 +13107,16 @@ int spider_mbase_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); @@ -12742,18 +13133,29 @@ int spider_mbase_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); @@ -12803,9 +13205,12 @@ ha_rows spider_mbase_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, @@ -12831,6 +13236,8 @@ ha_rows spider_mbase_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); @@ -12841,6 +13248,8 @@ ha_rows spider_mbase_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); @@ -12859,6 +13268,8 @@ ha_rows spider_mbase_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); @@ -12868,6 +13279,8 @@ ha_rows spider_mbase_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); @@ -12887,6 +13300,8 @@ ha_rows spider_mbase_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); @@ -12894,6 +13309,8 @@ ha_rows spider_mbase_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); @@ -12901,6 +13318,8 @@ ha_rows spider_mbase_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); @@ -12933,13 +13352,18 @@ int spider_mbase_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); @@ -12955,10 +13379,14 @@ int spider_mbase_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); @@ -12993,14 +13421,31 @@ int spider_mbase_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); } @@ -13023,13 +13468,18 @@ int spider_mbase_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); @@ -13045,11 +13495,15 @@ int spider_mbase_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); @@ -13072,13 +13526,18 @@ int spider_mbase_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); @@ -13094,11 +13553,15 @@ int spider_mbase_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); @@ -13122,13 +13585,18 @@ int spider_mbase_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); @@ -13144,11 +13612,15 @@ int spider_mbase_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); @@ -13172,13 +13644,18 @@ int spider_mbase_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); @@ -13194,11 +13671,15 @@ int spider_mbase_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); @@ -13221,13 +13702,18 @@ int spider_mbase_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); @@ -13243,11 +13729,15 @@ int spider_mbase_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); @@ -13270,13 +13760,18 @@ int spider_mbase_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); @@ -13292,11 +13787,15 @@ int spider_mbase_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); @@ -13322,6 +13821,14 @@ int spider_mbase_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(), @@ -13329,9 +13836,17 @@ int spider_mbase_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); @@ -13347,6 +13862,14 @@ int spider_mbase_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, @@ -13354,9 +13877,17 @@ int spider_mbase_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 08d7d3e083d..d3147c19f2f 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -1804,16 +1804,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); } @@ -2002,14 +2004,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; @@ -2020,14 +2039,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; @@ -2057,14 +2093,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 { @@ -2073,14 +2126,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); } @@ -10990,112 +11060,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; @@ -11106,9 +11070,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, @@ -11132,6 +11099,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); @@ -11140,6 +11109,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); @@ -11155,11 +11126,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); @@ -11175,6 +11150,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))) @@ -11182,6 +11159,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); @@ -11236,105 +11215,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++) @@ -11346,19 +11226,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, @@ -11382,6 +11256,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); @@ -11390,6 +11266,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); @@ -11405,11 +11283,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); @@ -11427,6 +11309,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); @@ -11435,6 +11319,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); @@ -11480,9 +11366,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, @@ -11506,6 +11395,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); @@ -11515,6 +11406,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); @@ -11531,12 +11424,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); @@ -11553,18 +11450,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); @@ -11597,9 +11505,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, @@ -11623,6 +11534,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); @@ -11632,6 +11545,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); @@ -11648,12 +11563,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); @@ -11670,18 +11589,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); @@ -11791,9 +11721,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, @@ -11819,6 +11752,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); @@ -11829,6 +11764,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); @@ -11847,6 +11784,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); @@ -11856,6 +11795,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); @@ -11875,6 +11816,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); @@ -11882,6 +11825,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); @@ -11889,6 +11834,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); @@ -11922,13 +11869,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); @@ -11944,10 +11896,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); @@ -11993,13 +11949,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); @@ -12015,11 +11976,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); @@ -12042,13 +12007,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); @@ -12064,11 +12034,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); @@ -12092,13 +12066,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); @@ -12114,11 +12093,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); @@ -12142,13 +12125,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); @@ -12164,11 +12152,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); @@ -12191,13 +12183,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); @@ -12213,11 +12210,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); @@ -12240,13 +12241,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); @@ -12262,11 +12268,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); @@ -12292,6 +12302,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(), @@ -12299,9 +12317,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); @@ -12317,6 +12343,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, @@ -12324,9 +12358,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_group_by_handler.cc b/storage/spider/spd_group_by_handler.cc index 3b57092c4ce..c83ee753e5b 100644 --- a/storage/spider/spd_group_by_handler.cc +++ b/storage/spider/spd_group_by_handler.cc @@ -1410,6 +1410,7 @@ int spider_group_by_handler::init_scan() } } else { #endif + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_SELECT_SQL)) { @@ -1420,6 +1421,12 @@ int spider_group_by_handler::init_scan() dbton_hdl->set_sql_for_exec(SPIDER_SQL_TYPE_SELECT_SQL, link_idx, link_idx_chain))) { + 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( @@ -1429,11 +1436,15 @@ int spider_group_by_handler::init_scan() 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); @@ -1458,6 +1469,8 @@ int spider_group_by_handler::init_scan() spider->result_list.quick_mode, &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); @@ -1474,6 +1487,8 @@ int spider_group_by_handler::init_scan() DBUG_RETURN(error_num); } spider->connection_ids[link_idx] = 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 (fields->is_first_link_ok_chain(link_idx_chain)) diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index c32b476b474..b0a3dae72ba 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -18,6 +18,8 @@ #if MYSQL_VERSION_ID < 50500 #define spider_my_free(A,B) my_free(A,B) +#define pthread_mutex_assert_owner(A) +#define pthread_mutex_assert_not_owner(A) #else #define spider_my_free(A,B) my_free(A) #ifdef pthread_mutex_t @@ -40,6 +42,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 83c5a37555f..ca3b7fa08ed 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -6355,13 +6355,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); @@ -6374,6 +6379,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); -- cgit v1.2.1 From 9dedba16ab12976487377208afe4721ea7b322ce Mon Sep 17 00:00:00 2001 From: Kentoku SHIBA Date: Fri, 4 Sep 2020 22:10:57 +0900 Subject: 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 fb453ddc637..5e7b5a1e8ce 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -2258,6 +2258,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); @@ -2265,6 +2266,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)) @@ -2286,11 +2292,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); @@ -2325,6 +2335,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); @@ -2351,6 +2363,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) @@ -2750,6 +2764,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); @@ -2757,6 +2772,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)) @@ -2775,11 +2795,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); @@ -2814,6 +2838,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); @@ -2840,6 +2866,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) @@ -3216,6 +3244,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); @@ -3224,6 +3253,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)) @@ -3242,11 +3276,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); @@ -3281,6 +3319,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); @@ -3307,6 +3347,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) @@ -3600,6 +3642,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); @@ -3608,6 +3651,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)) @@ -3626,11 +3674,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); @@ -3665,6 +3717,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); @@ -3691,6 +3745,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) @@ -4044,6 +4100,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); @@ -4051,6 +4108,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)) @@ -4069,11 +4131,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); @@ -4108,6 +4174,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); @@ -4134,6 +4202,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) @@ -4670,6 +4740,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); @@ -4678,6 +4749,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)) @@ -4702,11 +4778,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); @@ -4742,6 +4822,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); @@ -4770,6 +4852,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) @@ -5463,6 +5547,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); @@ -5471,6 +5556,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)) @@ -5496,11 +5586,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); @@ -5542,6 +5636,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); @@ -5577,6 +5673,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); @@ -5603,6 +5701,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) @@ -6110,6 +6210,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); @@ -6118,6 +6219,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)) @@ -6142,11 +6248,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); @@ -6182,6 +6292,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); @@ -6210,6 +6322,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) @@ -6907,6 +7021,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); @@ -6915,6 +7030,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)) @@ -6940,11 +7060,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); @@ -6986,6 +7110,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); @@ -7021,6 +7147,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); @@ -7047,6 +7175,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) @@ -7524,6 +7654,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); @@ -7532,6 +7663,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)) @@ -7541,11 +7677,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); @@ -7580,6 +7720,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); @@ -7606,6 +7748,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) @@ -8116,6 +8260,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)) { @@ -8125,6 +8270,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( @@ -8134,10 +8285,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); @@ -8171,6 +8326,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); @@ -8197,6 +8354,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) @@ -10455,9 +10614,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 */ @@ -10475,6 +10637,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); @@ -12217,6 +12381,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)) { @@ -12226,6 +12391,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( @@ -12235,10 +12406,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); @@ -12275,6 +12450,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); @@ -12300,6 +12477,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 c1c2ce07476..30296215952 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -2385,6 +2385,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); @@ -2414,6 +2415,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 @@ -2491,6 +2494,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); @@ -2501,11 +2506,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; @@ -2569,12 +2577,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 13ff6c568de..f77603d0d3a 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -208,23 +208,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; @@ -238,11 +229,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())) @@ -250,20 +237,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); } @@ -303,6 +282,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) { @@ -551,7 +531,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 @@ -559,25 +538,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", @@ -604,6 +576,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); } } @@ -619,6 +592,7 @@ int spider_db_before_query( } } conn->in_before_query = FALSE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(0); } @@ -631,6 +605,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) { @@ -673,6 +648,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) { @@ -687,6 +663,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); } @@ -708,6 +685,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); } @@ -720,6 +698,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); } @@ -745,6 +724,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); } @@ -766,6 +746,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); } @@ -782,6 +763,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); } @@ -791,6 +773,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); } @@ -813,6 +796,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); } @@ -821,6 +805,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); } @@ -843,33 +828,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 ( @@ -884,13 +861,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); @@ -900,12 +874,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) } @@ -934,19 +902,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] @@ -977,8 +937,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] && @@ -1002,10 +960,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); } @@ -1019,15 +973,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); @@ -1063,6 +1018,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); @@ -1109,6 +1066,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); @@ -1135,6 +1094,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); @@ -3644,6 +3605,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); } @@ -3660,6 +3622,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); } @@ -3691,6 +3654,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); } @@ -3734,6 +3698,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); } @@ -3773,6 +3738,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); } @@ -3801,6 +3767,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); } @@ -3808,6 +3775,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); } @@ -3851,6 +3819,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); } @@ -3874,6 +3843,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); } @@ -3885,6 +3855,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); } @@ -4043,6 +4014,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); } @@ -4068,6 +4040,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); } @@ -4078,6 +4051,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); } @@ -4163,15 +4137,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); @@ -4381,10 +4355,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); @@ -4420,6 +4398,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); @@ -4447,6 +4427,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) @@ -4487,6 +4469,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))) { @@ -4613,6 +4597,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); @@ -4620,6 +4605,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)) @@ -4629,10 +4619,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); @@ -4667,6 +4661,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); @@ -4693,6 +4689,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) @@ -4813,6 +4811,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); @@ -4820,6 +4819,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)) @@ -4829,10 +4833,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); @@ -4867,6 +4875,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); @@ -4893,6 +4903,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) @@ -5561,8 +5573,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) @@ -5617,61 +5627,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] @@ -5709,15 +5708,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 && @@ -5743,8 +5739,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) { @@ -5780,11 +5778,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; @@ -5793,14 +5788,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) @@ -5822,15 +5815,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(); @@ -5840,25 +5830,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 } @@ -5902,8 +5888,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, @@ -5911,6 +5900,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) @@ -5959,9 +5950,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 && @@ -5988,6 +5982,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); @@ -6115,6 +6111,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)) { @@ -6124,6 +6121,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( @@ -6134,7 +6137,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 { @@ -6200,6 +6207,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)) { @@ -6209,14 +6217,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); @@ -6229,7 +6237,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) @@ -6254,6 +6266,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)) { @@ -6263,6 +6276,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( @@ -6273,7 +6292,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); } } } @@ -6341,6 +6364,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)) { @@ -6350,6 +6374,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( @@ -6359,10 +6389,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); @@ -6397,6 +6431,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); @@ -6435,6 +6471,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); @@ -6449,6 +6487,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); @@ -6478,6 +6518,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); @@ -6666,6 +6708,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); @@ -6673,6 +6716,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)) @@ -6688,10 +6736,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); @@ -6729,6 +6781,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); @@ -6795,6 +6849,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); @@ -6803,11 +6859,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); } @@ -6852,8 +6910,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, @@ -6899,6 +6960,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); @@ -6907,6 +6970,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); @@ -6963,6 +7028,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)) { @@ -6972,6 +7038,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( @@ -6980,9 +7052,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))) @@ -7094,6 +7184,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); @@ -7101,6 +7192,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)) @@ -7116,10 +7212,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); @@ -7154,6 +7254,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); @@ -7179,6 +7281,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) @@ -7271,6 +7375,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)) { @@ -7280,6 +7385,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( @@ -7289,6 +7400,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, @@ -7311,6 +7424,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); @@ -7339,6 +7454,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); @@ -7373,6 +7490,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); @@ -7399,6 +7518,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); @@ -7426,6 +7547,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); @@ -8807,7 +8930,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)) @@ -8830,9 +8960,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); @@ -8851,8 +8978,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) { @@ -9064,12 +9189,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) @@ -9099,19 +9226,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() || @@ -9120,8 +9241,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) || @@ -9135,7 +9254,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); @@ -9145,12 +9263,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) } @@ -9164,25 +9276,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) || @@ -9197,17 +9301,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 @@ -9271,13 +9368,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); @@ -9293,6 +9395,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); @@ -9336,13 +9440,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); @@ -9360,6 +9469,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); @@ -9368,6 +9479,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); @@ -9553,13 +9666,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); @@ -9570,6 +9688,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); @@ -9584,6 +9704,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)); @@ -9596,13 +9718,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); @@ -9683,8 +9817,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; @@ -9694,8 +9842,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 { @@ -9715,8 +9876,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; @@ -9729,11 +9904,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; } } @@ -9741,11 +9928,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, @@ -9774,6 +9973,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; @@ -9789,6 +9992,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; @@ -9815,6 +10022,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; @@ -9832,6 +10043,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; @@ -9844,12 +10059,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; @@ -9870,6 +10093,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)); @@ -9877,6 +10106,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); } @@ -9919,9 +10152,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, @@ -9931,6 +10167,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); @@ -9939,6 +10177,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); @@ -10079,8 +10319,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) @@ -10095,16 +10333,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; @@ -10153,11 +10389,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; @@ -10293,23 +10524,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); } @@ -10359,6 +10588,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; @@ -10397,24 +10627,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) { @@ -10422,7 +10647,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); @@ -10448,24 +10681,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); } @@ -10502,3 +10733,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 2be4c810c06..9ed29d015b3 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); @@ -4973,6 +5226,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; @@ -4985,14 +5246,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 ( @@ -5009,6 +5271,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); @@ -5028,6 +5292,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); @@ -5036,6 +5302,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); @@ -5048,6 +5316,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); @@ -5064,6 +5334,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); @@ -5076,6 +5348,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); @@ -5084,6 +5358,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); @@ -5096,6 +5372,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); @@ -5107,6 +5385,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); @@ -5119,6 +5399,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); @@ -5127,6 +5409,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); @@ -5139,6 +5423,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); @@ -5147,6 +5433,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); @@ -10347,9 +10635,12 @@ int spider_mysql_handler::show_table_status( 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; conn->disable_connect_retry = TRUE; @@ -10375,6 +10666,8 @@ int spider_mysql_handler::show_table_status( if ((error_num = spider_db_ping(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -10384,6 +10677,8 @@ int spider_mysql_handler::show_table_status( if ((error_num = spider_db_set_names(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -10400,12 +10695,16 @@ int spider_mysql_handler::show_table_status( &spider->need_mons[link_idx]) ) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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 { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -10422,6 +10721,8 @@ int spider_mysql_handler::show_table_status( if (spider_param_dry_access()) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -10431,9 +10732,17 @@ int spider_mysql_handler::show_table_status( if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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 { @@ -10446,6 +10755,8 @@ int spider_mysql_handler::show_table_status( } } conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -10488,9 +10799,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; conn->disable_connect_retry = TRUE; @@ -10516,6 +10830,8 @@ int spider_mysql_handler::show_table_status( if ((error_num = spider_db_ping(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -10525,6 +10841,8 @@ int spider_mysql_handler::show_table_status( if ((error_num = spider_db_set_names(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -10541,12 +10859,16 @@ int spider_mysql_handler::show_table_status( &spider->need_mons[link_idx]) ) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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 { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -10563,6 +10885,8 @@ int spider_mysql_handler::show_table_status( if (spider_param_dry_access()) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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,6 +10896,8 @@ int spider_mysql_handler::show_table_status( if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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))) @@ -10580,6 +10906,8 @@ int spider_mysql_handler::show_table_status( DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_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); @@ -10664,9 +10992,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, @@ -10690,6 +11021,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); @@ -10698,6 +11031,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); @@ -10713,11 +11048,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); @@ -10735,6 +11074,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); @@ -10743,6 +11084,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); @@ -10797,9 +11140,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, @@ -10823,6 +11169,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); @@ -10831,6 +11179,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); @@ -10846,11 +11196,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); @@ -10868,6 +11222,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); @@ -10876,6 +11232,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); @@ -10942,9 +11300,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, @@ -10968,6 +11329,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); @@ -10977,6 +11340,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); @@ -10993,12 +11358,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); @@ -11015,18 +11384,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); @@ -11076,9 +11456,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, @@ -11104,6 +11487,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); @@ -11114,6 +11499,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); @@ -11132,6 +11519,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); @@ -11141,6 +11530,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); @@ -11160,6 +11551,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); @@ -11167,6 +11560,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); @@ -11174,6 +11569,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); @@ -11206,13 +11603,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); @@ -11228,10 +11630,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); @@ -11266,14 +11672,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); } @@ -11296,13 +11719,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); @@ -11318,11 +11746,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); @@ -11345,13 +11777,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); @@ -11367,11 +11804,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); @@ -11395,13 +11836,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); @@ -11417,11 +11863,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); @@ -11445,13 +11895,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); @@ -11467,11 +11922,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); @@ -11494,13 +11953,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); @@ -11516,11 +11980,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); @@ -11543,13 +12011,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); @@ -11565,11 +12038,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); @@ -11595,6 +12072,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(), @@ -11602,9 +12087,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); @@ -11620,6 +12113,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, @@ -11627,9 +12128,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 281e3188067..d5d41f4a994 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); } @@ -10449,112 +10519,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; @@ -10565,9 +10529,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, @@ -10591,6 +10558,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); @@ -10599,6 +10568,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); @@ -10614,11 +10585,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); @@ -10634,6 +10609,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))) @@ -10641,6 +10618,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); @@ -10695,105 +10674,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++) @@ -10805,19 +10685,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, @@ -10841,6 +10715,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); @@ -10849,6 +10725,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); @@ -10864,11 +10742,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); @@ -10886,6 +10768,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); @@ -10894,6 +10778,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); @@ -10939,9 +10825,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, @@ -10965,6 +10854,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); @@ -10974,6 +10865,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); @@ -10990,12 +10883,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); @@ -11012,18 +10909,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); @@ -11056,9 +10964,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, @@ -11082,6 +10993,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); @@ -11091,6 +11004,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); @@ -11107,12 +11022,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); @@ -11129,18 +11048,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); @@ -11250,9 +11180,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, @@ -11278,6 +11211,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); @@ -11288,6 +11223,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); @@ -11306,6 +11243,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); @@ -11315,6 +11254,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); @@ -11334,6 +11275,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); @@ -11341,6 +11284,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); @@ -11348,6 +11293,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); @@ -11381,13 +11328,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); @@ -11403,10 +11355,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); @@ -11452,13 +11408,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); @@ -11474,11 +11435,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); @@ -11501,13 +11466,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); @@ -11523,11 +11493,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); @@ -11551,13 +11525,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); @@ -11573,11 +11552,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); @@ -11601,13 +11584,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); @@ -11623,11 +11611,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); @@ -11650,13 +11642,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); @@ -11672,11 +11669,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); @@ -11699,13 +11700,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); @@ -11721,11 +11727,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); @@ -11751,6 +11761,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(), @@ -11758,9 +11776,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); @@ -11776,6 +11802,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, @@ -11783,9 +11817,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 a6ce2efe774..a871e186d96 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 7c591cf691d..39f51fa1b59 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -5815,13 +5815,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); @@ -5834,6 +5839,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); -- cgit v1.2.1 From 420c4dcc7e05748ae876707a1afe464134916aa7 Mon Sep 17 00:00:00 2001 From: Kentoku SHIBA Date: Fri, 4 Sep 2020 22:10:57 +0900 Subject: 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); -- cgit v1.2.1 From 30ff61640375ab28abdf87e786d0ce9feb1a9027 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 7 Sep 2020 12:08:26 +0200 Subject: MDEV-23680 Assertion `data' failed in crcr32_calc_pclmulqdq Fix DBUG_ASSERT --- mysql-test/main/func_math.result | 6 ++++++ mysql-test/main/func_math.test | 5 +++++ mysys/crc32/crc32_x86.c | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/func_math.result b/mysql-test/main/func_math.result index 5da1ab02159..37188dab623 100644 --- a/mysql-test/main/func_math.result +++ b/mysql-test/main/func_math.result @@ -3591,5 +3591,11 @@ t2 CREATE TABLE `t2` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2, t1; # +# MDEV-23680 Assertion `data' failed in crcr32_calc_pclmulqdq +# +SELECT CRC32(ExtractValue('', '/a/b')) AS f; +f +0 +# # End of 10.5 tests # diff --git a/mysql-test/main/func_math.test b/mysql-test/main/func_math.test index 7f8fe9e7e73..6bce8bdaad6 100644 --- a/mysql-test/main/func_math.test +++ b/mysql-test/main/func_math.test @@ -1883,6 +1883,11 @@ CREATE TABLE t2 AS SELECT UUID_SHORT() - a FROM t1; SHOW CREATE TABLE t2; DROP TABLE t2, t1; +--echo # +--echo # MDEV-23680 Assertion `data' failed in crcr32_calc_pclmulqdq +--echo # +SELECT CRC32(ExtractValue('', '/a/b')) AS f; + --echo # --echo # End of 10.5 tests diff --git a/mysys/crc32/crc32_x86.c b/mysys/crc32/crc32_x86.c index 48c930e762e..1e5d2a0a089 100644 --- a/mysys/crc32/crc32_x86.c +++ b/mysys/crc32/crc32_x86.c @@ -219,7 +219,7 @@ static inline uint32_t crcr32_calc_pclmulqdq(const uint8_t *data, uint32_t data_ __m128i temp, fold, k; uint32_t n; - DBUG_ASSERT(data); + DBUG_ASSERT(data != NULL || data_len == 0); DBUG_ASSERT(params); if (unlikely(data_len == 0)) -- cgit v1.2.1 From a8f6bbb7a804472f1a8f08b6f05b456c265c9a6c Mon Sep 17 00:00:00 2001 From: Sujatha Date: Tue, 30 Jun 2020 16:42:44 +0530 Subject: 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, -- cgit v1.2.1 From f99cace77fbf3076137ba63b024465c6ab6ee25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 7 Sep 2020 15:31:54 +0300 Subject: MDEV-22924 Corruption in MVCC read via secondary index An unsafe optimization was introduced by commit 2347ffd843b8e4ee9d8eaafab05368435db59ece (MDEV-20301) which is based on mysql/mysql-server@3f3136188f1bd383f77f97823cf6ebd72d5e4d7e or mysql/mysql-server@647a3814a91c3d3bffc70ddff5513398e3f37bd4 in MySQL 8.0.12 or MySQL 8.0.13 (which in turn is based on the contribution in MySQL Bug #84958). Row_sel_get_clust_rec_for_mysql::operator(): In addition to checking that the pointer to the record matches, also check the latest modification of the page (FIL_PAGE_LSN) as well as the page identifier. Only if all three match, it is safe to reuse cached_old_vers. Row_sel_get_clust_rec_for_mysql::check_eq(): Assert that the PRIMARY KEY of the cached old version of the record corresponds to the latest version. We got a test case where CHECK TABLE, UPDATE and purge would be hammering on the same table (with only 6 rows) and a pointer that was originally pointing to a record pk=2 would match a cached_clust_rec that was pointing to a record pk=1. In the diagnosed `rr replay` trace, we would wrongly return an old cached version of the pk=1 record, instead of retrieving the correct version of the pk=2 record. Because of this, CHECK TABLE would fail to count one of the records in a secondary index, and report failure. This bug appears to affect MVCC reads via secondary indexes only. The purge of history in secondary indexes uses a different code path, and so do checks for implicit record locks. --- storage/innobase/include/dict0mem.h | 19 +++++++++++ storage/innobase/row/row0sel.cc | 63 ++++++++++++++++++++++++++++++------- 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index 804176e2d5b..21d9e763178 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -1014,6 +1014,25 @@ struct dict_index_t{ /** @return whether the index includes virtual columns */ bool has_virtual() const { return type & DICT_VIRTUAL; } + /** @return the position of DB_TRX_ID */ + uint16_t db_trx_id() const { + DBUG_ASSERT(is_primary()); + DBUG_ASSERT(n_uniq); + return n_uniq; + } + /** @return the position of DB_ROLL_PTR */ + uint16_t db_roll_ptr() const + { + return static_cast(db_trx_id() + 1); + } + + /** @return the offset of the metadata BLOB field, + or the first user field after the PRIMARY KEY,DB_TRX_ID,DB_ROLL_PTR */ + uint16_t first_user_field() const + { + return static_cast(db_trx_id() + 2); + } + /** @return whether the index is corrupted */ inline bool is_corrupted() const; diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index ae168ad5130..6951e0c7aac 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -3303,20 +3303,46 @@ row_sel_build_prev_vers_for_mysql( return(err); } -/** Helper class to cache clust_rec and old_ver */ +/** Helper class to cache clust_rec and old_vers */ class Row_sel_get_clust_rec_for_mysql { - const rec_t *cached_clust_rec; - rec_t *cached_old_vers; + const rec_t *cached_clust_rec; + rec_t *cached_old_vers; + lsn_t cached_lsn; + page_id_t cached_page_id; -public: - Row_sel_get_clust_rec_for_mysql() : - cached_clust_rec(NULL), cached_old_vers(NULL) {} +#ifdef UNIV_DEBUG + void check_eq(const dict_index_t *index, const rec_offs *offsets) const + { + rec_offs vers_offs[REC_OFFS_HEADER_SIZE + MAX_REF_PARTS]; + rec_offs_init(vers_offs); + mem_heap_t *heap= nullptr; + + ut_ad(rec_offs_validate(cached_clust_rec, index, offsets)); + ut_ad(index->first_user_field() <= rec_offs_n_fields(offsets)); + ut_ad(vers_offs == rec_get_offsets(cached_old_vers, index, vers_offs, true, + index->db_trx_id(), &heap)); + ut_ad(!heap); + for (auto n= index->db_trx_id(); n--; ) + { + const dict_col_t *col= dict_index_get_nth_col(index, n); + ulint len1, len2; + const byte *b1= rec_get_nth_field(cached_clust_rec, offsets, n, &len1); + const byte *b2= rec_get_nth_field(cached_old_vers, vers_offs, n, &len2); + ut_ad(!cmp_data_data(col->mtype, col->prtype, b1, len1, b2, len2)); + } + } +#endif - dberr_t operator()(row_prebuilt_t *prebuilt, dict_index_t *sec_index, - const rec_t *rec, que_thr_t *thr, const rec_t **out_rec, - rec_offs **offsets, mem_heap_t **offset_heap, - dtuple_t **vrow, mtr_t *mtr); +public: + Row_sel_get_clust_rec_for_mysql() : + cached_clust_rec(NULL), cached_old_vers(NULL), cached_lsn(0), + cached_page_id(page_id_t(0,0)) {} + + dberr_t operator()(row_prebuilt_t *prebuilt, dict_index_t *sec_index, + const rec_t *rec, que_thr_t *thr, const rec_t **out_rec, + rec_offs **offsets, mem_heap_t **offset_heap, + dtuple_t **vrow, mtr_t *mtr); }; /*********************************************************************//** @@ -3516,8 +3542,18 @@ Row_sel_get_clust_rec_for_mysql::operator()( && !lock_clust_rec_cons_read_sees( clust_rec, clust_index, *offsets, trx_get_read_view(trx))) { + const buf_page_t& bpage = btr_pcur_get_block( + prebuilt->clust_pcur)->page; + + lsn_t lsn = bpage.newest_modification; + if (!lsn) { + lsn = mach_read_from_8( + page_align(clust_rec) + FIL_PAGE_LSN); + } - if (clust_rec != cached_clust_rec) { + if (lsn != cached_lsn + || bpage.id != cached_page_id + || clust_rec != cached_clust_rec) { /* The following call returns 'offsets' associated with 'old_vers' */ err = row_sel_build_prev_vers_for_mysql( @@ -3529,6 +3565,8 @@ Row_sel_get_clust_rec_for_mysql::operator()( goto err_exit; } + cached_lsn = lsn; + cached_page_id = bpage.id; cached_clust_rec = clust_rec; cached_old_vers = old_vers; } else { @@ -3539,7 +3577,8 @@ Row_sel_get_clust_rec_for_mysql::operator()( version of clust_rec and its old version old_vers. Re-calculate the offsets for old_vers. */ - if (old_vers != NULL) { + if (old_vers) { + ut_d(check_eq(clust_index, *offsets)); *offsets = rec_get_offsets( old_vers, clust_index, *offsets, true, ULINT_UNDEFINED, offset_heap); -- cgit v1.2.1 From 92ffab382c3f5f000662c13c102c773fad6e636e Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Thu, 13 Aug 2020 21:37:09 +0300 Subject: MDEV-23473 Query_log_event::pack_info does not check flags2_inited A mtr failure in rpl.rpl_mariadb_slave_capability mismatch: -slave-relay-bin.000005 # Query # # BEGIN +slave-relay-bin.000005 # Query # # set foreign_key_checks=1, check_constraint_checks=1; BEGIN was fixed by {{80544a5878ac}}, and without any check for {{flags_inited}} which is a pattern in the sources. This ticket therefore merely makes sure through an assert that a relation between the two remain in {{Query_log_event::pack_info}}. --- sql/log_event_server.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index 49e818b3b97..dd7e166059a 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -1033,6 +1033,9 @@ void Query_log_event::pack_info(Protocol *protocol) append_identifier(protocol->thd, &buf, db, db_len); buf.append(STRING_WITH_LEN("; ")); } + + DBUG_ASSERT(!flags2 || flags2_inited); + if (flags2 & (OPTION_NO_FOREIGN_KEY_CHECKS | OPTION_AUTO_IS_NULL | OPTION_RELAXED_UNIQUE_CHECKS | OPTION_NO_CHECK_CONSTRAINT_CHECKS | -- cgit v1.2.1 From 9842ed4e6dde3f8dfda753e069b72975be73218a Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Mon, 7 Sep 2020 21:54:08 +0300 Subject: MDEV-23549 CREATE fails after DROP without FRM Related to 7c2ba9e: ha_table_exists() is replaced by dd_frm_type(). ha_table_exists() checked the existence of share and that succeeded to enter the execution branch of ha_delete_table() where tdc_remove_table() was called. Now it is skipped because dd_frm_type() returns TABLE_TYPE_UNKNOWN. Fix it by calling tdc_remove_table() in this case as well. --- mysql-test/main/drop_table_force.result | 9 +++++++++ mysql-test/main/drop_table_force.test | 11 +++++++++++ sql/sql_table.cc | 1 + 3 files changed, 21 insertions(+) diff --git a/mysql-test/main/drop_table_force.result b/mysql-test/main/drop_table_force.result index d3142887ade..622589eb3b9 100644 --- a/mysql-test/main/drop_table_force.result +++ b/mysql-test/main/drop_table_force.result @@ -120,3 +120,12 @@ flush tables; drop table t2; ERROR 42S02: Unknown table 'test.t2' db.opt +# +# MDEV-23549 CREATE fails after DROP without FRM +# +create table t1 (a int); +select * from t1; +a +drop table t1; +create table t1 (a int); +drop table t1; diff --git a/mysql-test/main/drop_table_force.test b/mysql-test/main/drop_table_force.test index 518b4e754c3..f3073e3b67d 100644 --- a/mysql-test/main/drop_table_force.test +++ b/mysql-test/main/drop_table_force.test @@ -213,3 +213,14 @@ flush tables; --error ER_BAD_TABLE_ERROR drop table t2; --list_files $DATADIR/test/ + +--echo # +--echo # MDEV-23549 CREATE fails after DROP without FRM +--echo # +create table t1 (a int); +select * from t1; +--remove_file $datadir/test/t1.frm + +drop table t1; +create table t1 (a int); +drop table t1; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 57045c251a7..15d190c3139 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2443,6 +2443,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, was_table|= wrong_drop_sequence; local_non_tmp_error= 1; error= table_type == TABLE_TYPE_UNKNOWN ? ENOENT : -1; + tdc_remove_table(thd, db.str, table_name.str); } else { -- cgit v1.2.1 From c5517cd86440b6669509211b1ad10f837a929952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Tue, 8 Sep 2020 11:14:37 +0300 Subject: MDEV-23638 : DROP TRIGGER in Galera Cluster not replicating Drop trigger handling was missing from wsrep_can_run_in_toi in 10.5 for some reason. --- mysql-test/suite/galera/r/galera_trigger.result | 44 +++++++++++++++++++++++++ mysql-test/suite/galera/t/galera_trigger.test | 36 ++++++++++++++++++++ sql/wsrep_mysqld.cc | 8 +++++ 3 files changed, 88 insertions(+) diff --git a/mysql-test/suite/galera/r/galera_trigger.result b/mysql-test/suite/galera/r/galera_trigger.result index 48147492979..40b63b327af 100644 --- a/mysql-test/suite/galera/r/galera_trigger.result +++ b/mysql-test/suite/galera/r/galera_trigger.result @@ -32,3 +32,47 @@ id 200 DROP TRIGGER tr1; DROP TABLE t1; +connection node_1; +CREATE TABLE t1(id int not null auto_increment, value int not null, primary key (id)) engine=innodb; +CREATE TABLE t2(id int not null auto_increment, tbl varchar(64) not null, action varchar(64) not null, primary key (id)); +create trigger log_insert after insert on t1 +for each row begin +insert into t2(tbl, action) values ('t1', 'INSERT'); +end| +insert into t1(value) values (1); +insert into t1(value) values (2); +connection node_2; +set session wsrep_sync_wait=15; +insert into t1(value) values (3); +insert into t1(value) values (4); +select * from t2; +id tbl action +1 t1 INSERT +3 t1 INSERT +4 t1 INSERT +6 t1 INSERT +connection node_1; +drop trigger if exists log_insert; +insert into t1(value) values (5); +select * from t2; +id tbl action +1 t1 INSERT +3 t1 INSERT +4 t1 INSERT +6 t1 INSERT +connection node_2; +insert into t1(value) values (6); +select * from t2; +id tbl action +1 t1 INSERT +3 t1 INSERT +4 t1 INSERT +6 t1 INSERT +connection node_1; +select * from t2; +id tbl action +1 t1 INSERT +3 t1 INSERT +4 t1 INSERT +6 t1 INSERT +drop table t1, t2; diff --git a/mysql-test/suite/galera/t/galera_trigger.test b/mysql-test/suite/galera/t/galera_trigger.test index 54508583f4b..f85a75d0ff1 100644 --- a/mysql-test/suite/galera/t/galera_trigger.test +++ b/mysql-test/suite/galera/t/galera_trigger.test @@ -33,4 +33,40 @@ SELECT * FROM t1; DROP TRIGGER tr1; DROP TABLE t1; +# +# MDEV-23638 : DROP TRIGGER in Galera Cluster not replicating +# +--connection node_1 +CREATE TABLE t1(id int not null auto_increment, value int not null, primary key (id)) engine=innodb; + +CREATE TABLE t2(id int not null auto_increment, tbl varchar(64) not null, action varchar(64) not null, primary key (id)); + +--delimiter | +create trigger log_insert after insert on t1 +for each row begin + insert into t2(tbl, action) values ('t1', 'INSERT'); +end| +--delimiter ; + +insert into t1(value) values (1); +insert into t1(value) values (2); + +--connection node_2 +set session wsrep_sync_wait=15; +insert into t1(value) values (3); +insert into t1(value) values (4); +select * from t2; + +--connection node_1 +drop trigger if exists log_insert; +insert into t1(value) values (5); +select * from t2; + +--connection node_2 +insert into t1(value) values (6); +select * from t2; + +--connection node_1 +select * from t2; +drop table t1, t2; diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index ae664e951b5..a6b0991e82b 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -1927,6 +1927,14 @@ bool wsrep_can_run_in_toi(THD *thd, const char *db, const char *table, } return true; break; + case SQLCOM_DROP_TRIGGER: + DBUG_ASSERT(table_list); + if (thd->find_temporary_table(table_list)) + { + return false; + } + return true; + break; case SQLCOM_ALTER_TABLE: if (create_info && !wsrep_should_replicate_ddl(thd, create_info->db_type->db_type)) -- cgit v1.2.1 From e38ac391044a433d63f4a4de9d2a10a44e9437e2 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 4 Sep 2020 00:15:22 +0300 Subject: MDEV-23662: Make S3 Storage Engine usable with MinIO Add @@s3_port and @@s3_use_http. One can set these to access the local MinIO, for example. --- mysql-test/suite/s3/basic.result | 2 ++ mysql-test/suite/s3/my.cnf | 12 ++++++++++++ mysql-test/suite/s3/slave.cnf | 12 ++++++++++++ storage/maria/ha_s3.cc | 15 +++++++++++++++ storage/maria/s3_func.c | 6 ++++++ storage/maria/s3_func.h | 2 ++ 6 files changed, 49 insertions(+) diff --git a/mysql-test/suite/s3/basic.result b/mysql-test/suite/s3/basic.result index 9cddca79fc5..cf7d7377d92 100644 --- a/mysql-test/suite/s3/basic.result +++ b/mysql-test/suite/s3/basic.result @@ -94,11 +94,13 @@ s3_pagecache_age_threshold X s3_pagecache_buffer_size X s3_pagecache_division_limit X s3_pagecache_file_hash_size X +s3_port X s3_protocol_version X s3_region X s3_replicate_alter_as_create_select X s3_secret_key X s3_slave_ignore_updates X +s3_use_http X show variables like "s3_slave%"; Variable_name Value s3_slave_ignore_updates OFF diff --git a/mysql-test/suite/s3/my.cnf b/mysql-test/suite/s3/my.cnf index 6f8c27d4d0d..e810449d5b3 100644 --- a/mysql-test/suite/s3/my.cnf +++ b/mysql-test/suite/s3/my.cnf @@ -10,3 +10,15 @@ s3=ON #s3-access-key=... #s3-secret-key=... #s3-region=eu-north-1 + +## +## Configuration for local MinIO +## +s3-host-name="127.0.0.1" +# Note: s3-host-name="localhost" doesn't work. It causes +# libmarias3 to use the wrong variant of the protocol. +s3-bucket=storage-engine +s3-access-key=minioadmin +s3-secret-key=minioadmin +s3-port=9000 +s3-use-http=ON diff --git a/mysql-test/suite/s3/slave.cnf b/mysql-test/suite/s3/slave.cnf index 250a46e6322..c5e7f466226 100644 --- a/mysql-test/suite/s3/slave.cnf +++ b/mysql-test/suite/s3/slave.cnf @@ -6,3 +6,15 @@ s3=ON #s3-access-key=... #s3-secret-key=... #s3-region=eu-north-1 + +## +## Configuration for local MinIO +## +s3-host-name="127.0.0.1" +# Note: s3-host-name="localhost" doesn't work. It causes +# libmarias3 to use the wrong variant of the protocol. +s3-bucket=storage-engine +s3-access-key=minioadmin +s3-secret-key=minioadmin +s3-port=9000 +s3-use-http=ON diff --git a/storage/maria/ha_s3.cc b/storage/maria/ha_s3.cc index 1aae5a5b81f..190d99035a5 100644 --- a/storage/maria/ha_s3.cc +++ b/storage/maria/ha_s3.cc @@ -80,6 +80,8 @@ static ulong s3_pagecache_file_hash_size; static ulonglong s3_pagecache_buffer_size; static char *s3_bucket, *s3_access_key=0, *s3_secret_key=0, *s3_region; static char *s3_host_name; +static int s3_port; +static my_bool s3_use_http; static char *s3_tmp_access_key=0, *s3_tmp_secret_key=0; static my_bool s3_debug= 0, s3_slave_ignore_updates= 0; static my_bool s3_replicate_alter_as_create_select= 0; @@ -181,6 +183,15 @@ static MYSQL_SYSVAR_STR(host_name, s3_host_name, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, "AWS host name", 0, 0, DEFAULT_AWS_HOST_NAME); +static MYSQL_SYSVAR_INT(port, s3_port, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, + "Port number to connect to (0 means use default)", + NULL /*check*/, NULL /*update*/, 0 /*default*/, + 0 /*min*/, 65535 /*max*/, 1 /*blk*/); +static MYSQL_SYSVAR_BOOL(use_http, s3_use_http, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, + "If true, force use of HTTP protocol", + NULL /*check*/, NULL /*update*/, 0 /*default*/); static MYSQL_SYSVAR_STR(access_key, s3_tmp_access_key, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY | PLUGIN_VAR_MEMALLOC, "AWS access key", @@ -276,6 +287,8 @@ static my_bool s3_info_init(S3_INFO *info) return 1; info->protocol_version= (uint8_t) s3_protocol_version; lex_string_set(&info->host_name, s3_host_name); + info->port= s3_port; + info->use_http= s3_use_http; lex_string_set(&info->access_key, s3_access_key); lex_string_set(&info->secret_key, s3_secret_key); lex_string_set(&info->region, s3_region); @@ -1050,6 +1063,8 @@ static struct st_mysql_sys_var* system_variables[]= { MYSQL_SYSVAR(pagecache_division_limit), MYSQL_SYSVAR(pagecache_file_hash_size), MYSQL_SYSVAR(host_name), + MYSQL_SYSVAR(port), + MYSQL_SYSVAR(use_http), MYSQL_SYSVAR(bucket), MYSQL_SYSVAR(access_key), MYSQL_SYSVAR(secret_key), diff --git a/storage/maria/s3_func.c b/storage/maria/s3_func.c index bbaf048d534..9f40790a371 100644 --- a/storage/maria/s3_func.c +++ b/storage/maria/s3_func.c @@ -157,6 +157,12 @@ ms3_st *s3_open_connection(S3_INFO *s3) if (s3->protocol_version) ms3_set_option(s3_client, MS3_OPT_FORCE_PROTOCOL_VERSION, &s3->protocol_version); + if (s3->port) + ms3_set_option(s3_client, MS3_OPT_PORT_NUMBER, &s3->port); + + if (s3->use_http) + ms3_set_option(s3_client, MS3_OPT_USE_HTTP, NULL); + return s3_client; } diff --git a/storage/maria/s3_func.h b/storage/maria/s3_func.h index 8981517dd4d..bd5275494bc 100644 --- a/storage/maria/s3_func.h +++ b/storage/maria/s3_func.h @@ -45,6 +45,8 @@ typedef struct s3_info { /* Connection strings */ LEX_CSTRING access_key, secret_key, region, bucket, host_name; + int port; // 0 means 'Use default' + my_bool use_http; /* Will be set by caller or by ma_open() */ LEX_CSTRING database, table; -- cgit v1.2.1 From 64c10b03a0021cb415ca5b024d4951819bcaeb01 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 4 Sep 2020 10:23:28 +1000 Subject: MDEV-23662: Make S3 Storage Engine tests usable added plugin-maturity = alpha to s3 mtr cnf files and a missing plugin-load-add=ha_s3 in the slave configuration. --- mysql-test/suite/s3/my.cnf | 1 + mysql-test/suite/s3/slave.cnf | 2 ++ 2 files changed, 3 insertions(+) diff --git a/mysql-test/suite/s3/my.cnf b/mysql-test/suite/s3/my.cnf index e810449d5b3..ad3aa908993 100644 --- a/mysql-test/suite/s3/my.cnf +++ b/mysql-test/suite/s3/my.cnf @@ -2,6 +2,7 @@ !include include/default_client.cnf [mysqld.1] +plugin-maturity = alpha plugin-load-add=ha_s3 s3=ON #s3-host-name=s3.amazonaws.com diff --git a/mysql-test/suite/s3/slave.cnf b/mysql-test/suite/s3/slave.cnf index c5e7f466226..12d767dea05 100644 --- a/mysql-test/suite/s3/slave.cnf +++ b/mysql-test/suite/s3/slave.cnf @@ -1,4 +1,6 @@ [mysqld.2] +plugin-maturity = alpha +plugin-load-add=ha_s3 s3=ON #s3-host-name=s3.amazonaws.com #s3-protocol-version=Amazon -- cgit v1.2.1 From f98b8d36bd6ccae7616621b6b23bf9fabc1010ca Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 4 Sep 2020 10:44:05 +1000 Subject: MDEV-23662: Make S3 Storage Engine tests better To ensure that S3 is using its access and secret key in the right way, make these different in the test suite. --- mysql-test/suite/s3/my.cnf | 2 +- mysql-test/suite/s3/slave.cnf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/s3/my.cnf b/mysql-test/suite/s3/my.cnf index ad3aa908993..03060f8a0ef 100644 --- a/mysql-test/suite/s3/my.cnf +++ b/mysql-test/suite/s3/my.cnf @@ -19,7 +19,7 @@ s3-host-name="127.0.0.1" # Note: s3-host-name="localhost" doesn't work. It causes # libmarias3 to use the wrong variant of the protocol. s3-bucket=storage-engine -s3-access-key=minioadmin +s3-access-key=minio s3-secret-key=minioadmin s3-port=9000 s3-use-http=ON diff --git a/mysql-test/suite/s3/slave.cnf b/mysql-test/suite/s3/slave.cnf index 12d767dea05..514171b383c 100644 --- a/mysql-test/suite/s3/slave.cnf +++ b/mysql-test/suite/s3/slave.cnf @@ -16,7 +16,7 @@ s3-host-name="127.0.0.1" # Note: s3-host-name="localhost" doesn't work. It causes # libmarias3 to use the wrong variant of the protocol. s3-bucket=storage-engine -s3-access-key=minioadmin +s3-access-key=minio s3-secret-key=minioadmin s3-port=9000 s3-use-http=ON -- cgit v1.2.1 From 7478e0858f1c75da2d24f77737bfa3c2864388c8 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Sat, 5 Sep 2020 22:24:32 +0300 Subject: Update libmarias3 to PR#91 which adds capability to specify port number --- storage/maria/libmarias3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/maria/libmarias3 b/storage/maria/libmarias3 index d172e86c162..919024c98b9 160000 --- a/storage/maria/libmarias3 +++ b/storage/maria/libmarias3 @@ -1 +1 @@ -Subproject commit d172e86c16224b4e0229ca6f102e662a2315aeff +Subproject commit 919024c98b965c978e872da7df0c31db7515035b -- cgit v1.2.1 From d252f44c5dde42a934651d67a88ae99b50be12c8 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Mon, 7 Sep 2020 16:07:11 +0300 Subject: Update libmarias3 to PR#92: updated PR#91, adds capability to support port number --- storage/maria/libmarias3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/maria/libmarias3 b/storage/maria/libmarias3 index 919024c98b9..7aa450e3a02 160000 --- a/storage/maria/libmarias3 +++ b/storage/maria/libmarias3 @@ -1 +1 @@ -Subproject commit 919024c98b965c978e872da7df0c31db7515035b +Subproject commit 7aa450e3a02a20ef62616666a2b582f4d07fb5b3 -- cgit v1.2.1 From b1009ae5c16697d5eef443cc6a60a74301148c73 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Wed, 9 Sep 2020 11:58:15 +0530 Subject: MDEV-23456 fil_space_crypt_t::write_page0() is accessing an uninitialized page buf_page_create() is invoked when page is initialized. So that previous contents of the page ignored. In few cases, it calls buf_page_get_gen() is called to fetch the page from buffer pool. It should take x-latch on the page. If other thread uses the block or block io state is different from BUF_IO_NONE then release the mutex and check the state and buffer fix count again. For compressed page, use the existing free block from LRU list to create new page. Retry to fetch the compressed page if it is in flush list fseg_create(), fseg_create_general(): Introduce block as a parameter where segment header is placed. It is used to avoid repetitive x-latch on the same page Change the assert to check whether the page has SX latch and X latch in all callee function of buf_page_create() mtr_t::get_fix_count(): Get the buffer fix count of the given block added by the mtr FindBlock is added to find the buffer fix count of the given block acquired by the mini-transaction --- storage/innobase/btr/btr0btr.cc | 10 +-- storage/innobase/buf/buf0buf.cc | 112 ++++++++++++++++++++-------- storage/innobase/buf/buf0dblwr.cc | 10 ++- storage/innobase/dict/dict0boot.cc | 2 +- storage/innobase/fsp/fsp0fsp.cc | 149 ++++++++++++++++--------------------- storage/innobase/include/fsp0fsp.h | 66 +++++++++------- storage/innobase/include/mtr0mtr.h | 4 + storage/innobase/log/log0recv.cc | 1 - storage/innobase/mtr/mtr0mtr.cc | 35 +++++++++ storage/innobase/trx/trx0rseg.cc | 2 +- storage/innobase/trx/trx0sys.cc | 2 +- storage/innobase/trx/trx0undo.cc | 4 +- 12 files changed, 240 insertions(+), 157 deletions(-) diff --git a/storage/innobase/btr/btr0btr.cc b/storage/innobase/btr/btr0btr.cc index 313790f1db3..3b0e755bc91 100644 --- a/storage/innobase/btr/btr0btr.cc +++ b/storage/innobase/btr/btr0btr.cc @@ -1086,8 +1086,7 @@ btr_create( if (type & DICT_IBUF) { /* Allocate first the ibuf header page */ buf_block_t* ibuf_hdr_block = fseg_create( - space, 0, - IBUF_HEADER + IBUF_TREE_SEG_HEADER, mtr); + space, IBUF_HEADER + IBUF_TREE_SEG_HEADER, mtr); if (ibuf_hdr_block == NULL) { return(FIL_NULL); @@ -1118,7 +1117,7 @@ btr_create( flst_init(block->frame + PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST, mtr); } else { - block = fseg_create(space, 0, + block = fseg_create(space, PAGE_HEADER + PAGE_BTR_SEG_TOP, mtr); if (block == NULL) { @@ -1127,8 +1126,9 @@ btr_create( buf_block_dbg_add_level(block, SYNC_TREE_NODE_NEW); - if (!fseg_create(space, block->page.id.page_no(), - PAGE_HEADER + PAGE_BTR_SEG_LEAF, mtr)) { + if (!fseg_create(space, + PAGE_HEADER + PAGE_BTR_SEG_LEAF, mtr, + block)) { /* Not enough space for new segment, free root segment before return. */ btr_free_root(block, mtr, diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index 5858d9cd2d3..cfc79868482 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -5564,14 +5564,13 @@ buf_page_create( buf_frame_t* frame; buf_block_t* block; buf_block_t* free_block = NULL; - buf_pool_t* buf_pool = buf_pool_get(page_id); + buf_pool_t* buf_pool= buf_pool_get(page_id); rw_lock_t* hash_lock; ut_ad(mtr->is_active()); ut_ad(page_id.space() != 0 || !page_size.is_compressed()); - +loop: free_block = buf_LRU_get_free_block(buf_pool); - buf_pool_mutex_enter(buf_pool); hash_lock = buf_page_hash_lock_get(buf_pool, page_id); @@ -5583,20 +5582,67 @@ buf_page_create( && buf_page_in_file(&block->page) && !buf_pool_watch_is_sentinel(buf_pool, &block->page)) { ut_d(block->page.file_page_was_freed = FALSE); - + buf_page_state page_state = buf_block_get_state(block); #ifdef BTR_CUR_HASH_ADAPT - bool drop_hash_entry = - (block->page.state == BUF_BLOCK_FILE_PAGE - && block->index); + const dict_index_t *drop_hash_entry= NULL; +#endif + switch (page_state) { + default: + ut_ad(0); + break; + case BUF_BLOCK_ZIP_PAGE: + case BUF_BLOCK_ZIP_DIRTY: + buf_block_init_low(free_block); + mutex_enter(&buf_pool->zip_mutex); - if (drop_hash_entry) { - mutex_enter(&block->mutex); - /* Avoid a hang if I/O is going on. Release - the buffer pool mutex and page hash lock - and wait for I/O to complete */ - while (buf_block_get_io_fix(block) != BUF_IO_NONE) { - buf_block_fix(block); - mutex_exit(&block->mutex); + buf_page_mutex_enter(free_block); + if (buf_page_get_io_fix(&block->page) != BUF_IO_NONE) { + mutex_exit(&buf_pool->zip_mutex); + rw_lock_x_unlock(hash_lock); + buf_LRU_block_free_non_file_page(free_block); + buf_pool_mutex_exit(buf_pool); + buf_page_mutex_exit(free_block); + + goto loop; + } + + rw_lock_x_lock(&free_block->lock); + + buf_relocate(&block->page, &free_block->page); + if (page_state == BUF_BLOCK_ZIP_DIRTY) { + ut_ad(block->page.in_flush_list); + ut_ad(block->page.oldest_modification > 0); + buf_flush_relocate_on_flush_list( + &block->page, &free_block->page); + } else { + ut_ad(block->page.oldest_modification == 0); + ut_ad(!block->page.in_flush_list); +#ifdef UNIV_DEBUG + UT_LIST_REMOVE( + buf_pool->zip_clean, &block->page); +#endif + } + + free_block->page.state = BUF_BLOCK_FILE_PAGE; + mutex_exit(&buf_pool->zip_mutex); + free_block->lock_hash_val = lock_rec_hash( + page_id.space(), page_id.page_no()); + buf_unzip_LRU_add_block(free_block, false); + buf_page_free_descriptor(&block->page); + block = free_block; + buf_block_fix(block); + buf_page_mutex_exit(free_block); + free_block = NULL; + break; + case BUF_BLOCK_FILE_PAGE: + buf_block_fix(block); + const int32_t num_fix_count = + mtr->get_fix_count(block) + 1; + buf_page_mutex_enter(block); + while (buf_block_get_io_fix(block) != BUF_IO_NONE + || (num_fix_count + != block->page.buf_fix_count)) { + buf_page_mutex_exit(block); buf_pool_mutex_exit(buf_pool); rw_lock_x_unlock(hash_lock); @@ -5604,33 +5650,39 @@ buf_page_create( buf_pool_mutex_enter(buf_pool); rw_lock_x_lock(hash_lock); - mutex_enter(&block->mutex); - buf_block_unfix(block); + buf_page_mutex_enter(block); } + rw_lock_x_lock(&block->lock); - mutex_exit(&block->mutex); - } + buf_page_mutex_exit(block); +#ifdef BTR_CUR_HASH_ADAPT + drop_hash_entry = block->index; #endif + break; + } /* Page can be found in buf_pool */ buf_pool_mutex_exit(buf_pool); rw_lock_x_unlock(hash_lock); - buf_block_free(free_block); + if (free_block) { + buf_block_free(free_block); + } #ifdef BTR_CUR_HASH_ADAPT if (drop_hash_entry) { btr_search_drop_page_hash_index(block); - rw_lock_x_unlock(&block->lock); } #endif /* BTR_CUR_HASH_ADAPT */ - if (!recv_recovery_is_on()) { - return buf_page_get_with_no_latch(page_id, page_size, - mtr); +#ifdef UNIV_DEBUG + if (!fsp_is_system_temporary(page_id.space())) { + rw_lock_s_lock_nowait( + &block->debug_latch, + __FILE__, __LINE__); } +#endif /* UNIV_DEBUG */ + + mtr_memo_push(mtr, block, MTR_MEMO_PAGE_X_FIX); - mutex_exit(&recv_sys->mutex); - block = buf_page_get_with_no_latch(page_id, page_size, mtr); - mutex_enter(&recv_sys->mutex); return block; } @@ -5645,6 +5697,8 @@ buf_page_create( buf_page_init(buf_pool, page_id, page_size, block); + rw_lock_x_lock(&block->lock); + rw_lock_x_unlock(hash_lock); /* The block must be put to the LRU list */ @@ -5662,7 +5716,6 @@ buf_page_create( by IO-fixing and X-latching the block. */ buf_page_set_io_fix(&block->page, BUF_IO_READ); - rw_lock_x_lock(&block->lock); buf_page_mutex_exit(block); /* buf_pool->mutex may be released and reacquired by @@ -5684,12 +5737,11 @@ buf_page_create( buf_unzip_LRU_add_block(block, FALSE); buf_page_set_io_fix(&block->page, BUF_IO_NONE); - rw_lock_x_unlock(&block->lock); } buf_pool_mutex_exit(buf_pool); - mtr_memo_push(mtr, block, MTR_MEMO_BUF_FIX); + mtr_memo_push(mtr, block, MTR_MEMO_PAGE_X_FIX); buf_page_set_accessed(&block->page); diff --git a/storage/innobase/buf/buf0dblwr.cc b/storage/innobase/buf/buf0dblwr.cc index 17185eab650..30f24d57391 100644 --- a/storage/innobase/buf/buf0dblwr.cc +++ b/storage/innobase/buf/buf0dblwr.cc @@ -170,6 +170,7 @@ buf_dblwr_create() { buf_block_t* block2; buf_block_t* new_block; + buf_block_t* trx_sys_block; byte* doublewrite; byte* fseg_header; ulint page_no; @@ -209,9 +210,14 @@ start_again: } } - block2 = fseg_create(TRX_SYS_SPACE, TRX_SYS_PAGE_NO, + trx_sys_block = buf_page_get( + page_id_t(TRX_SYS_SPACE, TRX_SYS_PAGE_NO), + page_size_t(srv_page_size, srv_page_size, 0), RW_X_LATCH, + &mtr); + + block2 = fseg_create(TRX_SYS_SPACE, TRX_SYS_DOUBLEWRITE - + TRX_SYS_DOUBLEWRITE_FSEG, &mtr); + + TRX_SYS_DOUBLEWRITE_FSEG, &mtr, trx_sys_block); if (block2 == NULL) { too_small: diff --git a/storage/innobase/dict/dict0boot.cc b/storage/innobase/dict/dict0boot.cc index 9294cf6263c..8e4732f8214 100644 --- a/storage/innobase/dict/dict0boot.cc +++ b/storage/innobase/dict/dict0boot.cc @@ -179,7 +179,7 @@ dict_hdr_create( /* Create the dictionary header file block in a new, allocated file segment in the system tablespace */ - block = fseg_create(DICT_HDR_SPACE, 0, + block = fseg_create(DICT_HDR_SPACE, DICT_HDR + DICT_HDR_FSEG_HEADER, mtr); ut_a(DICT_HDR_PAGE_NO == block->page.id.page_no()); diff --git a/storage/innobase/fsp/fsp0fsp.cc b/storage/innobase/fsp/fsp0fsp.cc index 8a393b15952..667da08eeea 100644 --- a/storage/innobase/fsp/fsp0fsp.cc +++ b/storage/innobase/fsp/fsp0fsp.cc @@ -117,7 +117,6 @@ to minimize file space fragmentation. @param[in] direction if the new page is needed because of an index page split, and records are inserted there in order, into which direction they go alphabetically: FSP_DOWN, FSP_UP, FSP_NO_DIR -@param[in] rw_latch RW_SX_LATCH, RW_X_LATCH @param[in,out] mtr mini-transaction @param[in,out] init_mtr mtr or another mini-transaction in which the page should be initialized. If init_mtr != mtr, but the page is @@ -136,7 +135,6 @@ fseg_alloc_free_page_low( fseg_inode_t* seg_inode, ulint hint, byte direction, - rw_lock_type_t rw_latch, mtr_t* mtr, mtr_t* init_mtr #ifdef UNIV_DEBUG @@ -224,7 +222,9 @@ xdes_set_bit( ulint bit_index; ulint descr_byte; - ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_SX_FIX)); + ut_ad(mtr_memo_contains_page( + mtr, descr, + MTR_MEMO_PAGE_SX_FIX | MTR_MEMO_PAGE_X_FIX)); ut_ad((bit == XDES_FREE_BIT) || (bit == XDES_CLEAN_BIT)); ut_ad(offset < FSP_EXTENT_SIZE); @@ -351,7 +351,9 @@ xdes_set_state( ut_ad(descr && mtr); ut_ad(state >= XDES_FREE); ut_ad(state <= XDES_FSEG); - ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_SX_FIX)); + ut_ad(mtr_memo_contains_page( + mtr, descr, + MTR_MEMO_PAGE_SX_FIX | MTR_MEMO_PAGE_X_FIX)); mlog_write_ulint(descr + XDES_STATE, state, MLOG_4BYTES, mtr); } @@ -388,7 +390,9 @@ xdes_init( ulint i; ut_ad(descr && mtr); - ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_SX_FIX)); + ut_ad(mtr_memo_contains_page( + mtr, descr, + MTR_MEMO_PAGE_SX_FIX | MTR_MEMO_PAGE_X_FIX)); ut_ad((XDES_SIZE - XDES_BITMAP) % 4 == 0); for (i = XDES_BITMAP; i < XDES_SIZE; i += 4) { @@ -423,7 +427,8 @@ xdes_get_descriptor_with_space_hdr( ulint descr_page_no; page_t* descr_page; ut_ad(mtr_memo_contains(mtr, space, MTR_MEMO_SPACE_X_LOCK)); - ut_ad(mtr_memo_contains_page(mtr, sp_header, MTR_MEMO_PAGE_SX_FIX)); + ut_ad(mtr_memo_contains_page(mtr, sp_header, MTR_MEMO_PAGE_SX_FIX) + || mtr_memo_contains_page(mtr, sp_header, MTR_MEMO_PAGE_X_FIX)); ut_ad(page_offset(sp_header) == FSP_HEADER_OFFSET); /* Read free limit and space size */ limit = mach_read_from_4(sp_header + FSP_FREE_LIMIT); @@ -701,7 +706,6 @@ fsp_header_init(ulint space_id, ulint size, mtr_t* mtr) const page_size_t page_size(space->flags); block = buf_page_create(page_id, page_size, mtr); - buf_page_get(page_id, page_size, RW_SX_LATCH, mtr); buf_block_dbg_add_level(block, SYNC_FSP_PAGE); space->size_in_header = size; @@ -1100,9 +1104,6 @@ fsp_fill_free_list( block = buf_page_create( page_id, page_size, mtr); - buf_page_get( - page_id, page_size, RW_SX_LATCH, mtr); - buf_block_dbg_add_level(block, SYNC_FSP_PAGE); fsp_init_file_page(space, block, mtr); @@ -1120,9 +1121,6 @@ fsp_fill_free_list( block = buf_page_create( page_id, page_size, mtr); - buf_page_get( - page_id, page_size, RW_SX_LATCH, mtr); - buf_block_dbg_add_level(block, SYNC_FSP_PAGE); fsp_init_file_page(space, block, mtr); @@ -1268,7 +1266,6 @@ x-latched only by mtr, and freed in mtr in that case. @param[in,out] space tablespace @param[in] offset page number of the allocated page @param[in] page_size page size of the allocated page -@param[in] rw_latch RW_SX_LATCH, RW_X_LATCH @param[in,out] mtr mini-transaction of the allocation @param[in,out] init_mtr mini-transaction for initializing the page @return block, initialized if init_mtr==mtr @@ -1279,7 +1276,6 @@ fsp_page_create( fil_space_t* space, page_no_t offset, const page_size_t& page_size, - rw_lock_type_t rw_latch, mtr_t* mtr, mtr_t* init_mtr) { @@ -1289,26 +1285,10 @@ fsp_page_create( page_size, init_mtr); ut_d(bool latched = mtr_memo_contains_flagged(mtr, block, - MTR_MEMO_PAGE_X_FIX - | MTR_MEMO_PAGE_SX_FIX)); - - ut_ad(rw_latch == RW_X_LATCH || rw_latch == RW_SX_LATCH); - - /* Mimic buf_page_get(), but avoid the buf_pool->page_hash lookup. */ - if (rw_latch == RW_X_LATCH) { - rw_lock_x_lock(&block->lock); - } else { - rw_lock_sx_lock(&block->lock); - } - - buf_block_buf_fix_inc(block, __FILE__, __LINE__); - mtr_memo_push(init_mtr, block, rw_latch == RW_X_LATCH - ? MTR_MEMO_PAGE_X_FIX : MTR_MEMO_PAGE_SX_FIX); + MTR_MEMO_PAGE_X_FIX)); if (init_mtr == mtr - || (rw_latch == RW_X_LATCH - ? rw_lock_get_x_lock_count(&block->lock) == 1 - : rw_lock_get_sx_lock_count(&block->lock) == 1)) { + || rw_lock_get_x_lock_count(&block->lock) == 1) { /* Initialize the page, unless it was already SX-latched in mtr. (In this case, we would want to @@ -1325,7 +1305,6 @@ The page is marked as used. @param[in,out] space tablespace @param[in] page_size page size @param[in] hint hint of which page would be desirable -@param[in] rw_latch RW_SX_LATCH, RW_X_LATCH @param[in,out] mtr mini-transaction @param[in,out] init_mtr mini-transaction in which the page should be initialized (may be the same as mtr) @@ -1339,7 +1318,6 @@ fsp_alloc_free_page( fil_space_t* space, const page_size_t& page_size, ulint hint, - rw_lock_type_t rw_latch, mtr_t* mtr, mtr_t* init_mtr) { @@ -1431,8 +1409,7 @@ fsp_alloc_free_page( } fsp_alloc_from_free_frag(header, descr, free, mtr); - return(fsp_page_create(space, page_no, page_size, rw_latch, - mtr, init_mtr)); + return(fsp_page_create(space, page_no, page_size, mtr, init_mtr)); } /** Frees a single page of a space. @@ -1669,8 +1646,7 @@ fsp_alloc_seg_inode_page( const page_size_t page_size(space->flags); - block = fsp_alloc_free_page( - space, page_size, 0, RW_SX_LATCH, mtr, mtr); + block = fsp_alloc_free_page(space, page_size, 0, mtr, mtr); if (block == NULL) { @@ -1678,7 +1654,7 @@ fsp_alloc_seg_inode_page( } buf_block_dbg_add_level(block, SYNC_FSP_PAGE); - ut_ad(rw_lock_get_sx_lock_count(&block->lock) == 1); + ut_ad(rw_lock_get_x_lock_count(&block->lock) == 1); mlog_write_ulint(block->frame + FIL_PAGE_TYPE, FIL_PAGE_INODE, MLOG_2BYTES, mtr); @@ -1987,32 +1963,36 @@ fseg_get_n_frag_pages( return(count); } -/**********************************************************************//** -Creates a new segment. +/** Creates a new segment. +@param[in] space_id space_id +@param[in] byte_offset byte offset of the created segment + header on the page +@param[in] has_done_reservation TRUE if the caller has already + done the reservation for the pages + with fsp_reserve_free_externts + (at least 2 extents: one for + the inode and the other for the + segment) then there is no need to do + the check for this individual + operation +@param[in,out] mtr mini-transaction +@param[in] block block where the segment header is + placed. If it is null then new page + will be allocated and it will belong + to the created segment @return the block where the segment header is placed, x-latched, NULL if could not create segment because of lack of space */ buf_block_t* fseg_create_general( -/*================*/ - ulint space_id,/*!< in: space id */ - ulint page, /*!< in: page where the segment header is placed: if - this is != 0, the page must belong to another segment, - if this is 0, a new page will be allocated and it - will belong to the created segment */ - ulint byte_offset, /*!< in: byte offset of the created segment header - on the page */ - ibool has_done_reservation, /*!< in: TRUE if the caller has already - done the reservation for the pages with - fsp_reserve_free_extents (at least 2 extents: one for - the inode and the other for the segment) then there is - no need to do the check for this individual - operation */ - mtr_t* mtr) /*!< in/out: mini-transaction */ + ulint space_id, + ulint byte_offset, + ibool has_done_reservation, + mtr_t* mtr, + buf_block_t* block) { fsp_header_t* space_header; fseg_inode_t* inode; ib_id_t seg_id; - buf_block_t* block = 0; /* remove warning */ fseg_header_t* header = 0; /* remove warning */ ulint n_reserved; ulint i; @@ -2027,14 +2007,12 @@ fseg_create_general( const page_size_t page_size(space->flags); ut_d(space->modify_check(*mtr)); - if (page != 0) { - block = buf_page_get(page_id_t(space_id, page), page_size, - RW_SX_LATCH, mtr); - + if (block) { header = byte_offset + buf_block_get_frame(block); - const ulint type = space_id == TRX_SYS_SPACE - && page == TRX_SYS_PAGE_NO + const ulint type = + (block->page.id.space() == TRX_SYS_SPACE + && block->page.id.page_no() == TRX_SYS_PAGE_NO) ? FIL_PAGE_TYPE_TRX_SYS : FIL_PAGE_TYPE_SYS; @@ -2075,9 +2053,9 @@ fseg_create_general( fseg_set_nth_frag_page_no(inode, i, FIL_NULL, mtr); } - if (page == 0) { + if (!block) { block = fseg_alloc_free_page_low(space, page_size, - inode, 0, FSP_UP, RW_SX_LATCH, + inode, 0, FSP_UP, mtr, mtr #ifdef UNIV_DEBUG , has_done_reservation @@ -2095,7 +2073,7 @@ fseg_create_general( goto funct_exit; } - ut_ad(rw_lock_get_sx_lock_count(&block->lock) == 1); + ut_ad(rw_lock_get_x_lock_count(&block->lock) == 1); header = byte_offset + buf_block_get_frame(block); mlog_write_ulint(buf_block_get_frame(block) + FIL_PAGE_TYPE, @@ -2120,23 +2098,25 @@ funct_exit: DBUG_RETURN(block); } -/**********************************************************************//** -Creates a new segment. +/** Creates a new segment. +@param[in] space space id +@param[in] byte_offset byte offset of the created segment header + on the page +@param[in,out] mtr mini-transaction +@param[in,out] block block where segment header is placed; + If it is null then new page will be + allocated and it will belong to + the created segment @return the block where the segment header is placed, x-latched, NULL if could not create segment because of lack of space */ buf_block_t* fseg_create( -/*========*/ - ulint space, /*!< in: space id */ - ulint page, /*!< in: page where the segment header is placed: if - this is != 0, the page must belong to another segment, - if this is 0, a new page will be allocated and it - will belong to the created segment */ - ulint byte_offset, /*!< in: byte offset of the created segment header - on the page */ - mtr_t* mtr) /*!< in/out: mini-transaction */ + ulint space, + ulint byte_offset, + mtr_t* mtr, + buf_block_t* block) { - return(fseg_create_general(space, page, byte_offset, FALSE, mtr)); + return(fseg_create_general(space, byte_offset, FALSE, mtr, block)); } /**********************************************************************//** @@ -2334,7 +2314,6 @@ minimize file space fragmentation. @param[in] direction if the new page is needed because of an index page split, and records are inserted there in order, into which direction they go alphabetically: FSP_DOWN, FSP_UP, FSP_NO_DIR -@param[in] rw_latch RW_SX_LATCH, RW_X_LATCH @param[in,out] mtr mini-transaction @param[in,out] init_mtr mtr or another mini-transaction in which the page should be initialized. If init_mtr != mtr, but the page is @@ -2353,7 +2332,6 @@ fseg_alloc_free_page_low( fseg_inode_t* seg_inode, ulint hint, byte direction, - rw_lock_type_t rw_latch, mtr_t* mtr, mtr_t* init_mtr #ifdef UNIV_DEBUG @@ -2496,7 +2474,7 @@ take_hinted_page: /* 6. We allocate an individual page from the space ===================================================*/ buf_block_t* block = fsp_alloc_free_page( - space, page_size, hint, rw_latch, mtr, init_mtr); + space, page_size, hint, mtr, init_mtr); ut_ad(!has_done_reservation || block != NULL); @@ -2577,8 +2555,7 @@ got_hinted_page: fseg_mark_page_used(seg_inode, ret_page, ret_descr, mtr); } - return(fsp_page_create(space, ret_page, page_size, rw_latch, - mtr, init_mtr)); + return(fsp_page_create(space, ret_page, page_size, mtr, init_mtr)); } /**********************************************************************//** @@ -2633,7 +2610,7 @@ fseg_alloc_free_page_general( block = fseg_alloc_free_page_low(space, page_size, inode, hint, direction, - RW_X_LATCH, mtr, init_mtr + mtr, init_mtr #ifdef UNIV_DEBUG , has_done_reservation #endif /* UNIV_DEBUG */ @@ -3388,7 +3365,7 @@ fseg_print_low( ulint page_no; ib_id_t seg_id; - ut_ad(mtr_memo_contains_page(mtr, inode, MTR_MEMO_PAGE_SX_FIX)); + ut_ad(mtr_memo_contains_page(mtr, inode, MTR_MEMO_PAGE_X_FIX)); space = page_get_space_id(page_align(inode)); page_no = page_get_page_no(page_align(inode)); diff --git a/storage/innobase/include/fsp0fsp.h b/storage/innobase/include/fsp0fsp.h index 8debdb00013..a50be6f8998 100644 --- a/storage/innobase/include/fsp0fsp.h +++ b/storage/innobase/include/fsp0fsp.h @@ -407,42 +407,52 @@ fsp_header_inc_size( ulint space_id, /*!< in: space id */ ulint size_inc, /*!< in: size increment in pages */ mtr_t* mtr); /*!< in/out: mini-transaction */ -/**********************************************************************//** -Creates a new segment. + +/** Creates a new segment. +@param[in] space space id +@param[in] byte_offset byte offset of the created segment header + on the page +@param[in,out] mtr mini-transaction +@param[in,out] block block where segment header is placed; + If it is null then new page will be + allocated and it will belong to + the created segment @return the block where the segment header is placed, x-latched, NULL if could not create segment because of lack of space */ buf_block_t* fseg_create( -/*========*/ - ulint space_id,/*!< in: space id */ - ulint page, /*!< in: page where the segment header is placed: if - this is != 0, the page must belong to another segment, - if this is 0, a new page will be allocated and it - will belong to the created segment */ - ulint byte_offset, /*!< in: byte offset of the created segment header - on the page */ - mtr_t* mtr); /*!< in/out: mini-transaction */ -/**********************************************************************//** -Creates a new segment. + ulint space, + ulint byte_offset, + mtr_t* mtr, + buf_block_t* block=NULL); + +/** Creates a new segment. +@param[in] space_id space_id +@param[in] byte_offset byte offset of the created segment + header on the page +@param[in] has_done_reservation TRUE if the caller has already + done the reservation for the pages + with fsp_reserve_free_externts + (at least 2 extents: one for + the inode and the other for the + segment) then there is no need to do + the check for this individual + operation +@param[in,out] mtr mini-transaction +@param[in] block block where the segment header is + placed. If it is null then new page + will be allocated and it will belong + to the created segment @return the block where the segment header is placed, x-latched, NULL if could not create segment because of lack of space */ buf_block_t* fseg_create_general( -/*================*/ - ulint space_id,/*!< in: space id */ - ulint page, /*!< in: page where the segment header is placed: if - this is != 0, the page must belong to another segment, - if this is 0, a new page will be allocated and it - will belong to the created segment */ - ulint byte_offset, /*!< in: byte offset of the created segment header - on the page */ - ibool has_done_reservation, /*!< in: TRUE if the caller has already - done the reservation for the pages with - fsp_reserve_free_extents (at least 2 extents: one for - the inode and the other for the segment) then there is - no need to do the check for this individual - operation */ - mtr_t* mtr); /*!< in/out: mini-transaction */ + ulint space_id, + ulint byte_offset, + ibool has_done_reservation, + mtr_t* mtr, + buf_block_t* block); + /**********************************************************************//** Calculates the number of pages reserved by a segment, and how many pages are currently used. diff --git a/storage/innobase/include/mtr0mtr.h b/storage/innobase/include/mtr0mtr.h index e91590d48d1..5270cd671db 100644 --- a/storage/innobase/include/mtr0mtr.h +++ b/storage/innobase/include/mtr0mtr.h @@ -434,6 +434,10 @@ struct mtr_t { static inline bool is_block_dirtied(const buf_block_t* block) MY_ATTRIBUTE((warn_unused_result)); + /** Get the buffer fix count for the block added by this mtr. + @param[in] block block to be checked + @return number of buffer count added by this mtr */ + int32_t get_fix_count(buf_block_t *block); private: /** Look up the system tablespace. */ void lookup_sys_space(); diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index c4fd5f84879..cf05563be02 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -2362,7 +2362,6 @@ init_fail: { i.created = true; buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK); - mtr.x_latch_at_savepoint(0, block); recv_recover_page(block, mtr, recv_addr, i.lsn); ut_ad(mtr.has_committed()); } diff --git a/storage/innobase/mtr/mtr0mtr.cc b/storage/innobase/mtr/mtr0mtr.cc index b649d907c23..6d0492f30f2 100644 --- a/storage/innobase/mtr/mtr0mtr.cc +++ b/storage/innobase/mtr/mtr0mtr.cc @@ -308,6 +308,32 @@ struct DebugCheck { }; #endif +/** Find buffer fix count of the given block acquired by the +mini-transaction */ +struct FindBlock +{ + int32_t num_fix; + buf_block_t *block; + + FindBlock(buf_block_t *block_buf): num_fix(0), block(block_buf) {} + bool operator()(const mtr_memo_slot_t* slot) + { + if (slot->object != NULL) + { + buf_block_t *mtr_block= reinterpret_cast(slot->object); + if (mtr_block == block) + num_fix++; + } + + return true; + } + + int32_t get_num_fix() + { + return num_fix; + } +}; + /** Release a resource acquired by the mini-transaction. */ struct ReleaseBlocks { /** Release specific object */ @@ -804,6 +830,15 @@ mtr_t::release_free_extents(ulint n_reserved) space->release_free_extents(n_reserved); } +int32_t mtr_t::get_fix_count(buf_block_t *block) +{ + struct FindBlock find_block(block); + Iterate iteration(find_block); + if (m_memo.for_each_block(iteration)) + return iteration.functor.get_num_fix(); + return 0; +} + #ifdef UNIV_DEBUG /** Check if memo contains the given item. @return true if contains */ diff --git a/storage/innobase/trx/trx0rseg.cc b/storage/innobase/trx/trx0rseg.cc index 60ebfa3c9a8..ac946adc8b5 100644 --- a/storage/innobase/trx/trx0rseg.cc +++ b/storage/innobase/trx/trx0rseg.cc @@ -57,7 +57,7 @@ trx_rseg_header_create( MTR_MEMO_SPACE_X_LOCK)); /* Allocate a new file segment for the rollback segment */ - block = fseg_create(space, 0, TRX_RSEG + TRX_RSEG_FSEG_HEADER, mtr); + block = fseg_create(space, TRX_RSEG + TRX_RSEG_FSEG_HEADER, mtr); if (block == NULL) { /* No space left */ diff --git a/storage/innobase/trx/trx0sys.cc b/storage/innobase/trx/trx0sys.cc index 2225c69b62e..8d00bd824a2 100644 --- a/storage/innobase/trx/trx0sys.cc +++ b/storage/innobase/trx/trx0sys.cc @@ -422,7 +422,7 @@ trx_sysf_create( mtr_x_lock_space(TRX_SYS_SPACE, mtr); /* Create the trx sys file block in a new allocated file segment */ - block = fseg_create(TRX_SYS_SPACE, 0, TRX_SYS + TRX_SYS_FSEG_HEADER, + block = fseg_create(TRX_SYS_SPACE, TRX_SYS + TRX_SYS_FSEG_HEADER, mtr); buf_block_dbg_add_level(block, SYNC_TRX_SYS_HEADER); diff --git a/storage/innobase/trx/trx0undo.cc b/storage/innobase/trx/trx0undo.cc index f9e76e5d772..5d4fcdcf53f 100644 --- a/storage/innobase/trx/trx0undo.cc +++ b/storage/innobase/trx/trx0undo.cc @@ -446,9 +446,9 @@ trx_undo_seg_create( } /* Allocate a new file segment for the undo log */ - block = fseg_create_general(space, 0, + block = fseg_create_general(space, TRX_UNDO_SEG_HDR - + TRX_UNDO_FSEG_HEADER, TRUE, mtr); + + TRX_UNDO_FSEG_HEADER, TRUE, mtr, NULL); fil_space_release_free_extents(space, n_reserved); -- cgit v1.2.1 From c26eae0cc02b0a8fd67901bf56adbb472c791981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 9 Sep 2020 12:01:03 +0300 Subject: MDEV-23456 fixup: Fix mtr_t::get_fix_count() Before commit 05fa4558e0e82302ece981deabce764491464eb2 (MDEV-22110) we have slot->type == MTR_MEMO_MODIFY that are unrelated to incrementing the buffer-fix count. FindBlock::operator(): In debug builds, skip MTR_MEMO_MODIFY entries. Also, simplify the code a little. This fixes an infinite loop in the tests innodb.innodb_defragment and innodb.innodb_wl6326_big. --- storage/innobase/mtr/mtr0mtr.cc | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/storage/innobase/mtr/mtr0mtr.cc b/storage/innobase/mtr/mtr0mtr.cc index 6d0492f30f2..424ac0b53f0 100644 --- a/storage/innobase/mtr/mtr0mtr.cc +++ b/storage/innobase/mtr/mtr0mtr.cc @@ -313,25 +313,17 @@ mini-transaction */ struct FindBlock { int32_t num_fix; - buf_block_t *block; + const buf_block_t *const block; + + FindBlock(const buf_block_t *block_buf): num_fix(0), block(block_buf) {} - FindBlock(buf_block_t *block_buf): num_fix(0), block(block_buf) {} bool operator()(const mtr_memo_slot_t* slot) { - if (slot->object != NULL) - { - buf_block_t *mtr_block= reinterpret_cast(slot->object); - if (mtr_block == block) - num_fix++; - } - + if (slot->object == block) + ut_d(if (slot->type != MTR_MEMO_MODIFY)) + num_fix++; return true; } - - int32_t get_num_fix() - { - return num_fix; - } }; /** Release a resource acquired by the mini-transaction. */ @@ -832,10 +824,9 @@ mtr_t::release_free_extents(ulint n_reserved) int32_t mtr_t::get_fix_count(buf_block_t *block) { - struct FindBlock find_block(block); - Iterate iteration(find_block); + Iterate iteration((FindBlock(block))); if (m_memo.for_each_block(iteration)) - return iteration.functor.get_num_fix(); + return iteration.functor.num_fix; return 0; } -- cgit v1.2.1 From 64c8fa58a8fe57fea8d43c8608c0e550e172305b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 9 Sep 2020 12:04:42 +0300 Subject: MDEV-23685 SIGSEGV on ADD FOREIGN KEY after failed ADD KEY dict_foreign_qualify_index(): Reject corrupted or garbage indexes. For index stubs that are created on virtual columns, no dict_field_t::col would be assign. Instead, the entire table definition would be reloaded on a successful operation. --- mysql-test/suite/innodb/r/foreign_key.result | 11 +++++++++++ mysql-test/suite/innodb/t/foreign_key.test | 13 +++++++++++++ storage/innobase/dict/dict0dict.cc | 6 +++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/innodb/r/foreign_key.result b/mysql-test/suite/innodb/r/foreign_key.result index fb4175c0327..769c1465f60 100644 --- a/mysql-test/suite/innodb/r/foreign_key.result +++ b/mysql-test/suite/innodb/r/foreign_key.result @@ -740,4 +740,15 @@ t2 CREATE TABLE `t2` ( CREATE TABLE t2 (f1 INT NOT NULL)ENGINE=InnoDB; ERROR 42S01: Table 't2' already exists DROP TABLE t2, t1; +# +# MDEV-23685 SIGSEGV on ADD FOREIGN KEY after failed attempt +# to create unique key on virtual column +# +CREATE TABLE t1 (pk INT PRIMARY KEY, a INT, b INT AS (a)) ENGINE=InnODB; +INSERT INTO t1 (pk,a) VALUES (1,10),(2,10); +ALTER TABLE t1 ADD UNIQUE INDEX ind9 (b), LOCK=SHARED; +ERROR 23000: Duplicate entry '10' for key 'ind9' +SET FOREIGN_KEY_CHECKS= 0; +ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES t1 (pk); +DROP TABLE t1; # End of 10.2 tests diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test index e0d83338dc2..9b9c639f86b 100644 --- a/mysql-test/suite/innodb/t/foreign_key.test +++ b/mysql-test/suite/innodb/t/foreign_key.test @@ -720,6 +720,19 @@ SHOW CREATE TABLE t2; CREATE TABLE t2 (f1 INT NOT NULL)ENGINE=InnoDB; DROP TABLE t2, t1; +--echo # +--echo # MDEV-23685 SIGSEGV on ADD FOREIGN KEY after failed attempt +--echo # to create unique key on virtual column +--echo # +CREATE TABLE t1 (pk INT PRIMARY KEY, a INT, b INT AS (a)) ENGINE=InnODB; + +INSERT INTO t1 (pk,a) VALUES (1,10),(2,10); +--error ER_DUP_ENTRY +ALTER TABLE t1 ADD UNIQUE INDEX ind9 (b), LOCK=SHARED; +SET FOREIGN_KEY_CHECKS= 0; +ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES t1 (pk); +DROP TABLE t1; + --echo # End of 10.2 tests --source include/wait_until_count_sessions.inc diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 84478d7528b..ba0cb9e4d4e 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -6609,7 +6609,11 @@ dict_foreign_qualify_index( return(false); } - if (index->type & (DICT_SPATIAL | DICT_FTS)) { + if (index->type & (DICT_SPATIAL | DICT_FTS | DICT_CORRUPT)) { + return false; + } + + if (index->online_status >= ONLINE_INDEX_ABORTED) { return false; } -- cgit v1.2.1 From d44c0f46c51bf456010360e4e73959a6130c00b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 9 Sep 2020 12:26:51 +0300 Subject: MDEV-22924 fixup: Replace C++11 nullptr Only starting with MariaDB Server 10.4 we may depend on C++11. --- storage/innobase/row/row0sel.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index 6951e0c7aac..2b6d34b8837 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -3316,7 +3316,7 @@ class Row_sel_get_clust_rec_for_mysql { rec_offs vers_offs[REC_OFFS_HEADER_SIZE + MAX_REF_PARTS]; rec_offs_init(vers_offs); - mem_heap_t *heap= nullptr; + mem_heap_t *heap= NULL; ut_ad(rec_offs_validate(cached_clust_rec, index, offsets)); ut_ad(index->first_user_field() <= rec_offs_n_fields(offsets)); -- cgit v1.2.1 From 040ae4c59bdf0f93caf410679b6b34aca5ebd4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 9 Sep 2020 13:02:25 +0300 Subject: MDEV-22924 fixup: Replace C++11 auto --- storage/innobase/row/row0sel.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index 2b6d34b8837..c07b42ea8d7 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -3323,7 +3323,7 @@ class Row_sel_get_clust_rec_for_mysql ut_ad(vers_offs == rec_get_offsets(cached_old_vers, index, vers_offs, true, index->db_trx_id(), &heap)); ut_ad(!heap); - for (auto n= index->db_trx_id(); n--; ) + for (unsigned n= index->db_trx_id(); n--; ) { const dict_col_t *col= dict_index_get_nth_col(index, n); ulint len1, len2; -- cgit v1.2.1 From 0eb38243ce09691cf46dd5fb875c1a1a1b75aff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 9 Sep 2020 13:04:11 +0300 Subject: MDEV-23456 fixup: Simplify a comparison --- storage/innobase/fsp/fsp0fsp.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/storage/innobase/fsp/fsp0fsp.cc b/storage/innobase/fsp/fsp0fsp.cc index 667da08eeea..58aa18ac323 100644 --- a/storage/innobase/fsp/fsp0fsp.cc +++ b/storage/innobase/fsp/fsp0fsp.cc @@ -2010,9 +2010,8 @@ fseg_create_general( if (block) { header = byte_offset + buf_block_get_frame(block); - const ulint type = - (block->page.id.space() == TRX_SYS_SPACE - && block->page.id.page_no() == TRX_SYS_PAGE_NO) + const ulint type = block->page.id == page_id_t(TRX_SYS_SPACE, + TRX_SYS_PAGE_NO) ? FIL_PAGE_TYPE_TRX_SYS : FIL_PAGE_TYPE_SYS; -- cgit v1.2.1 From e17d0eb6d205c5eb309a775d18e0a51642ec7216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 9 Sep 2020 14:16:07 +0300 Subject: MDEV-23593 : galera_3nodes.GCF-376 MTR failed: Table 'test.t1' doesn't exist Add wait_condition to make sure table is there. --- mysql-test/suite/galera_3nodes/t/GCF-376.test | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mysql-test/suite/galera_3nodes/t/GCF-376.test b/mysql-test/suite/galera_3nodes/t/GCF-376.test index 8543ebbc56a..ff5bfbfb209 100644 --- a/mysql-test/suite/galera_3nodes/t/GCF-376.test +++ b/mysql-test/suite/galera_3nodes/t/GCF-376.test @@ -17,6 +17,9 @@ CREATE TABLE test.t1 (f1 INTEGER PRIMARY KEY, f2 CHAR(1)) ENGINE=InnoDB; --connection node_2 +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; +--source include/wait_condition.inc + SET GLOBAL wsrep_on=OFF; INSERT INTO t1 VALUES (1, 'a'); SET GLOBAL wsrep_on=ON; -- cgit v1.2.1 From a569dc55fb96bbb2c345670752b07848e759e220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 9 Sep 2020 14:46:17 +0300 Subject: MDEV-23592 : galera_3nodes.inconsistency_shutdown MTR failed: Could not open '../galera/include/galera_have_debug_sync.inc' for reading, errno: 2 Correct include path. --- mysql-test/suite/galera_3nodes/t/inconsistency_shutdown.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/suite/galera_3nodes/t/inconsistency_shutdown.test b/mysql-test/suite/galera_3nodes/t/inconsistency_shutdown.test index 7add9f48cfc..aa9ef08c107 100644 --- a/mysql-test/suite/galera_3nodes/t/inconsistency_shutdown.test +++ b/mysql-test/suite/galera_3nodes/t/inconsistency_shutdown.test @@ -7,7 +7,7 @@ --source include/have_innodb.inc --source include/have_debug.inc --source include/have_debug_sync.inc ---source ../galera/include/galera_have_debug_sync.inc +--source include/galera_have_debug_sync.inc # Save original auto_increment_offset values. --let $node_1=node_1 -- cgit v1.2.1 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: MDEV-23706 : Galera test failure on galera_autoinc_sst_mariabackup Remove infinite procedure and use direct INSERTs. --- .../galera/r/galera_autoinc_sst_mariabackup.result | 69 ++++++++------- .../galera/t/galera_autoinc_sst_mariabackup.test | 97 ++++++++-------------- 2 files changed, 67 insertions(+), 99 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); -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; +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; -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 +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; -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_2a; +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 ---source include/start_mysqld.inc - -INSERT INTO t1 VALUES (DEFAULT); - -# Terminate the stored procedure - ---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 +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_2 -# CR_SERVER_LOST ---error 2013,2006 ---reap - -# Confirm that the count is correct and that the cluster is intact +--connection node_2a +--source include/start_mysqld.inc +--source include/wait_until_connected_again.inc + +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 ---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 -- cgit v1.2.1 From 90bea7c32c0eb905f3d129630f26b8cdfa0d92db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 9 Sep 2020 11:00:04 +0300 Subject: MDEV-23613 : galera_sr.galera_sr_kill_slave MTR failed: query 'LOCK TABLE t2 WRITE' failed: 1146: Table 'test.t2' doesn't exist Remove unnecessary sleeps from test and replace them with proper wait_conditions. --- .../suite/galera_sr/r/galera_sr_kill_slave.result | 24 ++++++++++----------- .../suite/galera_sr/t/galera_sr_kill_slave.test | 25 +++++++++++++--------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/mysql-test/suite/galera_sr/r/galera_sr_kill_slave.result b/mysql-test/suite/galera_sr/r/galera_sr_kill_slave.result index d14de27d2b7..eab6110afb1 100644 --- a/mysql-test/suite/galera_sr/r/galera_sr_kill_slave.result +++ b/mysql-test/suite/galera_sr/r/galera_sr_kill_slave.result @@ -2,9 +2,9 @@ connection node_2; connection node_1; CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB; connection node_2; -SELECT COUNT(*) = 0 FROM t1; -COUNT(*) = 0 -1 +SELECT COUNT(*) AS EXPECT_0 FROM t1; +EXPECT_0 +0 connection node_1; CREATE TABLE t2 (f1 INTEGER); connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2; @@ -39,16 +39,16 @@ INSERT INTO t1 VALUES (13); INSERT INTO t1 VALUES (14); INSERT INTO t1 VALUES (15); COMMIT; -SELECT COUNT(*) = 0 FROM mysql.wsrep_streaming_log; -COUNT(*) = 0 -1 +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; +EXPECT_0 +0 connection node_2; -SELECT COUNT(*) = 15 FROM t1; -COUNT(*) = 15 -1 -SELECT COUNT(*) = 0 FROM mysql.wsrep_streaming_log; -COUNT(*) = 0 -1 +SELECT COUNT(*) AS EXPECT_15 FROM t1; +EXPECT_15 +15 +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; +EXPECT_0 +0 connection node_1; DROP TABLE t1; DROP TABLE t2; diff --git a/mysql-test/suite/galera_sr/t/galera_sr_kill_slave.test b/mysql-test/suite/galera_sr/t/galera_sr_kill_slave.test index a76a03e49b9..cbf7213c69f 100644 --- a/mysql-test/suite/galera_sr/t/galera_sr_kill_slave.test +++ b/mysql-test/suite/galera_sr/t/galera_sr_kill_slave.test @@ -13,12 +13,17 @@ CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB; # Block node #2's applier before table t1's inserts have come into play --connection node_2 -SELECT COUNT(*) = 0 FROM t1; +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1' +--source include/wait_condition.inc +SELECT COUNT(*) AS EXPECT_0 FROM t1; --connection node_1 CREATE TABLE t2 (f1 INTEGER); --connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2 +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't2' +--source include/wait_condition.inc + LOCK TABLE t2 WRITE; --connection node_1 @@ -39,11 +44,8 @@ INSERT INTO t1 VALUES (3); INSERT INTO t1 VALUES (4); INSERT INTO t1 VALUES (5); ---sleep 2 - --connection node_2 --source include/kill_galera.inc ---sleep 1 --connection node_1 INSERT INTO t1 VALUES (6); @@ -54,8 +56,6 @@ INSERT INTO t1 VALUES (10); --connection node_2 --source include/start_mysqld.inc ---sleep 1 - --source include/wait_until_connected_again.inc --source include/galera_wait_ready.inc @@ -67,12 +67,17 @@ INSERT INTO t1 VALUES (14); INSERT INTO t1 VALUES (15); COMMIT; -SELECT COUNT(*) = 0 FROM mysql.wsrep_streaming_log; +--let $wait_condition = SELECT COUNT(*) = 0 FROM mysql.wsrep_streaming_log +--source include/wait_condition.inc + +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; --connection node_2 ---sleep 5 -SELECT COUNT(*) = 15 FROM t1; -SELECT COUNT(*) = 0 FROM mysql.wsrep_streaming_log; +--let $wait_condition = SELECT COUNT(*) = 15 FROM t1 +--source include/wait_condition.inc + +SELECT COUNT(*) AS EXPECT_15 FROM t1; +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; --connection node_1 -- cgit v1.2.1 From 44e7e1f0d334a7ded3c256878a5a7907a7b2cf16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 9 Sep 2020 11:41:42 +0300 Subject: MDEV-23611 : galera_sr.galera_sr_kill_query MTR failed: 15 instead of 0 on "SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log;" Add wait_condition to stabilize test. --- mysql-test/suite/galera_sr/r/galera_sr_kill_query.result | 16 ++++++++++++---- mysql-test/suite/galera_sr/t/galera_sr_kill_query.test | 13 +++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/mysql-test/suite/galera_sr/r/galera_sr_kill_query.result b/mysql-test/suite/galera_sr/r/galera_sr_kill_query.result index 82f41a2faaa..c775cd854a7 100644 --- a/mysql-test/suite/galera_sr/r/galera_sr_kill_query.result +++ b/mysql-test/suite/galera_sr/r/galera_sr_kill_query.result @@ -17,17 +17,25 @@ SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; SELECT COUNT(*) AS EXPECT_0 FROM t1; EXPECT_0 0 -SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; -EXPECT_0 -0 INSERT INTO t1 SELECT 1 FROM ten AS t1, ten AS t2, ten AS t3; SELECT COUNT(*) AS EXPECT_1000 FROM t1; EXPECT_1000 1000 -connection node_1a; +connection node_1; SET GLOBAL wsrep_sync_wait=15; SELECT COUNT(*) AS EXPECT_1000 FROM t1; EXPECT_1000 1000 +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; +EXPECT_0 +0 +connection node_2; +SELECT COUNT(*) AS EXPECT_1000 FROM t1; +EXPECT_1000 +1000 +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; +EXPECT_0 +0 +connection node_1; DROP TABLE t1; DROP TABLE ten; diff --git a/mysql-test/suite/galera_sr/t/galera_sr_kill_query.test b/mysql-test/suite/galera_sr/t/galera_sr_kill_query.test index 5282baed86d..8bce5f6bc36 100644 --- a/mysql-test/suite/galera_sr/t/galera_sr_kill_query.test +++ b/mysql-test/suite/galera_sr/t/galera_sr_kill_query.test @@ -33,18 +33,27 @@ SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; # Confirm that the kill caused the updates made so far to be removed --connection node_2 +--let $wait_condition = SELECT COUNT(*) = 0 FROM t1 +--source include/wait_condition.inc SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; SELECT COUNT(*) AS EXPECT_0 FROM t1; -SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; # Confirm that the transaction can be reissued in its entirety on the slave without a conflict INSERT INTO t1 SELECT 1 FROM ten AS t1, ten AS t2, ten AS t3; SELECT COUNT(*) AS EXPECT_1000 FROM t1; ---connection node_1a +--connection node_1 SET GLOBAL wsrep_sync_wait=15; +--let $wait_condition = SELECT COUNT(*) = 1000 FROM t1; +--source include/wait_condition.inc +SELECT COUNT(*) AS EXPECT_1000 FROM t1; +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; + +--connection node_2 SELECT COUNT(*) AS EXPECT_1000 FROM t1; +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; +--connection node_1 DROP TABLE t1; DROP TABLE ten; -- cgit v1.2.1 From cf9b3b25b41f714d681c80736e98c402076d989b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 9 Sep 2020 13:05:19 +0300 Subject: MDEV-23608 : galera_sr.GCF-597 MTR failed: query 'ROLLBACK' succeeded - should have failed with errno 1213 Added wait_condition to wait correct streaming state. --- mysql-test/suite/galera_sr/r/GCF-597.result | 6 ++++++ mysql-test/suite/galera_sr/t/GCF-597.test | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/galera_sr/r/GCF-597.result b/mysql-test/suite/galera_sr/r/GCF-597.result index 7afca229251..52b13ba3268 100644 --- a/mysql-test/suite/galera_sr/r/GCF-597.result +++ b/mysql-test/suite/galera_sr/r/GCF-597.result @@ -15,7 +15,13 @@ INSERT INTO t1 VALUES (2); INSERT INTO t1 VALUES (3); INSERT INTO t1 VALUES (4); INSERT INTO t1 VALUES (5); +connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; +connection node_1a; +connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2; +connection node_2a; connection node_2; ROLLBACK; ERROR 40001: Deadlock found when trying to get lock; try restarting transaction DROP TABLE t1; +disconnect node_1a; +disconnect node_2a; diff --git a/mysql-test/suite/galera_sr/t/GCF-597.test b/mysql-test/suite/galera_sr/t/GCF-597.test index d3d80ffc4f8..9c86e598154 100644 --- a/mysql-test/suite/galera_sr/t/GCF-597.test +++ b/mysql-test/suite/galera_sr/t/GCF-597.test @@ -22,8 +22,21 @@ INSERT INTO t1 VALUES (3); INSERT INTO t1 VALUES (4); INSERT INTO t1 VALUES (5); +--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1 +--connection node_1a +--let $wait_condition = SELECT COUNT(*) = 5 FROM mysql.wsrep_streaming_log +--source include/wait_condition.inc + +--connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2 +--connection node_2a +--let $wait_condition = SELECT COUNT(*) = 5 FROM mysql.wsrep_streaming_log +--source include/wait_condition.inc + --connection node_2 --error ER_LOCK_DEADLOCK ROLLBACK; -DROP TABLE t1; \ No newline at end of file +DROP TABLE t1; + +--disconnect node_1a +--disconnect node_2a -- cgit v1.2.1 From 1bb3ad6dfc885112d05d8d73b066f18a416ca965 Mon Sep 17 00:00:00 2001 From: Geert Hendrickx Date: Thu, 27 Aug 2020 17:30:03 +0200 Subject: 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 -- cgit v1.2.1 From 75e82f71f16c3248387e00bc6e4fe4da02555325 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Wed, 9 Sep 2020 17:14:48 +0530 Subject: 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. --- .../suite/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 | 1594 +++----------------- 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, 285 insertions(+), 1449 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) -{ - fts_t* fts = parent_table->fts; - - if (trx_get_dict_operation(trx) == TRX_DICT_OP_NONE) { - trx_set_dict_operation(trx, TRX_DICT_OP_INDEX); - } - - 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"); - } -} - -/** 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) -{ - fts_t* fts = table->fts; - - if (trx_get_dict_operation(trx) == TRX_DICT_OP_NONE) { - trx_set_dict_operation(trx, TRX_DICT_OP_INDEX); - } - - 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; - } - } -} - -/** 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) -{ - dict_table_t* table; - dict_index_t* index; - table = dict_table_open_on_id( - aux_table->parent_id, TRUE, DICT_TABLE_OP_NORMAL); - - if (table == NULL) { - return(0); - } - - 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(); - } - } - - dict_table_close(table, true, false); - return(0); -} - -/* 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) -{ - fts_aux_table_t aux_table; - char* parent_table_name = NULL; - - if (fts_is_aux_table_name(&aux_table, aux_table_name, aux_table_len)) { - dict_table_t* parent_table; - - parent_table = dict_table_open_on_id( - aux_table.parent_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); - } - } - - return(parent_table_name); -} - -/** 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) -{ - 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; +bool fts_check_aux_table(const char *name, + table_id_t *table_id, + index_id_t *index_id) +{ + ulint len= strlen(name); + const char* ptr; + const char* end= name + len; - for (ulint count = 0; count < ib_vector_size(tables); - ++count) { + ut_ad(len <= MAX_FULL_NAME_LEN); + ptr= static_cast(memchr(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 && 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; +} + +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) +{ + mutex_enter(&fil_system->mutex); + + 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; + + 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 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) +{ + btr_pcur_t pcur; + mtr_t mtr; + trx_t* trx = trx_allocate_for_background(); + trx->op_info = "checking fts orphaned tables"; + + row_mysql_lock_data_dictionary(trx); + + 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); + + 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)); - 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); + 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); +} - 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 */ +/** 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) { - 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); + 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); + + /* Drop all fts aux and common table */ + dberr_t err= fts_drop_table(trx, fts_table_name); + + if (err == DB_FAIL) + { + char *path= fil_make_filepath(NULL, fts_table_name, IBD, false); + + if (path != NULL) + { + os_file_delete_if_exists(innodb_data_file_key, path , NULL); + ut_free(path); + } + } + } +} + +/** 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() +{ + fts_space_set_t fts_space_set; + fil_get_fts_spaces(fts_space_set); - /* 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 (fts_space_set.empty()) + return; - if (heap != NULL) { - mem_heap_free(heap); - } + fts_check_orphaned_tables(fts_space_set); - /** 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) { + if (fts_space_set.empty()) + return; - UT_DELETE_ARRAY(*it); - } + 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); -- cgit v1.2.1 From f19da4a05a14e217e77600cd452a345d209101cf Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Mon, 7 Sep 2020 14:23:05 +0530 Subject: 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); - - if (fil_space_t* space = fil_space_get_space(id)) { - space->recv_size = size; - } + mutex_enter(&fil_system.mutex); + ut_ad(id < SRV_LOG_SPACE_FIRST_ID); - 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); -- cgit v1.2.1 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: 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)); -- cgit v1.2.1 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: 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. --- mysql-test/suite/galera/r/galera_fk_cascade_delete_debug.result | 1 + mysql-test/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 -- cgit v1.2.1 From d2bf1ed0300fb79e25d049387499440063771cc3 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 31 Aug 2020 09:54:46 +0200 Subject: MDEV-23492 performance_schema_digests_size changing from default to 5000 when enabling performance_schema max allowed value limit should be larger than any auto-sized value --- mysql-test/suite/sys_vars/r/sysvars_server_embedded.result | 2 +- mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result | 2 +- sql/sys_vars.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result index 704f893e32e..7bfa2f626f0 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result @@ -2328,7 +2328,7 @@ VARIABLE_SCOPE GLOBAL VARIABLE_TYPE BIGINT VARIABLE_COMMENT Size of the statement digest. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 -NUMERIC_MAX_VALUE 200 +NUMERIC_MAX_VALUE 1048576 NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY YES diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result index f2b7f14cc99..8854fab4209 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result @@ -2488,7 +2488,7 @@ VARIABLE_SCOPE GLOBAL VARIABLE_TYPE BIGINT VARIABLE_COMMENT Size of the statement digest. Use 0 to disable, -1 for automated sizing. NUMERIC_MIN_VALUE -1 -NUMERIC_MAX_VALUE 200 +NUMERIC_MAX_VALUE 1048576 NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY YES diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 4bda42b2ffa..64040243df0 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -362,7 +362,7 @@ static Sys_var_long Sys_pfs_digest_size( "Size of the statement digest." " Use 0 to disable, -1 for automated sizing.", PARSED_EARLY READ_ONLY GLOBAL_VAR(pfs_param.m_digest_sizing), - CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 200), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024), DEFAULT(PFS_AUTOSCALE_VALUE), BLOCK_SIZE(1)); static Sys_var_long Sys_pfs_events_transactions_history_long_size( -- cgit v1.2.1 From 5ad36aa3b8cb02450e5ade50f13d4a7c8e68947b Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 8 Sep 2020 18:54:56 +0200 Subject: de-virtualize redundantly virtual Item method and remove a couple of useless MY_TEST's --- sql/item.h | 2 +- sql/opt_index_cond_pushdown.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/item.h b/sql/item.h index 34ceae62c8e..19b7b5d03e9 100644 --- a/sql/item.h +++ b/sql/item.h @@ -2392,7 +2392,7 @@ public: if (join_tab_idx_arg < join_tab_idx) join_tab_idx= join_tab_idx_arg; } - virtual uint get_join_tab_idx() { return join_tab_idx; } + uint get_join_tab_idx() const { return join_tab_idx; } table_map view_used_tables(TABLE_LIST *view) { diff --git a/sql/opt_index_cond_pushdown.cc b/sql/opt_index_cond_pushdown.cc index 360ae028f36..15bc2074e1f 100644 --- a/sql/opt_index_cond_pushdown.cc +++ b/sql/opt_index_cond_pushdown.cc @@ -206,7 +206,7 @@ static Item *make_cond_for_index(THD *thd, Item *cond, TABLE *table, uint keyno, new_cond->argument_list()->push_back(fix, thd->mem_root); used_tables|= fix->used_tables(); } - if (MY_TEST(item->marker == ICP_COND_USES_INDEX_ONLY)) + if (item->marker == ICP_COND_USES_INDEX_ONLY) { n_marked++; item->marker= 0; @@ -239,7 +239,7 @@ static Item *make_cond_for_index(THD *thd, Item *cond, TABLE *table, uint keyno, if (!fix) return (COND*) 0; new_cond->argument_list()->push_back(fix, thd->mem_root); - if (MY_TEST(item->marker == ICP_COND_USES_INDEX_ONLY)) + if (item->marker == ICP_COND_USES_INDEX_ONLY) { n_marked++; item->marker= 0; -- cgit v1.2.1 From 897b51db434d58e5cfe0079195bb81b7ff624fce Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 10 Sep 2020 12:12:47 +0200 Subject: make S3 tests to run when S3 is statically linked * use the environment variable HA_S3_SO, not a literal ha_s3 in cnf files * make ConfigFactory to support empty option values * update no_s3.result after MDEV-11412 --- mysql-test/lib/My/ConfigFactory.pm | 2 +- mysql-test/suite/s3/my.cnf | 2 +- mysql-test/suite/s3/no_s3.result | 2 -- mysql-test/suite/s3/slave.cnf | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/mysql-test/lib/My/ConfigFactory.pm b/mysql-test/lib/My/ConfigFactory.pm index db5c1aa1875..3249a06256c 100644 --- a/mysql-test/lib/My/ConfigFactory.pm +++ b/mysql-test/lib/My/ConfigFactory.pm @@ -347,7 +347,7 @@ sub resolve_at_variable { or croak "There is no group named '$group_name' that ", "can be used to resolve '$option_name' for test '$self->{testname}'"; - my $value= $from_group->value($option_name); + my $value= $from_group->value($option_name) || ''; $res .= $before.$value; } $res .= $after; diff --git a/mysql-test/suite/s3/my.cnf b/mysql-test/suite/s3/my.cnf index 03060f8a0ef..a979bf31817 100644 --- a/mysql-test/suite/s3/my.cnf +++ b/mysql-test/suite/s3/my.cnf @@ -3,7 +3,7 @@ [mysqld.1] plugin-maturity = alpha -plugin-load-add=ha_s3 +plugin-load-add=@ENV.HA_S3_SO s3=ON #s3-host-name=s3.amazonaws.com #s3-protocol-version=Amazon diff --git a/mysql-test/suite/s3/no_s3.result b/mysql-test/suite/s3/no_s3.result index 89ab3ea97a1..9333944cf66 100644 --- a/mysql-test/suite/s3/no_s3.result +++ b/mysql-test/suite/s3/no_s3.result @@ -9,5 +9,3 @@ ERROR 42000: Table 's3_unique_table' uses an extension that doesn't exist in thi rename table s3_unique_table to t1; ERROR HY000: Error on rename of './test/s3_unique_table' to './test/t1' (errno: 138 "Unsupported extension used for table") drop table s3_unique_table; -Warnings: -Warning 1112 Table 's3_unique_table' uses an extension that doesn't exist in this MariaDB version diff --git a/mysql-test/suite/s3/slave.cnf b/mysql-test/suite/s3/slave.cnf index 514171b383c..b9b1da73a92 100644 --- a/mysql-test/suite/s3/slave.cnf +++ b/mysql-test/suite/s3/slave.cnf @@ -1,6 +1,6 @@ [mysqld.2] plugin-maturity = alpha -plugin-load-add=ha_s3 +plugin-load-add=@ENV.HA_S3_SO s3=ON #s3-host-name=s3.amazonaws.com #s3-protocol-version=Amazon -- cgit v1.2.1 From 5f2728d594bf0202afebeff2323324df79b50425 Mon Sep 17 00:00:00 2001 From: Erol Guven Date: Mon, 24 Aug 2020 11:25:37 +0100 Subject: Define variable to override endpoint url --- plugin/aws_key_management/aws_key_management_plugin.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugin/aws_key_management/aws_key_management_plugin.cc b/plugin/aws_key_management/aws_key_management_plugin.cc index 489dd375387..348c171b618 100644 --- a/plugin/aws_key_management/aws_key_management_plugin.cc +++ b/plugin/aws_key_management/aws_key_management_plugin.cc @@ -81,6 +81,7 @@ static unsigned long key_spec; static unsigned long log_level; static int rotate_key; static int request_timeout; +static char* endpoint_url; #ifndef DBUG_OFF #define WITH_AWS_MOCK 1 @@ -229,6 +230,10 @@ static int aws_init() { clientConfiguration.region = region; } + if (endpoint_url && endpoint_url[0]) + { + clientConfiguration.endpointOverride = endpoint_url; + } if (request_timeout) { clientConfiguration.requestTimeoutMs= request_timeout; @@ -711,6 +716,11 @@ static MYSQL_SYSVAR_STR(region, region, "AWS region. For example us-east-1, or eu-central-1. If no value provided, SDK default is used.", NULL, NULL, ""); +static MYSQL_SYSVAR_STR(endpoint_url, endpoint_url, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, + "Used to override the default AWS API endpoint. If not set, the default will be used", + NULL, NULL, ""); + #if WITH_AWS_MOCK static MYSQL_SYSVAR_BOOL(mock, mock, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, @@ -725,6 +735,7 @@ static struct st_mysql_sys_var* settings[]= { MYSQL_SYSVAR(log_level), MYSQL_SYSVAR(request_timeout), MYSQL_SYSVAR(region), + MYSQL_SYSVAR(endpoint_url), #if WITH_AWS_MOCK MYSQL_SYSVAR(mock), #endif -- cgit v1.2.1 From bfd1ed5a130ecb9c1061f0e75d30463439a66277 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Fri, 11 Sep 2020 12:24:29 +0530 Subject: 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; } -- cgit v1.2.1 From af834c218a59b0f187edb19aa4f8bd476b9ed6ac Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Fri, 11 Sep 2020 16:37:13 +0530 Subject: 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); -- cgit v1.2.1 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: 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. --- mysql-test/suite/galera_3nodes/r/galera_var_dirty_reads2.result | 2 +- mysql-test/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 -- cgit v1.2.1 From c3a3b4596c9e1c922afb00b4222c6496535f0f40 Mon Sep 17 00:00:00 2001 From: Sachin Date: Fri, 11 Sep 2020 15:27:58 +0100 Subject: 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. -- cgit v1.2.1 From 269f9c948c5f6bd0bdf8382d5c2ae266a02149e6 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sat, 12 Sep 2020 09:27:46 +1000 Subject: 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 */ } -- cgit v1.2.1 From ae8ff3a067c046bf7df1cce175078914c6879d81 Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Wed, 9 Sep 2020 11:41:06 +1000 Subject: 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. --- mysql-test/suite/gcol/r/innodb_virtual_fk.result | 29 +++++++++++++++++ mysql-test/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)) { - - dfield_set_null(&upd_field->new_val); - } - - if (!node->is_delete - && (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE)) { - - 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); + bool set_null = + node->is_delete + ? (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) + : (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL); - if (new_vfield == NULL) { - return DB_COMPUTE_VALUE_FAILED; - } + 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); - dfield_copy(&(upd_field->new_val), new_vfield); + if (new_vfield == NULL) { + return DB_COMPUTE_VALUE_FAILED; } - n_diff++; + dfield_copy(&upd_field->new_val, new_vfield); + + if (!dfield_datas_are_binary_equal( + upd_field->old_v_val, + &upd_field->new_val, 0)) + n_diff++; } update->n_fields = n_diff; -- cgit v1.2.1 From 80075ba011fb1b90aaf349a17a6f94145c5c8864 Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Mon, 7 Sep 2020 19:43:23 +0300 Subject: 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 +- mysql-test/suite/mariabackup/rpl_slave_info.result | 37 ++++++++++ mysql-test/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 -- cgit v1.2.1 From fd5cbbb91ee0d00aeefdd59e5538a30c011e51ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 14 Sep 2020 11:48:36 +0300 Subject: MDEV-23591 : galera_3nodes.GCF-354 MTR failed: 1047: WSREP has not yet prepared node for application use Stabilize test. --- mysql-test/suite/galera_3nodes/r/GCF-354.result | 11 ++++++----- mysql-test/suite/galera_3nodes/t/GCF-354.test | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/mysql-test/suite/galera_3nodes/r/GCF-354.result b/mysql-test/suite/galera_3nodes/r/GCF-354.result index dad57fe15ec..1fa4265edcf 100644 --- a/mysql-test/suite/galera_3nodes/r/GCF-354.result +++ b/mysql-test/suite/galera_3nodes/r/GCF-354.result @@ -1,17 +1,18 @@ connection node_2; connection node_1; -connection node_2; -SET wsrep_on=OFF; -DROP SCHEMA test; connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3; connection node_3; connection node_1; connection node_2; connection node_3; +connection node_2; SET wsrep_on=OFF; -CREATE TABLE test.t1 (f1 INTEGER); +DROP SCHEMA test; +connection node_3; +SET SESSION wsrep_on=OFF; +CREATE TABLE test.t1 (f1 INTEGER) engine=innodb; connection node_1; -CREATE TABLE test.t1 (f1 INTEGER); +CREATE TABLE test.t1 (f1 INTEGER) engine=innodb; SHOW STATUS LIKE 'wsrep_cluster_status'; Variable_name Value wsrep_cluster_status Primary diff --git a/mysql-test/suite/galera_3nodes/t/GCF-354.test b/mysql-test/suite/galera_3nodes/t/GCF-354.test index c428aee7732..d4e2bc095fa 100644 --- a/mysql-test/suite/galera_3nodes/t/GCF-354.test +++ b/mysql-test/suite/galera_3nodes/t/GCF-354.test @@ -1,11 +1,5 @@ --source include/galera_cluster.inc ---source include/have_innodb.inc -# -# 1. Create different inconsistencies on nodes 2 and 3 -# ---connection node_2 -SET wsrep_on=OFF; -DROP SCHEMA test; +--source include/force_restart.inc --connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3 --connection node_3 @@ -16,15 +10,23 @@ DROP SCHEMA test; --let $node_3=node_3 --source ../galera/include/auto_increment_offset_save.inc +# +# 1. Create different inconsistencies on nodes 2 and 3 +# +--connection node_2 SET wsrep_on=OFF; -CREATE TABLE test.t1 (f1 INTEGER); +DROP SCHEMA test; + +--connection node_3 +SET SESSION wsrep_on=OFF; +CREATE TABLE test.t1 (f1 INTEGER) engine=innodb; # # 2. The following should generate different errors on nodes 2 and 3 and # trigger voting with 3 different votes. node_1 should remain alone # in the cluster. # --connection node_1 -CREATE TABLE test.t1 (f1 INTEGER); +CREATE TABLE test.t1 (f1 INTEGER) engine=innodb; --let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' --source include/wait_condition.inc -- cgit v1.2.1 From 5768f57d243e3fa945d79fcdc1a3eacb1e4ebb0d Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Mon, 14 Sep 2020 21:19:56 +1000 Subject: 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 # -- cgit v1.2.1 From 2bac9782aa81ad386beaf00eb126ccf2d15031a1 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 12 Sep 2020 10:33:33 +0200 Subject: make install: don't assume $DESTDIR exists WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX} means that this path already exists, which is not necessarily the case for make install. Create it `mkdir -p` style. --- cmake/mariadb_connector_c.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/mariadb_connector_c.cmake b/cmake/mariadb_connector_c.cmake index b1d784ff39b..a9b103345cd 100644 --- a/cmake/mariadb_connector_c.cmake +++ b/cmake/mariadb_connector_c.cmake @@ -42,8 +42,7 @@ ADD_SUBDIRECTORY(libmariadb) IF(UNIX) INSTALL(CODE "EXECUTE_PROCESS( - COMMAND ${CMAKE_COMMAND} -E make_directory ${INSTALL_BINDIR} - WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}) + COMMAND ${CMAKE_COMMAND} -E make_directory \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${INSTALL_BINDIR}) EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E create_symlink mariadb_config ${INSTALL_BINDIR}/mariadb-config WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX})" -- cgit v1.2.1 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: 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. --- .../suite/galera_sr/r/galera_sr_rollback_retry.result | 15 ++++++++------- .../suite/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; -- cgit v1.2.1 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: 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. -- cgit v1.2.1 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: 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 -- cgit v1.2.1 From 873cc1e77a734d1806b2cd0217042d1f9f19e5e7 Mon Sep 17 00:00:00 2001 From: Sujatha Date: Wed, 16 Sep 2020 14:03:32 +0530 Subject: 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 +- .../r/binlog_show_binlog_event_random_pos.result | 3 ++ .../t/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, -- cgit v1.2.1 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: 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. --- .../suite/galera/r/galera_wan_restart_ist.result | 55 +++++++++++----- .../suite/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 -- cgit v1.2.1 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: MDEV-21769 : `galera_3nodes.galera_safe_to_bootstrap` fails Add wait_condition to wait correct cluster configuration. --- .../suite/galera_3nodes/r/galera_safe_to_bootstrap.result | 6 ++++-- .../suite/galera_3nodes/t/galera_safe_to_bootstrap.cnf | 10 ++++++++++ .../suite/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 -- cgit v1.2.1 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: 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 +++--- .../suite/galera_3nodes/r/galera_ipv6_mariabackup.result | 6 +++--- .../galera_3nodes/r/galera_ipv6_mariabackup_section.result | 6 +++--- .../suite/galera_3nodes/r/galera_ipv6_mysqldump.result | 6 +++--- mysql-test/suite/galera_3nodes/r/galera_ipv6_rsync.result | 6 +++--- .../suite/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 +++-- mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.cnf | 3 +++ mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.opt | 1 - .../suite/galera_3nodes/t/galera_ipv6_mariabackup.test | 4 ++-- .../galera_3nodes/t/galera_ipv6_mariabackup_section.cnf | 12 +++++++----- .../galera_3nodes/t/galera_ipv6_mariabackup_section.opt | 1 - .../galera_3nodes/t/galera_ipv6_mariabackup_section.test | 4 ++-- mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.cnf | 3 +++ mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.opt | 1 - mysql-test/suite/galera_3nodes/t/galera_ipv6_mysqldump.test | 4 ++-- mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.cnf | 3 +++ mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.opt | 1 - mysql-test/suite/galera_3nodes/t/galera_ipv6_rsync.test | 4 ++-- .../suite/galera_3nodes/t/galera_ipv6_rsync_section.cnf | 11 +++++++---- .../suite/galera_3nodes/t/galera_ipv6_rsync_section.opt | 1 - .../suite/galera_3nodes/t/galera_ipv6_rsync_section.test | 4 ++-- .../suite/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 -- cgit v1.2.1 From 852771ba1e41142a84f90e76e4ed228fc7699700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 11 Sep 2020 15:52:22 +0300 Subject: MDEV-23719: Remove buf_block_t::lock_hash_val The InnoDB buffer block page descriptor is caching a value buf_block_t::lock_hash_val that should be quick to compute in the first place, as suggested by commit 14be81438098923e95bda6d635d638991e60116b. lock_rec_fold(): Define as page_id_t::fold() instead of ut_fold_ulint_pair(). --- storage/innobase/buf/buf0buf.cc | 10 ---------- storage/innobase/gis/gis0sea.cc | 1 - storage/innobase/include/buf0buf.h | 17 ----------------- storage/innobase/include/buf0buf.ic | 18 ------------------ storage/innobase/include/lock0lock.ic | 2 +- storage/innobase/include/lock0priv.ic | 10 ++++++---- storage/innobase/lock/lock0lock.cc | 12 ------------ 7 files changed, 7 insertions(+), 63 deletions(-) diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index 4094c24fac2..85e21371e37 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -1763,10 +1763,6 @@ inline bool buf_pool_t::realloc(buf_block_t *block) new_block->left_side = TRUE; #endif /* BTR_CUR_HASH_ADAPT */ - new_block->lock_hash_val = block->lock_hash_val; - ut_ad(new_block->lock_hash_val == lock_rec_hash( - id.space(), id.page_no())); - hash_lock->write_unlock(); /* free block */ @@ -3368,9 +3364,6 @@ evict_from_pool: /* Set after buf_relocate(). */ block->page.set_buf_fix_count(1); - block->lock_hash_val = lock_rec_hash(page_id.space(), - page_id.page_no()); - if (!block->page.oldest_modification()) { ut_d(UT_LIST_REMOVE(buf_pool.zip_clean, &block->page)); } else { @@ -3800,7 +3793,6 @@ void buf_block_t::initialise(const page_id_t page_id, ulint zip_size, { ut_ad(page.state() != BUF_BLOCK_FILE_PAGE); buf_block_init_low(this); - lock_hash_val= lock_rec_hash(page_id.space(), page_id.page_no()); page.init(page_id, fix); page_zip_set_size(&page.zip, zip_size); } @@ -3884,8 +3876,6 @@ loop: #endif free_block->page.set_state(BUF_BLOCK_FILE_PAGE); - free_block->lock_hash_val= lock_rec_hash( - page_id.space(), page_id.page_no()); buf_unzip_LRU_add_block(free_block, FALSE); hash_lock->write_unlock(); buf_page_free_descriptor(&block->page); diff --git a/storage/innobase/gis/gis0sea.cc b/storage/innobase/gis/gis0sea.cc index 853db180277..dab15188bd4 100644 --- a/storage/innobase/gis/gis0sea.cc +++ b/storage/innobase/gis/gis0sea.cc @@ -1528,7 +1528,6 @@ rtr_copy_buf( ut_d(matches->block.in_withdraw_list = block->in_withdraw_list); /* Skip buf_block_t::lock */ - matches->block.lock_hash_val = block->lock_hash_val; matches->block.modify_clock = block->modify_clock; #ifdef BTR_CUR_HASH_ADAPT matches->block.n_hash_helps = block->n_hash_helps; diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index fa873fe8741..04d74b6e36f 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -596,16 +596,6 @@ inline uint buf_page_full_crc32_size(const byte* buf, bool* comp, bool* cr) } #ifndef UNIV_INNOCHECKSUM -/**********************************************************************//** -Gets the hash value of a block. This can be used in searches in the -lock hash table. -@return lock hash value */ -UNIV_INLINE -unsigned -buf_block_get_lock_hash_val( -/*========================*/ - const buf_block_t* block) /*!< in: block */ - MY_ATTRIBUTE((warn_unused_result)); #ifdef UNIV_DEBUG /** Find a block in the buffer pool that points to a given compressed page. @param[in] data pointer to compressed page @@ -1070,13 +1060,6 @@ struct buf_block_t{ a block is in the unzip_LRU list if page.state() == BUF_BLOCK_FILE_PAGE and page.zip.data != NULL */ - uint32_t lock_hash_val; /*!< hashed value of the page address - in the record lock hash table; - protected by buf_block_t::lock - (or buf_pool.mutex - in buf_page_get_gen(), - buf_page_init_for_read() - and buf_page_create()) */ /* @} */ /** @name Optimistic search field */ /* @{ */ diff --git a/storage/innobase/include/buf0buf.ic b/storage/innobase/include/buf0buf.ic index cda7d435725..2384c46af02 100644 --- a/storage/innobase/include/buf0buf.ic +++ b/storage/innobase/include/buf0buf.ic @@ -154,24 +154,6 @@ ok: } #endif /* UNIV_DEBUG */ -/**********************************************************************//** -Gets the hash value of the page the pointer is pointing to. This can be used -in searches in the lock hash table. -@return lock hash value */ -UNIV_INLINE -unsigned -buf_block_get_lock_hash_val( -/*========================*/ - const buf_block_t* block) /*!< in: block */ -{ - ut_ad(block); - ut_ad(block->page.in_file()); - ut_ad(rw_lock_own(&(((buf_block_t*) block)->lock), RW_LOCK_X) - || rw_lock_own(&(((buf_block_t*) block)->lock), RW_LOCK_S)); - - return(block->lock_hash_val); -} - /********************************************************************//** Allocates a buf_page_t descriptor. This function must succeed. In case of failure we assert in this function. diff --git a/storage/innobase/include/lock0lock.ic b/storage/innobase/include/lock0lock.ic index 6146f835be9..674821a4931 100644 --- a/storage/innobase/include/lock0lock.ic +++ b/storage/innobase/include/lock0lock.ic @@ -39,7 +39,7 @@ lock_rec_fold( ulint space, /*!< in: space */ ulint page_no)/*!< in: page number */ { - return(ut_fold_ulint_pair(space, page_no)); + return page_id_t(space, page_no).fold(); } /*********************************************************************//** diff --git a/storage/innobase/include/lock0priv.ic b/storage/innobase/include/lock0priv.ic index 7468110deeb..8fa7338e02b 100644 --- a/storage/innobase/include/lock0priv.ic +++ b/storage/innobase/include/lock0priv.ic @@ -164,12 +164,14 @@ lock_rec_get_first_on_page( { ut_ad(lock_mutex_own()); - ulint space = block->page.id().space(); - ulint page_no = block->page.id().page_no(); - ulint hash = buf_block_get_lock_hash_val(block); + const page_id_t page_id(block->page.id()); + + ulint space = page_id.space(); + ulint page_no = page_id.page_no(); for (lock_t* lock = static_cast( - HASH_GET_FIRST(lock_hash, hash)); + HASH_GET_FIRST(lock_hash, + lock_rec_hash(space, page_no))); lock != NULL; lock = static_cast(HASH_GET_NEXT(hash, lock))) { diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index 2c888f55b69..e5718a9e75c 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -515,18 +515,6 @@ void lock_sys_t::resize(ulint n_cells) HASH_MIGRATE(&old_hash, &prdt_page_hash, lock_t, hash, lock_rec_lock_fold); old_hash.free(); - - /* need to update block->lock_hash_val */ - mutex_enter(&buf_pool.mutex); - for (buf_page_t* bpage = UT_LIST_GET_FIRST(buf_pool.LRU); - bpage; bpage = UT_LIST_GET_NEXT(LRU, bpage)) { - if (bpage->state() == BUF_BLOCK_FILE_PAGE) { - const page_id_t id(bpage->id()); - reinterpret_cast(bpage)->lock_hash_val - = lock_rec_hash(id.space(), id.page_no()); - } - } - mutex_exit(&buf_pool.mutex); mutex_exit(&mutex); } -- cgit v1.2.1 From 00cd53d39aa932718ead738e61d590da28579574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 11 Sep 2020 15:55:30 +0300 Subject: MDEV-23719: Make lock_sys use page_id_t Since commit 8ccb3caafb7cba0fca12e89c5c9b67a740364fdd it should be more efficient to use page_id_t rather than two separate variables for tablespace identifier and page number. lock_rec_fold(): Replaced with page_id_t::fold(). lock_rec_hash(): Replaced with lock_sys.hash(page_id). lock_rec_expl_exist_on_page(), lock_rec_get_first_on_page_addr(), lock_rec_get_first_on_page(): Replaced with lock_sys.get_first(). --- storage/innobase/btr/btr0cur.cc | 3 +- storage/innobase/gis/gis0rtree.cc | 15 +- storage/innobase/gis/gis0sea.cc | 12 +- storage/innobase/handler/i_s.cc | 4 +- storage/innobase/ibuf/ibuf0ibuf.cc | 18 +- storage/innobase/include/lock0lock.h | 77 ++++---- storage/innobase/include/lock0lock.ic | 34 +--- storage/innobase/include/lock0prdt.h | 24 +-- storage/innobase/include/lock0priv.h | 37 ---- storage/innobase/include/lock0priv.ic | 132 ++----------- storage/innobase/include/lock0types.h | 17 +- storage/innobase/include/trx0i_s.h | 7 +- storage/innobase/lock/lock0lock.cc | 346 ++++++++++++---------------------- storage/innobase/lock/lock0prdt.cc | 76 +++----- storage/innobase/row/row0purge.cc | 5 +- storage/innobase/trx/trx0i_s.cc | 29 +-- 16 files changed, 259 insertions(+), 577 deletions(-) diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index 9c627ecd145..a190c11eb0a 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -5423,8 +5423,7 @@ btr_cur_compress_if_useful( const buf_block_t* block = btr_cur_get_block(cursor); /* Check whether page lock prevents the compression */ - if (!lock_test_prdt_page_lock(trx, block->page.id().space(), - block->page.id().page_no())) { + if (!lock_test_prdt_page_lock(trx, block->page.id())) { return(false); } } diff --git a/storage/innobase/gis/gis0rtree.cc b/storage/innobase/gis/gis0rtree.cc index 778202a11c6..2e50d1b2cad 100644 --- a/storage/innobase/gis/gis0rtree.cc +++ b/storage/innobase/gis/gis0rtree.cc @@ -652,8 +652,7 @@ rtr_adjust_upper_level( new_prdt.op = 0; lock_prdt_update_parent(block, new_block, &prdt, &new_prdt, - index->table->space_id, - page_cursor->block->page.id().page_no()); + page_cursor->block->page.id()); mem_heap_free(heap); @@ -881,8 +880,6 @@ rtr_page_split_and_insert( buf_block_t* block; page_t* page; page_t* new_page; - ulint page_no; - ulint hint_page_no; buf_block_t* new_block; page_zip_des_t* page_zip; page_zip_des_t* new_page_zip; @@ -931,7 +928,7 @@ func_start: ut_ad(mtr->memo_contains_flagged(block, MTR_MEMO_PAGE_X_FIX)); ut_ad(page_get_n_recs(page) >= 1); - page_no = block->page.id().page_no(); + const page_id_t page_id(block->page.id()); if (!page_has_prev(page) && !page_is_leaf(page)) { first_rec = page_rec_get_next( @@ -969,10 +966,9 @@ func_start: static_cast(first_rec)); /* Allocate a new page to the index */ - hint_page_no = page_no + 1; const uint16_t page_level = btr_page_get_level(page); - new_block = btr_page_alloc(cursor->index, hint_page_no, FSP_UP, - page_level, mtr, mtr); + new_block = btr_page_alloc(cursor->index, page_id.page_no() + 1, + FSP_UP, page_level, mtr, mtr); if (!new_block) { return NULL; } @@ -1155,8 +1151,7 @@ after_insert: /* Check any predicate locks need to be moved/copied to the new page */ - lock_prdt_update_split(new_block, &prdt, &new_prdt, - cursor->index->table->space_id, page_no); + lock_prdt_update_split(new_block, &prdt, &new_prdt, page_id); /* Adjust the upper level. */ rtr_adjust_upper_level(cursor, flags, block, new_block, diff --git a/storage/innobase/gis/gis0sea.cc b/storage/innobase/gis/gis0sea.cc index dab15188bd4..21783a94e9c 100644 --- a/storage/innobase/gis/gis0sea.cc +++ b/storage/innobase/gis/gis0sea.cc @@ -298,8 +298,9 @@ rtr_pcur_getnext_from_path( && mode != PAGE_CUR_RTREE_LOCATE) { ut_ad(rtr_info->thr); lock_place_prdt_page_lock( - index->table->space_id, - next_page_no, index, + page_id_t(block->page.id().space(), + next_page_no), + index, rtr_info->thr); } new_split = true; @@ -1689,7 +1690,6 @@ rtr_cur_search_with_match( const rec_t* best_rec; const rec_t* last_match_rec = NULL; bool match_init = false; - ulint space = block->page.id().space(); page_cur_mode_t orig_mode = mode; const rec_t* first_rec = NULL; @@ -1870,7 +1870,11 @@ rtr_cur_search_with_match( /* Lock the page, preventing it from being shrunk */ lock_place_prdt_page_lock( - space, page_no, index, + page_id_t(block->page + .id() + .space(), + page_no), + index, rtr_info->thr); } } else { diff --git a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc index 4cff424179c..a5713e32d86 100644 --- a/storage/innobase/handler/i_s.cc +++ b/storage/innobase/handler/i_s.cc @@ -699,10 +699,10 @@ fill_innodb_locks_from_cache( OK(field_store_string(fields[IDX_LOCK_INDEX], row->lock_index)); OK(fields[IDX_LOCK_SPACE]->store( - row->lock_space, true)); + row->lock_page.space(), true)); fields[IDX_LOCK_SPACE]->set_notnull(); OK(fields[IDX_LOCK_PAGE]->store( - row->lock_page, true)); + row->lock_page.page_no(), true)); fields[IDX_LOCK_PAGE]->set_notnull(); OK(fields[IDX_LOCK_REC]->store( row->lock_rec, true)); diff --git a/storage/innobase/ibuf/ibuf0ibuf.cc b/storage/innobase/ibuf/ibuf0ibuf.cc index a3ed5b104c6..ca13e2e33af 100644 --- a/storage/innobase/ibuf/ibuf0ibuf.cc +++ b/storage/innobase/ibuf/ibuf0ibuf.cc @@ -3329,18 +3329,22 @@ fail_exit: and done mtr_commit(&mtr) to release the latch. */ ibuf_mtr_start(&bitmap_mtr); - index->set_modified(bitmap_mtr); bitmap_page = ibuf_bitmap_get_map_page(page_id, zip_size, &bitmap_mtr); /* We check if the index page is suitable for buffered entries */ - if (buf_pool.page_hash_contains(page_id) - || lock_rec_expl_exist_on_page(page_id.space(), - page_id.page_no())) { - + if (buf_pool.page_hash_contains(page_id)) { +commit_exit: ibuf_mtr_commit(&bitmap_mtr); goto fail_exit; + } else { + lock_mutex_enter(); + const auto lock_exists = lock_sys.get_first(page_id); + lock_mutex_exit(); + if (lock_exists) { + goto commit_exit; + } } if (op == IBUF_OP_INSERT) { @@ -3378,8 +3382,7 @@ fail_exit: dfield_t* field; if (counter == ULINT_UNDEFINED) { - ibuf_mtr_commit(&bitmap_mtr); - goto fail_exit; + goto commit_exit; } field = dtuple_get_nth_field( @@ -3391,6 +3394,7 @@ fail_exit: /* Set the bitmap bit denoting that the insert buffer contains buffered entries for this index page, if the bit is not set yet */ + index->set_modified(bitmap_mtr); ibuf_bitmap_page_set_bits( bitmap_page, page_id, physical_size, true, &bitmap_mtr); ibuf_mtr_commit(&bitmap_mtr); diff --git a/storage/innobase/include/lock0lock.h b/storage/innobase/include/lock0lock.h index ab697a730d2..dd25c52101f 100644 --- a/storage/innobase/include/lock0lock.h +++ b/storage/innobase/include/lock0lock.h @@ -252,15 +252,6 @@ lock_rec_restore_from_page_infimum( state; lock bits are reset on the infimum */ /*********************************************************************//** -Determines if there are explicit record locks on a page. -@return an explicit record lock on the page, or NULL if there are none */ -lock_t* -lock_rec_expl_exist_on_page( -/*========================*/ - ulint space, /*!< in: space id */ - ulint page_no)/*!< in: page number */ - MY_ATTRIBUTE((warn_unused_result)); -/*********************************************************************//** Checks if locks of other transactions prevent an immediate insert of a record. If they do, first tests if the query thread should anyway be suspended for some reason; if not, then puts the transaction and @@ -487,28 +478,6 @@ lock_rec_unlock( and release possible other transactions waiting because of these locks. */ void lock_release(trx_t* trx); -/*********************************************************************//** -Calculates the fold value of a page file address: used in inserting or -searching for a lock in the hash table. -@return folded value */ -UNIV_INLINE -ulint -lock_rec_fold( -/*==========*/ - ulint space, /*!< in: space */ - ulint page_no)/*!< in: page number */ - MY_ATTRIBUTE((const)); -/*********************************************************************//** -Calculates the hash value of a page file address: used in inserting or -searching for a lock in the hash table. -@return hashed value */ -UNIV_INLINE -unsigned -lock_rec_hash( -/*==========*/ - ulint space, /*!< in: space */ - ulint page_no);/*!< in: page number */ - /*************************************************************//** Get the lock hash table */ UNIV_INLINE @@ -819,6 +788,46 @@ public: /** Closes the lock system at database shutdown. */ void close(); + + /** @return the hash value for a page address */ + ulint hash(const page_id_t id) const + { ut_ad(mutex_own(&mutex)); return rec_hash.calc_hash(id.fold()); } + + /** Get the first lock on a page. + @param lock_hash hash table to look at + @param id page number + @return first lock + @retval nullptr if none exists */ + lock_t *get_first(const hash_table_t &lock_hash, const page_id_t id) const + { + ut_ad(&lock_hash == &rec_hash || &lock_hash == &prdt_hash || + &lock_hash == &prdt_page_hash); + for (lock_t *lock= static_cast + (HASH_GET_FIRST(&lock_hash, hash(id))); + lock; lock= static_cast(HASH_GET_NEXT(hash, lock))) + if (lock->un_member.rec_lock.page_id == id) + return lock; + return nullptr; + } + + /** Get the first record lock on a page. + @param id page number + @return first lock + @retval nullptr if none exists */ + lock_t *get_first(const page_id_t id) const + { return get_first(rec_hash, id); } + /** Get the first predicate lock on a SPATIAL INDEX page. + @param id page number + @return first lock + @retval nullptr if none exists */ + lock_t *get_first_prdt(const page_id_t id) const + { return get_first(prdt_hash, id); } + /** Get the first predicate lock on a SPATIAL INDEX page. + @param id page number + @return first lock + @retval nullptr if none exists */ + lock_t *get_first_prdt_page(const page_id_t id) const + { return get_first(prdt_page_hash, id); } }; /*********************************************************************//** @@ -858,8 +867,7 @@ lock_rec_discard( without checking for deadlocks or conflicts. @param[in] type_mode lock mode and wait flag; type will be replaced with LOCK_REC -@param[in] space tablespace id -@param[in] page_no index page number +@param[in] page_id index page number @param[in] page R-tree index page, or NULL @param[in] heap_no record heap number in the index page @param[in] index the index tree @@ -873,8 +881,7 @@ lock_rec_create_low( que_thr_t* thr, /*!< thread owning trx */ #endif unsigned type_mode, - ulint space, - ulint page_no, + const page_id_t page_id, const page_t* page, ulint heap_no, dict_index_t* index, diff --git a/storage/innobase/include/lock0lock.ic b/storage/innobase/include/lock0lock.ic index 674821a4931..2d5b6ff37f1 100644 --- a/storage/innobase/include/lock0lock.ic +++ b/storage/innobase/include/lock0lock.ic @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2018, MariaDB Corporation. +Copyright (c) 2017, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -28,34 +28,6 @@ Created 5/7/1996 Heikki Tuuri #include "buf0buf.h" #include "page0page.h" -/*********************************************************************//** -Calculates the fold value of a page file address: used in inserting or -searching for a lock in the hash table. -@return folded value */ -UNIV_INLINE -ulint -lock_rec_fold( -/*==========*/ - ulint space, /*!< in: space */ - ulint page_no)/*!< in: page number */ -{ - return page_id_t(space, page_no).fold(); -} - -/*********************************************************************//** -Calculates the hash value of a page file address: used in inserting or -searching for a lock in the hash table. -@return hashed value */ -UNIV_INLINE -unsigned -lock_rec_hash( -/*==========*/ - ulint space, /*!< in: space */ - ulint page_no)/*!< in: page number */ -{ - return unsigned(lock_sys.rec_hash.calc_hash(lock_rec_fold(space, page_no))); -} - /*********************************************************************//** Gets the heap_no of the smallest user record on a page. @return heap_no of smallest user record, or PAGE_HEAP_NO_SUPREMUM */ @@ -122,12 +94,10 @@ lock_rec_create( trx mutex */ { btr_assert_not_corrupted(block, index); - const page_id_t id(block->page.id()); return lock_rec_create_low( #ifdef WITH_WSREP c_lock, thr, #endif - type_mode, id.space(), id.page_no(), - block->frame, heap_no, + type_mode, block->page.id(), block->frame, heap_no, index, trx, caller_owns_trx_mutex); } diff --git a/storage/innobase/include/lock0prdt.h b/storage/innobase/include/lock0prdt.h index 59cf0130625..43d68996691 100644 --- a/storage/innobase/include/lock0prdt.h +++ b/storage/innobase/include/lock0prdt.h @@ -58,9 +58,7 @@ Acquire a "Page" lock on a block @return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */ dberr_t lock_place_prdt_page_lock( -/*======================*/ - ulint space, /*!< in: space for the page to lock */ - ulint pageno, /*!< in: page number */ + const page_id_t page_id, /*!< in: page identifier */ dict_index_t* index, /*!< in: secondary index */ que_thr_t* thr); /*!< in: query thread */ @@ -108,8 +106,7 @@ lock_prdt_update_split( buf_block_t* new_block, /*!< in/out: the new half page */ lock_prdt_t* prdt, /*!< in: MBR on the old page */ lock_prdt_t* new_prdt, /*!< in: MBR on the new page */ - ulint space, /*!< in: space id */ - ulint page_no); /*!< in: page number */ + const page_id_t page_id); /*!< in: page number */ /**************************************************************//** Ajust locks from an ancester page of Rtree on the appropriate level . */ @@ -120,8 +117,7 @@ lock_prdt_update_parent( buf_block_t* right_block, /*!< in/out: the new half page */ lock_prdt_t* left_prdt, /*!< in: MBR on the old page */ lock_prdt_t* right_prdt, /*!< in: MBR on the new page */ - ulint space, /*!< in: space id */ - ulint page_no); /*!< in: page number */ + const page_id_t page_id); /*!< in: parent page */ /*********************************************************************//** Checks if locks of other transactions prevent an immediate insert of @@ -190,17 +186,11 @@ lock_prdt_rec_move( const buf_block_t* donator); /*!< in: buffer block containing the donating record */ -/** Check whether there are R-tree Page lock on a buffer page +/** Check whether there are R-tree Page lock on a page @param[in] trx trx to test the lock -@param[in] space space id for the page -@param[in] page_no page number -@return true if there is none */ -bool -lock_test_prdt_page_lock( -/*=====================*/ - const trx_t* trx, - ulint space, - ulint page_no); +@param[in] page_id page identifier +@return true if there is none */ +bool lock_test_prdt_page_lock(const trx_t *trx, const page_id_t page_id); /** Removes predicate lock objects set on an index page which is discarded. @param[in] block page to be discarded diff --git a/storage/innobase/include/lock0priv.h b/storage/innobase/include/lock0priv.h index 2743becea8f..1b2f9d0f0d3 100644 --- a/storage/innobase/include/lock0priv.h +++ b/storage/innobase/include/lock0priv.h @@ -539,29 +539,6 @@ lock_t* lock_rec_get_next_on_page( /*======================*/ lock_t* lock); /*!< in: a record lock */ -/*********************************************************************//** -Gets the first record lock on a page, where the page is identified by its -file address. -@return first lock, NULL if none exists */ -UNIV_INLINE -lock_t* -lock_rec_get_first_on_page_addr( -/*============================*/ - hash_table_t* lock_hash, /* Lock hash table */ - ulint space, /*!< in: space */ - ulint page_no); /*!< in: page number */ - -/*********************************************************************//** -Gets the first record lock on a page, where the page is identified by a -pointer to it. -@return first lock, NULL if none exists */ -UNIV_INLINE -lock_t* -lock_rec_get_first_on_page( -/*=======================*/ - hash_table_t* lock_hash, /*!< in: lock hash table */ - const buf_block_t* block); /*!< in: buffer block */ - /*********************************************************************//** Gets the next explicit lock request on a record. @@ -632,20 +609,6 @@ lock_get_wait( /*==========*/ const lock_t* lock); /*!< in: lock */ -/*********************************************************************//** -Looks for a suitable type record lock struct by the same trx on the same page. -This can be used to save space when a new record lock should be set on a page: -no new struct is needed, if a suitable old is found. -@return lock or NULL */ -UNIV_INLINE -lock_t* -lock_rec_find_similar_on_page( -/*==========================*/ - ulint type_mode, /*!< in: lock type_mode field */ - ulint heap_no, /*!< in: heap number of the record */ - lock_t* lock, /*!< in: lock_rec_get_first_on_page() */ - const trx_t* trx); /*!< in: transaction */ - /*********************************************************************//** Checks if a transaction has the specified table lock, or stronger. This function should only be called by the thread that owns the transaction. diff --git a/storage/innobase/include/lock0priv.ic b/storage/innobase/include/lock0priv.ic index 8fa7338e02b..e16949a4917 100644 --- a/storage/innobase/include/lock0priv.ic +++ b/storage/innobase/include/lock0priv.ic @@ -121,70 +121,6 @@ lock_rec_get_next_on_page( return((lock_t*) lock_rec_get_next_on_page_const(lock)); } -/*********************************************************************//** -Gets the first record lock on a page, where the page is identified by its -file address. -@return first lock, NULL if none exists */ -UNIV_INLINE -lock_t* -lock_rec_get_first_on_page_addr( -/*============================*/ - hash_table_t* lock_hash, /* Lock hash table */ - ulint space, /*!< in: space */ - ulint page_no) /*!< in: page number */ -{ - ut_ad(lock_mutex_own()); - - for (lock_t* lock = static_cast( - HASH_GET_FIRST(lock_hash, - lock_rec_hash(space, page_no))); - lock != NULL; - lock = static_cast(HASH_GET_NEXT(hash, lock))) { - - if (lock->un_member.rec_lock.space == space - && lock->un_member.rec_lock.page_no == page_no) { - - return(lock); - } - } - - return(NULL); -} - -/*********************************************************************//** -Gets the first record lock on a page, where the page is identified by a -pointer to it. -@return first lock, NULL if none exists */ -UNIV_INLINE -lock_t* -lock_rec_get_first_on_page( -/*=======================*/ - hash_table_t* lock_hash, /*!< in: lock hash table */ - const buf_block_t* block) /*!< in: buffer block */ -{ - ut_ad(lock_mutex_own()); - - const page_id_t page_id(block->page.id()); - - ulint space = page_id.space(); - ulint page_no = page_id.page_no(); - - for (lock_t* lock = static_cast( - HASH_GET_FIRST(lock_hash, - lock_rec_hash(space, page_no))); - lock != NULL; - lock = static_cast(HASH_GET_NEXT(hash, lock))) { - - if (lock->un_member.rec_lock.space == space - && lock->un_member.rec_lock.page_no == page_no) { - - return(lock); - } - } - - return(NULL); -} - /*********************************************************************//** Gets the next explicit lock request on a record. @return next lock, NULL if none exists or if heap_no == ULINT_UNDEFINED */ @@ -229,16 +165,11 @@ lock_rec_get_first( const buf_block_t* block, /*!< in: block containing the record */ ulint heap_no)/*!< in: heap number of the record */ { - ut_ad(lock_mutex_own()); - - for (lock_t* lock = lock_rec_get_first_on_page(hash, block); lock; - lock = lock_rec_get_next_on_page(lock)) { - if (lock_rec_get_nth_bit(lock, heap_no)) { - return(lock); - } - } - - return(NULL); + for (lock_t *lock= lock_sys.get_first(*hash, block->page.id()); + lock; lock= lock_rec_get_next_on_page(lock)) + if (lock_rec_get_nth_bit(lock, heap_no)) + return lock; + return nullptr; } /*********************************************************************//** @@ -275,23 +206,15 @@ lock_rec_get_next_on_page_const( /*============================*/ const lock_t* lock) /*!< in: a record lock */ { - ut_ad(lock_mutex_own()); - ut_ad(lock_get_type_low(lock) == LOCK_REC); - - ulint space = lock->un_member.rec_lock.space; - ulint page_no = lock->un_member.rec_lock.page_no; - - while ((lock = static_cast(HASH_GET_NEXT(hash, lock))) - != NULL) { - - if (lock->un_member.rec_lock.space == space - && lock->un_member.rec_lock.page_no == page_no) { + ut_ad(lock_mutex_own()); + ut_ad(lock_get_type_low(lock) == LOCK_REC); - return(lock); - } - } + const page_id_t page_id(lock->un_member.rec_lock.page_id); - return(NULL); + while (!!(lock= static_cast(HASH_GET_NEXT(hash, lock)))) + if (lock->un_member.rec_lock.page_id == page_id) + break; + return lock; } /*********************************************************************//** @@ -354,37 +277,6 @@ lock_get_wait( return(lock->type_mode & LOCK_WAIT); } -/*********************************************************************//** -Looks for a suitable type record lock struct by the same trx on the same page. -This can be used to save space when a new record lock should be set on a page: -no new struct is needed, if a suitable old is found. -@return lock or NULL */ -UNIV_INLINE -lock_t* -lock_rec_find_similar_on_page( -/*==========================*/ - ulint type_mode, /*!< in: lock type_mode field */ - ulint heap_no, /*!< in: heap number of the record */ - lock_t* lock, /*!< in: lock_rec_get_first_on_page() */ - const trx_t* trx) /*!< in: transaction */ -{ - ut_ad(lock_mutex_own()); - - for (/* No op */; - lock != NULL; - lock = lock_rec_get_next_on_page(lock)) { - - if (lock->trx == trx - && lock->type_mode == type_mode - && lock_rec_get_n_bits(lock) > heap_no) { - - return(lock); - } - } - - return(NULL); -} - /*********************************************************************//** Checks if a transaction has the specified table lock, or stronger. This function should only be called by the thread that owns the transaction. diff --git a/storage/innobase/include/lock0types.h b/storage/innobase/include/lock0types.h index cb04afdf9db..23307375426 100644 --- a/storage/innobase/include/lock0types.h +++ b/storage/innobase/include/lock0types.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2018, 2019, MariaDB Corporation. +Copyright (c) 2018, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -25,6 +25,7 @@ Created 5/7/1996 Heikki Tuuri *******************************************************/ #include "dict0types.h" +#include "buf0types.h" #include "ut0lst.h" #ifndef lock0types_h @@ -89,8 +90,8 @@ struct lock_table_t { /** Record lock for a page */ struct lock_rec_t { - ib_uint32_t space; /*!< space id */ - ib_uint32_t page_no; /*!< page number */ + /** page identifier */ + page_id_t page_id; ib_uint32_t n_bits; /*!< number of bits in the lock bitmap; NOTE: the lock bitmap is placed immediately after the @@ -105,12 +106,12 @@ struct lock_rec_t { /** Print the record lock into the given output stream @param[in,out] out the output stream @return the given output stream. */ -inline -std::ostream& lock_rec_t::print(std::ostream& out) const +inline std::ostream &lock_rec_t::print(std::ostream &out) const { - out << "[lock_rec_t: space=" << space << ", page_no=" << page_no - << ", n_bits=" << n_bits << "]"; - return(out); + out << "[lock_rec_t: space=" << page_id.space() + << ", page_no=" << page_id.page_no() + << ", n_bits=" << n_bits << "]"; + return out; } inline diff --git a/storage/innobase/include/trx0i_s.h b/storage/innobase/include/trx0i_s.h index 892ee3cfe18..98b84fe0985 100644 --- a/storage/innobase/include/trx0i_s.h +++ b/storage/innobase/include/trx0i_s.h @@ -31,6 +31,7 @@ Created July 17, 2007 Vasil Dimov #include "trx0types.h" #include "dict0types.h" +#include "buf0types.h" /** The maximum amount of memory that can be consumed by innodb_trx, innodb_locks and innodb_lock_waits information schema tables. */ @@ -90,10 +91,8 @@ struct i_s_locks_row_t { lock_get_table_name() */ /** index name of a record lock; NULL for table locks */ const char* lock_index; - /** tablespace identifier of the record; 0 if !lock_index */ - uint32_t lock_space; - /** page number of the record; 0 if !lock_index */ - uint32_t lock_page; + /** page identifier of the record; (0,0) if !lock_index */ + page_id_t lock_page; /** heap number of the record; 0 if !lock_index */ uint16_t lock_rec; /** lock mode corresponding to lock_mode_values_typelib */ diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index e5718a9e75c..88ed047ed77 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -477,13 +477,9 @@ void lock_sys_t::create(ulint n_cells) /** Calculates the fold value of a lock: used in migrating the hash table. @param[in] lock record lock object @return folded value */ -static -ulint -lock_rec_lock_fold( - const lock_t* lock) +static ulint lock_rec_lock_fold(const lock_t *lock) { - return(lock_rec_fold(lock->un_member.rec_lock.space, - lock->un_member.rec_lock.page_no)); + return lock->un_member.rec_lock.page_id.fold(); } @@ -846,26 +842,6 @@ lock_rec_find_set_bit( return(ULINT_UNDEFINED); } -/*********************************************************************//** -Determines if there are explicit record locks on a page. -@return an explicit record lock on the page, or NULL if there are none */ -lock_t* -lock_rec_expl_exist_on_page( -/*========================*/ - ulint space, /*!< in: space id */ - ulint page_no)/*!< in: page number */ -{ - lock_t* lock; - - lock_mutex_enter(); - /* Only used in ibuf pages, so rec_hash is good enough */ - lock = lock_rec_get_first_on_page_addr(&lock_sys.rec_hash, - space, page_no); - lock_mutex_exit(); - - return(lock); -} - /*********************************************************************//** Resets the record lock bitmap to zero. NOTE: does not touch the wait_lock pointer in the transaction! This function is used in lock object creation @@ -887,7 +863,7 @@ lock_rec_bitmap_reset( ut_ad((lock_rec_get_n_bits(lock) % 8) == 0); - memset(&lock[1], 0, n_bytes); + memset(reinterpret_cast(&lock[1]), 0, n_bytes); } /*********************************************************************//** @@ -919,35 +895,21 @@ lock_rec_get_prev( ulint heap_no)/*!< in: heap number of the record */ { lock_t* lock; - ulint space; - ulint page_no; lock_t* found_lock = NULL; - hash_table_t* hash; ut_ad(lock_mutex_own()); ut_ad(lock_get_type_low(in_lock) == LOCK_REC); - space = in_lock->un_member.rec_lock.space; - page_no = in_lock->un_member.rec_lock.page_no; - - hash = lock_hash_get(in_lock->type_mode); - - for (lock = lock_rec_get_first_on_page_addr(hash, space, page_no); - /* No op */; + for (lock = lock_sys.get_first(*lock_hash_get(in_lock->type_mode), + in_lock->un_member.rec_lock.page_id); + lock != in_lock; lock = lock_rec_get_next_on_page(lock)) { - - ut_ad(lock); - - if (lock == in_lock) { - - return(found_lock); - } - if (lock_rec_get_nth_bit(lock, heap_no)) { - found_lock = lock; } } + + return found_lock; } /*============= FUNCTIONS FOR ANALYZING RECORD LOCK QUEUE ================*/ @@ -1285,8 +1247,7 @@ wsrep_print_wait_locks( without checking for deadlocks or conflicts. @param[in] type_mode lock mode and wait flag; type will be replaced with LOCK_REC -@param[in] space tablespace id -@param[in] page_no index page number +@param[in] page_id index page number @param[in] page R-tree index page, or NULL @param[in] heap_no record heap number in the index page @param[in] index the index tree @@ -1300,8 +1261,7 @@ lock_rec_create_low( que_thr_t* thr, /*!< thread owning trx */ #endif unsigned type_mode, - ulint space, - ulint page_no, + const page_id_t page_id, const page_t* page, ulint heap_no, dict_index_t* index, @@ -1370,8 +1330,7 @@ lock_rec_create_low( lock->trx = trx; lock->type_mode = (type_mode & unsigned(~LOCK_TYPE_MASK)) | LOCK_REC; lock->index = index; - lock->un_member.rec_lock.space = uint32_t(space); - lock->un_member.rec_lock.page_no = uint32_t(page_no); + lock->un_member.rec_lock.page_id = page_id; if (UNIV_LIKELY(!(type_mode & (LOCK_PREDICATE | LOCK_PRDT_PAGE)))) { lock->un_member.rec_lock.n_bits = uint32_t(n_bytes * 8); @@ -1457,10 +1416,10 @@ lock_rec_create_low( == INNODB_LOCK_SCHEDULE_ALGORITHM_VATS && !thd_is_replication_slave_thread(trx->mysql_thd)) { HASH_PREPEND(lock_t, hash, &lock_sys.rec_hash, - lock_rec_fold(space, page_no), lock); + page_id.fold(), lock); } else { HASH_INSERT(lock_t, hash, lock_hash_get(type_mode), - lock_rec_fold(space, page_no), lock); + page_id.fold(), lock); } if (!holds_trx_mutex) { @@ -1514,19 +1473,14 @@ static dberr_t lock_rec_insert_by_trx_age( lock_t *in_lock) /*!< in: lock to be insert */{ - ulint space; - ulint page_no; - ulint rec_fold; lock_t* node; lock_t* next; hash_table_t* hash; hash_cell_t* cell; - 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); + const page_id_t page_id(in_lock->un_member.rec_lock.page_id); hash = lock_hash_get(in_lock->type_mode); - cell = &hash->array[hash->calc_hash(rec_fold)]; + cell = &hash->array[hash->calc_hash(page_id.fold())]; node = (lock_t *) cell->node; // If in_lock is not a wait lock, we insert it to the head of the list. @@ -1568,9 +1522,6 @@ bool lock_queue_validate( const lock_t *in_lock) /*!< in: lock whose hash list is to be validated */ { - ulint space; - ulint page_no; - ulint rec_fold; hash_table_t* hash; hash_cell_t* cell; lock_t* next; @@ -1580,11 +1531,9 @@ lock_queue_validate( return true; } - 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); + const page_id_t page_id(in_lock->un_member.rec_lock.page_id); hash = lock_hash_get(in_lock->type_mode); - cell = &hash->array[hash->calc_hash(rec_fold)]; + cell = &hash->array[hash->calc_hash(page_id.fold())]; next = (lock_t *) cell->node; while (next != NULL) { // If this is a granted lock, check that there's no wait lock before it. @@ -1741,6 +1690,36 @@ lock_rec_enqueue_waiting( return DB_LOCK_WAIT; } +/*********************************************************************//** +Looks for a suitable type record lock struct by the same trx on the same page. +This can be used to save space when a new record lock should be set on a page: +no new struct is needed, if a suitable old is found. +@return lock or NULL */ +static inline +lock_t* +lock_rec_find_similar_on_page( + ulint type_mode, /*!< in: lock type_mode field */ + ulint heap_no, /*!< in: heap number of the record */ + lock_t* lock, /*!< in: lock_sys.get_first() */ + const trx_t* trx) /*!< in: transaction */ +{ + ut_ad(lock_mutex_own()); + + for (/* No op */; + lock != NULL; + lock = lock_rec_get_next_on_page(lock)) { + + if (lock->trx == trx + && lock->type_mode == type_mode + && lock_rec_get_n_bits(lock) > heap_no) { + + return(lock); + } + } + + return(NULL); +} + /*********************************************************************//** Adds a record lock request in the record queue. The request is normally added as the last in the queue, but if there are no waiting lock requests @@ -1828,11 +1807,11 @@ lock_rec_add_to_queue( lock_t* lock; lock_t* first_lock; - hash_table_t* hash = lock_hash_get(type_mode); /* Look for a waiting lock request on the same record or on a gap */ - for (first_lock = lock = lock_rec_get_first_on_page(hash, block); + for (first_lock = lock = lock_sys.get_first(*lock_hash_get(type_mode), + block->page.id()); lock != NULL; lock = lock_rec_get_next_on_page(lock)) { @@ -1911,7 +1890,7 @@ lock_rec_lock( if (lock_table_has(trx, index->table, static_cast(LOCK_MODE_MASK & mode))); - else if (lock_t *lock= lock_rec_get_first_on_page(&lock_sys.rec_hash, block)) + else if (lock_t *lock= lock_sys.get_first(block->page.id())) { trx_mutex_enter(trx); if (lock_rec_get_next_on_page(lock) || @@ -1992,28 +1971,22 @@ lock_rec_has_to_wait_in_queue( const lock_t* wait_lock) /*!< in: waiting record lock */ { const lock_t* lock; - ulint space; - ulint page_no; ulint heap_no; ulint bit_mask; ulint bit_offset; - hash_table_t* hash; ut_ad(wait_lock); ut_ad(lock_mutex_own()); ut_ad(lock_get_wait(wait_lock)); ut_ad(lock_get_type_low(wait_lock) == LOCK_REC); - space = wait_lock->un_member.rec_lock.space; - page_no = wait_lock->un_member.rec_lock.page_no; heap_no = lock_rec_find_set_bit(wait_lock); bit_offset = heap_no / 8; bit_mask = static_cast(1) << (heap_no % 8); - hash = lock_hash_get(wait_lock->type_mode); - - for (lock = lock_rec_get_first_on_page_addr(hash, space, page_no); + for (lock = lock_sys.get_first(*lock_hash_get(wait_lock->type_mode), + wait_lock->un_member.rec_lock.page_id); #ifdef WITH_WSREP lock && #endif @@ -2132,9 +2105,7 @@ lock_rec_cancel( trx_mutex_exit(lock->trx); } -static -void -lock_grant_and_move_on_page(ulint rec_fold, ulint space, ulint page_no) +static void lock_grant_and_move_on_page(ulint rec_fold, const page_id_t id) { lock_t* lock; lock_t* previous = static_cast( @@ -2143,15 +2114,13 @@ lock_grant_and_move_on_page(ulint rec_fold, ulint space, ulint page_no) if (previous == NULL) { return; } - if (previous->un_member.rec_lock.space == space && - previous->un_member.rec_lock.page_no == page_no) { + if (previous->un_member.rec_lock.page_id == id) { lock = previous; } else { while (previous->hash && - (previous->hash->un_member.rec_lock.space != space || - previous->hash->un_member.rec_lock.page_no != page_no)) { - previous = previous->hash; + (previous->hash->un_member.rec_lock.page_id != id)) { + previous = previous->hash; } lock = previous->hash; } @@ -2162,8 +2131,7 @@ lock_grant_and_move_on_page(ulint rec_fold, ulint space, ulint page_no) while (lock) { /* If the lock is a wait lock on this page, and it does not need to wait. */ if (lock_get_wait(lock) - && lock->un_member.rec_lock.space == space - && lock->un_member.rec_lock.page_no == page_no + && lock->un_member.rec_lock.page_id == id && !lock_rec_has_to_wait_in_queue(lock)) { lock_grant(lock); @@ -2190,22 +2158,19 @@ to a lock. NOTE: all record locks contained in in_lock are removed. @param[in,out] in_lock record lock */ static void lock_rec_dequeue_from_page(lock_t* in_lock) { - ulint space; - ulint page_no; hash_table_t* lock_hash; ut_ad(lock_mutex_own()); ut_ad(lock_get_type_low(in_lock) == LOCK_REC); /* We may or may not be holding in_lock->trx->mutex here. */ - space = in_lock->un_member.rec_lock.space; - page_no = in_lock->un_member.rec_lock.page_no; + const page_id_t page_id(in_lock->un_member.rec_lock.page_id); in_lock->index->table->n_rec_locks--; lock_hash = lock_hash_get(in_lock->type_mode); - ulint rec_fold = lock_rec_fold(space, page_no); + const ulint rec_fold = page_id.fold(); HASH_DELETE(lock_t, hash, lock_hash, rec_fold, in_lock); UT_LIST_REMOVE(in_lock->trx->lock.trx_locks, in_lock); @@ -2221,8 +2186,7 @@ static void lock_rec_dequeue_from_page(lock_t* in_lock) grant locks if there are no conflicting locks ahead. Stop at the first X lock that is waiting or has been granted. */ - for (lock_t* lock = lock_rec_get_first_on_page_addr( - lock_hash, space, page_no); + for (lock_t* lock = lock_sys.get_first(*lock_hash, page_id); lock != NULL; lock = lock_rec_get_next_on_page(lock)) { @@ -2234,7 +2198,7 @@ static void lock_rec_dequeue_from_page(lock_t* in_lock) } } } else { - lock_grant_and_move_on_page(rec_fold, space, page_no); + lock_grant_and_move_on_page(rec_fold, page_id); } } @@ -2247,8 +2211,6 @@ lock_rec_discard( record locks which are contained in this lock object are removed */ { - ulint space; - ulint page_no; trx_lock_t* trx_lock; ut_ad(lock_mutex_own()); @@ -2256,13 +2218,10 @@ lock_rec_discard( trx_lock = &in_lock->trx->lock; - space = in_lock->un_member.rec_lock.space; - page_no = in_lock->un_member.rec_lock.page_no; - in_lock->index->table->n_rec_locks--; HASH_DELETE(lock_t, hash, lock_hash_get(in_lock->type_mode), - lock_rec_fold(space, page_no), in_lock); + in_lock->un_member.rec_lock.page_id.fold(), in_lock); UT_LIST_REMOVE(trx_lock->trx_locks, in_lock); @@ -2274,29 +2233,19 @@ lock_rec_discard( Removes record lock objects set on an index page which is discarded. This function does not move locks, or check for waiting locks, therefore the lock bitmaps must already be reset when this function is called. */ -static -void -lock_rec_free_all_from_discard_page_low( -/*====================================*/ - ulint space, - ulint page_no, - hash_table_t* lock_hash) +static void lock_rec_free_all_from_discard_page_low(const page_id_t id, + hash_table_t *lock_hash) { - lock_t* lock; - lock_t* next_lock; - - lock = lock_rec_get_first_on_page_addr(lock_hash, space, page_no); + lock_t *lock= lock_sys.get_first(*lock_hash, id); - while (lock != NULL) { - ut_ad(lock_rec_find_set_bit(lock) == ULINT_UNDEFINED); - ut_ad(!lock_get_wait(lock)); - - next_lock = lock_rec_get_next_on_page(lock); - - lock_rec_discard(lock); - - lock = next_lock; - } + while (lock) + { + ut_ad(lock_rec_find_set_bit(lock) == ULINT_UNDEFINED); + ut_ad(!lock_get_wait(lock)); + lock_t *next_lock= lock_rec_get_next_on_page(lock); + lock_rec_discard(lock); + lock= next_lock; + } } /*************************************************************//** @@ -2308,20 +2257,10 @@ lock_rec_free_all_from_discard_page( /*================================*/ const buf_block_t* block) /*!< in: page to be discarded */ { - ulint space; - ulint page_no; - - ut_ad(lock_mutex_own()); - - space = block->page.id().space(); - page_no = block->page.id().page_no(); - - lock_rec_free_all_from_discard_page_low( - space, page_no, &lock_sys.rec_hash); - lock_rec_free_all_from_discard_page_low( - space, page_no, &lock_sys.prdt_hash); - lock_rec_free_all_from_discard_page_low( - space, page_no, &lock_sys.prdt_page_hash); + const page_id_t page_id(block->page.id()); + lock_rec_free_all_from_discard_page_low(page_id, &lock_sys.rec_hash); + lock_rec_free_all_from_discard_page_low(page_id, &lock_sys.prdt_hash); + lock_rec_free_all_from_discard_page_low(page_id, &lock_sys.prdt_page_hash); } /*============= RECORD LOCK MOVING AND INHERITING ===================*/ @@ -2588,7 +2527,7 @@ lock_move_reorganize_page( lock_mutex_enter(); /* FIXME: This needs to deal with predicate lock too */ - lock = lock_rec_get_first_on_page(&lock_sys.rec_hash, block); + lock = lock_sys.get_first(block->page.id()); if (lock == NULL) { lock_mutex_exit(); @@ -2721,7 +2660,7 @@ lock_move_rec_list_end( table to the end of the hash chain, and lock_rec_add_to_queue does not reuse locks if there are waiters in the queue. */ - for (lock = lock_rec_get_first_on_page(&lock_sys.rec_hash, block); + for (lock = lock_sys.get_first(block->page.id()); lock; lock = lock_rec_get_next_on_page(lock)) { const rec_t* rec1 = rec; @@ -2837,7 +2776,7 @@ lock_move_rec_list_start( lock_mutex_enter(); - for (lock = lock_rec_get_first_on_page(&lock_sys.rec_hash, block); + for (lock = lock_sys.get_first(block->page.id()); lock; lock = lock_rec_get_next_on_page(lock)) { const rec_t* rec1; @@ -2950,7 +2889,7 @@ lock_rtr_move_rec_list( lock_mutex_enter(); - for (lock = lock_rec_get_first_on_page(&lock_sys.rec_hash, block); + for (lock = lock_sys.get_first(block->page.id()); lock; lock = lock_rec_get_next_on_page(lock)) { ulint moved = 0; @@ -3067,10 +3006,7 @@ lock_update_merge_right( /* there should exist no page lock on the left page, otherwise, it will be blocked from merge */ - ut_ad(!lock_rec_get_first_on_page_addr( - &lock_sys.prdt_page_hash, - left_block->page.id().space(), - left_block->page.id().page_no())); + ut_ad(!lock_sys.get_first_prdt_page(left_block->page.id())); lock_rec_free_all_from_discard_page(left_block); @@ -3189,10 +3125,7 @@ lock_update_merge_left( /* there should exist no page lock on the right page, otherwise, it will be blocked from merge */ - ut_ad(!lock_rec_get_first_on_page_addr( - &lock_sys.prdt_page_hash, - right_block->page.id().space(), - right_block->page.id().page_no())); + ut_ad(!lock_sys.get_first_prdt_page(right_block->page.id())); lock_rec_free_all_from_discard_page(right_block); @@ -3240,13 +3173,13 @@ lock_update_discard( const page_t* page = block->frame; const rec_t* rec; ulint heap_no; + const page_id_t page_id(block->page.id()); lock_mutex_enter(); - if (lock_rec_get_first_on_page(&lock_sys.rec_hash, block)) { - ut_ad(!lock_rec_get_first_on_page(&lock_sys.prdt_hash, block)); - ut_ad(!lock_rec_get_first_on_page(&lock_sys.prdt_page_hash, - block)); + if (lock_sys.get_first(page_id)) { + ut_ad(!lock_sys.get_first_prdt(page_id)); + ut_ad(!lock_sys.get_first_prdt_page(page_id)); /* Inherit all the locks on the page to the record and reset all the locks on the page */ @@ -3280,16 +3213,13 @@ lock_update_discard( } while (heap_no != PAGE_HEAP_NO_SUPREMUM); } - lock_rec_free_all_from_discard_page_low( - block->page.id().space(), block->page.id().page_no(), - &lock_sys.rec_hash); + lock_rec_free_all_from_discard_page_low(page_id, + &lock_sys.rec_hash); } else { + lock_rec_free_all_from_discard_page_low(page_id, + &lock_sys.prdt_hash); lock_rec_free_all_from_discard_page_low( - block->page.id().space(), block->page.id().page_no(), - &lock_sys.prdt_hash); - lock_rec_free_all_from_discard_page_low( - block->page.id().space(), block->page.id().page_no(), - &lock_sys.prdt_page_hash); + page_id, &lock_sys.prdt_page_hash); } lock_mutex_exit(); @@ -4061,16 +3991,10 @@ lock_grant_and_move_on_rec( ulint heap_no) { lock_t* lock; - ulint space; - ulint page_no; - ulint rec_fold; - - space = first_lock->un_member.rec_lock.space; - page_no = first_lock->un_member.rec_lock.page_no; - rec_fold = lock_rec_fold(space, page_no); - + const page_id_t page_id(first_lock->un_member.rec_lock.page_id); + const ulint rec_fold= page_id.fold(); lock_t* previous = static_cast( - lock_sys.rec_hash.array[lock_sys.rec_hash.calc_hash(rec_fold)] + lock_sys.rec_hash.array[lock_sys.hash(page_id)] .node); if (previous == NULL) { return; @@ -4089,8 +4013,7 @@ lock_grant_and_move_on_rec( for (;lock != NULL;) { /* If the lock is a wait lock on this page, and it does not need to wait. */ - if (lock->un_member.rec_lock.space == space - && lock->un_member.rec_lock.page_no == page_no + if (lock->un_member.rec_lock.page_id == page_id && lock_rec_get_nth_bit(lock, heap_no) && lock_get_wait(lock) && !lock_rec_has_to_wait_in_queue(lock)) { @@ -4392,19 +4315,15 @@ lock_table_print(FILE* file, const lock_t* lock) @param[in,out] mtr mini-transaction for accessing the record */ static void lock_rec_print(FILE* file, const lock_t* lock, mtr_t& mtr) { - ulint space; - ulint page_no; - ut_ad(lock_mutex_own()); ut_a(lock_get_type_low(lock) == LOCK_REC); - space = lock->un_member.rec_lock.space; - page_no = lock->un_member.rec_lock.page_no; + const page_id_t page_id(lock->un_member.rec_lock.page_id); - fprintf(file, "RECORD LOCKS space id %lu page no %lu n bits %lu " - "index %s of table ", - (ulong) space, (ulong) page_no, - (ulong) lock_rec_get_n_bits(lock), + fprintf(file, "RECORD LOCKS space id %u page no %u n bits " ULINTPF + " index %s of table ", + page_id.space(), page_id.page_no(), + lock_rec_get_n_bits(lock), lock->index->name()); ut_print_name(file, lock->trx, lock->index->table->name.m_name); fprintf(file, " trx id " TRX_ID_FMT, trx_get_id_for_print(lock->trx)); @@ -4441,8 +4360,7 @@ static void lock_rec_print(FILE* file, const lock_t* lock, mtr_t& mtr) rec_offs_init(offsets_); mtr.start(); - const buf_block_t* block = buf_page_try_get(page_id_t(space, page_no), - &mtr); + const buf_block_t* block = buf_page_try_get(page_id, &mtr); for (ulint i = 0; i < lock_rec_get_n_bits(lock); ++i) { @@ -4941,13 +4859,9 @@ lock_rec_validate_page( rec_offs* offsets = offsets_; rec_offs_init(offsets_); - ut_ad(!lock_mutex_own()); - lock_mutex_enter(); loop: - lock = lock_rec_get_first_on_page_addr( - &lock_sys.rec_hash, - block->page.id().space(), block->page.id().page_no()); + lock = lock_sys.get_first(block->page.id()); if (!lock) { goto function_exit; @@ -5019,7 +4933,7 @@ lock_rec_validate( /*==============*/ ulint start, /*!< in: lock_sys.rec_hash bucket */ - ib_uint64_t* limit) /*!< in/out: upper limit of + page_id_t* limit) /*!< in/out: upper limit of (space, page_no) */ { ut_ad(lock_mutex_own()); @@ -5029,14 +4943,10 @@ lock_rec_validate( lock != NULL; lock = static_cast(HASH_GET_NEXT(hash, lock))) { - ib_uint64_t current; - ut_ad(!trx_is_ac_nl_ro(lock->trx)); ut_ad(lock_get_type(lock) == LOCK_REC); - current = ut_ull_create( - lock->un_member.rec_lock.space, - lock->un_member.rec_lock.page_no); + page_id_t current(lock->un_member.rec_lock.page_id); if (current > *limit) { *limit = current + 1; @@ -5049,12 +4959,7 @@ lock_rec_validate( /*********************************************************************//** Validate a record lock's block */ -static -void -lock_rec_block_validate( -/*====================*/ - ulint space_id, - ulint page_no) +static void lock_rec_block_validate(const page_id_t page_id) { /* The lock and the block that it is referring to may be freed at this point. We pass BUF_GET_POSSIBLY_FREED to skip a debug check. @@ -5069,12 +4974,12 @@ lock_rec_block_validate( discard or rebuild a tablespace do hold an exclusive table lock, which would conflict with any locks referring to the tablespace from other transactions. */ - if (fil_space_t* space = fil_space_acquire(space_id)) { + if (fil_space_t* space = fil_space_acquire(page_id.space())) { dberr_t err = DB_SUCCESS; mtr_start(&mtr); block = buf_page_get_gen( - page_id_t(space_id, page_no), + page_id, space->zip_size(), RW_X_LATCH, NULL, BUF_GET_POSSIBLY_FREED, @@ -5083,8 +4988,7 @@ lock_rec_block_validate( if (err != DB_SUCCESS) { ib::error() << "Lock rec block validate failed for tablespace " << space->name - << " space_id " << space_id - << " page_no " << page_no << " err " << err; + << page_id << " err " << err; } if (block) { @@ -5128,13 +5032,7 @@ bool lock_validate() /*===========*/ { - typedef std::pair page_addr_t; - typedef std::set< - page_addr_t, - std::less, - ut_allocator > page_addr_set; - - page_addr_set pages; + std::set pages; lock_mutex_enter(); @@ -5146,24 +5044,21 @@ lock_validate() validation check. */ for (ulint i = 0; i < lock_sys.rec_hash.n_cells; i++) { - ib_uint64_t limit = 0; + page_id_t limit(0, 0); while (const lock_t* lock = lock_rec_validate(i, &limit)) { if (lock_rec_find_set_bit(lock) == ULINT_UNDEFINED) { /* The lock bitmap is empty; ignore it. */ continue; } - const lock_rec_t& l = lock->un_member.rec_lock; - pages.insert(std::make_pair(l.space, l.page_no)); + pages.insert(lock->un_member.rec_lock.page_id); } } lock_mutex_exit(); - for (page_addr_set::const_iterator it = pages.begin(); - it != pages.end(); - ++it) { - lock_rec_block_validate((*it).first, (*it).second); + for (const page_id_t page_id : pages) { + lock_rec_block_validate(page_id); } return(true); @@ -6460,10 +6355,6 @@ DeadlockChecker::get_first_lock(ulint* heap_no) const const lock_t* lock = m_wait_lock; if (lock_get_type_low(lock) == LOCK_REC) { - hash_table_t* lock_hash = lock->type_mode & LOCK_PREDICATE - ? &lock_sys.prdt_hash - : &lock_sys.rec_hash; - /* We are only interested in records that match the heap_no. */ *heap_no = lock_rec_find_set_bit(lock); @@ -6471,10 +6362,11 @@ DeadlockChecker::get_first_lock(ulint* heap_no) const ut_ad(*heap_no != ULINT_UNDEFINED); /* Find the locks on the page. */ - lock = lock_rec_get_first_on_page_addr( - lock_hash, - lock->un_member.rec_lock.space, - lock->un_member.rec_lock.page_no); + lock = lock_sys.get_first( + lock->type_mode & LOCK_PREDICATE + ? lock_sys.prdt_hash + : lock_sys.rec_hash, + lock->un_member.rec_lock.page_id); /* Position on the first lock on the physical record.*/ if (!lock_rec_get_nth_bit(lock, *heap_no)) { diff --git a/storage/innobase/lock/lock0prdt.cc b/storage/innobase/lock/lock0prdt.cc index a04fd3fe73c..1eb96a0dcf0 100644 --- a/storage/innobase/lock/lock0prdt.cc +++ b/storage/innobase/lock/lock0prdt.cc @@ -394,7 +394,8 @@ lock_prdt_find_on_page( ut_ad(lock_mutex_own()); - for (lock = lock_rec_get_first_on_page(lock_hash_get(type_mode), block); + for (lock = lock_sys.get_first(*lock_hash_get(type_mode), + block->page.id()); lock != NULL; lock = lock_rec_get_next_on_page(lock)) { @@ -457,7 +458,8 @@ lock_prdt_add_to_queue( lock_t* lock; - for (lock = lock_rec_get_first_on_page(lock_hash_get(type_mode), block); + for (lock = lock_sys.get_first(*lock_hash_get(type_mode), + block->page.id()); lock != NULL; lock = lock_rec_get_next_on_page(lock)) { @@ -619,16 +621,12 @@ lock_prdt_update_parent( buf_block_t* right_block, /*!< in/out: the new half page */ lock_prdt_t* left_prdt, /*!< in: MBR on the old page */ lock_prdt_t* right_prdt, /*!< in: MBR on the new page */ - ulint space, /*!< in: parent space id */ - ulint page_no) /*!< in: parent page number */ + const page_id_t page_id) /*!< in: parent page */ { - lock_t* lock; - lock_mutex_enter(); /* Get all locks in parent */ - for (lock = lock_rec_get_first_on_page_addr( - &lock_sys.prdt_hash, space, page_no); + for (lock_t *lock = lock_sys.get_first_prdt(page_id); lock; lock = lock_rec_get_next_on_page(lock)) { lock_prdt_t* lock_prdt; @@ -675,21 +673,15 @@ lock_prdt_update_split_low( buf_block_t* new_block, /*!< in/out: the new half page */ lock_prdt_t* prdt, /*!< in: MBR on the old page */ lock_prdt_t* new_prdt, /*!< in: MBR on the new page */ - ulint space, /*!< in: space id */ - ulint page_no, /*!< in: page number */ + const page_id_t page_id, /*!< in: page number */ unsigned type_mode) /*!< in: LOCK_PREDICATE or LOCK_PRDT_PAGE */ { lock_t* lock; - lock_mutex_enter(); - - for (lock = lock_rec_get_first_on_page_addr( - lock_hash_get(type_mode), space, page_no); + for (lock = lock_sys.get_first(*lock_hash_get(type_mode), page_id); lock; lock = lock_rec_get_next_on_page(lock)) { - ut_ad(lock); - /* First dealing with Page Lock */ if (lock->type_mode & LOCK_PRDT_PAGE) { /* Duplicate the lock to new page */ @@ -739,8 +731,6 @@ lock_prdt_update_split_low( trx_mutex_exit(lock->trx); } } - - lock_mutex_exit(); } /**************************************************************//** @@ -751,14 +741,17 @@ lock_prdt_update_split( buf_block_t* new_block, /*!< in/out: the new half page */ lock_prdt_t* prdt, /*!< in: MBR on the old page */ lock_prdt_t* new_prdt, /*!< in: MBR on the new page */ - ulint space, /*!< in: space id */ - ulint page_no) /*!< in: page number */ + const page_id_t page_id) /*!< in: page number */ { + lock_mutex_enter(); + lock_prdt_update_split_low(new_block, prdt, new_prdt, - space, page_no, LOCK_PREDICATE); + page_id, LOCK_PREDICATE); lock_prdt_update_split_low(new_block, NULL, NULL, - space, page_no, LOCK_PRDT_PAGE); + page_id, LOCK_PRDT_PAGE); + + lock_mutex_exit(); } /*********************************************************************//** @@ -814,9 +807,9 @@ lock_prdt_lock( ut_ad(!dict_index_is_online_ddl(index)); ut_ad(type_mode & (LOCK_PREDICATE | LOCK_PRDT_PAGE)); - hash_table_t* hash = type_mode == LOCK_PREDICATE - ? &lock_sys.prdt_hash - : &lock_sys.prdt_page_hash; + const hash_table_t& hash = type_mode == LOCK_PREDICATE + ? lock_sys.prdt_hash + : lock_sys.prdt_page_hash; /* Another transaction cannot have an implicit lock on the record, because when we come here, we already have modified the clustered @@ -826,7 +819,7 @@ lock_prdt_lock( lock_mutex_enter(); const unsigned prdt_mode = type_mode | mode; - lock_t* lock = lock_rec_get_first_on_page(hash, block); + lock_t* lock = lock_sys.get_first(hash, block->page.id()); if (lock == NULL) { lock = lock_rec_create( @@ -905,9 +898,7 @@ Acquire a "Page" lock on a block @return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */ dberr_t lock_place_prdt_page_lock( -/*======================*/ - ulint space, /*!< in: space for the page to lock */ - ulint page_no, /*!< in: page number */ + const page_id_t page_id, /*!< in: page identifier */ dict_index_t* index, /*!< in: secondary index */ que_thr_t* thr) /*!< in: query thread */ { @@ -924,9 +915,7 @@ lock_place_prdt_page_lock( lock_mutex_enter(); - const lock_t* lock = lock_rec_get_first_on_page_addr( - &lock_sys.prdt_page_hash, space, page_no); - + const lock_t* lock = lock_sys.get_first_prdt_page(page_id); const ulint mode = LOCK_S | LOCK_PRDT_PAGE; trx_t* trx = thr_get_trx(thr); @@ -952,7 +941,7 @@ lock_place_prdt_page_lock( #ifdef WITH_WSREP NULL, NULL, /* FIXME: replicate SPATIAL INDEX locks */ #endif - mode, space, page_no, NULL, PRDT_HEAPNO, + mode, page_id, NULL, PRDT_HEAPNO, index, trx, FALSE); #ifdef PRDT_DIAG @@ -967,25 +956,19 @@ lock_place_prdt_page_lock( /** Check whether there are R-tree Page lock on a page @param[in] trx trx to test the lock -@param[in] space space id for the page -@param[in] page_no page number +@param[in] page_id page identifier @return true if there is none */ -bool -lock_test_prdt_page_lock( - const trx_t* trx, - ulint space, - ulint page_no) +bool lock_test_prdt_page_lock(const trx_t *trx, const page_id_t page_id) { lock_t* lock; lock_mutex_enter(); - lock = lock_rec_get_first_on_page_addr( - &lock_sys.prdt_page_hash, space, page_no); + lock = lock_sys.get_first_prdt_page(page_id); lock_mutex_exit(); - return(lock == NULL || trx == lock->trx); + return(!lock || trx == lock->trx); } /*************************************************************//** @@ -1030,15 +1013,10 @@ lock_prdt_page_free_from_discard( { lock_t* lock; lock_t* next_lock; - ulint space; - ulint page_no; ut_ad(lock_mutex_own()); - space = block->page.id().space(); - page_no = block->page.id().page_no(); - - lock = lock_rec_get_first_on_page_addr(lock_hash, space, page_no); + lock = lock_sys.get_first(*lock_hash, block->page.id()); while (lock != NULL) { next_lock = lock_rec_get_next_on_page(lock); diff --git a/storage/innobase/row/row0purge.cc b/storage/innobase/row/row0purge.cc index aec4fa32ad7..5579e53b6c1 100644 --- a/storage/innobase/row/row0purge.cc +++ b/storage/innobase/row/row0purge.cc @@ -499,9 +499,8 @@ row_purge_remove_sec_if_poss_leaf( && btr_cur->rtr_info->thr ? thr_get_trx( btr_cur->rtr_info->thr) - : NULL, - block->page.id().space(), - block->page.id().page_no())) { + : nullptr, + block->page.id())) { /* this is the last record on page, and it has a "page" lock on it, which mean search is still depending diff --git a/storage/innobase/trx/trx0i_s.cc b/storage/innobase/trx/trx0i_s.cc index 2736dbd285f..82477399552 100644 --- a/storage/innobase/trx/trx0i_s.cc +++ b/storage/innobase/trx/trx0i_s.cc @@ -394,13 +394,11 @@ i_s_locks_row_validate( if (!row->lock_index) { /* table lock */ ut_ad(!row->lock_data); - ut_ad(!row->lock_space); - ut_ad(!row->lock_page); + ut_ad(row->lock_page == page_id_t(0, 0)); ut_ad(!row->lock_rec); } else { /* record lock */ /* row->lock_data == NULL if buf_page_try_get() == NULL */ - ut_ad(row->lock_page); } return(TRUE); @@ -631,9 +629,7 @@ fill_lock_data( mtr_start(&mtr); - block = buf_page_try_get(page_id_t(lock->un_member.rec_lock.space, - lock->un_member.rec_lock.page_no), - &mtr); + block = buf_page_try_get(lock->un_member.rec_lock.page_id, &mtr); if (block == NULL) { @@ -754,8 +750,7 @@ static bool fill_locks_row( return false; } - row->lock_space = lock->un_member.rec_lock.space; - row->lock_page = lock->un_member.rec_lock.page_no; + row->lock_page = lock->un_member.rec_lock.page_id; row->lock_rec = heap_no; if (!fill_lock_data(&row->lock_data, lock, heap_no, cache)) { @@ -766,8 +761,7 @@ static bool fill_locks_row( } else { row->lock_index = NULL; - row->lock_space = 0; - row->lock_page = 0; + row->lock_page = page_id_t(0, 0); row->lock_rec = 0; row->lock_data = NULL; @@ -831,13 +825,9 @@ fold_lock( switch (lock_get_type(lock)) { case LOCK_REC: ut_a(heap_no != 0xFFFF); - ret = ut_fold_ulint_pair((ulint) lock->trx->id, - lock->un_member.rec_lock.space); - - ret = ut_fold_ulint_pair(ret, - lock->un_member.rec_lock.page_no); - + lock->un_member.rec_lock.page_id. + fold()); ret = ut_fold_ulint_pair(ret, heap_no); break; @@ -880,8 +870,7 @@ locks_row_eq_lock( ut_a(heap_no != 0xFFFF); return(row->lock_trx_id == lock->trx->id - && row->lock_space == lock->un_member.rec_lock.space - && row->lock_page == lock->un_member.rec_lock.page_no + && row->lock_page == lock->un_member.rec_lock.page_id && row->lock_rec == heap_no); case LOCK_TABLE: @@ -1477,8 +1466,8 @@ trx_i_s_create_lock_id( res_len = snprintf(lock_id, lock_id_size, TRX_ID_FMT ":%u:%u:%u", - row->lock_trx_id, row->lock_space, - row->lock_page, row->lock_rec); + row->lock_trx_id, row->lock_page.space(), + row->lock_page.page_no(), row->lock_rec); } else { /* table lock */ res_len = snprintf(lock_id, lock_id_size, -- cgit v1.2.1 From d61c5696faaf21a942cafab6df631fb1d86fd72c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 10 Sep 2020 14:10:15 +0300 Subject: Make a test more robust Change buffering will occasionally happen if other pages are not flushed quickly enough. --- .../suite/innodb/r/innodb-wl5522-debug.result | 21 ------------- mysql-test/suite/innodb/t/innodb-wl5522-debug.test | 35 ---------------------- 2 files changed, 56 deletions(-) diff --git a/mysql-test/suite/innodb/r/innodb-wl5522-debug.result b/mysql-test/suite/innodb/r/innodb-wl5522-debug.result index ad79967a2e5..8e255e18bec 100644 --- a/mysql-test/suite/innodb/r/innodb-wl5522-debug.result +++ b/mysql-test/suite/innodb/r/innodb-wl5522-debug.result @@ -488,8 +488,6 @@ INDEX idx3(c4(512))) Engine=InnoDB; connect purge_control,localhost,root; START TRANSACTION WITH CONSISTENT SNAPSHOT; connection default; -SET GLOBAL innodb_monitor_reset = ibuf_merges; -SET GLOBAL innodb_monitor_reset = ibuf_merges_insert; INSERT INTO t1 SELECT 1 + seq, 1 + (seq MOD 4), REPEAT(SUBSTR('abcd', 1 + (seq MOD 4), 1), 2048), @@ -660,22 +658,9 @@ COUNT(*) SELECT SUM(c2) FROM t1; SUM(c2) 124160 -SELECT name -FROM information_schema.innodb_metrics -WHERE name = 'ibuf_merges_insert' AND count = 0; -name -ibuf_merges_insert FLUSH TABLES t1 FOR EXPORT; backup: t1 UNLOCK TABLES; -SELECT name -FROM information_schema.innodb_metrics -WHERE name = 'ibuf_merges' AND count > 0; -name -SELECT name -FROM information_schema.innodb_metrics -WHERE name = 'ibuf_merges_inserts' AND count > 0; -name connection purge_control; COMMIT; disconnect purge_control; @@ -954,10 +939,4 @@ SET SESSION debug_dbug=@saved_debug_dbug; DROP TABLE t1; unlink: t1.ibd unlink: t1.cfg -set global innodb_monitor_disable = all; -set global innodb_monitor_reset_all = all; -set global innodb_monitor_enable = default; -set global innodb_monitor_disable = default; -set global innodb_monitor_reset = default; -set global innodb_monitor_reset_all = default; SET GLOBAL INNODB_FILE_PER_TABLE=@file_per_table; diff --git a/mysql-test/suite/innodb/t/innodb-wl5522-debug.test b/mysql-test/suite/innodb/t/innodb-wl5522-debug.test index 30746f5fad8..07c2adeb550 100644 --- a/mysql-test/suite/innodb/t/innodb-wl5522-debug.test +++ b/mysql-test/suite/innodb/t/innodb-wl5522-debug.test @@ -1016,14 +1016,6 @@ EOF DROP TABLE t1; ---disable_query_log -# Enable metrics for the counters we are going to use -set global innodb_monitor_enable = purge_stop_count; -set global innodb_monitor_enable = purge_resume_count; -set global innodb_monitor_enable = ibuf_merges; -set global innodb_monitor_enable = ibuf_merges_insert; ---enable_query_log - # # Create a large table with delete marked records, disable purge during # the update so that we can test the IMPORT purge code. @@ -1042,9 +1034,6 @@ connect (purge_control,localhost,root); START TRANSACTION WITH CONSISTENT SNAPSHOT; connection default; -SET GLOBAL innodb_monitor_reset = ibuf_merges; -SET GLOBAL innodb_monitor_reset = ibuf_merges_insert; - INSERT INTO t1 SELECT 1 + seq, 1 + (seq MOD 4), REPEAT(SUBSTR('abcd', 1 + (seq MOD 4), 1), 2048), @@ -1075,10 +1064,6 @@ SELECT c1, c2 FROM t1; SELECT COUNT(*) FROM t1; SELECT SUM(c2) FROM t1; -SELECT name - FROM information_schema.innodb_metrics - WHERE name = 'ibuf_merges_insert' AND count = 0; - FLUSH TABLES t1 FOR EXPORT; perl; @@ -1088,14 +1073,6 @@ EOF UNLOCK TABLES; -SELECT name - FROM information_schema.innodb_metrics - WHERE name = 'ibuf_merges' AND count > 0; - -SELECT name - FROM information_schema.innodb_metrics - WHERE name = 'ibuf_merges_inserts' AND count > 0; - # Enable normal operation connection purge_control; COMMIT; @@ -1385,21 +1362,9 @@ do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl"; ib_unlink_tablespace("test", "t1"); EOF -set global innodb_monitor_disable = all; -set global innodb_monitor_reset_all = all; - --- disable_warnings -set global innodb_monitor_enable = default; -set global innodb_monitor_disable = default; -set global innodb_monitor_reset = default; -set global innodb_monitor_reset_all = default; --- enable_warnings - --disable_query_log call mtr.add_suppression("InnoDB: The log sequence numbers [0-9]+ and [0-9]+ in ibdata files do not match the log sequence number [0-9]+ in the ib_logfiles!"); call mtr.add_suppression("'Resource temporarily unavailable'"); -call mtr.add_suppression("Monitor ibuf_merges is already enabled"); -call mtr.add_suppression("Monitor ibuf_merges_insert is already enabled"); call mtr.add_suppression("Got error -1 when reading table '.*'"); call mtr.add_suppression("InnoDB: Table '.*' tablespace is set as discarded."); call mtr.add_suppression("InnoDB: Tablespace '.*' exists in the cache.*"); -- cgit v1.2.1 From ab56cbcd811595822f38e50d224f52dbaab81c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 15 Sep 2020 12:50:19 +0300 Subject: Stabilize and clean up a test The counter buffer_flush_background_total_pages may be unreliable, because pages can be flushed in different means. So, let us only check INNODB_BUFFER_POOL_PAGES_FLUSHED. --- mysql-test/suite/innodb/r/purge_secondary.result | 11 +---------- mysql-test/suite/innodb/t/purge_secondary.test | 11 ++--------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/mysql-test/suite/innodb/r/purge_secondary.result b/mysql-test/suite/innodb/r/purge_secondary.result index 1b5f2896887..7c2b4151e76 100644 --- a/mysql-test/suite/innodb/r/purge_secondary.result +++ b/mysql-test/suite/innodb/r/purge_secondary.result @@ -141,18 +141,9 @@ WHERE NAME='test/t1'; OTHER_INDEX_SIZE 1 ALTER TABLE t1 DROP INDEX `sidx`; -INSERT INTO t1 () VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(); -INSERT INTO t1 (a) SELECT NULL FROM t1; -INSERT INTO t1 (a) SELECT NULL FROM t1; -INSERT INTO t1 (a) SELECT NULL FROM t1; -INSERT INTO t1 (a) SELECT NULL FROM t1; -INSERT INTO t1 (a) SELECT NULL FROM t1; +INSERT INTO t1 (a) SELECT * FROM seq_1_to_544; ALTER TABLE t1 FORCE, ALGORITHM=INPLACE; ALTER TABLE t1 FORCE, ALGORITHM=INPLACE; -SELECT NAME, SUBSYSTEM FROM INFORMATION_SCHEMA.INNODB_METRICS -WHERE NAME="buffer_LRU_batch_flush_total_pages" AND COUNT > 0; -NAME SUBSYSTEM -buffer_LRU_batch_flush_total_pages buffer SELECT (variable_value > 0) FROM information_schema.global_status WHERE LOWER(variable_name) LIKE 'INNODB_BUFFER_POOL_PAGES_FLUSHED'; (variable_value > 0) diff --git a/mysql-test/suite/innodb/t/purge_secondary.test b/mysql-test/suite/innodb/t/purge_secondary.test index bf702b6b737..34b4ce06f5f 100644 --- a/mysql-test/suite/innodb/t/purge_secondary.test +++ b/mysql-test/suite/innodb/t/purge_secondary.test @@ -1,4 +1,5 @@ --source include/have_innodb.inc +--source include/have_sequence.inc # Ensure that the history list length will actually be decremented by purge. SET @saved_frequency = @@GLOBAL.innodb_purge_rseg_truncate_frequency; @@ -123,18 +124,10 @@ WHERE NAME='test/t1'; # Work around MDEV-13942, Dropping the spatial index to avoid the possible hang ALTER TABLE t1 DROP INDEX `sidx`; -INSERT INTO t1 () VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(); -INSERT INTO t1 (a) SELECT NULL FROM t1; -INSERT INTO t1 (a) SELECT NULL FROM t1; -INSERT INTO t1 (a) SELECT NULL FROM t1; -INSERT INTO t1 (a) SELECT NULL FROM t1; -INSERT INTO t1 (a) SELECT NULL FROM t1; +INSERT INTO t1 (a) SELECT * FROM seq_1_to_544; ALTER TABLE t1 FORCE, ALGORITHM=INPLACE; ALTER TABLE t1 FORCE, ALGORITHM=INPLACE; -SELECT NAME, SUBSYSTEM FROM INFORMATION_SCHEMA.INNODB_METRICS -WHERE NAME="buffer_LRU_batch_flush_total_pages" AND COUNT > 0; - SELECT (variable_value > 0) FROM information_schema.global_status WHERE LOWER(variable_name) LIKE 'INNODB_BUFFER_POOL_PAGES_FLUSHED'; -- cgit v1.2.1 From ccbe6bb6fc3cbe31e74404723f4ab78f7c530950 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 17 Sep 2020 16:07:37 +0200 Subject: MDEV-19935 Create unified CRC-32 interface Add CRC32C code to mysys. The x86-64 implementation uses PCMULQDQ in addition to CRC32 instruction after Intel whitepaper, and is ported from rocksdb code. Optimized ARM and POWER CRC32 were already present in mysys. --- config.h.cmake | 9 - extra/CMakeLists.txt | 12 - extra/innochecksum.cc | 1 - extra/mariabackup/backup_copy.cc | 1 - extra/mariabackup/xbstream.cc | 2 - extra/mariabackup/xtrabackup.cc | 4 - include/my_sys.h | 14 +- mysys/CMakeLists.txt | 44 +- mysys/checksum.c | 57 -- mysys/crc32/crc32_arm64.c | 19 +- mysys/crc32/crc32_ppc64.c | 678 +------------------ mysys/crc32/crc32c.cc | 1254 +++++++++++++++++++++++++++++++++++ mysys/crc32/crc32c_ppc.c | 5 + mysys/crc32/crc32c_ppc.h | 19 + mysys/crc32/crc_ppc64.h | 664 +++++++++++++++++++ mysys/crc32ieee.cc | 63 ++ mysys/my_init.c | 3 - storage/innobase/CMakeLists.txt | 2 - storage/innobase/include/ut0crc32.h | 27 +- storage/innobase/innodb.cmake | 10 - storage/innobase/srv/srv0srv.cc | 1 - storage/innobase/srv/srv0start.cc | 2 +- storage/innobase/ut/ut0crc32.cc | 346 ---------- unittest/mysys/CMakeLists.txt | 4 +- unittest/mysys/crc32-t.c | 69 ++ 25 files changed, 2125 insertions(+), 1185 deletions(-) delete mode 100644 mysys/checksum.c create mode 100644 mysys/crc32/crc32c.cc create mode 100644 mysys/crc32/crc32c_ppc.c create mode 100644 mysys/crc32/crc32c_ppc.h create mode 100644 mysys/crc32/crc_ppc64.h create mode 100644 mysys/crc32ieee.cc delete mode 100644 storage/innobase/ut/ut0crc32.cc create mode 100644 unittest/mysys/crc32-t.c diff --git a/config.h.cmake b/config.h.cmake index 3e41e0ac3af..5a48df0a135 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -103,15 +103,6 @@ #cmakedefine HAVE_LIBWRAP 1 #cmakedefine HAVE_SYSTEMD 1 -#cmakedefine HAVE_CPUID_INSTRUCTION 1 -#cmakedefine HAVE_CLMUL_INSTRUCTION 1 -#cmakedefine HAVE_CRC32_VPMSUM 1 - -/* Support ARMv8 crc + crypto */ -#cmakedefine HAVE_ARMV8_CRC 1 -#cmakedefine HAVE_ARMV8_CRYPTO 1 -#cmakedefine HAVE_ARMV8_CRC_CRYPTO_INTRINSICS 1 - /* Does "struct timespec" have a "sec" and "nsec" field? */ #cmakedefine HAVE_TIMESPEC_TS_SEC 1 diff --git a/extra/CMakeLists.txt b/extra/CMakeLists.txt index b7b1d215711..8f4c434ed34 100644 --- a/extra/CMakeLists.txt +++ b/extra/CMakeLists.txt @@ -73,20 +73,8 @@ IF(WITH_INNOBASE_STORAGE_ENGINE) # We use the InnoDB code directly in case the code changes. ADD_DEFINITIONS("-DUNIV_INNOCHECKSUM") - # Avoid generating Hardware Capabilities due to crc32 instructions - IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_SYSTEM_PROCESSOR MATCHES "i386") - MY_CHECK_CXX_COMPILER_FLAG("-Wa,-nH") - IF(have_CXX__Wa__nH) - ADD_COMPILE_FLAGS( - ../storage/innobase/ut/ut0crc32.cc - COMPILE_FLAGS "-Wa,-nH" - ) - ENDIF() - ENDIF() - SET(INNOBASE_SOURCES ../storage/innobase/buf/buf0checksum.cc - ../storage/innobase/ut/ut0crc32.cc ../storage/innobase/ut/ut0ut.cc ../storage/innobase/buf/buf0buf.cc ../storage/innobase/page/page0zip.cc diff --git a/extra/innochecksum.cc b/extra/innochecksum.cc index d8d043d89b9..7805dc4283f 100644 --- a/extra/innochecksum.cc +++ b/extra/innochecksum.cc @@ -1583,7 +1583,6 @@ int main( /* enable when space_id of given file is zero. */ bool is_system_tablespace = false; - ut_crc32_init(); MY_INIT(argv[0]); DBUG_ENTER("main"); DBUG_PROCESS(argv[0]); diff --git a/extra/mariabackup/backup_copy.cc b/extra/mariabackup/backup_copy.cc index 965b1e9e4b6..ef2e59ab379 100644 --- a/extra/mariabackup/backup_copy.cc +++ b/extra/mariabackup/backup_copy.cc @@ -1833,7 +1833,6 @@ copy_back() srv_max_n_threads = 1000; sync_check_init(); - ut_crc32_init(); /* copy undo tablespaces */ diff --git a/extra/mariabackup/xbstream.cc b/extra/mariabackup/xbstream.cc index 761b8e69890..c22c7cc8f39 100644 --- a/extra/mariabackup/xbstream.cc +++ b/extra/mariabackup/xbstream.cc @@ -97,8 +97,6 @@ main(int argc, char **argv) { MY_INIT(argv[0]); - my_checksum_init(); - if (get_options(&argc, &argv)) { goto err; } diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index 650ab49fbcd..c8e41f13e3f 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -4011,9 +4011,6 @@ fail: ut_d(sync_check_enable()); /* Reset the system variables in the recovery module. */ trx_pool_init(); - - ut_crc32_init(); - my_checksum_init(); recv_sys.create(); #ifdef WITH_INNODB_DISALLOW_WRITES @@ -5386,7 +5383,6 @@ static bool xtrabackup_prepare_func(char** argv) sync_check_init(); ut_d(sync_check_enable()); - ut_crc32_init(); recv_sys.create(); log_sys.create(); recv_sys.recovery_on = true; diff --git a/include/my_sys.h b/include/my_sys.h index 98a3cfd275a..e39452a376d 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -901,18 +901,10 @@ extern int my_compress_buffer(uchar *dest, size_t *destLen, extern int packfrm(const uchar *, size_t, uchar **, size_t *); extern int unpackfrm(uchar **, size_t *, const uchar *); -void my_checksum_init(void); -#ifdef HAVE_CRC32_VPMSUM -extern ha_checksum my_checksum(ha_checksum, const void *, size_t); -#else -typedef ha_checksum (*my_crc32_t)(ha_checksum, const void *, size_t); -extern MYSQL_PLUGIN_IMPORT my_crc32_t my_checksum; -#endif +extern uint32 my_checksum(uint32, const void *, size_t); +extern uint32 my_crc32c(uint32, const void *, size_t); -#if defined(__GNUC__) && defined(HAVE_ARMV8_CRC) -int crc32_aarch64_available(void); -const char *crc32c_aarch64_available(void); -#endif +extern const char *my_crc32c_implementation(); #ifdef DBUG_ASSERT_EXISTS extern void my_debug_put_break_here(void); diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index 099ba63c8e7..3cc84a6abc8 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -16,7 +16,7 @@ INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/mysys) -SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c my_default.c +SET(MYSYS_SOURCES array.c charset-def.c charset.c crc32ieee.cc my_default.c get_password.c errors.c hash.c list.c mf_cache.c mf_dirname.c mf_fn_ext.c @@ -45,7 +45,7 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c my_default.c my_uuid.c wqueue.c waiting_threads.c ma_dyncol.c ../sql-common/my_time.c my_rdtsc.c my_context.c psi_noop.c my_atomic_writes.c my_cpu.c my_likely.c my_largepage.c - file_logger.c my_dlerror.c) + file_logger.c my_dlerror.c crc32/crc32c.cc) IF (WIN32) SET (MYSYS_SOURCES ${MYSYS_SOURCES} @@ -59,25 +59,23 @@ IF (WIN32) ENDIF() IF(MSVC) - SET(HAVE_CPUID_INSTRUCTION 1 CACHE BOOL "") - SET(HAVE_CLMUL_INSTRUCTION 1 CACHE BOOL "") SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_x86.c) + ADD_DEFINITIONS(-DHAVE_SSE42 -DHAVE_PCLMUL) IF(CLANG_CL) - SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.c PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul") + SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.cc crc32/crc32c.c PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul") ENDIF() ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i386|i686") - SET(HAVE_CPUID_INSTRUCTION 1 CACHE BOOL "") MY_CHECK_C_COMPILER_FLAG(-msse4.2) MY_CHECK_C_COMPILER_FLAG(-mpclmul) CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H) CHECK_INCLUDE_FILE(x86intrin.h HAVE_X86INTRIN_H) IF(have_C__msse4.2 AND have_C__mpclmul AND HAVE_CPUID_H AND HAVE_X86INTRIN_H) - SET(HAVE_CLMUL_INSTRUCTION 1 CACHE BOOL "") SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_x86.c) - SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.c PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul") + SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.c crc32/crc32c.cc PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul") + ADD_DEFINITIONS(-DHAVE_SSE42 -DHAVE_PCLMUL) ENDIF() ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64") - IF(CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) + IF(CMAKE_COMPILER_IS_GNUCC) include(CheckCXXSourceCompiles) CHECK_CXX_SOURCE_COMPILES(" @@ -99,23 +97,29 @@ ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64") #include int main() { foo(0); getauxval(AT_HWCAP); }" HAVE_ARMV8_CRYPTO) - CHECK_C_COMPILER_FLAG(-march=armv8-a+crc+crypto HAVE_ARMV8_CRC_CRYPTO_INTRINSICS) - IF(HAVE_ARMV8_CRC_CRYPTO_INTRINSICS) + CHECK_C_COMPILER_FLAG(-march=armv8-a+crc+crypto HAVE_ARMV8_CRC_CRYPTO_MARCH) + + IF(HAVE_ARMV8_CRC_CRYPTO_MARCH) + CHECK_INCLUDE_FILE(arm_acle.h HAVE_ARM_ACLE_H -march=armv8-a+crc+crypto) + IF(HAVE_ARM_ACLE_H) + ADD_DEFINITIONS(-DHAVE_ARMV8_CRC_CRYPTO_INTRINSICS) + ENDIF() + IF(HAVE_ARMV8_CRC) + ADD_DEFINITIONS(-DHAVE_ARMV8_CRC) + ENDIF() + IF(HAVE_ARMV8_CRYPTO) + ADD_DEFINITIONS(-DHAVE_ARMV8_CRYPTO) + ENDIF() SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_arm64.c) SET_SOURCE_FILES_PROPERTIES(crc32/crc32_arm64.c PROPERTIES COMPILE_FLAGS "-march=armv8-a+crc+crypto") ENDIF() ENDIF() ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64") - SET(HAVE_CRC32_VPMSUM 1 PARENT_SCOPE) - SET(MYSYS_SOURCES ${MYSYS_SOURCES} $ $) - - ADD_LIBRARY(crc32c OBJECT crc32/crc32_ppc64.c) - ADD_LIBRARY(crc32ieee OBJECT crc32/crc32_ppc64.c) - - SET_TARGET_PROPERTIES(crc32c crc32ieee PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -maltivec -mvsx -mpower8-vector -mcrypto -mpower8-vector") - SET_TARGET_PROPERTIES(crc32ieee PROPERTIES COMPILE_DEFINITIONS "CRC32_FUNCTION=my_checksum;CRC32_CONSTANTS_HEADER=\"pcc_crc32_constants.h\"") - SET_TARGET_PROPERTIES(crc32c PROPERTIES COMPILE_DEFINITIONS "CRC32_FUNCTION=crc32c_vpmsum;CRC32_CONSTANTS_HEADER=\"pcc_crc32c_constants.h\"") + SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_ppc64.c crc32/crc32c_ppc.c) + SET_SOURCE_FILES_PROPERTIES(crc32/crc32_ppc64.c crc32/crc32c_ppc.c PROPERTIES + COMPILE_FLAGS "${COMPILE_FLAGS} -maltivec -mvsx -mpower8-vector -mcrypto -mpower8-vector") + ADD_DEFINITIONS(-DHAVE_POWER8 -DHAS_ALTIVEC) ENDIF() IF(UNIX) diff --git a/mysys/checksum.c b/mysys/checksum.c deleted file mode 100644 index 6e6633600a9..00000000000 --- a/mysys/checksum.c +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ - - -#include -#include -#include - -#if !defined(HAVE_CRC32_VPMSUM) -/* TODO: remove this once zlib adds inherent support for hardware accelerated -crc32 for all architectures. */ -static unsigned int my_crc32_zlib(unsigned int crc, const void *data, - size_t len) -{ - return (unsigned int) crc32(crc, data, (unsigned int) len); -} - -my_crc32_t my_checksum= my_crc32_zlib; -#endif - -#ifdef HAVE_CLMUL_INSTRUCTION -extern int crc32_pclmul_enabled(); -extern unsigned int crc32_pclmul(unsigned int, const void *, size_t); - -/*----------------------------- x86_64 ---------------------------------*/ -void my_checksum_init(void) -{ - if (crc32_pclmul_enabled()) - my_checksum= crc32_pclmul; -} -#elif defined(__GNUC__) && defined(HAVE_ARMV8_CRC) -/*----------------------------- aarch64 --------------------------------*/ - -extern unsigned int crc32_aarch64(unsigned int, const void *, size_t); - -/* Ideally all ARM 64 bit processor should support crc32 but if some model -doesn't support better to find it out through auxillary vector. */ -void my_checksum_init(void) -{ - if (crc32_aarch64_available()) - my_checksum= crc32_aarch64; -} -#else -void my_checksum_init(void) {} -#endif diff --git a/mysys/crc32/crc32_arm64.c b/mysys/crc32/crc32_arm64.c index a7eb2a47442..b82d4701e6f 100644 --- a/mysys/crc32/crc32_arm64.c +++ b/mysys/crc32/crc32_arm64.c @@ -57,6 +57,12 @@ asm(".arch_extension crypto"); #define CRC32CH(crc, value) __asm__("crc32ch %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value)) #define CRC32CB(crc, value) __asm__("crc32cb %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value)) +#define CRC32X(crc, value) __asm__("crc32x %w[c], %w[c], %x[v]":[c]"+r"(crc):[v]"r"(value)) +#define CRC32W(crc, value) __asm__("crc32w %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value)) +#define CRC32H(crc, value) __asm__("crc32h %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value)) +#define CRC32B(crc, value) __asm__("crc32b %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value)) + + #define CRC32C3X8(buffer, ITR) \ __asm__("crc32cx %w[c1], %w[c1], %x[v]":[c1]"+r"(crc1):[v]"r"(*((const uint64_t *)buffer + 42*1 + (ITR))));\ __asm__("crc32cx %w[c2], %w[c2], %x[v]":[c2]"+r"(crc2):[v]"r"(*((const uint64_t *)buffer + 42*2 + (ITR))));\ @@ -73,6 +79,11 @@ asm(".arch_extension crypto"); #define CRC32CH(crc, value) (crc) = __crc32ch((crc), (value)) #define CRC32CB(crc, value) (crc) = __crc32cb((crc), (value)) +#define CRC32X(crc, value) (crc) = __crc32d((crc), (value)) +#define CRC32W(crc, value) (crc) = __crc32w((crc), (value)) +#define CRC32H(crc, value) (crc) = __crc32h((crc), (value)) +#define CRC32B(crc, value) (crc) = __crc32b((crc), (value)) + #define CRC32C3X8(buffer, ITR) \ crc1 = __crc32cd(crc1, *((const uint64_t *)buffer + 42*1 + (ITR)));\ crc2 = __crc32cd(crc2, *((const uint64_t *)buffer + 42*2 + (ITR)));\ @@ -119,7 +130,7 @@ uint32_t crc32c_aarch64(uint32_t crc, const unsigned char *buffer, uint64_t len) uint32_t crc0, crc1, crc2; int64_t length= (int64_t)len; - crc= 0xFFFFFFFFU; + crc^= 0xffffffff; /* Pmull runtime check here. * Raspberry Pi 4 supports crc32 but doesn't support pmull (MDEV-23030). @@ -282,16 +293,16 @@ unsigned int crc32_aarch64(unsigned int crc, const void *buf, size_t len) /* if start pointer is not 8 bytes aligned */ while ((buf1 != (const uint8_t *) buf8) && len) { - crc= __crc32b(crc, *buf1++); + CRC32B(crc, *buf1++); len--; } for (; len >= 8; len-= 8) - crc= __crc32d(crc, *buf8++); + CRC32X(crc, *buf8++); buf1= (const uint8_t *) buf8; while (len--) - crc= __crc32b(crc, *buf1++); + CRC32B(crc, *buf1++); return ~crc; } diff --git a/mysys/crc32/crc32_ppc64.c b/mysys/crc32/crc32_ppc64.c index 2e8b9fc1b12..76df88ee231 100644 --- a/mysys/crc32/crc32_ppc64.c +++ b/mysys/crc32/crc32_ppc64.c @@ -1,675 +1,5 @@ -/* - * Calculate the checksum of data that is 16 byte aligned and a multiple of - * 16 bytes. - * - * The first step is to reduce it to 1024 bits. We do this in 8 parallel - * chunks in order to mask the latency of the vpmsum instructions. If we - * have more than 32 kB of data to checksum we repeat this step multiple - * times, passing in the previous 1024 bits. - * - * The next step is to reduce the 1024 bits to 64 bits. This step adds - * 32 bits of 0s to the end - this matches what a CRC does. We just - * calculate constants that land the data in this 32 bits. - * - * We then use fixed point Barrett reduction to compute a mod n over GF(2) - * for n = CRC using POWER8 instructions. We use x = 32. - * - * http://en.wikipedia.org/wiki/Barrett_reduction - * - * This code uses gcc vector builtins instead using assembly directly. - * - * Copyright (C) 2017 Rogerio Alves , IBM - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of either: - * - * a) the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) - * any later version, or - * b) the Apache License, Version 2.0 - */ - -#include - -#define POWER8_INTRINSICS +#define CRC32_FUNCTION my_checksum #define CRC_TABLE - -#ifdef CRC32_CONSTANTS_HEADER -#include CRC32_CONSTANTS_HEADER -#else -#include "crc32_constants.h" -#endif - -#define VMX_ALIGN 16 -#define VMX_ALIGN_MASK (VMX_ALIGN-1) - -#ifdef REFLECT -static unsigned int crc32_align(unsigned int crc, const unsigned char *p, - unsigned long len) -{ - while (len--) - crc = crc_table[(crc ^ *p++) & 0xff] ^ (crc >> 8); - return crc; -} -#else -static unsigned int crc32_align(unsigned int crc, const unsigned char *p, - unsigned long len) -{ - while (len--) - crc = crc_table[((crc >> 24) ^ *p++) & 0xff] ^ (crc << 8); - return crc; -} -#endif - -static unsigned int __attribute__ ((aligned (32))) -__crc32_vpmsum(unsigned int crc, const void* p, unsigned long len); - -#ifndef CRC32_FUNCTION -#define CRC32_FUNCTION crc32_vpmsum -#endif - -unsigned int CRC32_FUNCTION(unsigned int crc, const unsigned char *p, - unsigned long len) -{ - unsigned int prealign; - unsigned int tail; - -#ifdef CRC_XOR - crc ^= 0xffffffff; -#endif - - if (len < VMX_ALIGN + VMX_ALIGN_MASK) { - crc = crc32_align(crc, p, len); - goto out; - } - - if ((unsigned long)p & VMX_ALIGN_MASK) { - prealign = VMX_ALIGN - ((unsigned long)p & VMX_ALIGN_MASK); - crc = crc32_align(crc, p, prealign); - len -= prealign; - p += prealign; - } - - crc = __crc32_vpmsum(crc, p, len & ~VMX_ALIGN_MASK); - - tail = len & VMX_ALIGN_MASK; - if (tail) { - p += len & ~VMX_ALIGN_MASK; - crc = crc32_align(crc, p, tail); - } - -out: -#ifdef CRC_XOR - crc ^= 0xffffffff; -#endif - - return crc; -} - -#if defined (__clang__) -#include "clang_workaround.h" -#else -#define __builtin_pack_vector(a, b) __builtin_pack_vector_int128 ((a), (b)) -#define __builtin_unpack_vector_0(a) __builtin_unpack_vector_int128 ((vector __int128_t)(a), 0) -#define __builtin_unpack_vector_1(a) __builtin_unpack_vector_int128 ((vector __int128_t)(a), 1) -#endif - -/* When we have a load-store in a single-dispatch group and address overlap - * such that foward is not allowed (load-hit-store) the group must be flushed. - * A group ending NOP prevents the flush. - */ -#define GROUP_ENDING_NOP asm("ori 2,2,0" ::: "memory") - -#if defined(__BIG_ENDIAN__) && defined (REFLECT) -#define BYTESWAP_DATA -#elif defined(__LITTLE_ENDIAN__) && !defined(REFLECT) -#define BYTESWAP_DATA -#endif - -#ifdef BYTESWAP_DATA -#define VEC_PERM(vr, va, vb, vc) vr = vec_perm(va, vb,\ - (__vector unsigned char) vc) -#if defined(__LITTLE_ENDIAN__) -/* Byte reverse permute constant LE. */ -static const __vector unsigned long long vperm_const - __attribute__ ((aligned(16))) = { 0x08090A0B0C0D0E0FUL, - 0x0001020304050607UL }; -#else -static const __vector unsigned long long vperm_const - __attribute__ ((aligned(16))) = { 0x0F0E0D0C0B0A0908UL, - 0X0706050403020100UL }; -#endif -#else -#define VEC_PERM(vr, va, vb, vc) -#endif - -static unsigned int __attribute__ ((aligned (32))) -__crc32_vpmsum(unsigned int crc, const void* p, unsigned long len) { - - const __vector unsigned long long vzero = {0,0}; - const __vector unsigned long long vones = {0xffffffffffffffffUL, - 0xffffffffffffffffUL}; - -#ifdef REFLECT - __vector unsigned char vsht_splat; - const __vector unsigned long long vmask_32bit = - (__vector unsigned long long)vec_sld((__vector unsigned char)vzero, - (__vector unsigned char)vones, 4); -#endif - - const __vector unsigned long long vmask_64bit = - (__vector unsigned long long)vec_sld((__vector unsigned char)vzero, - (__vector unsigned char)vones, 8); - - __vector unsigned long long vcrc; - - __vector unsigned long long vconst1, vconst2; - - /* vdata0-vdata7 will contain our data (p). */ - __vector unsigned long long vdata0, vdata1, vdata2, vdata3, vdata4, - vdata5, vdata6, vdata7; - - /* v0-v7 will contain our checksums */ - __vector unsigned long long v0 = {0,0}; - __vector unsigned long long v1 = {0,0}; - __vector unsigned long long v2 = {0,0}; - __vector unsigned long long v3 = {0,0}; - __vector unsigned long long v4 = {0,0}; - __vector unsigned long long v5 = {0,0}; - __vector unsigned long long v6 = {0,0}; - __vector unsigned long long v7 = {0,0}; - - - /* Vector auxiliary variables. */ - __vector unsigned long long va0, va1, va2, va3, va4, va5, va6, va7; - - unsigned int result = 0; - unsigned int offset; /* Constant table offset. */ - - unsigned long i; /* Counter. */ - unsigned long chunks; - - unsigned long block_size; - int next_block = 0; - - /* Align by 128 bits. The last 128 bit block will be processed at end. */ - unsigned long length = len & 0xFFFFFFFFFFFFFF80UL; - -#ifdef REFLECT - vcrc = (__vector unsigned long long)__builtin_pack_vector(0UL, crc); -#else - vcrc = (__vector unsigned long long)__builtin_pack_vector(crc, 0UL); - - /* Shift into top 32 bits */ - vcrc = (__vector unsigned long long)vec_sld((__vector unsigned char)vcrc, - (__vector unsigned char)vzero, 4); -#endif - - /* Short version. */ - if (len < 256) { - /* Calculate where in the constant table we need to start. */ - offset = 256 - len; - - vconst1 = vec_ld(offset, vcrc_short_const); - vdata0 = vec_ld(0, (__vector unsigned long long*) p); - VEC_PERM(vdata0, vdata0, vconst1, vperm_const); - - /* xor initial value*/ - vdata0 = vec_xor(vdata0, vcrc); - - vdata0 = (__vector unsigned long long) __builtin_crypto_vpmsumw - ((__vector unsigned int)vdata0, (__vector unsigned int)vconst1); - v0 = vec_xor(v0, vdata0); - - for (i = 16; i < len; i += 16) { - vconst1 = vec_ld(offset + i, vcrc_short_const); - vdata0 = vec_ld(i, (__vector unsigned long long*) p); - VEC_PERM(vdata0, vdata0, vconst1, vperm_const); - vdata0 = (__vector unsigned long long) __builtin_crypto_vpmsumw - ((__vector unsigned int)vdata0, (__vector unsigned int)vconst1); - v0 = vec_xor(v0, vdata0); - } - } else { - - /* Load initial values. */ - vdata0 = vec_ld(0, (__vector unsigned long long*) p); - vdata1 = vec_ld(16, (__vector unsigned long long*) p); - - VEC_PERM(vdata0, vdata0, vdata0, vperm_const); - VEC_PERM(vdata1, vdata1, vdata1, vperm_const); - - vdata2 = vec_ld(32, (__vector unsigned long long*) p); - vdata3 = vec_ld(48, (__vector unsigned long long*) p); - - VEC_PERM(vdata2, vdata2, vdata2, vperm_const); - VEC_PERM(vdata3, vdata3, vdata3, vperm_const); - - vdata4 = vec_ld(64, (__vector unsigned long long*) p); - vdata5 = vec_ld(80, (__vector unsigned long long*) p); - - VEC_PERM(vdata4, vdata4, vdata4, vperm_const); - VEC_PERM(vdata5, vdata5, vdata5, vperm_const); - - vdata6 = vec_ld(96, (__vector unsigned long long*) p); - vdata7 = vec_ld(112, (__vector unsigned long long*) p); - - VEC_PERM(vdata6, vdata6, vdata6, vperm_const); - VEC_PERM(vdata7, vdata7, vdata7, vperm_const); - - /* xor in initial value */ - vdata0 = vec_xor(vdata0, vcrc); - - p = (char *)p + 128; - - do { - /* Checksum in blocks of MAX_SIZE. */ - block_size = length; - if (block_size > MAX_SIZE) { - block_size = MAX_SIZE; - } - - length = length - block_size; - - /* - * Work out the offset into the constants table to start at. Each - * constant is 16 bytes, and it is used against 128 bytes of input - * data - 128 / 16 = 8 - */ - offset = (MAX_SIZE/8) - (block_size/8); - /* We reduce our final 128 bytes in a separate step */ - chunks = (block_size/128)-1; - - vconst1 = vec_ld(offset, vcrc_const); - - va0 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata0, - (__vector unsigned long long)vconst1); - va1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata1, - (__vector unsigned long long)vconst1); - va2 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata2, - (__vector unsigned long long)vconst1); - va3 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata3, - (__vector unsigned long long)vconst1); - va4 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata4, - (__vector unsigned long long)vconst1); - va5 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata5, - (__vector unsigned long long)vconst1); - va6 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata6, - (__vector unsigned long long)vconst1); - va7 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata7, - (__vector unsigned long long)vconst1); - - if (chunks > 1) { - offset += 16; - vconst2 = vec_ld(offset, vcrc_const); - GROUP_ENDING_NOP; - - vdata0 = vec_ld(0, (__vector unsigned long long*) p); - VEC_PERM(vdata0, vdata0, vdata0, vperm_const); - - vdata1 = vec_ld(16, (__vector unsigned long long*) p); - VEC_PERM(vdata1, vdata1, vdata1, vperm_const); - - vdata2 = vec_ld(32, (__vector unsigned long long*) p); - VEC_PERM(vdata2, vdata2, vdata2, vperm_const); - - vdata3 = vec_ld(48, (__vector unsigned long long*) p); - VEC_PERM(vdata3, vdata3, vdata3, vperm_const); - - vdata4 = vec_ld(64, (__vector unsigned long long*) p); - VEC_PERM(vdata4, vdata4, vdata4, vperm_const); - - vdata5 = vec_ld(80, (__vector unsigned long long*) p); - VEC_PERM(vdata5, vdata5, vdata5, vperm_const); - - vdata6 = vec_ld(96, (__vector unsigned long long*) p); - VEC_PERM(vdata6, vdata6, vdata6, vperm_const); - - vdata7 = vec_ld(112, (__vector unsigned long long*) p); - VEC_PERM(vdata7, vdata7, vdata7, vperm_const); - - p = (char *)p + 128; - - /* - * main loop. We modulo schedule it such that it takes three - * iterations to complete - first iteration load, second - * iteration vpmsum, third iteration xor. - */ - for (i = 0; i < chunks-2; i++) { - vconst1 = vec_ld(offset, vcrc_const); - offset += 16; - GROUP_ENDING_NOP; - - v0 = vec_xor(v0, va0); - va0 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata0, (__vector unsigned long long)vconst2); - vdata0 = vec_ld(0, (__vector unsigned long long*) p); - VEC_PERM(vdata0, vdata0, vdata0, vperm_const); - GROUP_ENDING_NOP; - - v1 = vec_xor(v1, va1); - va1 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata1, (__vector unsigned long long)vconst2); - vdata1 = vec_ld(16, (__vector unsigned long long*) p); - VEC_PERM(vdata1, vdata1, vdata1, vperm_const); - GROUP_ENDING_NOP; - - v2 = vec_xor(v2, va2); - va2 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata2, (__vector unsigned long long)vconst2); - vdata2 = vec_ld(32, (__vector unsigned long long*) p); - VEC_PERM(vdata2, vdata2, vdata2, vperm_const); - GROUP_ENDING_NOP; - - v3 = vec_xor(v3, va3); - va3 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata3, (__vector unsigned long long)vconst2); - vdata3 = vec_ld(48, (__vector unsigned long long*) p); - VEC_PERM(vdata3, vdata3, vdata3, vperm_const); - - vconst2 = vec_ld(offset, vcrc_const); - GROUP_ENDING_NOP; - - v4 = vec_xor(v4, va4); - va4 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata4, (__vector unsigned long long)vconst1); - vdata4 = vec_ld(64, (__vector unsigned long long*) p); - VEC_PERM(vdata4, vdata4, vdata4, vperm_const); - GROUP_ENDING_NOP; - - v5 = vec_xor(v5, va5); - va5 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata5, (__vector unsigned long long)vconst1); - vdata5 = vec_ld(80, (__vector unsigned long long*) p); - VEC_PERM(vdata5, vdata5, vdata5, vperm_const); - GROUP_ENDING_NOP; - - v6 = vec_xor(v6, va6); - va6 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata6, (__vector unsigned long long)vconst1); - vdata6 = vec_ld(96, (__vector unsigned long long*) p); - VEC_PERM(vdata6, vdata6, vdata6, vperm_const); - GROUP_ENDING_NOP; - - v7 = vec_xor(v7, va7); - va7 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata7, (__vector unsigned long long)vconst1); - vdata7 = vec_ld(112, (__vector unsigned long long*) p); - VEC_PERM(vdata7, vdata7, vdata7, vperm_const); - - p = (char *)p + 128; - } - - /* First cool down*/ - vconst1 = vec_ld(offset, vcrc_const); - offset += 16; - - v0 = vec_xor(v0, va0); - va0 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata0, (__vector unsigned long long)vconst1); - GROUP_ENDING_NOP; - - v1 = vec_xor(v1, va1); - va1 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata1, (__vector unsigned long long)vconst1); - GROUP_ENDING_NOP; - - v2 = vec_xor(v2, va2); - va2 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata2, (__vector unsigned long long)vconst1); - GROUP_ENDING_NOP; - - v3 = vec_xor(v3, va3); - va3 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata3, (__vector unsigned long long)vconst1); - GROUP_ENDING_NOP; - - v4 = vec_xor(v4, va4); - va4 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata4, (__vector unsigned long long)vconst1); - GROUP_ENDING_NOP; - - v5 = vec_xor(v5, va5); - va5 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata5, (__vector unsigned long long)vconst1); - GROUP_ENDING_NOP; - - v6 = vec_xor(v6, va6); - va6 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata6, (__vector unsigned long long)vconst1); - GROUP_ENDING_NOP; - - v7 = vec_xor(v7, va7); - va7 = __builtin_crypto_vpmsumd ((__vector unsigned long - long)vdata7, (__vector unsigned long long)vconst1); - }/* else */ - - /* Second cool down. */ - v0 = vec_xor(v0, va0); - v1 = vec_xor(v1, va1); - v2 = vec_xor(v2, va2); - v3 = vec_xor(v3, va3); - v4 = vec_xor(v4, va4); - v5 = vec_xor(v5, va5); - v6 = vec_xor(v6, va6); - v7 = vec_xor(v7, va7); - -#ifdef REFLECT - /* - * vpmsumd produces a 96 bit result in the least significant bits - * of the register. Since we are bit reflected we have to shift it - * left 32 bits so it occupies the least significant bits in the - * bit reflected domain. - */ - v0 = (__vector unsigned long long)vec_sld((__vector unsigned char)v0, - (__vector unsigned char)vzero, 4); - v1 = (__vector unsigned long long)vec_sld((__vector unsigned char)v1, - (__vector unsigned char)vzero, 4); - v2 = (__vector unsigned long long)vec_sld((__vector unsigned char)v2, - (__vector unsigned char)vzero, 4); - v3 = (__vector unsigned long long)vec_sld((__vector unsigned char)v3, - (__vector unsigned char)vzero, 4); - v4 = (__vector unsigned long long)vec_sld((__vector unsigned char)v4, - (__vector unsigned char)vzero, 4); - v5 = (__vector unsigned long long)vec_sld((__vector unsigned char)v5, - (__vector unsigned char)vzero, 4); - v6 = (__vector unsigned long long)vec_sld((__vector unsigned char)v6, - (__vector unsigned char)vzero, 4); - v7 = (__vector unsigned long long)vec_sld((__vector unsigned char)v7, - (__vector unsigned char)vzero, 4); -#endif - - /* xor with the last 1024 bits. */ - va0 = vec_ld(0, (__vector unsigned long long*) p); - VEC_PERM(va0, va0, va0, vperm_const); - - va1 = vec_ld(16, (__vector unsigned long long*) p); - VEC_PERM(va1, va1, va1, vperm_const); - - va2 = vec_ld(32, (__vector unsigned long long*) p); - VEC_PERM(va2, va2, va2, vperm_const); - - va3 = vec_ld(48, (__vector unsigned long long*) p); - VEC_PERM(va3, va3, va3, vperm_const); - - va4 = vec_ld(64, (__vector unsigned long long*) p); - VEC_PERM(va4, va4, va4, vperm_const); - - va5 = vec_ld(80, (__vector unsigned long long*) p); - VEC_PERM(va5, va5, va5, vperm_const); - - va6 = vec_ld(96, (__vector unsigned long long*) p); - VEC_PERM(va6, va6, va6, vperm_const); - - va7 = vec_ld(112, (__vector unsigned long long*) p); - VEC_PERM(va7, va7, va7, vperm_const); - - p = (char *)p + 128; - - vdata0 = vec_xor(v0, va0); - vdata1 = vec_xor(v1, va1); - vdata2 = vec_xor(v2, va2); - vdata3 = vec_xor(v3, va3); - vdata4 = vec_xor(v4, va4); - vdata5 = vec_xor(v5, va5); - vdata6 = vec_xor(v6, va6); - vdata7 = vec_xor(v7, va7); - - /* Check if we have more blocks to process */ - next_block = 0; - if (length != 0) { - next_block = 1; - - /* zero v0-v7 */ - v0 = vec_xor(v0, v0); - v1 = vec_xor(v1, v1); - v2 = vec_xor(v2, v2); - v3 = vec_xor(v3, v3); - v4 = vec_xor(v4, v4); - v5 = vec_xor(v5, v5); - v6 = vec_xor(v6, v6); - v7 = vec_xor(v7, v7); - } - length = length + 128; - - } while (next_block); - - /* Calculate how many bytes we have left. */ - length = (len & 127); - - /* Calculate where in (short) constant table we need to start. */ - offset = 128 - length; - - v0 = vec_ld(offset, vcrc_short_const); - v1 = vec_ld(offset + 16, vcrc_short_const); - v2 = vec_ld(offset + 32, vcrc_short_const); - v3 = vec_ld(offset + 48, vcrc_short_const); - v4 = vec_ld(offset + 64, vcrc_short_const); - v5 = vec_ld(offset + 80, vcrc_short_const); - v6 = vec_ld(offset + 96, vcrc_short_const); - v7 = vec_ld(offset + 112, vcrc_short_const); - - offset += 128; - - v0 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( - (__vector unsigned int)vdata0,(__vector unsigned int)v0); - v1 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( - (__vector unsigned int)vdata1,(__vector unsigned int)v1); - v2 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( - (__vector unsigned int)vdata2,(__vector unsigned int)v2); - v3 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( - (__vector unsigned int)vdata3,(__vector unsigned int)v3); - v4 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( - (__vector unsigned int)vdata4,(__vector unsigned int)v4); - v5 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( - (__vector unsigned int)vdata5,(__vector unsigned int)v5); - v6 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( - (__vector unsigned int)vdata6,(__vector unsigned int)v6); - v7 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( - (__vector unsigned int)vdata7,(__vector unsigned int)v7); - - /* Now reduce the tail (0-112 bytes). */ - for (i = 0; i < length; i+=16) { - vdata0 = vec_ld(i,(__vector unsigned long long*)p); - VEC_PERM(vdata0, vdata0, vdata0, vperm_const); - va0 = vec_ld(offset + i,vcrc_short_const); - va0 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( - (__vector unsigned int)vdata0,(__vector unsigned int)va0); - v0 = vec_xor(v0, va0); - } - - /* xor all parallel chunks together. */ - v0 = vec_xor(v0, v1); - v2 = vec_xor(v2, v3); - v4 = vec_xor(v4, v5); - v6 = vec_xor(v6, v7); - - v0 = vec_xor(v0, v2); - v4 = vec_xor(v4, v6); - - v0 = vec_xor(v0, v4); - } - - /* Barrett Reduction */ - vconst1 = vec_ld(0, v_Barrett_const); - vconst2 = vec_ld(16, v_Barrett_const); - - v1 = (__vector unsigned long long)vec_sld((__vector unsigned char)v0, - (__vector unsigned char)v0, 8); - v0 = vec_xor(v1,v0); - -#ifdef REFLECT - /* shift left one bit */ - vsht_splat = vec_splat_u8 (1); - v0 = (__vector unsigned long long)vec_sll ((__vector unsigned char)v0, - vsht_splat); -#endif - - v0 = vec_and(v0, vmask_64bit); - -#ifndef REFLECT - - /* - * Now for the actual algorithm. The idea is to calculate q, - * the multiple of our polynomial that we need to subtract. By - * doing the computation 2x bits higher (ie 64 bits) and shifting the - * result back down 2x bits, we round down to the nearest multiple. - */ - - /* ma */ - v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v0, - (__vector unsigned long long)vconst1); - /* q = floor(ma/(2^64)) */ - v1 = (__vector unsigned long long)vec_sld ((__vector unsigned char)vzero, - (__vector unsigned char)v1, 8); - /* qn */ - v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v1, - (__vector unsigned long long)vconst2); - /* a - qn, subtraction is xor in GF(2) */ - v0 = vec_xor (v0, v1); - /* - * Get the result into r3. We need to shift it left 8 bytes: - * V0 [ 0 1 2 X ] - * V0 [ 0 X 2 3 ] - */ - result = __builtin_unpack_vector_1 (v0); -#else - - /* - * The reflected version of Barrett reduction. Instead of bit - * reflecting our data (which is expensive to do), we bit reflect our - * constants and our algorithm, which means the intermediate data in - * our vector registers goes from 0-63 instead of 63-0. We can reflect - * the algorithm because we don't carry in mod 2 arithmetic. - */ - - /* bottom 32 bits of a */ - v1 = vec_and(v0, vmask_32bit); - - /* ma */ - v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v1, - (__vector unsigned long long)vconst1); - - /* bottom 32bits of ma */ - v1 = vec_and(v1, vmask_32bit); - /* qn */ - v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v1, - (__vector unsigned long long)vconst2); - /* a - qn, subtraction is xor in GF(2) */ - v0 = vec_xor (v0, v1); - - /* - * Since we are bit reflected, the result (ie the low 32 bits) is in - * the high 32 bits. We just need to shift it left 4 bytes - * V0 [ 0 1 X 3 ] - * V0 [ 0 X 2 3 ] - */ - - /* shift result into top 64 bits of */ - v0 = (__vector unsigned long long)vec_sld((__vector unsigned char)v0, - (__vector unsigned char)vzero, 4); - - result = __builtin_unpack_vector_0 (v0); -#endif - - return result; -} +#define POWER8_INTRINSICS +#include "pcc_crc32_constants.h" +#include "crc_ppc64.h" diff --git a/mysys/crc32/crc32c.cc b/mysys/crc32/crc32c.cc new file mode 100644 index 00000000000..4eaceb8c438 --- /dev/null +++ b/mysys/crc32/crc32c.cc @@ -0,0 +1,1254 @@ +// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. +// This source code is licensed under both the GPLv2 (found in the +// COPYING file in the root directory) and Apache 2.0 License +// (found in the LICENSE.Apache file in the root directory). +// +// Copyright (c) 2011 The LevelDB Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. See the AUTHORS file for names of contributors. +// +// A portable implementation of crc32c, optimized to handle +// four bytes at a time. + +// +// Copyright (c) 2011 The LevelDB Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. See the AUTHORS file for names of contributors. + + +#include +#include +#include +#include +#include +static inline uint32_t DecodeFixed32(const char *ptr) +{ + return uint4korr(ptr); +} + +static inline uint64_t DecodeFixed64(const char *ptr) +{ + return uint8korr(ptr); +} + +#include +#ifdef _MSC_VER +#include +#endif + +#ifdef HAVE_SSE42 +#include +#include +#ifdef __GNUC__ +#include +#endif +#endif + + +#ifdef __powerpc64__ +#include "crc32c_ppc.h" + +#if __linux__ +#include + +#ifndef PPC_FEATURE2_VEC_CRYPTO +#define PPC_FEATURE2_VEC_CRYPTO 0x02000000 +#endif + +#ifndef AT_HWCAP2 +#define AT_HWCAP2 26 +#endif + +#endif /* __linux__ */ + +#endif + +namespace mysys_namespace { +namespace crc32c { + +#if defined(HAVE_POWER8) && defined(HAS_ALTIVEC) +#ifdef __powerpc64__ +static int arch_ppc_crc32 = 0; +#endif /* __powerpc64__ */ +#endif + +static const uint32_t table0_[256] = { + 0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4, + 0xc79a971f, 0x35f1141c, 0x26a1e7e8, 0xd4ca64eb, + 0x8ad958cf, 0x78b2dbcc, 0x6be22838, 0x9989ab3b, + 0x4d43cfd0, 0xbf284cd3, 0xac78bf27, 0x5e133c24, + 0x105ec76f, 0xe235446c, 0xf165b798, 0x030e349b, + 0xd7c45070, 0x25afd373, 0x36ff2087, 0xc494a384, + 0x9a879fa0, 0x68ec1ca3, 0x7bbcef57, 0x89d76c54, + 0x5d1d08bf, 0xaf768bbc, 0xbc267848, 0x4e4dfb4b, + 0x20bd8ede, 0xd2d60ddd, 0xc186fe29, 0x33ed7d2a, + 0xe72719c1, 0x154c9ac2, 0x061c6936, 0xf477ea35, + 0xaa64d611, 0x580f5512, 0x4b5fa6e6, 0xb93425e5, + 0x6dfe410e, 0x9f95c20d, 0x8cc531f9, 0x7eaeb2fa, + 0x30e349b1, 0xc288cab2, 0xd1d83946, 0x23b3ba45, + 0xf779deae, 0x05125dad, 0x1642ae59, 0xe4292d5a, + 0xba3a117e, 0x4851927d, 0x5b016189, 0xa96ae28a, + 0x7da08661, 0x8fcb0562, 0x9c9bf696, 0x6ef07595, + 0x417b1dbc, 0xb3109ebf, 0xa0406d4b, 0x522bee48, + 0x86e18aa3, 0x748a09a0, 0x67dafa54, 0x95b17957, + 0xcba24573, 0x39c9c670, 0x2a993584, 0xd8f2b687, + 0x0c38d26c, 0xfe53516f, 0xed03a29b, 0x1f682198, + 0x5125dad3, 0xa34e59d0, 0xb01eaa24, 0x42752927, + 0x96bf4dcc, 0x64d4cecf, 0x77843d3b, 0x85efbe38, + 0xdbfc821c, 0x2997011f, 0x3ac7f2eb, 0xc8ac71e8, + 0x1c661503, 0xee0d9600, 0xfd5d65f4, 0x0f36e6f7, + 0x61c69362, 0x93ad1061, 0x80fde395, 0x72966096, + 0xa65c047d, 0x5437877e, 0x4767748a, 0xb50cf789, + 0xeb1fcbad, 0x197448ae, 0x0a24bb5a, 0xf84f3859, + 0x2c855cb2, 0xdeeedfb1, 0xcdbe2c45, 0x3fd5af46, + 0x7198540d, 0x83f3d70e, 0x90a324fa, 0x62c8a7f9, + 0xb602c312, 0x44694011, 0x5739b3e5, 0xa55230e6, + 0xfb410cc2, 0x092a8fc1, 0x1a7a7c35, 0xe811ff36, + 0x3cdb9bdd, 0xceb018de, 0xdde0eb2a, 0x2f8b6829, + 0x82f63b78, 0x709db87b, 0x63cd4b8f, 0x91a6c88c, + 0x456cac67, 0xb7072f64, 0xa457dc90, 0x563c5f93, + 0x082f63b7, 0xfa44e0b4, 0xe9141340, 0x1b7f9043, + 0xcfb5f4a8, 0x3dde77ab, 0x2e8e845f, 0xdce5075c, + 0x92a8fc17, 0x60c37f14, 0x73938ce0, 0x81f80fe3, + 0x55326b08, 0xa759e80b, 0xb4091bff, 0x466298fc, + 0x1871a4d8, 0xea1a27db, 0xf94ad42f, 0x0b21572c, + 0xdfeb33c7, 0x2d80b0c4, 0x3ed04330, 0xccbbc033, + 0xa24bb5a6, 0x502036a5, 0x4370c551, 0xb11b4652, + 0x65d122b9, 0x97baa1ba, 0x84ea524e, 0x7681d14d, + 0x2892ed69, 0xdaf96e6a, 0xc9a99d9e, 0x3bc21e9d, + 0xef087a76, 0x1d63f975, 0x0e330a81, 0xfc588982, + 0xb21572c9, 0x407ef1ca, 0x532e023e, 0xa145813d, + 0x758fe5d6, 0x87e466d5, 0x94b49521, 0x66df1622, + 0x38cc2a06, 0xcaa7a905, 0xd9f75af1, 0x2b9cd9f2, + 0xff56bd19, 0x0d3d3e1a, 0x1e6dcdee, 0xec064eed, + 0xc38d26c4, 0x31e6a5c7, 0x22b65633, 0xd0ddd530, + 0x0417b1db, 0xf67c32d8, 0xe52cc12c, 0x1747422f, + 0x49547e0b, 0xbb3ffd08, 0xa86f0efc, 0x5a048dff, + 0x8ecee914, 0x7ca56a17, 0x6ff599e3, 0x9d9e1ae0, + 0xd3d3e1ab, 0x21b862a8, 0x32e8915c, 0xc083125f, + 0x144976b4, 0xe622f5b7, 0xf5720643, 0x07198540, + 0x590ab964, 0xab613a67, 0xb831c993, 0x4a5a4a90, + 0x9e902e7b, 0x6cfbad78, 0x7fab5e8c, 0x8dc0dd8f, + 0xe330a81a, 0x115b2b19, 0x020bd8ed, 0xf0605bee, + 0x24aa3f05, 0xd6c1bc06, 0xc5914ff2, 0x37faccf1, + 0x69e9f0d5, 0x9b8273d6, 0x88d28022, 0x7ab90321, + 0xae7367ca, 0x5c18e4c9, 0x4f48173d, 0xbd23943e, + 0xf36e6f75, 0x0105ec76, 0x12551f82, 0xe03e9c81, + 0x34f4f86a, 0xc69f7b69, 0xd5cf889d, 0x27a40b9e, + 0x79b737ba, 0x8bdcb4b9, 0x988c474d, 0x6ae7c44e, + 0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351 +}; +static const uint32_t table1_[256] = { + 0x00000000, 0x13a29877, 0x274530ee, 0x34e7a899, + 0x4e8a61dc, 0x5d28f9ab, 0x69cf5132, 0x7a6dc945, + 0x9d14c3b8, 0x8eb65bcf, 0xba51f356, 0xa9f36b21, + 0xd39ea264, 0xc03c3a13, 0xf4db928a, 0xe7790afd, + 0x3fc5f181, 0x2c6769f6, 0x1880c16f, 0x0b225918, + 0x714f905d, 0x62ed082a, 0x560aa0b3, 0x45a838c4, + 0xa2d13239, 0xb173aa4e, 0x859402d7, 0x96369aa0, + 0xec5b53e5, 0xfff9cb92, 0xcb1e630b, 0xd8bcfb7c, + 0x7f8be302, 0x6c297b75, 0x58ced3ec, 0x4b6c4b9b, + 0x310182de, 0x22a31aa9, 0x1644b230, 0x05e62a47, + 0xe29f20ba, 0xf13db8cd, 0xc5da1054, 0xd6788823, + 0xac154166, 0xbfb7d911, 0x8b507188, 0x98f2e9ff, + 0x404e1283, 0x53ec8af4, 0x670b226d, 0x74a9ba1a, + 0x0ec4735f, 0x1d66eb28, 0x298143b1, 0x3a23dbc6, + 0xdd5ad13b, 0xcef8494c, 0xfa1fe1d5, 0xe9bd79a2, + 0x93d0b0e7, 0x80722890, 0xb4958009, 0xa737187e, + 0xff17c604, 0xecb55e73, 0xd852f6ea, 0xcbf06e9d, + 0xb19da7d8, 0xa23f3faf, 0x96d89736, 0x857a0f41, + 0x620305bc, 0x71a19dcb, 0x45463552, 0x56e4ad25, + 0x2c896460, 0x3f2bfc17, 0x0bcc548e, 0x186eccf9, + 0xc0d23785, 0xd370aff2, 0xe797076b, 0xf4359f1c, + 0x8e585659, 0x9dface2e, 0xa91d66b7, 0xbabffec0, + 0x5dc6f43d, 0x4e646c4a, 0x7a83c4d3, 0x69215ca4, + 0x134c95e1, 0x00ee0d96, 0x3409a50f, 0x27ab3d78, + 0x809c2506, 0x933ebd71, 0xa7d915e8, 0xb47b8d9f, + 0xce1644da, 0xddb4dcad, 0xe9537434, 0xfaf1ec43, + 0x1d88e6be, 0x0e2a7ec9, 0x3acdd650, 0x296f4e27, + 0x53028762, 0x40a01f15, 0x7447b78c, 0x67e52ffb, + 0xbf59d487, 0xacfb4cf0, 0x981ce469, 0x8bbe7c1e, + 0xf1d3b55b, 0xe2712d2c, 0xd69685b5, 0xc5341dc2, + 0x224d173f, 0x31ef8f48, 0x050827d1, 0x16aabfa6, + 0x6cc776e3, 0x7f65ee94, 0x4b82460d, 0x5820de7a, + 0xfbc3faf9, 0xe861628e, 0xdc86ca17, 0xcf245260, + 0xb5499b25, 0xa6eb0352, 0x920cabcb, 0x81ae33bc, + 0x66d73941, 0x7575a136, 0x419209af, 0x523091d8, + 0x285d589d, 0x3bffc0ea, 0x0f186873, 0x1cbaf004, + 0xc4060b78, 0xd7a4930f, 0xe3433b96, 0xf0e1a3e1, + 0x8a8c6aa4, 0x992ef2d3, 0xadc95a4a, 0xbe6bc23d, + 0x5912c8c0, 0x4ab050b7, 0x7e57f82e, 0x6df56059, + 0x1798a91c, 0x043a316b, 0x30dd99f2, 0x237f0185, + 0x844819fb, 0x97ea818c, 0xa30d2915, 0xb0afb162, + 0xcac27827, 0xd960e050, 0xed8748c9, 0xfe25d0be, + 0x195cda43, 0x0afe4234, 0x3e19eaad, 0x2dbb72da, + 0x57d6bb9f, 0x447423e8, 0x70938b71, 0x63311306, + 0xbb8de87a, 0xa82f700d, 0x9cc8d894, 0x8f6a40e3, + 0xf50789a6, 0xe6a511d1, 0xd242b948, 0xc1e0213f, + 0x26992bc2, 0x353bb3b5, 0x01dc1b2c, 0x127e835b, + 0x68134a1e, 0x7bb1d269, 0x4f567af0, 0x5cf4e287, + 0x04d43cfd, 0x1776a48a, 0x23910c13, 0x30339464, + 0x4a5e5d21, 0x59fcc556, 0x6d1b6dcf, 0x7eb9f5b8, + 0x99c0ff45, 0x8a626732, 0xbe85cfab, 0xad2757dc, + 0xd74a9e99, 0xc4e806ee, 0xf00fae77, 0xe3ad3600, + 0x3b11cd7c, 0x28b3550b, 0x1c54fd92, 0x0ff665e5, + 0x759baca0, 0x663934d7, 0x52de9c4e, 0x417c0439, + 0xa6050ec4, 0xb5a796b3, 0x81403e2a, 0x92e2a65d, + 0xe88f6f18, 0xfb2df76f, 0xcfca5ff6, 0xdc68c781, + 0x7b5fdfff, 0x68fd4788, 0x5c1aef11, 0x4fb87766, + 0x35d5be23, 0x26772654, 0x12908ecd, 0x013216ba, + 0xe64b1c47, 0xf5e98430, 0xc10e2ca9, 0xd2acb4de, + 0xa8c17d9b, 0xbb63e5ec, 0x8f844d75, 0x9c26d502, + 0x449a2e7e, 0x5738b609, 0x63df1e90, 0x707d86e7, + 0x0a104fa2, 0x19b2d7d5, 0x2d557f4c, 0x3ef7e73b, + 0xd98eedc6, 0xca2c75b1, 0xfecbdd28, 0xed69455f, + 0x97048c1a, 0x84a6146d, 0xb041bcf4, 0xa3e32483 +}; +static const uint32_t table2_[256] = { + 0x00000000, 0xa541927e, 0x4f6f520d, 0xea2ec073, + 0x9edea41a, 0x3b9f3664, 0xd1b1f617, 0x74f06469, + 0x38513ec5, 0x9d10acbb, 0x773e6cc8, 0xd27ffeb6, + 0xa68f9adf, 0x03ce08a1, 0xe9e0c8d2, 0x4ca15aac, + 0x70a27d8a, 0xd5e3eff4, 0x3fcd2f87, 0x9a8cbdf9, + 0xee7cd990, 0x4b3d4bee, 0xa1138b9d, 0x045219e3, + 0x48f3434f, 0xedb2d131, 0x079c1142, 0xa2dd833c, + 0xd62de755, 0x736c752b, 0x9942b558, 0x3c032726, + 0xe144fb14, 0x4405696a, 0xae2ba919, 0x0b6a3b67, + 0x7f9a5f0e, 0xdadbcd70, 0x30f50d03, 0x95b49f7d, + 0xd915c5d1, 0x7c5457af, 0x967a97dc, 0x333b05a2, + 0x47cb61cb, 0xe28af3b5, 0x08a433c6, 0xade5a1b8, + 0x91e6869e, 0x34a714e0, 0xde89d493, 0x7bc846ed, + 0x0f382284, 0xaa79b0fa, 0x40577089, 0xe516e2f7, + 0xa9b7b85b, 0x0cf62a25, 0xe6d8ea56, 0x43997828, + 0x37691c41, 0x92288e3f, 0x78064e4c, 0xdd47dc32, + 0xc76580d9, 0x622412a7, 0x880ad2d4, 0x2d4b40aa, + 0x59bb24c3, 0xfcfab6bd, 0x16d476ce, 0xb395e4b0, + 0xff34be1c, 0x5a752c62, 0xb05bec11, 0x151a7e6f, + 0x61ea1a06, 0xc4ab8878, 0x2e85480b, 0x8bc4da75, + 0xb7c7fd53, 0x12866f2d, 0xf8a8af5e, 0x5de93d20, + 0x29195949, 0x8c58cb37, 0x66760b44, 0xc337993a, + 0x8f96c396, 0x2ad751e8, 0xc0f9919b, 0x65b803e5, + 0x1148678c, 0xb409f5f2, 0x5e273581, 0xfb66a7ff, + 0x26217bcd, 0x8360e9b3, 0x694e29c0, 0xcc0fbbbe, + 0xb8ffdfd7, 0x1dbe4da9, 0xf7908dda, 0x52d11fa4, + 0x1e704508, 0xbb31d776, 0x511f1705, 0xf45e857b, + 0x80aee112, 0x25ef736c, 0xcfc1b31f, 0x6a802161, + 0x56830647, 0xf3c29439, 0x19ec544a, 0xbcadc634, + 0xc85da25d, 0x6d1c3023, 0x8732f050, 0x2273622e, + 0x6ed23882, 0xcb93aafc, 0x21bd6a8f, 0x84fcf8f1, + 0xf00c9c98, 0x554d0ee6, 0xbf63ce95, 0x1a225ceb, + 0x8b277743, 0x2e66e53d, 0xc448254e, 0x6109b730, + 0x15f9d359, 0xb0b84127, 0x5a968154, 0xffd7132a, + 0xb3764986, 0x1637dbf8, 0xfc191b8b, 0x595889f5, + 0x2da8ed9c, 0x88e97fe2, 0x62c7bf91, 0xc7862def, + 0xfb850ac9, 0x5ec498b7, 0xb4ea58c4, 0x11abcaba, + 0x655baed3, 0xc01a3cad, 0x2a34fcde, 0x8f756ea0, + 0xc3d4340c, 0x6695a672, 0x8cbb6601, 0x29faf47f, + 0x5d0a9016, 0xf84b0268, 0x1265c21b, 0xb7245065, + 0x6a638c57, 0xcf221e29, 0x250cde5a, 0x804d4c24, + 0xf4bd284d, 0x51fcba33, 0xbbd27a40, 0x1e93e83e, + 0x5232b292, 0xf77320ec, 0x1d5de09f, 0xb81c72e1, + 0xccec1688, 0x69ad84f6, 0x83834485, 0x26c2d6fb, + 0x1ac1f1dd, 0xbf8063a3, 0x55aea3d0, 0xf0ef31ae, + 0x841f55c7, 0x215ec7b9, 0xcb7007ca, 0x6e3195b4, + 0x2290cf18, 0x87d15d66, 0x6dff9d15, 0xc8be0f6b, + 0xbc4e6b02, 0x190ff97c, 0xf321390f, 0x5660ab71, + 0x4c42f79a, 0xe90365e4, 0x032da597, 0xa66c37e9, + 0xd29c5380, 0x77ddc1fe, 0x9df3018d, 0x38b293f3, + 0x7413c95f, 0xd1525b21, 0x3b7c9b52, 0x9e3d092c, + 0xeacd6d45, 0x4f8cff3b, 0xa5a23f48, 0x00e3ad36, + 0x3ce08a10, 0x99a1186e, 0x738fd81d, 0xd6ce4a63, + 0xa23e2e0a, 0x077fbc74, 0xed517c07, 0x4810ee79, + 0x04b1b4d5, 0xa1f026ab, 0x4bdee6d8, 0xee9f74a6, + 0x9a6f10cf, 0x3f2e82b1, 0xd50042c2, 0x7041d0bc, + 0xad060c8e, 0x08479ef0, 0xe2695e83, 0x4728ccfd, + 0x33d8a894, 0x96993aea, 0x7cb7fa99, 0xd9f668e7, + 0x9557324b, 0x3016a035, 0xda386046, 0x7f79f238, + 0x0b899651, 0xaec8042f, 0x44e6c45c, 0xe1a75622, + 0xdda47104, 0x78e5e37a, 0x92cb2309, 0x378ab177, + 0x437ad51e, 0xe63b4760, 0x0c158713, 0xa954156d, + 0xe5f54fc1, 0x40b4ddbf, 0xaa9a1dcc, 0x0fdb8fb2, + 0x7b2bebdb, 0xde6a79a5, 0x3444b9d6, 0x91052ba8 +}; +static const uint32_t table3_[256] = { + 0x00000000, 0xdd45aab8, 0xbf672381, 0x62228939, + 0x7b2231f3, 0xa6679b4b, 0xc4451272, 0x1900b8ca, + 0xf64463e6, 0x2b01c95e, 0x49234067, 0x9466eadf, + 0x8d665215, 0x5023f8ad, 0x32017194, 0xef44db2c, + 0xe964b13d, 0x34211b85, 0x560392bc, 0x8b463804, + 0x924680ce, 0x4f032a76, 0x2d21a34f, 0xf06409f7, + 0x1f20d2db, 0xc2657863, 0xa047f15a, 0x7d025be2, + 0x6402e328, 0xb9474990, 0xdb65c0a9, 0x06206a11, + 0xd725148b, 0x0a60be33, 0x6842370a, 0xb5079db2, + 0xac072578, 0x71428fc0, 0x136006f9, 0xce25ac41, + 0x2161776d, 0xfc24ddd5, 0x9e0654ec, 0x4343fe54, + 0x5a43469e, 0x8706ec26, 0xe524651f, 0x3861cfa7, + 0x3e41a5b6, 0xe3040f0e, 0x81268637, 0x5c632c8f, + 0x45639445, 0x98263efd, 0xfa04b7c4, 0x27411d7c, + 0xc805c650, 0x15406ce8, 0x7762e5d1, 0xaa274f69, + 0xb327f7a3, 0x6e625d1b, 0x0c40d422, 0xd1057e9a, + 0xaba65fe7, 0x76e3f55f, 0x14c17c66, 0xc984d6de, + 0xd0846e14, 0x0dc1c4ac, 0x6fe34d95, 0xb2a6e72d, + 0x5de23c01, 0x80a796b9, 0xe2851f80, 0x3fc0b538, + 0x26c00df2, 0xfb85a74a, 0x99a72e73, 0x44e284cb, + 0x42c2eeda, 0x9f874462, 0xfda5cd5b, 0x20e067e3, + 0x39e0df29, 0xe4a57591, 0x8687fca8, 0x5bc25610, + 0xb4868d3c, 0x69c32784, 0x0be1aebd, 0xd6a40405, + 0xcfa4bccf, 0x12e11677, 0x70c39f4e, 0xad8635f6, + 0x7c834b6c, 0xa1c6e1d4, 0xc3e468ed, 0x1ea1c255, + 0x07a17a9f, 0xdae4d027, 0xb8c6591e, 0x6583f3a6, + 0x8ac7288a, 0x57828232, 0x35a00b0b, 0xe8e5a1b3, + 0xf1e51979, 0x2ca0b3c1, 0x4e823af8, 0x93c79040, + 0x95e7fa51, 0x48a250e9, 0x2a80d9d0, 0xf7c57368, + 0xeec5cba2, 0x3380611a, 0x51a2e823, 0x8ce7429b, + 0x63a399b7, 0xbee6330f, 0xdcc4ba36, 0x0181108e, + 0x1881a844, 0xc5c402fc, 0xa7e68bc5, 0x7aa3217d, + 0x52a0c93f, 0x8fe56387, 0xedc7eabe, 0x30824006, + 0x2982f8cc, 0xf4c75274, 0x96e5db4d, 0x4ba071f5, + 0xa4e4aad9, 0x79a10061, 0x1b838958, 0xc6c623e0, + 0xdfc69b2a, 0x02833192, 0x60a1b8ab, 0xbde41213, + 0xbbc47802, 0x6681d2ba, 0x04a35b83, 0xd9e6f13b, + 0xc0e649f1, 0x1da3e349, 0x7f816a70, 0xa2c4c0c8, + 0x4d801be4, 0x90c5b15c, 0xf2e73865, 0x2fa292dd, + 0x36a22a17, 0xebe780af, 0x89c50996, 0x5480a32e, + 0x8585ddb4, 0x58c0770c, 0x3ae2fe35, 0xe7a7548d, + 0xfea7ec47, 0x23e246ff, 0x41c0cfc6, 0x9c85657e, + 0x73c1be52, 0xae8414ea, 0xcca69dd3, 0x11e3376b, + 0x08e38fa1, 0xd5a62519, 0xb784ac20, 0x6ac10698, + 0x6ce16c89, 0xb1a4c631, 0xd3864f08, 0x0ec3e5b0, + 0x17c35d7a, 0xca86f7c2, 0xa8a47efb, 0x75e1d443, + 0x9aa50f6f, 0x47e0a5d7, 0x25c22cee, 0xf8878656, + 0xe1873e9c, 0x3cc29424, 0x5ee01d1d, 0x83a5b7a5, + 0xf90696d8, 0x24433c60, 0x4661b559, 0x9b241fe1, + 0x8224a72b, 0x5f610d93, 0x3d4384aa, 0xe0062e12, + 0x0f42f53e, 0xd2075f86, 0xb025d6bf, 0x6d607c07, + 0x7460c4cd, 0xa9256e75, 0xcb07e74c, 0x16424df4, + 0x106227e5, 0xcd278d5d, 0xaf050464, 0x7240aedc, + 0x6b401616, 0xb605bcae, 0xd4273597, 0x09629f2f, + 0xe6264403, 0x3b63eebb, 0x59416782, 0x8404cd3a, + 0x9d0475f0, 0x4041df48, 0x22635671, 0xff26fcc9, + 0x2e238253, 0xf36628eb, 0x9144a1d2, 0x4c010b6a, + 0x5501b3a0, 0x88441918, 0xea669021, 0x37233a99, + 0xd867e1b5, 0x05224b0d, 0x6700c234, 0xba45688c, + 0xa345d046, 0x7e007afe, 0x1c22f3c7, 0xc167597f, + 0xc747336e, 0x1a0299d6, 0x782010ef, 0xa565ba57, + 0xbc65029d, 0x6120a825, 0x0302211c, 0xde478ba4, + 0x31035088, 0xec46fa30, 0x8e647309, 0x5321d9b1, + 0x4a21617b, 0x9764cbc3, 0xf54642fa, 0x2803e842 +}; + +// Used to fetch a naturally-aligned 32-bit word in little endian byte-order +static inline uint32_t LE_LOAD32(const uint8_t *p) { + return DecodeFixed32(reinterpret_cast(p)); +} + +#if defined(HAVE_SSE42) && (SIZEOF_SIZE_T == 8) +static inline uint64_t LE_LOAD64(const uint8_t *p) { + return DecodeFixed64(reinterpret_cast(p)); +} +#endif + +static inline void Slow_CRC32(uint64_t* l, uint8_t const **p) { + uint32_t c = static_cast(*l ^ LE_LOAD32(*p)); + *p += 4; + *l = table3_[c & 0xff] ^ + table2_[(c >> 8) & 0xff] ^ + table1_[(c >> 16) & 0xff] ^ + table0_[c >> 24]; + // DO it twice. + c = static_cast(*l ^ LE_LOAD32(*p)); + *p += 4; + *l = table3_[c & 0xff] ^ + table2_[(c >> 8) & 0xff] ^ + table1_[(c >> 16) & 0xff] ^ + table0_[c >> 24]; +} + +static inline void Fast_CRC32(uint64_t* l, uint8_t const **p) { +#ifndef HAVE_SSE42 + Slow_CRC32(l, p); +#elif (SIZEOF_SIZE_T == 8) + *l = _mm_crc32_u64(*l, LE_LOAD64(*p)); + *p += 8; +#else + *l = _mm_crc32_u32(static_cast(*l), LE_LOAD32(*p)); + *p += 4; + *l = _mm_crc32_u32(static_cast(*l), LE_LOAD32(*p)); + *p += 4; +#endif +} + +template +uint32_t ExtendImpl(uint32_t crc, const char* buf, size_t size) { + + const uint8_t *p = reinterpret_cast(buf); + const uint8_t *e = p + size; + uint64_t l = crc ^ 0xffffffffu; + +// Align n to (1 << m) byte boundary +#define ALIGN(n, m) ((n + ((1 << m) - 1)) & ~((1 << m) - 1)) + +#define STEP1 do { \ + int c = (l & 0xff) ^ *p++; \ + l = table0_[c] ^ (l >> 8); \ +} while (0) + + + // Point x at first 16-byte aligned byte in string. This might be + // just past the end of the string. + const uintptr_t pval = reinterpret_cast(p); + const uint8_t* x = reinterpret_cast(ALIGN(pval, 4)); + if (x <= e) { + // Process bytes until finished or p is 16-byte aligned + while (p != x) { + STEP1; + } + } + // Process bytes 16 at a time + while ((e-p) >= 16) { + CRC32(&l, &p); + CRC32(&l, &p); + } + // Process bytes 8 at a time + while ((e-p) >= 8) { + CRC32(&l, &p); + } + // Process the last few bytes + while (p != e) { + STEP1; + } +#undef STEP1 +#undef ALIGN + return static_cast(l ^ 0xffffffffu); +} + +// Detect if ARM64 CRC or not. +#ifndef HAVE_ARMV8_CRC +// Detect if SS42 or not. +#ifndef HAVE_POWER8 + +static bool isSSE42() { +#ifndef HAVE_SSE42 + return false; +#elif defined(__GNUC__) + uint32_t reax= 0, rebx= 0, recx= 0, redx= 0; + __cpuid(1, reax, rebx, recx, redx); + return (recx & ((int)1 << 20)) != 0; +#elif defined(_MSC_VER) + int info[4]; + __cpuid(info, 0x00000001); + return (info[2] & ((int)1 << 20)) != 0; +#else + return false; +#endif +} + +#ifdef HAVE_SSE42 +extern "C" int crc32_pclmul_enabled(); +#endif + +static bool isPCLMULQDQ() { +#ifdef HAVE_SSE42 + return crc32_pclmul_enabled(); +#else + return false; +#endif +} + +#endif // HAVE_POWER8 +#endif // HAVE_ARMV8_CRC + +typedef uint32_t (*Function)(uint32_t, const char*, size_t); + +#if defined(HAVE_POWER8) && defined(HAS_ALTIVEC) +uint32_t ExtendPPCImpl(uint32_t crc, const char *buf, size_t size) { + return crc32c_ppc(crc, (const unsigned char *)buf, size); +} + +#if __linux__ +static int arch_ppc_probe(void) { + arch_ppc_crc32 = 0; + +#if defined(__powerpc64__) + if (getauxval(AT_HWCAP2) & PPC_FEATURE2_VEC_CRYPTO) arch_ppc_crc32 = 1; +#endif /* __powerpc64__ */ + + return arch_ppc_crc32; +} +#endif // __linux__ + +static bool isAltiVec() { + if (arch_ppc_probe()) { + return true; + } else { + return false; + } +} +#endif + +#if defined(HAVE_ARMV8_CRC) +extern "C" const char *crc32c_aarch64_available(void); +extern "C" uint32_t crc32c_aarch64(uint32_t crc, const unsigned char *buffer, uint64_t len); + +static uint32_t ExtendARMImpl(uint32_t crc, const char *buf, size_t size) { + return crc32c_aarch64(crc, (const unsigned char *)buf, (size_t) size); +} +#endif + +extern "C" const char * my_crc32c_implementation() +{ +#if defined(HAVE_POWER8) && defined(HAS_ALTIVEC) + if (arch_ppc_probe()) + return "Using POWER8 crc32 instructions"; +#elif defined(HAVE_ARMV8_CRC) + const char *ret = crc32c_aarch64_available(); + if (ret) + return ret ; +#elif HAVE_SSE42 + if (isSSE42()) + { + if (SIZEOF_SIZE_T == 8 && isPCLMULQDQ()) + return "Using crc32 + pclmulqdq instructions"; + return "Using SSE4.2 crc32 instructions"; + } +#endif + return "Using generic crc32 instructions"; +} + + +/* + * Copyright 2016 Ferry Toth, Exalon Delft BV, The Netherlands + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the author be held liable for any damages + * arising from the use of this software. + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + * Ferry Toth + * ftoth@exalondelft.nl + * + * https://github.com/htot/crc32c + * + * Modified by Facebook + * + * Original intel whitepaper: + * "Fast CRC Computation for iSCSI Polynomial Using CRC32 Instruction" + * https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/crc-iscsi-polynomial-crc32-instruction-paper.pdf + * + * This version is from the folly library, created by Dave Watson + * +*/ +#if defined HAVE_SSE42 && defined HAVE_PCLMUL && SIZEOF_SIZE_T == 8 + + +#define CRCtriplet(crc, buf, offset) \ + crc##0 = _mm_crc32_u64(crc##0, *(buf##0 + offset)); \ + crc##1 = _mm_crc32_u64(crc##1, *(buf##1 + offset)); \ + crc##2 = _mm_crc32_u64(crc##2, *(buf##2 + offset)); + +#define CRCduplet(crc, buf, offset) \ + crc##0 = _mm_crc32_u64(crc##0, *(buf##0 + offset)); \ + crc##1 = _mm_crc32_u64(crc##1, *(buf##1 + offset)); + +#define CRCsinglet(crc, buf, offset) \ + crc = _mm_crc32_u64(crc, *(uint64_t*)(buf + offset)); + + +// Numbers taken directly from intel whitepaper. +// clang-format off +static const uint64_t clmul_constants[] = { + 0x14cd00bd6, 0x105ec76f0, 0x0ba4fc28e, 0x14cd00bd6, + 0x1d82c63da, 0x0f20c0dfe, 0x09e4addf8, 0x0ba4fc28e, + 0x039d3b296, 0x1384aa63a, 0x102f9b8a2, 0x1d82c63da, + 0x14237f5e6, 0x01c291d04, 0x00d3b6092, 0x09e4addf8, + 0x0c96cfdc0, 0x0740eef02, 0x18266e456, 0x039d3b296, + 0x0daece73e, 0x0083a6eec, 0x0ab7aff2a, 0x102f9b8a2, + 0x1248ea574, 0x1c1733996, 0x083348832, 0x14237f5e6, + 0x12c743124, 0x02ad91c30, 0x0b9e02b86, 0x00d3b6092, + 0x018b33a4e, 0x06992cea2, 0x1b331e26a, 0x0c96cfdc0, + 0x17d35ba46, 0x07e908048, 0x1bf2e8b8a, 0x18266e456, + 0x1a3e0968a, 0x11ed1f9d8, 0x0ce7f39f4, 0x0daece73e, + 0x061d82e56, 0x0f1d0f55e, 0x0d270f1a2, 0x0ab7aff2a, + 0x1c3f5f66c, 0x0a87ab8a8, 0x12ed0daac, 0x1248ea574, + 0x065863b64, 0x08462d800, 0x11eef4f8e, 0x083348832, + 0x1ee54f54c, 0x071d111a8, 0x0b3e32c28, 0x12c743124, + 0x0064f7f26, 0x0ffd852c6, 0x0dd7e3b0c, 0x0b9e02b86, + 0x0f285651c, 0x0dcb17aa4, 0x010746f3c, 0x018b33a4e, + 0x1c24afea4, 0x0f37c5aee, 0x0271d9844, 0x1b331e26a, + 0x08e766a0c, 0x06051d5a2, 0x093a5f730, 0x17d35ba46, + 0x06cb08e5c, 0x11d5ca20e, 0x06b749fb2, 0x1bf2e8b8a, + 0x1167f94f2, 0x021f3d99c, 0x0cec3662e, 0x1a3e0968a, + 0x19329634a, 0x08f158014, 0x0e6fc4e6a, 0x0ce7f39f4, + 0x08227bb8a, 0x1a5e82106, 0x0b0cd4768, 0x061d82e56, + 0x13c2b89c4, 0x188815ab2, 0x0d7a4825c, 0x0d270f1a2, + 0x10f5ff2ba, 0x105405f3e, 0x00167d312, 0x1c3f5f66c, + 0x0f6076544, 0x0e9adf796, 0x026f6a60a, 0x12ed0daac, + 0x1a2adb74e, 0x096638b34, 0x19d34af3a, 0x065863b64, + 0x049c3cc9c, 0x1e50585a0, 0x068bce87a, 0x11eef4f8e, + 0x1524fa6c6, 0x19f1c69dc, 0x16cba8aca, 0x1ee54f54c, + 0x042d98888, 0x12913343e, 0x1329d9f7e, 0x0b3e32c28, + 0x1b1c69528, 0x088f25a3a, 0x02178513a, 0x0064f7f26, + 0x0e0ac139e, 0x04e36f0b0, 0x0170076fa, 0x0dd7e3b0c, + 0x141a1a2e2, 0x0bd6f81f8, 0x16ad828b4, 0x0f285651c, + 0x041d17b64, 0x19425cbba, 0x1fae1cc66, 0x010746f3c, + 0x1a75b4b00, 0x18db37e8a, 0x0f872e54c, 0x1c24afea4, + 0x01e41e9fc, 0x04c144932, 0x086d8e4d2, 0x0271d9844, + 0x160f7af7a, 0x052148f02, 0x05bb8f1bc, 0x08e766a0c, + 0x0a90fd27a, 0x0a3c6f37a, 0x0b3af077a, 0x093a5f730, + 0x04984d782, 0x1d22c238e, 0x0ca6ef3ac, 0x06cb08e5c, + 0x0234e0b26, 0x063ded06a, 0x1d88abd4a, 0x06b749fb2, + 0x04597456a, 0x04d56973c, 0x0e9e28eb4, 0x1167f94f2, + 0x07b3ff57a, 0x19385bf2e, 0x0c9c8b782, 0x0cec3662e, + 0x13a9cba9e, 0x0e417f38a, 0x093e106a4, 0x19329634a, + 0x167001a9c, 0x14e727980, 0x1ddffc5d4, 0x0e6fc4e6a, + 0x00df04680, 0x0d104b8fc, 0x02342001e, 0x08227bb8a, + 0x00a2a8d7e, 0x05b397730, 0x168763fa6, 0x0b0cd4768, + 0x1ed5a407a, 0x0e78eb416, 0x0d2c3ed1a, 0x13c2b89c4, + 0x0995a5724, 0x1641378f0, 0x19b1afbc4, 0x0d7a4825c, + 0x109ffedc0, 0x08d96551c, 0x0f2271e60, 0x10f5ff2ba, + 0x00b0bf8ca, 0x00bf80dd2, 0x123888b7a, 0x00167d312, + 0x1e888f7dc, 0x18dcddd1c, 0x002ee03b2, 0x0f6076544, + 0x183e8d8fe, 0x06a45d2b2, 0x133d7a042, 0x026f6a60a, + 0x116b0f50c, 0x1dd3e10e8, 0x05fabe670, 0x1a2adb74e, + 0x130004488, 0x0de87806c, 0x000bcf5f6, 0x19d34af3a, + 0x18f0c7078, 0x014338754, 0x017f27698, 0x049c3cc9c, + 0x058ca5f00, 0x15e3e77ee, 0x1af900c24, 0x068bce87a, + 0x0b5cfca28, 0x0dd07448e, 0x0ded288f8, 0x1524fa6c6, + 0x059f229bc, 0x1d8048348, 0x06d390dec, 0x16cba8aca, + 0x037170390, 0x0a3e3e02c, 0x06353c1cc, 0x042d98888, + 0x0c4584f5c, 0x0d73c7bea, 0x1f16a3418, 0x1329d9f7e, + 0x0531377e2, 0x185137662, 0x1d8d9ca7c, 0x1b1c69528, + 0x0b25b29f2, 0x18a08b5bc, 0x19fb2a8b0, 0x02178513a, + 0x1a08fe6ac, 0x1da758ae0, 0x045cddf4e, 0x0e0ac139e, + 0x1a91647f2, 0x169cf9eb0, 0x1a0f717c4, 0x0170076fa, +}; + +// Compute the crc32c value for buffer smaller than 8 +static inline void align_to_8( + size_t len, + uint64_t& crc0, // crc so far, updated on return + const unsigned char*& next) { // next data pointer, updated on return + uint32_t crc32bit = static_cast(crc0); + if (len & 0x04) { + crc32bit = _mm_crc32_u32(crc32bit, *(uint32_t*)next); + next += sizeof(uint32_t); + } + if (len & 0x02) { + crc32bit = _mm_crc32_u16(crc32bit, *(uint16_t*)next); + next += sizeof(uint16_t); + } + if (len & 0x01) { + crc32bit = _mm_crc32_u8(crc32bit, *(next)); + next++; + } + crc0 = crc32bit; +} + +// +// CombineCRC performs pclmulqdq multiplication of 2 partial CRC's and a well +// chosen constant and xor's these with the remaining CRC. +// +static inline uint64_t CombineCRC( + size_t block_size, + uint64_t crc0, + uint64_t crc1, + uint64_t crc2, + const uint64_t* next2) { + const auto multiplier = + *(reinterpret_cast(clmul_constants) + block_size - 1); + const auto crc0_xmm = _mm_set_epi64x(0, crc0); + const auto res0 = _mm_clmulepi64_si128(crc0_xmm, multiplier, 0x00); + const auto crc1_xmm = _mm_set_epi64x(0, crc1); + const auto res1 = _mm_clmulepi64_si128(crc1_xmm, multiplier, 0x10); + const auto res = _mm_xor_si128(res0, res1); + crc0 = _mm_cvtsi128_si64(res); + crc0 = crc0 ^ *((uint64_t*)next2 - 1); + crc2 = _mm_crc32_u64(crc2, crc0); + return crc2; +} + +// Compute CRC-32C using the Intel hardware instruction. +static inline uint32_t crc32c_3way(uint32_t crc, const char* buf, size_t len) { + const unsigned char* next = (const unsigned char*)buf; + uint64_t count; + uint64_t crc0, crc1, crc2; + crc0 = crc ^ 0xffffffffu; + + + if (len >= 8) { + // if len > 216 then align and use triplets + if (len > 216) { + { + // Work on the bytes (< 8) before the first 8-byte alignment addr starts + auto align_bytes = (8 - (uintptr_t)next) & 7; + len -= align_bytes; + align_to_8(align_bytes, crc0, next); + } + + // Now work on the remaining blocks + count = len / 24; // number of triplets + len %= 24; // bytes remaining + uint64_t n = count >> 7; // #blocks = first block + full blocks + uint64_t block_size = count & 127; + if (block_size == 0) { + block_size = 128; + } else { + n++; + } + // points to the first byte of the next block + const uint64_t* next0 = (uint64_t*)next + block_size; + const uint64_t* next1 = next0 + block_size; + const uint64_t* next2 = next1 + block_size; + + crc1 = crc2 = 0; + // Use Duff's device, a for() loop inside a switch() + // statement. This needs to execute at least once, round len + // down to nearest triplet multiple + switch (block_size) { + case 128: + do { + // jumps here for a full block of len 128 + CRCtriplet(crc, next, -128); + /* fallthrough */ + case 127: + // jumps here or below for the first block smaller + CRCtriplet(crc, next, -127); + /* fallthrough */ + case 126: + CRCtriplet(crc, next, -126); // than 128 + /* fallthrough */ + case 125: + CRCtriplet(crc, next, -125); + /* fallthrough */ + case 124: + CRCtriplet(crc, next, -124); + /* fallthrough */ + case 123: + CRCtriplet(crc, next, -123); + /* fallthrough */ + case 122: + CRCtriplet(crc, next, -122); + /* fallthrough */ + case 121: + CRCtriplet(crc, next, -121); + /* fallthrough */ + case 120: + CRCtriplet(crc, next, -120); + /* fallthrough */ + case 119: + CRCtriplet(crc, next, -119); + /* fallthrough */ + case 118: + CRCtriplet(crc, next, -118); + /* fallthrough */ + case 117: + CRCtriplet(crc, next, -117); + /* fallthrough */ + case 116: + CRCtriplet(crc, next, -116); + /* fallthrough */ + case 115: + CRCtriplet(crc, next, -115); + /* fallthrough */ + case 114: + CRCtriplet(crc, next, -114); + /* fallthrough */ + case 113: + CRCtriplet(crc, next, -113); + /* fallthrough */ + case 112: + CRCtriplet(crc, next, -112); + /* fallthrough */ + case 111: + CRCtriplet(crc, next, -111); + /* fallthrough */ + case 110: + CRCtriplet(crc, next, -110); + /* fallthrough */ + case 109: + CRCtriplet(crc, next, -109); + /* fallthrough */ + case 108: + CRCtriplet(crc, next, -108); + /* fallthrough */ + case 107: + CRCtriplet(crc, next, -107); + /* fallthrough */ + case 106: + CRCtriplet(crc, next, -106); + /* fallthrough */ + case 105: + CRCtriplet(crc, next, -105); + /* fallthrough */ + case 104: + CRCtriplet(crc, next, -104); + /* fallthrough */ + case 103: + CRCtriplet(crc, next, -103); + /* fallthrough */ + case 102: + CRCtriplet(crc, next, -102); + /* fallthrough */ + case 101: + CRCtriplet(crc, next, -101); + /* fallthrough */ + case 100: + CRCtriplet(crc, next, -100); + /* fallthrough */ + case 99: + CRCtriplet(crc, next, -99); + /* fallthrough */ + case 98: + CRCtriplet(crc, next, -98); + /* fallthrough */ + case 97: + CRCtriplet(crc, next, -97); + /* fallthrough */ + case 96: + CRCtriplet(crc, next, -96); + /* fallthrough */ + case 95: + CRCtriplet(crc, next, -95); + /* fallthrough */ + case 94: + CRCtriplet(crc, next, -94); + /* fallthrough */ + case 93: + CRCtriplet(crc, next, -93); + /* fallthrough */ + case 92: + CRCtriplet(crc, next, -92); + /* fallthrough */ + case 91: + CRCtriplet(crc, next, -91); + /* fallthrough */ + case 90: + CRCtriplet(crc, next, -90); + /* fallthrough */ + case 89: + CRCtriplet(crc, next, -89); + /* fallthrough */ + case 88: + CRCtriplet(crc, next, -88); + /* fallthrough */ + case 87: + CRCtriplet(crc, next, -87); + /* fallthrough */ + case 86: + CRCtriplet(crc, next, -86); + /* fallthrough */ + case 85: + CRCtriplet(crc, next, -85); + /* fallthrough */ + case 84: + CRCtriplet(crc, next, -84); + /* fallthrough */ + case 83: + CRCtriplet(crc, next, -83); + /* fallthrough */ + case 82: + CRCtriplet(crc, next, -82); + /* fallthrough */ + case 81: + CRCtriplet(crc, next, -81); + /* fallthrough */ + case 80: + CRCtriplet(crc, next, -80); + /* fallthrough */ + case 79: + CRCtriplet(crc, next, -79); + /* fallthrough */ + case 78: + CRCtriplet(crc, next, -78); + /* fallthrough */ + case 77: + CRCtriplet(crc, next, -77); + /* fallthrough */ + case 76: + CRCtriplet(crc, next, -76); + /* fallthrough */ + case 75: + CRCtriplet(crc, next, -75); + /* fallthrough */ + case 74: + CRCtriplet(crc, next, -74); + /* fallthrough */ + case 73: + CRCtriplet(crc, next, -73); + /* fallthrough */ + case 72: + CRCtriplet(crc, next, -72); + /* fallthrough */ + case 71: + CRCtriplet(crc, next, -71); + /* fallthrough */ + case 70: + CRCtriplet(crc, next, -70); + /* fallthrough */ + case 69: + CRCtriplet(crc, next, -69); + /* fallthrough */ + case 68: + CRCtriplet(crc, next, -68); + /* fallthrough */ + case 67: + CRCtriplet(crc, next, -67); + /* fallthrough */ + case 66: + CRCtriplet(crc, next, -66); + /* fallthrough */ + case 65: + CRCtriplet(crc, next, -65); + /* fallthrough */ + case 64: + CRCtriplet(crc, next, -64); + /* fallthrough */ + case 63: + CRCtriplet(crc, next, -63); + /* fallthrough */ + case 62: + CRCtriplet(crc, next, -62); + /* fallthrough */ + case 61: + CRCtriplet(crc, next, -61); + /* fallthrough */ + case 60: + CRCtriplet(crc, next, -60); + /* fallthrough */ + case 59: + CRCtriplet(crc, next, -59); + /* fallthrough */ + case 58: + CRCtriplet(crc, next, -58); + /* fallthrough */ + case 57: + CRCtriplet(crc, next, -57); + /* fallthrough */ + case 56: + CRCtriplet(crc, next, -56); + /* fallthrough */ + case 55: + CRCtriplet(crc, next, -55); + /* fallthrough */ + case 54: + CRCtriplet(crc, next, -54); + /* fallthrough */ + case 53: + CRCtriplet(crc, next, -53); + /* fallthrough */ + case 52: + CRCtriplet(crc, next, -52); + /* fallthrough */ + case 51: + CRCtriplet(crc, next, -51); + /* fallthrough */ + case 50: + CRCtriplet(crc, next, -50); + /* fallthrough */ + case 49: + CRCtriplet(crc, next, -49); + /* fallthrough */ + case 48: + CRCtriplet(crc, next, -48); + /* fallthrough */ + case 47: + CRCtriplet(crc, next, -47); + /* fallthrough */ + case 46: + CRCtriplet(crc, next, -46); + /* fallthrough */ + case 45: + CRCtriplet(crc, next, -45); + /* fallthrough */ + case 44: + CRCtriplet(crc, next, -44); + /* fallthrough */ + case 43: + CRCtriplet(crc, next, -43); + /* fallthrough */ + case 42: + CRCtriplet(crc, next, -42); + /* fallthrough */ + case 41: + CRCtriplet(crc, next, -41); + /* fallthrough */ + case 40: + CRCtriplet(crc, next, -40); + /* fallthrough */ + case 39: + CRCtriplet(crc, next, -39); + /* fallthrough */ + case 38: + CRCtriplet(crc, next, -38); + /* fallthrough */ + case 37: + CRCtriplet(crc, next, -37); + /* fallthrough */ + case 36: + CRCtriplet(crc, next, -36); + /* fallthrough */ + case 35: + CRCtriplet(crc, next, -35); + /* fallthrough */ + case 34: + CRCtriplet(crc, next, -34); + /* fallthrough */ + case 33: + CRCtriplet(crc, next, -33); + /* fallthrough */ + case 32: + CRCtriplet(crc, next, -32); + /* fallthrough */ + case 31: + CRCtriplet(crc, next, -31); + /* fallthrough */ + case 30: + CRCtriplet(crc, next, -30); + /* fallthrough */ + case 29: + CRCtriplet(crc, next, -29); + /* fallthrough */ + case 28: + CRCtriplet(crc, next, -28); + /* fallthrough */ + case 27: + CRCtriplet(crc, next, -27); + /* fallthrough */ + case 26: + CRCtriplet(crc, next, -26); + /* fallthrough */ + case 25: + CRCtriplet(crc, next, -25); + /* fallthrough */ + case 24: + CRCtriplet(crc, next, -24); + /* fallthrough */ + case 23: + CRCtriplet(crc, next, -23); + /* fallthrough */ + case 22: + CRCtriplet(crc, next, -22); + /* fallthrough */ + case 21: + CRCtriplet(crc, next, -21); + /* fallthrough */ + case 20: + CRCtriplet(crc, next, -20); + /* fallthrough */ + case 19: + CRCtriplet(crc, next, -19); + /* fallthrough */ + case 18: + CRCtriplet(crc, next, -18); + /* fallthrough */ + case 17: + CRCtriplet(crc, next, -17); + /* fallthrough */ + case 16: + CRCtriplet(crc, next, -16); + /* fallthrough */ + case 15: + CRCtriplet(crc, next, -15); + /* fallthrough */ + case 14: + CRCtriplet(crc, next, -14); + /* fallthrough */ + case 13: + CRCtriplet(crc, next, -13); + /* fallthrough */ + case 12: + CRCtriplet(crc, next, -12); + /* fallthrough */ + case 11: + CRCtriplet(crc, next, -11); + /* fallthrough */ + case 10: + CRCtriplet(crc, next, -10); + /* fallthrough */ + case 9: + CRCtriplet(crc, next, -9); + /* fallthrough */ + case 8: + CRCtriplet(crc, next, -8); + /* fallthrough */ + case 7: + CRCtriplet(crc, next, -7); + /* fallthrough */ + case 6: + CRCtriplet(crc, next, -6); + /* fallthrough */ + case 5: + CRCtriplet(crc, next, -5); + /* fallthrough */ + case 4: + CRCtriplet(crc, next, -4); + /* fallthrough */ + case 3: + CRCtriplet(crc, next, -3); + /* fallthrough */ + case 2: + CRCtriplet(crc, next, -2); + /* fallthrough */ + case 1: + CRCduplet(crc, next, -1); // the final triplet is actually only 2 + //{ CombineCRC(); } + crc0 = CombineCRC(block_size, crc0, crc1, crc2, next2); + if (--n > 0) { + crc1 = crc2 = 0; + block_size = 128; + // points to the first byte of the next block + next0 = next2 + 128; + next1 = next0 + 128; // from here on all blocks are 128 long + next2 = next1 + 128; + } + /* fallthrough */ + case 0:; + } while (n > 0); + } + next = (const unsigned char*)next2; + } + uint64_t count2 = len >> 3; // 216 of less bytes is 27 or less singlets + len = len & 7; + next += (count2 * 8); + switch (count2) { + case 27: + CRCsinglet(crc0, next, -27 * 8); + /* fallthrough */ + case 26: + CRCsinglet(crc0, next, -26 * 8); + /* fallthrough */ + case 25: + CRCsinglet(crc0, next, -25 * 8); + /* fallthrough */ + case 24: + CRCsinglet(crc0, next, -24 * 8); + /* fallthrough */ + case 23: + CRCsinglet(crc0, next, -23 * 8); + /* fallthrough */ + case 22: + CRCsinglet(crc0, next, -22 * 8); + /* fallthrough */ + case 21: + CRCsinglet(crc0, next, -21 * 8); + /* fallthrough */ + case 20: + CRCsinglet(crc0, next, -20 * 8); + /* fallthrough */ + case 19: + CRCsinglet(crc0, next, -19 * 8); + /* fallthrough */ + case 18: + CRCsinglet(crc0, next, -18 * 8); + /* fallthrough */ + case 17: + CRCsinglet(crc0, next, -17 * 8); + /* fallthrough */ + case 16: + CRCsinglet(crc0, next, -16 * 8); + /* fallthrough */ + case 15: + CRCsinglet(crc0, next, -15 * 8); + /* fallthrough */ + case 14: + CRCsinglet(crc0, next, -14 * 8); + /* fallthrough */ + case 13: + CRCsinglet(crc0, next, -13 * 8); + /* fallthrough */ + case 12: + CRCsinglet(crc0, next, -12 * 8); + /* fallthrough */ + case 11: + CRCsinglet(crc0, next, -11 * 8); + /* fallthrough */ + case 10: + CRCsinglet(crc0, next, -10 * 8); + /* fallthrough */ + case 9: + CRCsinglet(crc0, next, -9 * 8); + /* fallthrough */ + case 8: + CRCsinglet(crc0, next, -8 * 8); + /* fallthrough */ + case 7: + CRCsinglet(crc0, next, -7 * 8); + /* fallthrough */ + case 6: + CRCsinglet(crc0, next, -6 * 8); + /* fallthrough */ + case 5: + CRCsinglet(crc0, next, -5 * 8); + /* fallthrough */ + case 4: + CRCsinglet(crc0, next, -4 * 8); + /* fallthrough */ + case 3: + CRCsinglet(crc0, next, -3 * 8); + /* fallthrough */ + case 2: + CRCsinglet(crc0, next, -2 * 8); + /* fallthrough */ + case 1: + CRCsinglet(crc0, next, -1 * 8); + /* fallthrough */ + case 0:; + } + } + { + align_to_8(len, crc0, next); + return (uint32_t)crc0 ^ 0xffffffffu; + } +} + +#else +#define NO_THREEWAY_CRC32C +#endif //HAVE_SSE42 && HAVE_PCLMUL + +static inline Function Choose_Extend() { +#ifdef HAVE_POWER8 + return isAltiVec() ? ExtendPPCImpl : ExtendImpl; +#elif defined(HAVE_ARMV8_CRC) + if(crc32c_aarch64_available()) { + return ExtendARMImpl; + } else { + return ExtendImpl; + } +#else + if (isSSE42()) { + if (isPCLMULQDQ()) { +#if defined HAVE_SSE42 && defined HAVE_PCLMUL && !defined NO_THREEWAY_CRC32C + return crc32c_3way; +#else + return ExtendImpl; // Fast_CRC32 will check HAVE_SSE42 itself +#endif + } + else { // no runtime PCLMULQDQ support but has SSE42 support + return ExtendImpl; + } + } // end of isSSE42() + else { + return ExtendImpl; + } +#endif +} + +static const Function ChosenExtend = Choose_Extend(); + +static inline uint32_t Extend(uint32_t crc, const char* buf, size_t size) { + return ChosenExtend(crc, buf, size); +} +} // namespace crc32c +} // namespace mysys_namespace + +extern "C" unsigned int my_crc32c(unsigned int crc, const char *buf, size_t size) +{ + return mysys_namespace::crc32c::Extend(crc,buf, size); +} diff --git a/mysys/crc32/crc32c_ppc.c b/mysys/crc32/crc32c_ppc.c new file mode 100644 index 00000000000..72f24283454 --- /dev/null +++ b/mysys/crc32/crc32c_ppc.c @@ -0,0 +1,5 @@ +#define CRC32_FUNCTION crc32c_ppc +#define CRC_TABLE +#define POWER8_INTRINSICS +#include "pcc_crc32c_constants.h" +#include "crc_ppc64.h" diff --git a/mysys/crc32/crc32c_ppc.h b/mysys/crc32/crc32c_ppc.h new file mode 100644 index 00000000000..c359061c610 --- /dev/null +++ b/mysys/crc32/crc32c_ppc.h @@ -0,0 +1,19 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// Copyright (c) 2017 International Business Machines Corp. +// All rights reserved. +// This source code is licensed under both the GPLv2 (found in the +// COPYING file in the root directory) and Apache 2.0 License +// (found in the LICENSE.Apache file in the root directory). + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t crc32c_ppc(uint32_t crc, unsigned char const *buffer, + unsigned len); + +#ifdef __cplusplus +} +#endif diff --git a/mysys/crc32/crc_ppc64.h b/mysys/crc32/crc_ppc64.h new file mode 100644 index 00000000000..eb9379abc6c --- /dev/null +++ b/mysys/crc32/crc_ppc64.h @@ -0,0 +1,664 @@ +/* + * Calculate the checksum of data that is 16 byte aligned and a multiple of + * 16 bytes. + * + * The first step is to reduce it to 1024 bits. We do this in 8 parallel + * chunks in order to mask the latency of the vpmsum instructions. If we + * have more than 32 kB of data to checksum we repeat this step multiple + * times, passing in the previous 1024 bits. + * + * The next step is to reduce the 1024 bits to 64 bits. This step adds + * 32 bits of 0s to the end - this matches what a CRC does. We just + * calculate constants that land the data in this 32 bits. + * + * We then use fixed point Barrett reduction to compute a mod n over GF(2) + * for n = CRC using POWER8 instructions. We use x = 32. + * + * http://en.wikipedia.org/wiki/Barrett_reduction + * + * This code uses gcc vector builtins instead using assembly directly. + * + * Copyright (C) 2017 Rogerio Alves , IBM + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of either: + * + * a) the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version, or + * b) the Apache License, Version 2.0 + */ + +#include + + +#define VMX_ALIGN 16 +#define VMX_ALIGN_MASK (VMX_ALIGN-1) + +#ifdef REFLECT +static unsigned int crc32_align(unsigned int crc, const unsigned char *p, + unsigned long len) +{ + while (len--) + crc = crc_table[(crc ^ *p++) & 0xff] ^ (crc >> 8); + return crc; +} +#else +static unsigned int crc32_align(unsigned int crc, const unsigned char *p, + unsigned long len) +{ + while (len--) + crc = crc_table[((crc >> 24) ^ *p++) & 0xff] ^ (crc << 8); + return crc; +} +#endif + +static unsigned int __attribute__ ((aligned (32))) +__crc32_vpmsum(unsigned int crc, const void* p, unsigned long len); + + +unsigned int CRC32_FUNCTION(unsigned int crc, const unsigned char *p, + unsigned long len) +{ + unsigned int prealign; + unsigned int tail; + +#ifdef CRC_XOR + crc ^= 0xffffffff; +#endif + + if (len < VMX_ALIGN + VMX_ALIGN_MASK) { + crc = crc32_align(crc, p, len); + goto out; + } + + if ((unsigned long)p & VMX_ALIGN_MASK) { + prealign = VMX_ALIGN - ((unsigned long)p & VMX_ALIGN_MASK); + crc = crc32_align(crc, p, prealign); + len -= prealign; + p += prealign; + } + + crc = __crc32_vpmsum(crc, p, len & ~VMX_ALIGN_MASK); + + tail = len & VMX_ALIGN_MASK; + if (tail) { + p += len & ~VMX_ALIGN_MASK; + crc = crc32_align(crc, p, tail); + } + +out: +#ifdef CRC_XOR + crc ^= 0xffffffff; +#endif + + return crc; +} + +#if defined (__clang__) +#include "clang_workaround.h" +#else +#define __builtin_pack_vector(a, b) __builtin_pack_vector_int128 ((a), (b)) +#define __builtin_unpack_vector_0(a) __builtin_unpack_vector_int128 ((vector __int128_t)(a), 0) +#define __builtin_unpack_vector_1(a) __builtin_unpack_vector_int128 ((vector __int128_t)(a), 1) +#endif + +/* When we have a load-store in a single-dispatch group and address overlap + * such that foward is not allowed (load-hit-store) the group must be flushed. + * A group ending NOP prevents the flush. + */ +#define GROUP_ENDING_NOP asm("ori 2,2,0" ::: "memory") + +#if defined(__BIG_ENDIAN__) && defined (REFLECT) +#define BYTESWAP_DATA +#elif defined(__LITTLE_ENDIAN__) && !defined(REFLECT) +#define BYTESWAP_DATA +#endif + +#ifdef BYTESWAP_DATA +#define VEC_PERM(vr, va, vb, vc) vr = vec_perm(va, vb,\ + (__vector unsigned char) vc) +#if defined(__LITTLE_ENDIAN__) +/* Byte reverse permute constant LE. */ +static const __vector unsigned long long vperm_const + __attribute__ ((aligned(16))) = { 0x08090A0B0C0D0E0FUL, + 0x0001020304050607UL }; +#else +static const __vector unsigned long long vperm_const + __attribute__ ((aligned(16))) = { 0x0F0E0D0C0B0A0908UL, + 0X0706050403020100UL }; +#endif +#else +#define VEC_PERM(vr, va, vb, vc) +#endif + +static unsigned int __attribute__ ((aligned (32))) +__crc32_vpmsum(unsigned int crc, const void* p, unsigned long len) { + + const __vector unsigned long long vzero = {0,0}; + const __vector unsigned long long vones = {0xffffffffffffffffUL, + 0xffffffffffffffffUL}; + +#ifdef REFLECT + __vector unsigned char vsht_splat; + const __vector unsigned long long vmask_32bit = + (__vector unsigned long long)vec_sld((__vector unsigned char)vzero, + (__vector unsigned char)vones, 4); +#endif + + const __vector unsigned long long vmask_64bit = + (__vector unsigned long long)vec_sld((__vector unsigned char)vzero, + (__vector unsigned char)vones, 8); + + __vector unsigned long long vcrc; + + __vector unsigned long long vconst1, vconst2; + + /* vdata0-vdata7 will contain our data (p). */ + __vector unsigned long long vdata0, vdata1, vdata2, vdata3, vdata4, + vdata5, vdata6, vdata7; + + /* v0-v7 will contain our checksums */ + __vector unsigned long long v0 = {0,0}; + __vector unsigned long long v1 = {0,0}; + __vector unsigned long long v2 = {0,0}; + __vector unsigned long long v3 = {0,0}; + __vector unsigned long long v4 = {0,0}; + __vector unsigned long long v5 = {0,0}; + __vector unsigned long long v6 = {0,0}; + __vector unsigned long long v7 = {0,0}; + + + /* Vector auxiliary variables. */ + __vector unsigned long long va0, va1, va2, va3, va4, va5, va6, va7; + + unsigned int result = 0; + unsigned int offset; /* Constant table offset. */ + + unsigned long i; /* Counter. */ + unsigned long chunks; + + unsigned long block_size; + int next_block = 0; + + /* Align by 128 bits. The last 128 bit block will be processed at end. */ + unsigned long length = len & 0xFFFFFFFFFFFFFF80UL; + +#ifdef REFLECT + vcrc = (__vector unsigned long long)__builtin_pack_vector(0UL, crc); +#else + vcrc = (__vector unsigned long long)__builtin_pack_vector(crc, 0UL); + + /* Shift into top 32 bits */ + vcrc = (__vector unsigned long long)vec_sld((__vector unsigned char)vcrc, + (__vector unsigned char)vzero, 4); +#endif + + /* Short version. */ + if (len < 256) { + /* Calculate where in the constant table we need to start. */ + offset = 256 - len; + + vconst1 = vec_ld(offset, vcrc_short_const); + vdata0 = vec_ld(0, (__vector unsigned long long*) p); + VEC_PERM(vdata0, vdata0, vconst1, vperm_const); + + /* xor initial value*/ + vdata0 = vec_xor(vdata0, vcrc); + + vdata0 = (__vector unsigned long long) __builtin_crypto_vpmsumw + ((__vector unsigned int)vdata0, (__vector unsigned int)vconst1); + v0 = vec_xor(v0, vdata0); + + for (i = 16; i < len; i += 16) { + vconst1 = vec_ld(offset + i, vcrc_short_const); + vdata0 = vec_ld(i, (__vector unsigned long long*) p); + VEC_PERM(vdata0, vdata0, vconst1, vperm_const); + vdata0 = (__vector unsigned long long) __builtin_crypto_vpmsumw + ((__vector unsigned int)vdata0, (__vector unsigned int)vconst1); + v0 = vec_xor(v0, vdata0); + } + } else { + + /* Load initial values. */ + vdata0 = vec_ld(0, (__vector unsigned long long*) p); + vdata1 = vec_ld(16, (__vector unsigned long long*) p); + + VEC_PERM(vdata0, vdata0, vdata0, vperm_const); + VEC_PERM(vdata1, vdata1, vdata1, vperm_const); + + vdata2 = vec_ld(32, (__vector unsigned long long*) p); + vdata3 = vec_ld(48, (__vector unsigned long long*) p); + + VEC_PERM(vdata2, vdata2, vdata2, vperm_const); + VEC_PERM(vdata3, vdata3, vdata3, vperm_const); + + vdata4 = vec_ld(64, (__vector unsigned long long*) p); + vdata5 = vec_ld(80, (__vector unsigned long long*) p); + + VEC_PERM(vdata4, vdata4, vdata4, vperm_const); + VEC_PERM(vdata5, vdata5, vdata5, vperm_const); + + vdata6 = vec_ld(96, (__vector unsigned long long*) p); + vdata7 = vec_ld(112, (__vector unsigned long long*) p); + + VEC_PERM(vdata6, vdata6, vdata6, vperm_const); + VEC_PERM(vdata7, vdata7, vdata7, vperm_const); + + /* xor in initial value */ + vdata0 = vec_xor(vdata0, vcrc); + + p = (char *)p + 128; + + do { + /* Checksum in blocks of MAX_SIZE. */ + block_size = length; + if (block_size > MAX_SIZE) { + block_size = MAX_SIZE; + } + + length = length - block_size; + + /* + * Work out the offset into the constants table to start at. Each + * constant is 16 bytes, and it is used against 128 bytes of input + * data - 128 / 16 = 8 + */ + offset = (MAX_SIZE/8) - (block_size/8); + /* We reduce our final 128 bytes in a separate step */ + chunks = (block_size/128)-1; + + vconst1 = vec_ld(offset, vcrc_const); + + va0 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata0, + (__vector unsigned long long)vconst1); + va1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata1, + (__vector unsigned long long)vconst1); + va2 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata2, + (__vector unsigned long long)vconst1); + va3 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata3, + (__vector unsigned long long)vconst1); + va4 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata4, + (__vector unsigned long long)vconst1); + va5 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata5, + (__vector unsigned long long)vconst1); + va6 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata6, + (__vector unsigned long long)vconst1); + va7 = __builtin_crypto_vpmsumd ((__vector unsigned long long)vdata7, + (__vector unsigned long long)vconst1); + + if (chunks > 1) { + offset += 16; + vconst2 = vec_ld(offset, vcrc_const); + GROUP_ENDING_NOP; + + vdata0 = vec_ld(0, (__vector unsigned long long*) p); + VEC_PERM(vdata0, vdata0, vdata0, vperm_const); + + vdata1 = vec_ld(16, (__vector unsigned long long*) p); + VEC_PERM(vdata1, vdata1, vdata1, vperm_const); + + vdata2 = vec_ld(32, (__vector unsigned long long*) p); + VEC_PERM(vdata2, vdata2, vdata2, vperm_const); + + vdata3 = vec_ld(48, (__vector unsigned long long*) p); + VEC_PERM(vdata3, vdata3, vdata3, vperm_const); + + vdata4 = vec_ld(64, (__vector unsigned long long*) p); + VEC_PERM(vdata4, vdata4, vdata4, vperm_const); + + vdata5 = vec_ld(80, (__vector unsigned long long*) p); + VEC_PERM(vdata5, vdata5, vdata5, vperm_const); + + vdata6 = vec_ld(96, (__vector unsigned long long*) p); + VEC_PERM(vdata6, vdata6, vdata6, vperm_const); + + vdata7 = vec_ld(112, (__vector unsigned long long*) p); + VEC_PERM(vdata7, vdata7, vdata7, vperm_const); + + p = (char *)p + 128; + + /* + * main loop. We modulo schedule it such that it takes three + * iterations to complete - first iteration load, second + * iteration vpmsum, third iteration xor. + */ + for (i = 0; i < chunks-2; i++) { + vconst1 = vec_ld(offset, vcrc_const); + offset += 16; + GROUP_ENDING_NOP; + + v0 = vec_xor(v0, va0); + va0 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata0, (__vector unsigned long long)vconst2); + vdata0 = vec_ld(0, (__vector unsigned long long*) p); + VEC_PERM(vdata0, vdata0, vdata0, vperm_const); + GROUP_ENDING_NOP; + + v1 = vec_xor(v1, va1); + va1 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata1, (__vector unsigned long long)vconst2); + vdata1 = vec_ld(16, (__vector unsigned long long*) p); + VEC_PERM(vdata1, vdata1, vdata1, vperm_const); + GROUP_ENDING_NOP; + + v2 = vec_xor(v2, va2); + va2 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata2, (__vector unsigned long long)vconst2); + vdata2 = vec_ld(32, (__vector unsigned long long*) p); + VEC_PERM(vdata2, vdata2, vdata2, vperm_const); + GROUP_ENDING_NOP; + + v3 = vec_xor(v3, va3); + va3 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata3, (__vector unsigned long long)vconst2); + vdata3 = vec_ld(48, (__vector unsigned long long*) p); + VEC_PERM(vdata3, vdata3, vdata3, vperm_const); + + vconst2 = vec_ld(offset, vcrc_const); + GROUP_ENDING_NOP; + + v4 = vec_xor(v4, va4); + va4 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata4, (__vector unsigned long long)vconst1); + vdata4 = vec_ld(64, (__vector unsigned long long*) p); + VEC_PERM(vdata4, vdata4, vdata4, vperm_const); + GROUP_ENDING_NOP; + + v5 = vec_xor(v5, va5); + va5 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata5, (__vector unsigned long long)vconst1); + vdata5 = vec_ld(80, (__vector unsigned long long*) p); + VEC_PERM(vdata5, vdata5, vdata5, vperm_const); + GROUP_ENDING_NOP; + + v6 = vec_xor(v6, va6); + va6 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata6, (__vector unsigned long long)vconst1); + vdata6 = vec_ld(96, (__vector unsigned long long*) p); + VEC_PERM(vdata6, vdata6, vdata6, vperm_const); + GROUP_ENDING_NOP; + + v7 = vec_xor(v7, va7); + va7 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata7, (__vector unsigned long long)vconst1); + vdata7 = vec_ld(112, (__vector unsigned long long*) p); + VEC_PERM(vdata7, vdata7, vdata7, vperm_const); + + p = (char *)p + 128; + } + + /* First cool down*/ + vconst1 = vec_ld(offset, vcrc_const); + offset += 16; + + v0 = vec_xor(v0, va0); + va0 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata0, (__vector unsigned long long)vconst1); + GROUP_ENDING_NOP; + + v1 = vec_xor(v1, va1); + va1 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata1, (__vector unsigned long long)vconst1); + GROUP_ENDING_NOP; + + v2 = vec_xor(v2, va2); + va2 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata2, (__vector unsigned long long)vconst1); + GROUP_ENDING_NOP; + + v3 = vec_xor(v3, va3); + va3 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata3, (__vector unsigned long long)vconst1); + GROUP_ENDING_NOP; + + v4 = vec_xor(v4, va4); + va4 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata4, (__vector unsigned long long)vconst1); + GROUP_ENDING_NOP; + + v5 = vec_xor(v5, va5); + va5 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata5, (__vector unsigned long long)vconst1); + GROUP_ENDING_NOP; + + v6 = vec_xor(v6, va6); + va6 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata6, (__vector unsigned long long)vconst1); + GROUP_ENDING_NOP; + + v7 = vec_xor(v7, va7); + va7 = __builtin_crypto_vpmsumd ((__vector unsigned long + long)vdata7, (__vector unsigned long long)vconst1); + }/* else */ + + /* Second cool down. */ + v0 = vec_xor(v0, va0); + v1 = vec_xor(v1, va1); + v2 = vec_xor(v2, va2); + v3 = vec_xor(v3, va3); + v4 = vec_xor(v4, va4); + v5 = vec_xor(v5, va5); + v6 = vec_xor(v6, va6); + v7 = vec_xor(v7, va7); + +#ifdef REFLECT + /* + * vpmsumd produces a 96 bit result in the least significant bits + * of the register. Since we are bit reflected we have to shift it + * left 32 bits so it occupies the least significant bits in the + * bit reflected domain. + */ + v0 = (__vector unsigned long long)vec_sld((__vector unsigned char)v0, + (__vector unsigned char)vzero, 4); + v1 = (__vector unsigned long long)vec_sld((__vector unsigned char)v1, + (__vector unsigned char)vzero, 4); + v2 = (__vector unsigned long long)vec_sld((__vector unsigned char)v2, + (__vector unsigned char)vzero, 4); + v3 = (__vector unsigned long long)vec_sld((__vector unsigned char)v3, + (__vector unsigned char)vzero, 4); + v4 = (__vector unsigned long long)vec_sld((__vector unsigned char)v4, + (__vector unsigned char)vzero, 4); + v5 = (__vector unsigned long long)vec_sld((__vector unsigned char)v5, + (__vector unsigned char)vzero, 4); + v6 = (__vector unsigned long long)vec_sld((__vector unsigned char)v6, + (__vector unsigned char)vzero, 4); + v7 = (__vector unsigned long long)vec_sld((__vector unsigned char)v7, + (__vector unsigned char)vzero, 4); +#endif + + /* xor with the last 1024 bits. */ + va0 = vec_ld(0, (__vector unsigned long long*) p); + VEC_PERM(va0, va0, va0, vperm_const); + + va1 = vec_ld(16, (__vector unsigned long long*) p); + VEC_PERM(va1, va1, va1, vperm_const); + + va2 = vec_ld(32, (__vector unsigned long long*) p); + VEC_PERM(va2, va2, va2, vperm_const); + + va3 = vec_ld(48, (__vector unsigned long long*) p); + VEC_PERM(va3, va3, va3, vperm_const); + + va4 = vec_ld(64, (__vector unsigned long long*) p); + VEC_PERM(va4, va4, va4, vperm_const); + + va5 = vec_ld(80, (__vector unsigned long long*) p); + VEC_PERM(va5, va5, va5, vperm_const); + + va6 = vec_ld(96, (__vector unsigned long long*) p); + VEC_PERM(va6, va6, va6, vperm_const); + + va7 = vec_ld(112, (__vector unsigned long long*) p); + VEC_PERM(va7, va7, va7, vperm_const); + + p = (char *)p + 128; + + vdata0 = vec_xor(v0, va0); + vdata1 = vec_xor(v1, va1); + vdata2 = vec_xor(v2, va2); + vdata3 = vec_xor(v3, va3); + vdata4 = vec_xor(v4, va4); + vdata5 = vec_xor(v5, va5); + vdata6 = vec_xor(v6, va6); + vdata7 = vec_xor(v7, va7); + + /* Check if we have more blocks to process */ + next_block = 0; + if (length != 0) { + next_block = 1; + + /* zero v0-v7 */ + v0 = vec_xor(v0, v0); + v1 = vec_xor(v1, v1); + v2 = vec_xor(v2, v2); + v3 = vec_xor(v3, v3); + v4 = vec_xor(v4, v4); + v5 = vec_xor(v5, v5); + v6 = vec_xor(v6, v6); + v7 = vec_xor(v7, v7); + } + length = length + 128; + + } while (next_block); + + /* Calculate how many bytes we have left. */ + length = (len & 127); + + /* Calculate where in (short) constant table we need to start. */ + offset = 128 - length; + + v0 = vec_ld(offset, vcrc_short_const); + v1 = vec_ld(offset + 16, vcrc_short_const); + v2 = vec_ld(offset + 32, vcrc_short_const); + v3 = vec_ld(offset + 48, vcrc_short_const); + v4 = vec_ld(offset + 64, vcrc_short_const); + v5 = vec_ld(offset + 80, vcrc_short_const); + v6 = vec_ld(offset + 96, vcrc_short_const); + v7 = vec_ld(offset + 112, vcrc_short_const); + + offset += 128; + + v0 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( + (__vector unsigned int)vdata0,(__vector unsigned int)v0); + v1 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( + (__vector unsigned int)vdata1,(__vector unsigned int)v1); + v2 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( + (__vector unsigned int)vdata2,(__vector unsigned int)v2); + v3 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( + (__vector unsigned int)vdata3,(__vector unsigned int)v3); + v4 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( + (__vector unsigned int)vdata4,(__vector unsigned int)v4); + v5 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( + (__vector unsigned int)vdata5,(__vector unsigned int)v5); + v6 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( + (__vector unsigned int)vdata6,(__vector unsigned int)v6); + v7 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( + (__vector unsigned int)vdata7,(__vector unsigned int)v7); + + /* Now reduce the tail (0-112 bytes). */ + for (i = 0; i < length; i+=16) { + vdata0 = vec_ld(i,(__vector unsigned long long*)p); + VEC_PERM(vdata0, vdata0, vdata0, vperm_const); + va0 = vec_ld(offset + i,vcrc_short_const); + va0 = (__vector unsigned long long)__builtin_crypto_vpmsumw ( + (__vector unsigned int)vdata0,(__vector unsigned int)va0); + v0 = vec_xor(v0, va0); + } + + /* xor all parallel chunks together. */ + v0 = vec_xor(v0, v1); + v2 = vec_xor(v2, v3); + v4 = vec_xor(v4, v5); + v6 = vec_xor(v6, v7); + + v0 = vec_xor(v0, v2); + v4 = vec_xor(v4, v6); + + v0 = vec_xor(v0, v4); + } + + /* Barrett Reduction */ + vconst1 = vec_ld(0, v_Barrett_const); + vconst2 = vec_ld(16, v_Barrett_const); + + v1 = (__vector unsigned long long)vec_sld((__vector unsigned char)v0, + (__vector unsigned char)v0, 8); + v0 = vec_xor(v1,v0); + +#ifdef REFLECT + /* shift left one bit */ + vsht_splat = vec_splat_u8 (1); + v0 = (__vector unsigned long long)vec_sll ((__vector unsigned char)v0, + vsht_splat); +#endif + + v0 = vec_and(v0, vmask_64bit); + +#ifndef REFLECT + + /* + * Now for the actual algorithm. The idea is to calculate q, + * the multiple of our polynomial that we need to subtract. By + * doing the computation 2x bits higher (ie 64 bits) and shifting the + * result back down 2x bits, we round down to the nearest multiple. + */ + + /* ma */ + v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v0, + (__vector unsigned long long)vconst1); + /* q = floor(ma/(2^64)) */ + v1 = (__vector unsigned long long)vec_sld ((__vector unsigned char)vzero, + (__vector unsigned char)v1, 8); + /* qn */ + v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v1, + (__vector unsigned long long)vconst2); + /* a - qn, subtraction is xor in GF(2) */ + v0 = vec_xor (v0, v1); + /* + * Get the result into r3. We need to shift it left 8 bytes: + * V0 [ 0 1 2 X ] + * V0 [ 0 X 2 3 ] + */ + result = __builtin_unpack_vector_1 (v0); +#else + + /* + * The reflected version of Barrett reduction. Instead of bit + * reflecting our data (which is expensive to do), we bit reflect our + * constants and our algorithm, which means the intermediate data in + * our vector registers goes from 0-63 instead of 63-0. We can reflect + * the algorithm because we don't carry in mod 2 arithmetic. + */ + + /* bottom 32 bits of a */ + v1 = vec_and(v0, vmask_32bit); + + /* ma */ + v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v1, + (__vector unsigned long long)vconst1); + + /* bottom 32bits of ma */ + v1 = vec_and(v1, vmask_32bit); + /* qn */ + v1 = __builtin_crypto_vpmsumd ((__vector unsigned long long)v1, + (__vector unsigned long long)vconst2); + /* a - qn, subtraction is xor in GF(2) */ + v0 = vec_xor (v0, v1); + + /* + * Since we are bit reflected, the result (ie the low 32 bits) is in + * the high 32 bits. We just need to shift it left 4 bytes + * V0 [ 0 1 X 3 ] + * V0 [ 0 X 2 3 ] + */ + + /* shift result into top 64 bits of */ + v0 = (__vector unsigned long long)vec_sld((__vector unsigned char)v0, + (__vector unsigned char)vzero, 4); + + result = __builtin_unpack_vector_0 (v0); +#endif + + return result; +} diff --git a/mysys/crc32ieee.cc b/mysys/crc32ieee.cc new file mode 100644 index 00000000000..5f8344b4f9d --- /dev/null +++ b/mysys/crc32ieee.cc @@ -0,0 +1,63 @@ +/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ + + +#include +#include +#include + +/* TODO: remove this once zlib adds inherent support for hardware accelerated +crc32 for all architectures. */ +static unsigned int my_crc32_zlib(unsigned int crc, const void *data, + size_t len) +{ + return (unsigned int) crc32(crc, (const Bytef *)data, (unsigned int) len); +} + +#ifdef HAVE_PCLMUL +extern "C" int crc32_pclmul_enabled(); +extern "C" unsigned int crc32_pclmul(unsigned int, const void *, size_t); +#elif defined(__GNUC__) && defined(HAVE_ARMV8_CRC) +extern "C" int crc32_aarch64_available(); +extern "C" unsigned int crc32_aarch64(unsigned int, const void *, size_t); +#endif + + +typedef unsigned int (*my_crc32_t)(unsigned int, const void *, size_t); + +static my_crc32_t init_crc32() +{ + my_crc32_t func= my_crc32_zlib; +#ifdef HAVE_PCLMUL + if (crc32_pclmul_enabled()) + func = crc32_pclmul; +#elif defined(__GNUC__) && defined(HAVE_ARMV8_CRC) + if (crc32_aarch64_available()) + func= crc32_aarch64; +#endif + return func; +} + +static const my_crc32_t my_checksum_func= init_crc32(); + +#ifndef __powerpc64__ +/* For powerpc, my_checksum is defined elsewhere.*/ +extern "C" unsigned int my_checksum(unsigned int crc, const void *data, size_t len) +{ + return my_checksum_func(crc, data, len); +} +#endif + + diff --git a/mysys/my_init.c b/mysys/my_init.c index cd9875017f0..2b420da03be 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -100,9 +100,6 @@ my_bool my_init(void) /* Initialize our mutex handling */ my_mutex_init(); - /* Initialize CPU architecture specific hardware based crc32 optimization */ - my_checksum_init(); - if (my_thread_global_init()) return 1; diff --git a/storage/innobase/CMakeLists.txt b/storage/innobase/CMakeLists.txt index 30409902e38..4fac94d211e 100644 --- a/storage/innobase/CMakeLists.txt +++ b/storage/innobase/CMakeLists.txt @@ -264,7 +264,6 @@ SET(INNOBASE_SOURCES include/ut0byte.h include/ut0byte.ic include/ut0counter.h - include/ut0crc32.h include/ut0dbg.h include/ut0list.h include/ut0list.ic @@ -340,7 +339,6 @@ SET(INNOBASE_SOURCES trx/trx0sys.cc trx/trx0trx.cc trx/trx0undo.cc - ut/ut0crc32.cc ut/ut0dbg.cc ut/ut0list.cc ut/ut0mem.cc diff --git a/storage/innobase/include/ut0crc32.h b/storage/innobase/include/ut0crc32.h index f33ca54cb96..0cbccb976e2 100644 --- a/storage/innobase/include/ut0crc32.h +++ b/storage/innobase/include/ut0crc32.h @@ -28,33 +28,10 @@ Created Aug 10, 2011 Vasil Dimov #define ut0crc32_h #include "univ.i" - -/********************************************************************//** -Initializes the data structures used by ut_crc32*(). Does not do any -allocations, would not hurt if called twice, but would be pointless. */ -void ut_crc32_init(); - -/** Append data to a CRC-32C checksum. -@param crc current checksum -@param s data to append to the checksum -@param size data length in bytes -@return CRC-32C, using the GF(2) primitive polynomial 0x11EDC6F41, -or 0x1EDC6F41 without the highest degree term */ -typedef uint32_t (*ut_crc32_func_t)(uint32_t crc, const byte *s, size_t size); - -/** Pointer to CRC32 calculation function. */ -extern ut_crc32_func_t ut_crc32_low; - -/** Text description of CRC32 implementation */ -extern const char* ut_crc32_implementation; - -/** Compute CRC-32C over a string of bytes. -@param s data -@param len data length in bytes -@return the CRC-32C of the data */ +#include static inline uint32_t ut_crc32(const byte *s, size_t size) { - return ut_crc32_low(0, s, size); + return my_crc32c(0, s, size); } #endif /* ut0crc32_h */ diff --git a/storage/innobase/innodb.cmake b/storage/innobase/innodb.cmake index dc6afe59088..978b33a2abe 100644 --- a/storage/innobase/innodb.cmake +++ b/storage/innobase/innodb.cmake @@ -209,16 +209,6 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "SunPro" PROPERTIES COMPILE_FLAGS -xO3) ENDIF() -# Avoid generating Hardware Capabilities due to crc32 instructions -IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_SYSTEM_PROCESSOR MATCHES "i386") - MY_CHECK_CXX_COMPILER_FLAG("-Wa,-nH") - IF(have_CXX__Wa__nH) - ADD_COMPILE_FLAGS( - ut/ut0crc32.cc - COMPILE_FLAGS "-Wa,-nH" - ) - ENDIF() -ENDIF() IF(MSVC) # Avoid "unreferenced label" warning in generated file diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index 236ca2080b7..14ed15a81c9 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -762,7 +762,6 @@ static void srv_init() /* Initialize some INFORMATION SCHEMA internal structures */ trx_i_s_cache_init(trx_i_s_cache); - ut_crc32_init(); } /*********************************************************************//** diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 3badbbdef73..229f4879bf8 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -1223,7 +1223,7 @@ dberr_t srv_start(bool create_new_db) srv_boot(); - ib::info() << ut_crc32_implementation; + ib::info() << my_crc32c_implementation(); if (!srv_read_only_mode) { diff --git a/storage/innobase/ut/ut0crc32.cc b/storage/innobase/ut/ut0crc32.cc deleted file mode 100644 index c83bb19ad76..00000000000 --- a/storage/innobase/ut/ut0crc32.cc +++ /dev/null @@ -1,346 +0,0 @@ -/***************************************************************************** - -Copyright (c) 2009, 2010 Facebook, Inc. All Rights Reserved. -Copyright (c) 2011, 2015, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2016, 2020, MariaDB Corporation. - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA - -*****************************************************************************/ - -/***************************************************************//** -@file ut/ut0crc32.cc -CRC32 implementation from Facebook, based on the zlib implementation. - -Created Aug 8, 2011, Vasil Dimov, based on mysys/my_crc32.c and -mysys/my_perf.c, contributed by Facebook under the following license. -********************************************************************/ - -/* Copyright (C) 2009-2010 Facebook, Inc. All Rights Reserved. - - Dual licensed under BSD license and GPLv2. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY FACEBOOK, INC. ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - EVENT SHALL FACEBOOK, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ - -/* The below CRC32 implementation is based on the implementation included with - * zlib with modifications to process 8 bytes at a time and using SSE 4.2 - * extensions when available. The polynomial constant has been changed to - * match the one used by SSE 4.2 and does not return the same value as the - * version used by zlib. The original zlib copyright notice follows. */ - -/* crc32.c -- compute the CRC-32 of a buf stream - * Copyright (C) 1995-2005 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Thanks to Rodney Brown for his contribution of faster - * CRC methods: exclusive-oring 32 bits of buf at a time, and pre-computing - * tables for updating the shift register in one step with three exclusive-ors - * instead of four steps with four exclusive-ors. This results in about a - * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. - */ - -// First include (the generated) my_config.h, to get correct platform defines. -#include "my_config.h" -#include - -#include "ut0crc32.h" -#include "my_valgrind.h" - -#ifdef HAVE_CPUID_INSTRUCTION -# ifdef _MSC_VER -# include -# else -# include -# if defined __GNUC__ && !defined __clang__ && __GNUC__ < 5 -/* does not really work in GCC before version 5 */ -# define _mm_crc32_u8(crc,data) __builtin_ia32_crc32qi(crc,data) -# define _mm_crc32_u32(crc,data) __builtin_ia32_crc32si(crc,data) -# define _mm_crc32_u64(crc,data) __builtin_ia32_crc32di(crc,data) -# else -# include -# endif -# endif -#endif - -/* CRC32 hardware implementation. */ - -#ifdef HAVE_CRC32_VPMSUM -extern "C" -unsigned int crc32c_vpmsum(unsigned int crc, const unsigned char *p, unsigned long len); -ut_crc32_func_t ut_crc32_low= crc32c_vpmsum; -const char* ut_crc32_implementation = "Using POWER8 crc32 instructions"; -#else -# if defined(__GNUC__) && defined(HAVE_ARMV8_CRC) -extern "C" { -uint32_t crc32c_aarch64(uint32_t crc, const unsigned char *buffer, uint64_t len); -}; -# elif defined HAVE_CPUID_INSTRUCTION -/** return whether SSE4.2 instructions are available */ -static inline bool has_sse4_2() -{ - /* We assume that the CPUID instruction and its parameter 1 are available. - We do not support any precursors of the Intel 80486. */ -# ifdef _MSC_VER - int data[4]; - __cpuid(data, 1); - return !!(data[2] & 1 << 20); -# else - uint32_t reax = 0, rebx = 0, recx = 0, redx = 0; - __cpuid(1, reax, rebx, recx, redx); - return !!(recx & 1 << 20); -# endif -} - -/** Append 8 bits (1 byte) to a CRC-32C checksum. -@param crc CRC-32C checksum so far -@param data data to be checksummed -@return the updated CRC-32C */ -__attribute__((target("sse4.2"))) -static inline ulint ut_crc32c_8(ulint crc, byte data) -{ - return _mm_crc32_u8(static_cast(crc), data); -} - -/** Append 64 bits (8 aligned bytes) to a CRC-32C checksum -@param[in] crc CRC-32C checksum so far -@param[in] data 8 bytes of aligned data -@return the updated CRC-32C */ -__attribute__((target("sse4.2"))) -static inline ulint ut_crc32c_64(ulint crc, uint64_t data) -{ -# if SIZEOF_SIZE_T > 4 - return _mm_crc32_u64(crc, data); -# else - crc= _mm_crc32_u32(crc, static_cast(data)); - crc= _mm_crc32_u32(crc, static_cast(data >> 32)); - return crc; -# endif -} - -/** Calculate CRC-32C using dedicated IA-32 or AMD64 instructions -@param crc current checksum -@param buf data to append to the checksum -@param len data length in bytes -@return CRC-32C (polynomial 0x11EDC6F41) */ -uint32_t ut_crc32_hw(uint32_t crc, const byte *buf, size_t len) -{ - ulint c= static_cast(~crc); - - /* Calculate byte-by-byte up to an 8-byte aligned address. After - this consume the input 8-bytes at a time. */ - while (len > 0 && (reinterpret_cast(buf) & 7) != 0) - { - c= ut_crc32c_8(c, *buf++); - len--; - } - - const uint64_t* b64= reinterpret_cast(buf); - - for (; len >= 128; len-= 128) - { - /* This call is repeated 16 times. 16 * 8 = 128. */ - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - c= ut_crc32c_64(c, *b64++); - } - - for (; len >= 8; len-= 8) - c= ut_crc32c_64(c, *b64++); - - buf= reinterpret_cast(b64); - - while (len--) - c= ut_crc32c_8(c, *buf++); - - return ~static_cast(c); -} -# endif /* (defined(__GNUC__) && defined(__i386__)) || _MSC_VER */ - -/* CRC32 software implementation. */ - -/* Precalculated table used to generate the CRC32 if the CPU does not -have support for it */ -static uint32_t ut_crc32_slice8_table[8][256]; - -/********************************************************************//** -Initializes the table that is used to generate the CRC32 if the CPU does -not have support for it. */ -static -void -ut_crc32_slice8_table_init() -/*========================*/ -{ - /* bit-reversed poly 0x1EDC6F41 (from SSE42 crc32 instruction) */ - static const uint32_t poly = 0x82f63b78; - uint32_t n; - uint32_t k; - uint32_t c; - - for (n = 0; n < 256; n++) { - c = n; - for (k = 0; k < 8; k++) { - c = (c & 1) ? (poly ^ (c >> 1)) : (c >> 1); - } - ut_crc32_slice8_table[0][n] = c; - } - - for (n = 0; n < 256; n++) { - c = ut_crc32_slice8_table[0][n]; - for (k = 1; k < 8; k++) { - c = ut_crc32_slice8_table[0][c & 0xFF] ^ (c >> 8); - ut_crc32_slice8_table[k][n] = c; - } - } -} - -/** Append 8 bits (1 byte) to a CRC-32C checksum. -@param crc CRC-32C checksum so far -@param data data to be checksummed -@return the updated CRC-32C */ -static inline uint32_t ut_crc32c_8_sw(uint32_t crc, byte data) -{ - const uint8_t i= (crc ^ data) & 0xFF; - - return (crc >> 8) ^ ut_crc32_slice8_table[0][i]; -} - -/** Append 64 bits (8 aligned bytes) to a CRC-32C checksum -@param[in] crc CRC-32C checksum so far -@param[in] data 8 bytes of aligned data -@return the updated CRC-32C */ -static inline uint32_t ut_crc32c_64_sw(uint32_t crc, uint64_t data) -{ -# ifdef WORDS_BIGENDIAN - data= data << 56 | - (data & 0x000000000000FF00ULL) << 40 | - (data & 0x0000000000FF0000ULL) << 24 | - (data & 0x00000000FF000000ULL) << 8 | - (data & 0x000000FF00000000ULL) >> 8 | - (data & 0x0000FF0000000000ULL) >> 24 | - (data & 0x00FF000000000000ULL) >> 40 | - data >> 56; -# endif /* WORDS_BIGENDIAN */ - - data^= crc; - return - ut_crc32_slice8_table[7][(data ) & 0xFF] ^ - ut_crc32_slice8_table[6][(data >> 8) & 0xFF] ^ - ut_crc32_slice8_table[5][(data >> 16) & 0xFF] ^ - ut_crc32_slice8_table[4][(data >> 24) & 0xFF] ^ - ut_crc32_slice8_table[3][(data >> 32) & 0xFF] ^ - ut_crc32_slice8_table[2][(data >> 40) & 0xFF] ^ - ut_crc32_slice8_table[1][(data >> 48) & 0xFF] ^ - ut_crc32_slice8_table[0][(data >> 56)]; -} - -/** Calculate CRC-32C using a look-up table. -@param crc current checksum -@param buf data to append to the checksum -@param len data length in bytes -@return CRC-32C (polynomial 0x11EDC6F41) */ -uint32_t ut_crc32_sw(uint32_t crc, const byte *buf, size_t len) -{ - crc= ~crc; - - /* Calculate byte-by-byte up to an 8-byte aligned address. After - this consume the input 8-bytes at a time. */ - while (len > 0 && (reinterpret_cast(buf) & 7) != 0) - { - crc= ut_crc32c_8_sw(crc, *buf++); - len--; - } - - const uint64_t* b64= reinterpret_cast(buf); - - for (; len >= 8; len-= 8) - crc= ut_crc32c_64_sw(crc, *b64++); - - buf= reinterpret_cast(b64); - - while (len--) - crc= ut_crc32c_8_sw(crc, *buf++); - - return ~crc; -} - -ut_crc32_func_t ut_crc32_low= ut_crc32_sw; -const char *ut_crc32_implementation= "Using generic crc32 instructions"; -#endif - -/********************************************************************//** -Initializes the data structures used by ut_crc32*(). Does not do any -allocations, would not hurt if called twice, but would be pointless. */ -void ut_crc32_init() -{ -#ifndef HAVE_CRC32_VPMSUM -# if defined(__GNUC__) && defined(HAVE_ARMV8_CRC) - if (const char *crc32c_implementation= crc32c_aarch64_available()) - { - ut_crc32_low= crc32c_aarch64; - ut_crc32_implementation= crc32c_implementation; - return; - } -# elif defined HAVE_CPUID_INSTRUCTION - if (has_sse4_2()) - { - ut_crc32_low= ut_crc32_hw; - ut_crc32_implementation= "Using SSE4.2 crc32 instructions"; - return; - } -# endif - ut_crc32_slice8_table_init(); -#endif /* !HAVE_CRC32_VPMSUM */ -} diff --git a/unittest/mysys/CMakeLists.txt b/unittest/mysys/CMakeLists.txt index 984b033e7aa..4b947ab780f 100644 --- a/unittest/mysys/CMakeLists.txt +++ b/unittest/mysys/CMakeLists.txt @@ -15,11 +15,11 @@ MY_ADD_TESTS(bitmap base64 my_atomic my_rdtsc lf my_malloc my_getopt dynstring byte_order - queues stacktrace LINK_LIBRARIES mysys) + queues stacktrace crc32 LINK_LIBRARIES mysys) MY_ADD_TESTS(my_vsnprintf LINK_LIBRARIES strings mysys) MY_ADD_TESTS(aes LINK_LIBRARIES mysys mysys_ssl) ADD_DEFINITIONS(${SSL_DEFINES}) - +INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) MY_ADD_TESTS(ma_dyncol LINK_LIBRARIES mysys) IF(WIN32) diff --git a/unittest/mysys/crc32-t.c b/unittest/mysys/crc32-t.c new file mode 100644 index 00000000000..c43be2cd586 --- /dev/null +++ b/unittest/mysys/crc32-t.c @@ -0,0 +1,69 @@ +/* Copyright (c) MariaDB 2020 + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ + +#include +#include +#include +#include +#include +#include +#include + +/* + Check that optimized crc32 (ieee, or ethernet polynomical) returns the same + result as zlib (not so well optimized, yet, but trustworthy) +*/ +#define DO_TEST_CRC32(crc,str) \ + ok(crc32(crc,(const Bytef *)str,(uint)(sizeof(str)-1)) == my_checksum(crc, str, sizeof(str)-1), "crc32 '%s'",str) + +/* Check that CRC32-C calculation returns correct result*/ +#define DO_TEST_CRC32C(crc,str,expected) \ + do { \ + unsigned int v = my_crc32c(crc, str, sizeof(str)-1); \ + printf("crc32(%u,'%s',%zu)=%u\n",crc,str,sizeof(str)-1,v); \ + ok(expected == my_crc32c(crc, str, sizeof(str)-1),"crc32c '%s'",str); \ + }while(0) + + +#define LONG_STR "1234567890234568900212345678901231213123321212123123123123123"\ + "............................................................................." \ + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \ + "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" \ + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" + +int main(int argc __attribute__((unused)),char *argv[]) +{ + MY_INIT(argv[0]); + plan(14); + printf("%s\n",my_crc32c_implementation()); + DO_TEST_CRC32(0,""); + DO_TEST_CRC32(1,""); + DO_TEST_CRC32(0,"12345"); + DO_TEST_CRC32(1,"12345"); + DO_TEST_CRC32(0,"1234567890123456789"); + DO_TEST_CRC32(0, LONG_STR); + ok(0 == my_checksum(0, NULL, 0) , "crc32 data = NULL, length = 0"); + + DO_TEST_CRC32C(0,"", 0); + DO_TEST_CRC32C(1,"", 1); + DO_TEST_CRC32C(0, "12345", 416359221); + DO_TEST_CRC32C(1, "12345", 549473433); + DO_TEST_CRC32C(0, "1234567890123456789", 2366987449); + DO_TEST_CRC32C(0, LONG_STR, 3009234172); + ok(0 == my_crc32c(0, NULL, 0), "crc32c data = NULL, length = 0"); + + my_end(0); + return exit_status(); +} -- cgit v1.2.1 From bfe612b738d43561d430fa022f9b4545e733ec86 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 17 Sep 2020 18:05:53 +0200 Subject: 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 -- cgit v1.2.1 From ade782c001affa69df80ed51e807e16198a9fe04 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 17 Sep 2020 22:27:45 +0200 Subject: 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) -- cgit v1.2.1 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: MDEV-23751 : galera_3nodes test failures on ipv6 sst tests Fix assertion text it was too tight for some systems. --- mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result | 2 +- .../suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result | 2 +- mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test | 8 ++++---- .../suite/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 -- cgit v1.2.1 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: 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. --- mysql-test/suite/galera_3nodes/r/galera_ipv6_mariabackup.result | 2 +- .../suite/galera_3nodes/r/galera_ipv6_mariabackup_section.result | 2 +- mysql-test/suite/galera_3nodes/t/galera_ipv6_mariabackup.test | 6 ++++-- .../suite/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 -- cgit v1.2.1 From 29a6d23622caabe59c1627e32518f2bfcf8143f9 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Sun, 20 Sep 2020 00:07:37 +0300 Subject: MDEV-23767: IN-to-subquery conversion is not visible in optimizer trace Add the printout --- mysql-test/main/opt_trace.result | 98 ++++++++++++++++++++++++++++++++++++++++ mysql-test/main/opt_trace.test | 26 +++++++++++ sql/sql_tvc.cc | 26 ++++++++++- 3 files changed, 148 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index b0b6120e271..8f4f6ec97ce 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -8684,5 +8684,103 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.mark_join_nest_as_const')) } ] drop table t0, t1, t2, t3; +# +# MDEV-23767: IN-to-subquery conversion is not visible in optimizer trace +# +create table t0 (a int); +INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +set @tmp=@@in_predicate_conversion_threshold; +set in_predicate_conversion_threshold=3; +explain select * from t0 where a in (1,2,3,4,5,6); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Using where +1 PRIMARY ref key0 key0 4 test.t0.a 2 FirstMatch(t0) +3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used +select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion')) +from information_schema.optimizer_trace; +json_detailed(json_extract(trace, '$**.in_to_subquery_conversion')) +[ + + { + "item": "t0.a in (1,2,3,4,5,6)", + "conversion": + [ + + { + "join_preparation": + { + "select_id": 2, + "steps": + [ + + { + "derived": + { + "table": "tvc_0", + "select_id": 3, + "algorithm": "materialized" + } + }, + + { + "transformation": + { + "select_id": 2, + "from": "IN (SELECT)", + "to": "materialization", + "sjm_scan_allowed": true, + "possible": true + } + }, + + { + "transformation": + { + "select_id": 2, + "from": "IN (SELECT)", + "to": "semijoin", + "chosen": true + } + }, + + { + "expanded_query": "/* select#2 */ select tvc_0._col_1 from (values (1),(2),(3),(4),(5),(6)) tvc_0" + } + ] + } + } + ] + } +] +explain select * from t0 where a in (1,2,3,4,5,a+1); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where +select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion')) +from information_schema.optimizer_trace; +json_detailed(json_extract(trace, '$**.in_to_subquery_conversion')) +[ + + { + "item": "t0.a in (1,2,3,4,5,t0.a + 1)", + "done": false, + "reason": "non-constant element in the IN-list" + } +] +explain select * from t0 where a in ('1','2','3','4','5','6'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where +select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion')) +from information_schema.optimizer_trace; +json_detailed(json_extract(trace, '$**.in_to_subquery_conversion')) +[ + + { + "item": "t0.a in ('1','2','3','4','5','6')", + "done": false, + "reason": "type mismatch" + } +] +set in_predicate_conversion_threshold=@tmp; +drop table t0; # End of 10.5 tests set optimizer_trace='enabled=off'; diff --git a/mysql-test/main/opt_trace.test b/mysql-test/main/opt_trace.test index d6030543313..314e5825c08 100644 --- a/mysql-test/main/opt_trace.test +++ b/mysql-test/main/opt_trace.test @@ -654,5 +654,31 @@ from information_schema.optimizer_trace; drop table t0, t1, t2, t3; +--echo # +--echo # MDEV-23767: IN-to-subquery conversion is not visible in optimizer trace +--echo # +create table t0 (a int); +INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +set @tmp=@@in_predicate_conversion_threshold; +set in_predicate_conversion_threshold=3; + +explain select * from t0 where a in (1,2,3,4,5,6); + +select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion')) +from information_schema.optimizer_trace; + +explain select * from t0 where a in (1,2,3,4,5,a+1); + +select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion')) +from information_schema.optimizer_trace; + +explain select * from t0 where a in ('1','2','3','4','5','6'); +select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion')) +from information_schema.optimizer_trace; + +set in_predicate_conversion_threshold=@tmp; +drop table t0; + --echo # End of 10.5 tests set optimizer_trace='enabled=off'; diff --git a/sql/sql_tvc.cc b/sql/sql_tvc.cc index 37f0f80e8a0..df774a5d8dd 100644 --- a/sql/sql_tvc.cc +++ b/sql/sql_tvc.cc @@ -22,6 +22,7 @@ #include "sql_explain.h" #include "sql_parse.h" #include "sql_cte.h" +#include "my_json_writer.h" /** @@ -903,6 +904,10 @@ Item *Item_func_in::in_predicate_to_in_subs_transformer(THD *thd, if (!transform_into_subq) return this; + Json_writer_object trace_wrapper(thd); + Json_writer_object trace_conv(thd, "in_to_subquery_conversion"); + trace_conv.add("item", this); + transform_into_subq= false; List values; @@ -922,13 +927,29 @@ Item *Item_func_in::in_predicate_to_in_subs_transformer(THD *thd, uint32 length= max_length_of_left_expr(); if (!length || length > tmp_table_max_key_length() || args[0]->cols() > tmp_table_max_key_parts()) + { + trace_conv.add("done", false); + trace_conv.add("reason", "key is too long"); return this; - + } + for (uint i=1; i < arg_count; i++) { - if (!args[i]->const_item() || cmp_row_types(args[0], args[i])) + if (!args[i]->const_item()) + { + trace_conv.add("done", false); + trace_conv.add("reason", "non-constant element in the IN-list"); return this; + } + + if (cmp_row_types(args[0], args[i])) + { + trace_conv.add("done", false); + trace_conv.add("reason", "type mismatch"); + return this; + } } + Json_writer_array trace_nested_obj(thd, "conversion"); Query_arena backup; Query_arena *arena= thd->activate_stmt_arena_if_needed(&backup); @@ -1020,6 +1041,7 @@ Item *Item_func_in::in_predicate_to_in_subs_transformer(THD *thd, goto err; parent_select->curr_tvc_name++; + return sq; err: -- cgit v1.2.1 From 6ab6b1510ed0851bda335a8919047c02860fe2e8 Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Sun, 20 Sep 2020 17:26:15 +0300 Subject: MDEV-23650 Test S3 in buildbot Temporarily disable failing S3 tests to allow the suite to run in buildbot: s3.partition and s3.partition_move are disabled due to MDEV-23648. While the problem is supposedly generic, the tests don't fail with Amazon setup, so they are disabled conditionally for emulator (MinIO). s3.replication_partition is disabled due to MDEV-23730, it fails both with Amazon and MinIO. s3.replication_mixed and s3.replication_stmt are disabled due to MDEV-23770, they also fail both with Amazon and the emulator. --- mysql-test/suite/s3/disabled.def | 3 +++ mysql-test/suite/s3/partition.test | 5 +++++ mysql-test/suite/s3/partition_move.test | 5 +++++ 3 files changed, 13 insertions(+) create mode 100644 mysql-test/suite/s3/disabled.def diff --git a/mysql-test/suite/s3/disabled.def b/mysql-test/suite/s3/disabled.def new file mode 100644 index 00000000000..8eae300e21e --- /dev/null +++ b/mysql-test/suite/s3/disabled.def @@ -0,0 +1,3 @@ +replication_partition : MDEV-23730: Server crashes in ha_maria::extra +replication_mixed : MDEV-23770: Replication failure +replication_stmt : MDEV-23770: Replication failure diff --git a/mysql-test/suite/s3/partition.test b/mysql-test/suite/s3/partition.test index 03bbc2f0da9..b60eb1bf2dd 100644 --- a/mysql-test/suite/s3/partition.test +++ b/mysql-test/suite/s3/partition.test @@ -1,3 +1,8 @@ +if (`SELECT @@s3_host_name <> "s3.amazonaws.com"`) +{ + skip The test is disabled for emulator environment due to MDEV-23648; +} + --source include/have_partition.inc --source include/have_s3.inc --source create_database.inc diff --git a/mysql-test/suite/s3/partition_move.test b/mysql-test/suite/s3/partition_move.test index 35edbd75b5a..1a5c45ca0b1 100644 --- a/mysql-test/suite/s3/partition_move.test +++ b/mysql-test/suite/s3/partition_move.test @@ -1,3 +1,8 @@ +if (`SELECT @@s3_host_name <> "s3.amazonaws.com"`) +{ + skip The test is disabled for emulator environment due to MDEV-23648; +} + --source include/have_partition.inc --source include/have_innodb.inc --source include/have_s3.inc -- cgit v1.2.1 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: 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; -- cgit v1.2.1 From 0a224edc3e24b28a3b2abcd3538a3d7d63d667c6 Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Sat, 19 Sep 2020 00:08:38 +0300 Subject: 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 +++++- .../suite/mariabackup/innodb_redo_overwrite.opt | 1 + .../suite/mariabackup/innodb_redo_overwrite.result | 28 +++++++++ .../suite/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 -- cgit v1.2.1 From 6c4c88dbb899adf4a7a3c9313a0e705c660b6994 Mon Sep 17 00:00:00 2001 From: Vlad Lesin Date: Mon, 21 Sep 2020 12:52:44 +0300 Subject: 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) -- cgit v1.2.1 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: Fix try. --- mysql-test/suite/galera_3nodes/galera_2x3nodes.cnf | 6 ++ .../galera_3nodes/r/galera_gtid_2_cluster.result | 76 +++++++++++++++++++++- .../galera_3nodes/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; + -- cgit v1.2.1 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: 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 -- cgit v1.2.1 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: 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(); -- cgit v1.2.1 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: 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. --- .../suite/encryption/r/create_or_replace.result | 26 ---- .../encryption/r/create_or_replace_big.result | 19 +++ .../suite/encryption/t/create_or_replace.opt | 1 - .../suite/encryption/t/create_or_replace.test | 142 --------------------- .../suite/encryption/t/create_or_replace_big.opt | 1 + .../suite/encryption/t/create_or_replace_big.test | 86 +++++++++++++ 6 files changed, 106 insertions(+), 169 deletions(-) delete mode 100644 mysql-test/suite/encryption/r/create_or_replace.result create mode 100644 mysql-test/suite/encryption/r/create_or_replace_big.result delete mode 100644 mysql-test/suite/encryption/t/create_or_replace.opt delete mode 100644 mysql-test/suite/encryption/t/create_or_replace.test create mode 100644 mysql-test/suite/encryption/t/create_or_replace_big.opt create mode 100644 mysql-test/suite/encryption/t/create_or_replace_big.test diff --git a/mysql-test/suite/encryption/r/create_or_replace.result b/mysql-test/suite/encryption/r/create_or_replace.result deleted file mode 100644 index 1671043b50d..00000000000 --- a/mysql-test/suite/encryption/r/create_or_replace.result +++ /dev/null @@ -1,26 +0,0 @@ -SET default_storage_engine = InnoDB; -CREATE TABLE t1 (pk INT PRIMARY KEY, c VARCHAR(256)); -CREATE TABLE t2 AS SELECT * FROM t1; -drop table t1,t2; -SET GLOBAL innodb_encryption_threads = 0; -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; -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; diff --git a/mysql-test/suite/encryption/r/create_or_replace_big.result b/mysql-test/suite/encryption/r/create_or_replace_big.result new file mode 100644 index 00000000000..87f56cc3e2c --- /dev/null +++ b/mysql-test/suite/encryption/r/create_or_replace_big.result @@ -0,0 +1,19 @@ +SET default_storage_engine = InnoDB; +CREATE TABLE t1 (pk INT PRIMARY KEY, c VARCHAR(256)); +CREATE TABLE t2 AS SELECT * FROM t1; +drop table t1,t2; +SET GLOBAL innodb_encryption_threads = 0; +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 ); +# 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.opt deleted file mode 100644 index 7d3f2da7971..00000000000 --- a/mysql-test/suite/encryption/t/create_or_replace.opt +++ /dev/null @@ -1 +0,0 @@ ---innodb-tablespaces-encryption diff --git a/mysql-test/suite/encryption/t/create_or_replace.test b/mysql-test/suite/encryption/t/create_or_replace.test deleted file mode 100644 index 3b2970e5162..00000000000 --- a/mysql-test/suite/encryption/t/create_or_replace.test +++ /dev/null @@ -1,142 +0,0 @@ ---source include/have_innodb.inc ---source include/have_file_key_management_plugin.inc ---source include/not_embedded.inc -# This is needed for longer testcase timeout at least P7/P8 ---source include/big_test.inc - -# -# MDEV-8164: Server crashes in pfs_mutex_enter_func after fil_crypt_is_closing or alike -# -SET default_storage_engine = InnoDB; - -CREATE TABLE t1 (pk INT PRIMARY KEY, c VARCHAR(256)); -CREATE TABLE t2 AS SELECT * FROM t1; - ---disable_abort_on_error ---disable_warnings ---disable_query_log - -let $i = 40; -while ($i) -{ -SET GLOBAL innodb_encrypt_tables = ON; -SET GLOBAL innodb_encryption_threads = 1; -CREATE OR REPLACE TABLE t1 AS SELECT * FROM t2; -CREATE OR REPLACE TABLE t2 AS SELECT * FROM t1; -SET GLOBAL innodb_encryption_rotation_iops = 100; -SET GLOBAL innodb_encrypt_tables = OFF; -CREATE OR REPLACE TABLE t2 AS SELECT * FROM t1; -CREATE OR REPLACE TABLE t1 AS SELECT * FROM t2; -dec $i; -} - ---enable_abort_on_error ---enable_warnings ---enable_query_log - -drop table t1,t2; -SET GLOBAL innodb_encryption_threads = 0; - -# -# 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_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) -{ - let $success=`SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0`; - if ($success) - { - let $cnt=0; - } - if (!$success) - { - real_sleep 1; - dec $cnt; - } -} -if (!$success) -{ - SELECT * FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION; - SHOW STATUS LIKE 'innodb_encryption%'; - -- die Timeout waiting for encryption threads -} ---echo # Success! - -SET GLOBAL innodb_encryption_threads = 0; -SET GLOBAL innodb_encrypt_tables = OFF; - -# Make sure that all dirty pages are flushed - --- source include/restart_mysqld.inc diff --git a/mysql-test/suite/encryption/t/create_or_replace_big.opt b/mysql-test/suite/encryption/t/create_or_replace_big.opt new file mode 100644 index 00000000000..7d3f2da7971 --- /dev/null +++ b/mysql-test/suite/encryption/t/create_or_replace_big.opt @@ -0,0 +1 @@ +--innodb-tablespaces-encryption diff --git a/mysql-test/suite/encryption/t/create_or_replace_big.test b/mysql-test/suite/encryption/t/create_or_replace_big.test new file mode 100644 index 00000000000..133bdfa3cb2 --- /dev/null +++ b/mysql-test/suite/encryption/t/create_or_replace_big.test @@ -0,0 +1,86 @@ +--source include/have_innodb.inc +--source include/have_file_key_management_plugin.inc +--source include/not_embedded.inc +# This is needed for longer testcase timeout at least P7/P8 +--source include/big_test.inc + +# +# MDEV-8164: Server crashes in pfs_mutex_enter_func after fil_crypt_is_closing or alike +# +SET default_storage_engine = InnoDB; + +CREATE TABLE t1 (pk INT PRIMARY KEY, c VARCHAR(256)); +CREATE TABLE t2 AS SELECT * FROM t1; + +--disable_abort_on_error +--disable_warnings +--disable_query_log + +let $i = 40; +while ($i) +{ +SET GLOBAL innodb_encrypt_tables = ON; +SET GLOBAL innodb_encryption_threads = 1; +CREATE OR REPLACE TABLE t1 AS SELECT * FROM t2; +CREATE OR REPLACE TABLE t2 AS SELECT * FROM t1; +SET GLOBAL innodb_encryption_rotation_iops = 100; +SET GLOBAL innodb_encrypt_tables = OFF; +CREATE OR REPLACE TABLE t2 AS SELECT * FROM t1; +CREATE OR REPLACE TABLE t1 AS SELECT * FROM t2; +dec $i; +} + +--enable_abort_on_error +--enable_warnings +--enable_query_log + +drop table t1,t2; +SET GLOBAL innodb_encryption_threads = 0; + +# +# 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 ); + +--echo # Wait max 10 min for key encryption threads to decrypt all spaces +let $cnt=600; +while ($cnt) +{ + let $success=`SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0`; + if ($success) + { + let $cnt=0; + } + if (!$success) + { + real_sleep 1; + dec $cnt; + } +} +if (!$success) +{ + SELECT * FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION; + SHOW STATUS LIKE 'innodb_encryption%'; + -- die Timeout waiting for encryption threads +} +--echo # Success! + +SET GLOBAL innodb_encryption_threads = 0; +SET GLOBAL innodb_encrypt_tables = OFF; + +DROP TABLE table0_int_autoinc, table1_int_autoinc, table10_int_autoinc; + +-- source include/restart_mysqld.inc -- cgit v1.2.1 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: 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; -- cgit v1.2.1 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: MDEV-23776: Add the reduced encryption.create_or_replace test This was forgotten in commit a9d8f5c1a55e03312211c637a1a916cc57573a73. --- .../suite/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 -- cgit v1.2.1 From 4c19227929b0d86616337585fb95a4bb8fe0d4b2 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 12 Dec 2017 11:24:39 +1100 Subject: 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= -- cgit v1.2.1 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: 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(); -- cgit v1.2.1 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: 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) { -- cgit v1.2.1 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: 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); -- cgit v1.2.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: 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 -- cgit v1.2.1 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: 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(); -- cgit v1.2.1 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: 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); } -- cgit v1.2.1 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: 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()) { -- cgit v1.2.1 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: 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; -- cgit v1.2.1 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: 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 -- cgit v1.2.1