diff options
author | Kentoku <kentokushiba@gmail.com> | 2019-03-04 07:12:32 +0900 |
---|---|---|
committer | Kentoku <kentokushiba@gmail.com> | 2019-03-05 07:15:25 +0900 |
commit | 60ed52fe9a5db04e10dd0d97da1f17961f413843 (patch) | |
tree | 7132f5b759c37648ec7b390e35819700c1cd5921 | |
parent | 4d37898f2d1d330e28756d5a9f4e75acbb0db508 (diff) | |
download | mariadb-git-60ed52fe9a5db04e10dd0d97da1f17961f413843.tar.gz |
MDEV-16249 CHECKSUM TABLE for a spider table is not parallel and saves all data in memory in the spider head by default
Add handler methods for pushing down checksum table with options.
44 files changed, 1138 insertions, 85 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index c13b26cdb86..f848b4b8de6 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -8373,7 +8373,20 @@ void ha_partition::get_dynamic_partition_info(PARTITION_STATS *stat_info, stat_info->check_time= file->stats.check_time; stat_info->check_sum= 0; if (file->ha_table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM)) - stat_info->check_sum= file->checksum(); + { + stat_info->check_sum_null= FALSE; + if (file->ha_table_flags() & HA_HAS_CHECKSUM_EXTENDED) + { + ulonglong crc= 0; + if (!file->pre_checksum_opt(0) && + !file->checksum_opt(&crc, 0)) + stat_info->check_sum= crc; + else + stat_info->check_sum_null= TRUE; + } + else + stat_info->check_sum= file->checksum(); + } return; } @@ -10613,6 +10626,41 @@ uint ha_partition::checksum() const DBUG_RETURN(sum); } +bool ha_partition::checksum_opt(ulonglong *crc, uint flags) +{ + ha_checksum sum= 0; + + DBUG_ENTER("ha_partition::checksum_opt"); + if ((table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM))) + { + handler **file= m_file; + do + { + ulonglong child_crc= 0; + if ((*file)->checksum_opt(&child_crc, flags)) + DBUG_RETURN(TRUE); + sum+= child_crc; + } while (*(++file)); + } + *crc= (ulonglong) sum; + DBUG_RETURN(FALSE); +} + +bool ha_partition::pre_checksum_opt(uint flags) +{ + DBUG_ENTER("ha_partition::pre_checksum_opt"); + if ((table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM))) + { + handler **file= m_file; + do + { + if ((*file)->pre_checksum_opt(flags)) + DBUG_RETURN(TRUE); + } while (*(++file)); + } + DBUG_RETURN(FALSE); +} + /**************************************************************************** MODULE enable/disable indexes diff --git a/sql/ha_partition.h b/sql/ha_partition.h index f385ceb6d3b..3738ef21461 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -1439,6 +1439,8 @@ public: virtual int net_read_dump(NET* net); */ virtual uint checksum() const; + virtual bool checksum_opt(ulonglong *crc, uint flags); + virtual bool pre_checksum_opt(uint flags); /* Enabled keycache for performance reasons, WL#4571 */ virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt); virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt); diff --git a/sql/handler.cc b/sql/handler.cc index 0269e85b123..e4b5802ad57 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -5001,7 +5001,20 @@ void handler::get_dynamic_partition_info(PARTITION_STATS *stat_info, stat_info->check_time= stats.check_time; stat_info->check_sum= 0; if (table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM)) - stat_info->check_sum= checksum(); + { + stat_info->check_sum_null= FALSE; + if (table_flags() & HA_HAS_CHECKSUM_EXTENDED) + { + ulonglong crc= 0; + if (!pre_checksum_opt(0) && + !checksum_opt(&crc, 0)) + stat_info->check_sum= crc; + else + stat_info->check_sum_null= TRUE; + } + else + stat_info->check_sum= checksum(); + } return; } diff --git a/sql/handler.h b/sql/handler.h index 8bee07c1287..1157c37df31 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -323,7 +323,10 @@ enum enum_alter_inplace_result { /** whether every data field explicitly stores length (holds for InnoDB ROW_FORMAT=REDUNDANT) */ #define HA_EXTENDED_TYPES_CONVERSION (1ULL << 57) -#define HA_LAST_TABLE_FLAG HA_EXTENDED_TYPES_CONVERSION + +/* Has checksum extended */ +#define HA_HAS_CHECKSUM_EXTENDED (1ULL << 59) +#define HA_LAST_TABLE_FLAG HA_HAS_CHECKSUM_EXTENDED /* bits in index_flags(index_number) for what you can do with index */ #define HA_READ_NEXT 1 /* TODO really use this flag */ @@ -1925,6 +1928,7 @@ typedef struct { time_t check_time; time_t update_time; ulonglong check_sum; + bool check_sum_null; } PARTITION_STATS; #define UNDEF_NODEGROUP 65535 @@ -3922,6 +3926,8 @@ public: virtual uint min_record_length(uint options) const { return 1; } virtual uint checksum() const { return 0; } + virtual bool checksum_opt(ulonglong *crc, uint flags) { return TRUE; } + virtual bool pre_checksum_opt(uint flags) { return FALSE; } virtual bool is_crashed() const { return 0; } virtual bool auto_repair(int error) const { return 0; } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 5e768ff31f7..a8bfffa251e 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -5631,8 +5631,21 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables, } if (file->ha_table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM)) { - table->field[18]->store((longlong) file->checksum(), TRUE); - table->field[18]->set_notnull(); + if (file->ha_table_flags() & HA_HAS_CHECKSUM_EXTENDED) + { + ulonglong crc; + if (!file->pre_checksum_opt(0) && + !file->checksum_opt(&crc, 0)) + { + table->field[18]->store((longlong) crc, TRUE); + table->field[18]->set_notnull(); + } + } + else + { + table->field[18]->store((longlong) file->checksum(), TRUE); + table->field[18]->set_notnull(); + } } } /* If table is a temporary table */ @@ -7262,7 +7275,8 @@ static void store_schema_partitions_record(THD *thd, TABLE *schema_table, table->field[20]->store_time(&time); table->field[20]->set_notnull(); } - if (file->ha_table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM)) + if ((file->ha_table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM)) && + !stat_info.check_sum_null) { table->field[21]->store((longlong) stat_info.check_sum, TRUE); table->field[21]->set_notnull(); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index fbf052249b4..5f54c8cd679 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -10801,10 +10801,22 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, else { /* Call ->checksum() if the table checksum matches 'old_mode' settings */ - if (!(check_opt->flags & T_EXTEND) && + if ((!(check_opt->flags & T_EXTEND) || (t->file->ha_table_flags() & HA_HAS_CHECKSUM_EXTENDED)) && (((t->file->ha_table_flags() & HA_HAS_OLD_CHECKSUM) && thd->variables.old_mode) || ((t->file->ha_table_flags() & HA_HAS_NEW_CHECKSUM) && !thd->variables.old_mode))) - protocol->store((ulonglong)t->file->checksum()); + { + if (t->file->ha_table_flags() & HA_HAS_CHECKSUM_EXTENDED) + { + ulonglong crc= 0; + if (t->file->pre_checksum_opt(check_opt->flags) || + t->file->checksum_opt(&crc, check_opt->flags)) + protocol->store_null(); + else + protocol->store(crc); + } + else + protocol->store((ulonglong)t->file->checksum()); + } else if (check_opt->flags & T_QUICK) protocol->store_null(); else diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index d10dcd98660..17d4831344d 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -1,4 +1,5 @@ -/* Copyright (C) 2008-2018 Kentoku Shiba +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -116,7 +117,7 @@ ha_spider::ha_spider( use_fields = FALSE; #endif use_pre_call = FALSE; - use_pre_records = FALSE; + use_pre_action = FALSE; #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS do_direct_update = FALSE; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) @@ -228,7 +229,7 @@ ha_spider::ha_spider( use_fields = FALSE; #endif use_pre_call = FALSE; - use_pre_records = FALSE; + use_pre_action = FALSE; #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS do_direct_update = FALSE; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) @@ -1805,7 +1806,7 @@ int ha_spider::reset() high_priority = FALSE; insert_delayed = FALSE; use_pre_call = FALSE; - use_pre_records = FALSE; + use_pre_action = FALSE; pre_bitmap_checked = FALSE; bulk_insert = FALSE; clone_bitmap_init = FALSE; @@ -9323,11 +9324,12 @@ int ha_spider::pre_records() result_list.casual_read[search_link_idx] = spider_param_casual_read(thd, share->casual_read); } - if ((error_num = spider_db_show_records(this, search_link_idx, TRUE))) + if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_RECORDS, this, + search_link_idx, TRUE))) { DBUG_RETURN(check_error_mode(error_num)); } - use_pre_records = TRUE; + use_pre_action = TRUE; DBUG_RETURN(0); } @@ -9339,14 +9341,14 @@ ha_rows ha_spider::records() DBUG_PRINT("info",("spider this=%p", this)); if (sql_command == SQLCOM_ALTER_TABLE) { - use_pre_records = FALSE; + use_pre_action = FALSE; DBUG_RETURN(0); } if (!(share->additional_table_flags & HA_HAS_RECORDS) && !this->result_list.direct_limit_offset) { DBUG_RETURN(handler::records()); } - if (!use_pre_records && !this->result_list.direct_limit_offset) + if (!use_pre_action && !this->result_list.direct_limit_offset) { THD *thd = trx->thd; if ( @@ -9357,17 +9359,81 @@ ha_rows ha_spider::records() spider_param_casual_read(thd, share->casual_read); } } - if ((error_num = spider_db_show_records(this, search_link_idx, FALSE))) + if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_RECORDS, this, + search_link_idx, FALSE))) { - use_pre_records = FALSE; + use_pre_action = FALSE; check_error_mode(error_num); DBUG_RETURN(HA_POS_ERROR); } - use_pre_records = FALSE; + use_pre_action = FALSE; share->records = table_rows; DBUG_RETURN(table_rows); } +#ifdef HA_HAS_CHECKSUM_EXTENDED +bool ha_spider::pre_checksum_opt( + uint flags +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::pre_checksum_opt"); + DBUG_PRINT("info",("spider this=%p", this)); + THD *thd = trx->thd; + if ( + spider_param_sync_autocommit(thd) && + (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) + ) { + result_list.casual_read[search_link_idx] = + spider_param_casual_read(thd, share->casual_read); + } + action_flags = flags; + if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE, this, + search_link_idx, TRUE))) + { + DBUG_RETURN((check_error_mode(error_num) != 0)); + } + use_pre_action = TRUE; + DBUG_RETURN(FALSE); +} + +bool ha_spider::checksum_opt( + ulonglong *crc, + uint flags +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::checksum_opt"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!use_pre_action && !this->result_list.direct_limit_offset) + { + THD *thd = trx->thd; + if ( + spider_param_sync_autocommit(thd) && + (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) + ) { + result_list.casual_read[search_link_idx] = + spider_param_casual_read(thd, share->casual_read); + } + } + action_flags = flags; + if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE, this, + search_link_idx, FALSE))) + { + use_pre_action = FALSE; + check_error_mode(error_num); + DBUG_RETURN(TRUE); + } + use_pre_action = FALSE; + if (checksum_null) + { + DBUG_RETURN(TRUE); + } + *crc = checksum_val; + DBUG_RETURN(FALSE); +} +#endif + const char *ha_spider::table_type() const { DBUG_ENTER("ha_spider::table_type"); diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h index d33d9a3a7dc..9e0f1aadc63 100644 --- a/storage/spider/ha_spider.h +++ b/storage/spider/ha_spider.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2008-2018 Kentoku Shiba +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -170,7 +171,7 @@ public: bool high_priority; bool insert_delayed; bool use_pre_call; - bool use_pre_records; + bool use_pre_action; bool pre_bitmap_checked; enum thr_lock_type lock_type; int lock_mode; @@ -243,6 +244,11 @@ public: SPIDER_ITEM_HLD *direct_aggregate_item_current; #endif ha_rows table_rows; +#ifdef HA_HAS_CHECKSUM_EXTENDED + ulonglong checksum_val; + bool checksum_null; + uint action_flags; +#endif /* for fulltext search */ bool ft_init_and_first; @@ -512,6 +518,15 @@ public: int check_crd(); int pre_records(); ha_rows records(); +#ifdef HA_HAS_CHECKSUM_EXTENDED + bool pre_checksum_opt( + uint flags + ); + bool checksum_opt( + ulonglong *crc, + uint flags + ); +#endif const char *table_type() const; ulonglong table_flags() const; const char *index_type( diff --git a/storage/spider/mysql-test/spider/bugfix/include/checksum_table_with_quick_mode_3_init.inc b/storage/spider/mysql-test/spider/bugfix/include/checksum_table_with_quick_mode_3_init.inc index bf2d9163b9a..123410380ab 100644 --- a/storage/spider/mysql-test/spider/bugfix/include/checksum_table_with_quick_mode_3_init.inc +++ b/storage/spider/mysql-test/spider/bugfix/include/checksum_table_with_quick_mode_3_init.inc @@ -21,7 +21,7 @@ let $CHILD2_1_CREATE_TABLES= let $CHILD2_1_SELECT_TABLES= SELECT pkey FROM tbl_a ORDER BY pkey; let $CHILD2_1_SELECT_ARGUMENT1= - SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'; --connection master_1 set @old_spider_quick_mode= @@spider_quick_mode; set session spider_quick_mode= 3; diff --git a/storage/spider/mysql-test/spider/bugfix/r/checksum_table_with_quick_mode_3.result b/storage/spider/mysql-test/spider/bugfix/r/checksum_table_with_quick_mode_3.result index eae4895411e..bd423d934f5 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/checksum_table_with_quick_mode_3.result +++ b/storage/spider/mysql-test/spider/bugfix/r/checksum_table_with_quick_mode_3.result @@ -44,10 +44,10 @@ CHECKSUM TABLE tbl_a EXTENDED; Table Checksum auto_test_local.tbl_a 1061386331 connection child2_1; -SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'; argument -select `pkey` from `auto_test_remote`.`tbl_a` -SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %' +checksum table `auto_test_remote`.`tbl_a` extended +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %' SELECT pkey FROM tbl_a ORDER BY pkey; pkey 0 diff --git a/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_deinit.inc b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_deinit.inc new file mode 100644 index 00000000000..52b0625ed9a --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_deinit.inc @@ -0,0 +1,16 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--connection master_1 +set session spider_bgs_mode= @old_spider_bgs_mode; +--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/feature/include/checksum_table_parallel_extended_deinit.inc b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_extended_deinit.inc new file mode 100644 index 00000000000..799bd983393 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_extended_deinit.inc @@ -0,0 +1 @@ +--source checksum_table_parallel_deinit.inc diff --git a/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_extended_init.inc b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_extended_init.inc new file mode 100644 index 00000000000..f17a532d53b --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_extended_init.inc @@ -0,0 +1,2 @@ +--source checksum_table_parallel_init.inc +--let $MASTER_1_CHECKSUM_TABLE= CHECKSUM TABLE tbl_a EXTENDED diff --git a/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_init.inc b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_init.inc new file mode 100644 index 00000000000..7aab82515a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_init.inc @@ -0,0 +1,53 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +if (!$HAVE_PARTITION) +{ + --source checksum_table_parallel_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a"' + PARTITION BY KEY(pkey) ( + PARTITION pt1 COMMENT='srv "s_2_1"', + PARTITION pt2 COMMENT='srv "s_2_2"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'; +--connection master_1 +set @old_spider_bgs_mode= @@spider_bgs_mode; +set session spider_bgs_mode= 1; diff --git a/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_no_opt_deinit.inc b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_no_opt_deinit.inc new file mode 100644 index 00000000000..799bd983393 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_no_opt_deinit.inc @@ -0,0 +1 @@ +--source checksum_table_parallel_deinit.inc diff --git a/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_no_opt_init.inc b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_no_opt_init.inc new file mode 100644 index 00000000000..230b6432a01 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_no_opt_init.inc @@ -0,0 +1,2 @@ +--source checksum_table_parallel_init.inc +--let $MASTER_1_CHECKSUM_TABLE= CHECKSUM TABLE tbl_a diff --git a/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_quick_deinit.inc b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_quick_deinit.inc new file mode 100644 index 00000000000..799bd983393 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_quick_deinit.inc @@ -0,0 +1 @@ +--source checksum_table_parallel_deinit.inc diff --git a/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_quick_init.inc b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_quick_init.inc new file mode 100644 index 00000000000..66f6ecbe0ef --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_quick_init.inc @@ -0,0 +1,2 @@ +--source checksum_table_parallel_init.inc +--let $MASTER_1_CHECKSUM_TABLE= CHECKSUM TABLE tbl_a QUICK diff --git a/storage/spider/mysql-test/spider/feature/r/checksum_table_parallel_extended.result b/storage/spider/mysql-test/spider/feature/r/checksum_table_parallel_extended.result new file mode 100644 index 00000000000..34587052181 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/r/checksum_table_parallel_extended.result @@ -0,0 +1,130 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_bgs_mode= @@spider_bgs_mode; +set session spider_bgs_mode= 1; + +this test is for MDEV-16967 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_1_2; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +connection child2_2_2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +LOCK TABLE tbl_a WRITE; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +LOCK TABLE tbl_a WRITE; +connection master_1; +CHECKSUM TABLE tbl_a EXTENDED; +connection child2_1_2; +SELECT SLEEP(1); +SLEEP(1) +0 +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'; +argument +checksum table `auto_test_remote`.`tbl_a` extended +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %' +connection child2_2_2; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'; +argument +checksum table `auto_test_remote2`.`tbl_a` extended +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %' +connection child2_1; +UNLOCK TABLES; +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +1 +3 +5 +7 +9 +11 +13 +15 +17 +19 +21 +23 +25 +27 +29 +connection child2_2; +UNLOCK TABLES; +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +2 +4 +6 +8 +10 +12 +14 +16 +18 +20 +22 +24 +26 +28 +connection master_1; +Table Checksum +auto_test_local.tbl_a 1061386331 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_bgs_mode= @old_spider_bgs_mode; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/feature/r/checksum_table_parallel_no_opt.result b/storage/spider/mysql-test/spider/feature/r/checksum_table_parallel_no_opt.result new file mode 100644 index 00000000000..e95551dba08 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/r/checksum_table_parallel_no_opt.result @@ -0,0 +1,130 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_bgs_mode= @@spider_bgs_mode; +set session spider_bgs_mode= 1; + +this test is for MDEV-16967 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_1_2; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +connection child2_2_2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +LOCK TABLE tbl_a WRITE; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +LOCK TABLE tbl_a WRITE; +connection master_1; +CHECKSUM TABLE tbl_a; +connection child2_1_2; +SELECT SLEEP(1); +SLEEP(1) +0 +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'; +argument +checksum table `auto_test_remote`.`tbl_a` +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %' +connection child2_2_2; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'; +argument +checksum table `auto_test_remote2`.`tbl_a` +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %' +connection child2_1; +UNLOCK TABLES; +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +1 +3 +5 +7 +9 +11 +13 +15 +17 +19 +21 +23 +25 +27 +29 +connection child2_2; +UNLOCK TABLES; +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +2 +4 +6 +8 +10 +12 +14 +16 +18 +20 +22 +24 +26 +28 +connection master_1; +Table Checksum +auto_test_local.tbl_a 1061386331 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_bgs_mode= @old_spider_bgs_mode; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/feature/r/checksum_table_parallel_quick.result b/storage/spider/mysql-test/spider/feature/r/checksum_table_parallel_quick.result new file mode 100644 index 00000000000..82acb94626b --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/r/checksum_table_parallel_quick.result @@ -0,0 +1,130 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_bgs_mode= @@spider_bgs_mode; +set session spider_bgs_mode= 1; + +this test is for MDEV-16967 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_1_2; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +connection child2_2_2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +LOCK TABLE tbl_a WRITE; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +LOCK TABLE tbl_a WRITE; +connection master_1; +CHECKSUM TABLE tbl_a QUICK; +connection child2_1_2; +SELECT SLEEP(1); +SLEEP(1) +0 +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'; +argument +checksum table `auto_test_remote`.`tbl_a` quick +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %' +connection child2_2_2; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'; +argument +checksum table `auto_test_remote2`.`tbl_a` quick +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %' +connection child2_1; +UNLOCK TABLES; +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +1 +3 +5 +7 +9 +11 +13 +15 +17 +19 +21 +23 +25 +27 +29 +connection child2_2; +UNLOCK TABLES; +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +2 +4 +6 +8 +10 +12 +14 +16 +18 +20 +22 +24 +26 +28 +connection master_1; +Table Checksum +auto_test_local.tbl_a NULL + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_bgs_mode= @old_spider_bgs_mode; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel.inc b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel.inc new file mode 100644 index 00000000000..13e5053d64c --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel.inc @@ -0,0 +1,107 @@ +--echo +--echo this test is for MDEV-16967 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--connection child2_1_2 +USE auto_test_remote; + +--connection child2_2 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +--connection child2_2_2 +USE auto_test_remote2; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +--disable_query_log +echo CHILD2_2_CREATE_TABLES; +eval $CHILD2_2_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; +LOCK TABLE tbl_a WRITE; + +--connection child2_2 +TRUNCATE TABLE mysql.general_log; +LOCK TABLE tbl_a WRITE; + +--connection master_1 +send_eval $MASTER_1_CHECKSUM_TABLE; + +--connection child2_1_2 +SELECT SLEEP(1); +eval $CHILD2_1_SELECT_ARGUMENT1; + +--connection child2_2_2 +eval $CHILD2_2_SELECT_ARGUMENT1; + +--connection child2_1 +UNLOCK TABLES; +eval $CHILD2_1_SELECT_TABLES; + +--connection child2_2 +UNLOCK TABLES; +eval $CHILD2_2_SELECT_TABLES; + +--connection master_1 +reap; + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--connection child2_2 +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings diff --git a/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_extended.cnf b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_extended.cnf new file mode 100644 index 00000000000..e0ffb99c38e --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_extended.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/feature/t/checksum_table_parallel_extended.test b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_extended.test new file mode 100644 index 00000000000..871e1e868ad --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_extended.test @@ -0,0 +1,5 @@ +--source ../include/checksum_table_parallel_extended_init.inc +--source checksum_table_parallel.inc +--source ../include/checksum_table_parallel_extended_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_no_opt.cnf b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_no_opt.cnf new file mode 100644 index 00000000000..e0ffb99c38e --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_no_opt.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/feature/t/checksum_table_parallel_no_opt.test b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_no_opt.test new file mode 100644 index 00000000000..0352d598df6 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_no_opt.test @@ -0,0 +1,5 @@ +--source ../include/checksum_table_parallel_no_opt_init.inc +--source checksum_table_parallel.inc +--source ../include/checksum_table_parallel_no_opt_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_quick.cnf b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_quick.cnf new file mode 100644 index 00000000000..e0ffb99c38e --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_quick.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/feature/t/checksum_table_parallel_quick.test b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_quick.test new file mode 100644 index 00000000000..f08f782e7c0 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_quick.test @@ -0,0 +1,5 @@ +--source ../include/checksum_table_parallel_quick_init.inc +--source checksum_table_parallel.inc +--source ../include/checksum_table_parallel_quick_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/include/checksum_table_with_quick_mode_3_init.inc b/storage/spider/mysql-test/spider/include/checksum_table_with_quick_mode_3_init.inc index 9ec61a1cb77..0bb12d8f874 100644 --- a/storage/spider/mysql-test/spider/include/checksum_table_with_quick_mode_3_init.inc +++ b/storage/spider/mysql-test/spider/include/checksum_table_with_quick_mode_3_init.inc @@ -21,7 +21,7 @@ let $CHILD2_1_CREATE_TABLES= let $CHILD2_1_SELECT_TABLES= SELECT pkey FROM tbl_a ORDER BY pkey; let $CHILD2_1_SELECT_ARGUMENT1= - SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'; --let $OUTPUT_CHILD_GROUP2_BACKUP= $OUTPUT_CHILD_GROUP2 --let $OUTPUT_CHILD_GROUP2= 1 --let $USE_GENERAL_LOG_BACKUP= $USE_GENERAL_LOG diff --git a/storage/spider/mysql-test/spider/r/checksum_table_with_quick_mode_3.result b/storage/spider/mysql-test/spider/r/checksum_table_with_quick_mode_3.result index ee8e1f056f3..2fe86099bc2 100644 --- a/storage/spider/mysql-test/spider/r/checksum_table_with_quick_mode_3.result +++ b/storage/spider/mysql-test/spider/r/checksum_table_with_quick_mode_3.result @@ -45,10 +45,10 @@ CHECKSUM TABLE tbl_a EXTENDED; Table Checksum auto_test_local.tbl_a 1061386331 connection child2_1; -SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'; argument -select `pkey` from `auto_test_remote`.`tbl_a` -SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %' +checksum table `auto_test_remote`.`tbl_a` extended +SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %' SELECT pkey FROM tbl_a ORDER BY pkey; pkey 0 diff --git a/storage/spider/mysql-test/spider/t/connect_child2_1.inc b/storage/spider/mysql-test/spider/t/connect_child2_1.inc index cd9b0c9ca9b..15e26031527 100644 --- a/storage/spider/mysql-test/spider/t/connect_child2_1.inc +++ b/storage/spider/mysql-test/spider/t/connect_child2_1.inc @@ -1 +1,2 @@ --connect (child2_1, localhost, root, , , $CHILD2_1_MYPORT, $CHILD2_1_MYSOCK) +--connect (child2_1_2, localhost, root, , , $CHILD2_1_MYPORT, $CHILD2_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/t/connect_child2_2.inc b/storage/spider/mysql-test/spider/t/connect_child2_2.inc index e145f66b630..75a50821ea7 100644 --- a/storage/spider/mysql-test/spider/t/connect_child2_2.inc +++ b/storage/spider/mysql-test/spider/t/connect_child2_2.inc @@ -1 +1,2 @@ --connect (child2_2, localhost, root, , , $CHILD2_2_MYPORT, $CHILD2_2_MYSOCK) +--connect (child2_2_2, localhost, root, , , $CHILD2_2_MYPORT, $CHILD2_2_MYSOCK) diff --git a/storage/spider/mysql-test/spider/t/test_deinit.inc b/storage/spider/mysql-test/spider/t/test_deinit.inc index 989bde26d3c..5a82b43ce0f 100644 --- a/storage/spider/mysql-test/spider/t/test_deinit.inc +++ b/storage/spider/mysql-test/spider/t/test_deinit.inc @@ -10,10 +10,12 @@ if ($USE_CHILD_GROUP2) --connection child2_1 --source ../include/deinit_child2_1.inc --disconnect child2_1 + --disconnect child2_1_2 --echo child2_2 --connection child2_2 --source ../include/deinit_child2_2.inc --disconnect child2_2 + --disconnect child2_2_2 --echo child2_3 --connection child2_3 --source ../include/deinit_child2_3.inc diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index ba59acd64bc..908a20e2d20 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -2802,23 +2802,20 @@ void *spider_bg_conn_action( { switch (conn->bg_simple_action) { - case SPIDER_BG_SIMPLE_CONNECT: + case SPIDER_SIMPLE_CONNECT: conn->db_conn->bg_connect(); break; - case SPIDER_BG_SIMPLE_DISCONNECT: + case SPIDER_SIMPLE_DISCONNECT: conn->db_conn->bg_disconnect(); break; - case SPIDER_BG_SIMPLE_RECORDS: - DBUG_PRINT("info",("spider bg simple records")); + default: spider = (ha_spider*) conn->bg_target; *conn->bg_error_num = - spider->dbton_handler[conn->dbton_id]-> - show_records(conn->link_idx); - break; - default: + spider_db_simple_action(conn->bg_simple_action, + spider->dbton_handler[conn->dbton_id], conn->link_idx); break; } - conn->bg_simple_action = SPIDER_BG_SIMPLE_NO_ACTION; + conn->bg_simple_action = SPIDER_SIMPLE_NO_ACTION; if (conn->bg_caller_wait) { pthread_mutex_lock(&conn->bg_conn_sync_mutex); diff --git a/storage/spider/spd_conn.h b/storage/spider/spd_conn.h index 0a9f99a1853..a382590f608 100644 --- a/storage/spider/spd_conn.h +++ b/storage/spider/spd_conn.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2008-2018 Kentoku Shiba +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,10 +18,13 @@ #define SPIDER_LOCK_MODE_SHARED 1 #define SPIDER_LOCK_MODE_EXCLUSIVE 2 -#define SPIDER_BG_SIMPLE_NO_ACTION 0 -#define SPIDER_BG_SIMPLE_CONNECT 1 -#define SPIDER_BG_SIMPLE_DISCONNECT 2 -#define SPIDER_BG_SIMPLE_RECORDS 3 +#define SPIDER_SIMPLE_NO_ACTION 0 +#define SPIDER_SIMPLE_CONNECT 1 +#define SPIDER_SIMPLE_DISCONNECT 2 +#define SPIDER_SIMPLE_RECORDS 3 +#ifdef HA_HAS_CHECKSUM_EXTENDED +#define SPIDER_SIMPLE_CHECKSUM_TABLE 4 +#endif uchar *spider_conn_get_key( SPIDER_CONN *conn, diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index 50e667c7009..e0a453da5fc 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -5653,7 +5653,38 @@ int spider_db_show_table_status( DBUG_RETURN(error_num); } -int spider_db_show_records( +int spider_db_simple_action( + uint simple_action, + spider_db_handler *db_handler, + int link_idx +) { + int error_num; + DBUG_ENTER("spider_db_simple_action"); + switch (simple_action) + { + case SPIDER_SIMPLE_RECORDS: + DBUG_PRINT("info",("spider simple records")); + error_num = db_handler->show_records( + link_idx + ); + break; +#ifdef HA_HAS_CHECKSUM_EXTENDED + case SPIDER_SIMPLE_CHECKSUM_TABLE: + DBUG_PRINT("info",("spider simple checksum_table")); + error_num = db_handler->checksum_table( + link_idx + ); + break; +#endif + default: + DBUG_ASSERT(0); + break; + } + DBUG_RETURN(error_num); +} + +int spider_db_simple_action( + uint simple_action, ha_spider *spider, int link_idx, bool pre_call @@ -5661,7 +5692,7 @@ int spider_db_show_records( int error_num; THD *thd = spider->trx->thd; SPIDER_CONN *conn; - DBUG_ENTER("spider_db_show_records"); + DBUG_ENTER("spider_db_simple_action"); if (pre_call) { if (spider_param_bgs_mode(thd, spider->share->bgs_mode)) @@ -5674,18 +5705,20 @@ int spider_db_show_records( conn = spider->conns[link_idx]; if (!(error_num = spider_create_conn_thread(conn))) { - spider_bg_conn_simple_action(conn, SPIDER_BG_SIMPLE_RECORDS, FALSE, + spider_bg_conn_simple_action(conn, simple_action, FALSE, spider, link_idx, (int *) &spider->result_list.bgs_error); } } else { conn = spider->conns[link_idx]; - error_num = spider->dbton_handler[conn->dbton_id]->show_records( + error_num = spider_db_simple_action( + simple_action, + spider->dbton_handler[conn->dbton_id], link_idx ); } } else { conn = spider->conns[link_idx]; - if (spider->use_pre_records) + if (spider->use_pre_action) { if (spider_param_bgs_mode(thd, spider->share->bgs_mode)) { @@ -5699,7 +5732,9 @@ int spider_db_show_records( error_num = 0; } } else { - error_num = spider->dbton_handler[conn->dbton_id]->show_records( + error_num = spider_db_simple_action( + simple_action, + spider->dbton_handler[conn->dbton_id], link_idx ); } diff --git a/storage/spider/spd_db_conn.h b/storage/spider/spd_db_conn.h index bf09d672685..529e7843689 100644 --- a/storage/spider/spd_db_conn.h +++ b/storage/spider/spd_db_conn.h @@ -692,7 +692,14 @@ int spider_db_show_table_status( uint flag ); -int spider_db_show_records( +int spider_db_simple_action( + uint simple_action, + spider_db_handler *db_handler, + int link_idx +); + +int spider_db_simple_action( + uint simple_action, ha_spider *spider, int link_idx, bool pre_call diff --git a/storage/spider/spd_db_include.cc b/storage/spider/spd_db_include.cc index a2f062e225b..c57fe2b285e 100644 --- a/storage/spider/spd_db_include.cc +++ b/storage/spider/spd_db_include.cc @@ -3826,6 +3826,16 @@ spider_db_result::spider_db_result( DBUG_VOID_RETURN; } +#ifdef HA_HAS_CHECKSUM_EXTENDED +int spider_db_result::fetch_table_checksum( + ha_spider *spider +) { + DBUG_ENTER("spider_db_result::fetch_table_checksum"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} +#endif + spider_db_conn::spider_db_conn( SPIDER_CONN *in_conn ) : conn(in_conn), dbton_id(in_conn->dbton_id) @@ -3834,3 +3844,20 @@ spider_db_conn::spider_db_conn( DBUG_PRINT("info",("spider this=%p", this)); DBUG_VOID_RETURN; } + +#ifdef HA_HAS_CHECKSUM_EXTENDED +bool spider_db_share::checksum_support() +{ + DBUG_ENTER("spider_db_share::checksum_support"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_handler::checksum_table( + int link_idx +) { + DBUG_ENTER("spider_db_handler::checksum_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} +#endif diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h index abff3f3a6e6..f176c7782c9 100644 --- a/storage/spider/spd_db_include.h +++ b/storage/spider/spd_db_include.h @@ -1112,6 +1112,11 @@ public: int mode, ha_rows &records ) = 0; +#ifdef HA_HAS_CHECKSUM_EXTENDED + virtual int fetch_table_checksum( + ha_spider *spider + ); +#endif virtual int fetch_table_cardinality( int mode, TABLE *table, @@ -1381,6 +1386,9 @@ public: spider_string *str ) = 0; #endif +#ifdef HA_HAS_CHECKSUM_EXTENDED + virtual bool checksum_support(); +#endif }; class spider_db_handler @@ -1753,6 +1761,11 @@ public: virtual int show_records( int link_idx ) = 0; +#ifdef HA_HAS_CHECKSUM_EXTENDED + virtual int checksum_table( + int link_idx + ); +#endif virtual int show_last_insert_id( int link_idx, ulonglong &last_insert_id diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index fe8793a2ec0..a7dbafe929e 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -153,6 +153,15 @@ static const char *name_quote_str = SPIDER_SQL_NAME_QUOTE_STR; #define SPIDER_SQL_USING_HASH_LEN sizeof(SPIDER_SQL_USING_HASH_STR) - 1 #endif +#define SPIDER_SQL_SHOW_RECORDS_RECORDS_POS 0 +#define SPIDER_SQL_EXPLAIN_SELECT_RECORDS_POS 8 + +#ifdef HA_HAS_CHECKSUM_EXTENDED +#define SPIDER_SQL_CHECKSUM_CHECKSUM_POS 1 +#define SPIDER_SQL_CHECKSUM_TABLE_STR "checksum table " +#define SPIDER_SQL_CHECKSUM_TABLE_LEN (sizeof(SPIDER_SQL_CHECKSUM_TABLE_STR) - 1) +#endif + #define SPIDER_SQL_LIKE_STR " like " #define SPIDER_SQL_LIKE_LEN (sizeof(SPIDER_SQL_LIKE_STR) - 1) #define SPIDER_SQL_LIMIT1_STR " limit 1" @@ -1242,13 +1251,14 @@ int spider_db_mbase_result::fetch_table_status( DBUG_RETURN(0); } -int spider_db_mbase_result::fetch_table_records( - int mode, - ha_rows &records +int spider_db_mbase_result::fetch_simple_action( + uint simple_action, + uint position, + void *param ) { int error_num; MYSQL_ROW mysql_row; - DBUG_ENTER("spider_db_mbase_result::fetch_table_records"); + DBUG_ENTER("spider_db_mbase_result::fetch_simple_action"); DBUG_PRINT("info",("spider this=%p", this)); if (!(mysql_row = mysql_fetch_row(db_result))) { @@ -1261,32 +1271,78 @@ int spider_db_mbase_result::fetch_table_records( } DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } - if (mode == 1) + if (num_fields() <= position) { - if (mysql_row[0]) - { - records = - (ha_rows) my_strtoll10(mysql_row[0], (char**) NULL, &error_num); - } else - records = (ha_rows) 0; - DBUG_PRINT("info", - ("spider records=%lld", records)); - } else { - if (num_fields() != 10) + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + switch (simple_action) + { + case SPIDER_SIMPLE_RECORDS: { - DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + ha_rows *records = (ha_rows *) param; + if (mysql_row[position]) + { + *records = + (ha_rows) my_strtoll10(mysql_row[position], (char**) NULL, + &error_num); + } else { + *records = (ha_rows) 0; + } + DBUG_PRINT("info", ("spider records=%lld", *records)); + break; } - - if (mysql_row[8]) +#ifdef HA_HAS_CHECKSUM_EXTENDED + case SPIDER_SIMPLE_CHECKSUM_TABLE: { - records = - (ha_rows) my_strtoll10(mysql_row[8], (char**) NULL, &error_num); - } else - records = 0; + ha_spider *spider = (ha_spider *) param; + if (mysql_row[position]) + { + spider->checksum_val = + (ulonglong) my_strtoll10(mysql_row[position], (char**) NULL, + &error_num); + DBUG_PRINT("info", ("spider checksum=%llu", spider->checksum_val)); + spider->checksum_null = FALSE; + } else { + spider->checksum_null = TRUE; + DBUG_PRINT("info", ("spider checksum is null")); + } + break; + } +#endif + default: + DBUG_ASSERT(0); + break; } DBUG_RETURN(0); } +int spider_db_mbase_result::fetch_table_records( + int mode, + ha_rows &records +) { + DBUG_ENTER("spider_db_mbase_result::fetch_table_records"); + DBUG_PRINT("info",("spider this=%p", this)); + if (mode == 1) + { + DBUG_RETURN(fetch_simple_action(SPIDER_SIMPLE_RECORDS, + SPIDER_SQL_SHOW_RECORDS_RECORDS_POS, &records)); + } else { + DBUG_RETURN(fetch_simple_action(SPIDER_SIMPLE_RECORDS, + SPIDER_SQL_EXPLAIN_SELECT_RECORDS_POS, &records)); + } +} + +#ifdef HA_HAS_CHECKSUM_EXTENDED +int spider_db_mbase_result::fetch_table_checksum( + ha_spider *spider +) { + DBUG_ENTER("spider_db_mbase_result::fetch_table_checksum"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(fetch_simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE, + SPIDER_SQL_CHECKSUM_CHECKSUM_POS, spider)); +} +#endif + int spider_db_mbase_result::fetch_table_cardinality( int mode, TABLE *table, @@ -6848,6 +6904,15 @@ int spider_mbase_share::discover_table_structure( } #endif +#ifdef HA_HAS_CHECKSUM_EXTENDED +bool spider_mbase_share::checksum_support() +{ + DBUG_ENTER("spider_mbase_share::checksum_support"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} +#endif + spider_mbase_handler::spider_mbase_handler( ha_spider *spider, spider_mbase_share *db_share, @@ -12862,7 +12927,8 @@ int spider_mbase_handler::show_index( DBUG_RETURN(0); } -int spider_mbase_handler::show_records( +int spider_mbase_handler::simple_action( + uint simple_action, int link_idx ) { int error_num; @@ -12870,7 +12936,49 @@ int spider_mbase_handler::show_records( SPIDER_DB_RESULT *res; SPIDER_SHARE *share = spider->share; uint pos = spider->conn_link_idx[link_idx]; - DBUG_ENTER("spider_mbase_handler::show_records"); + spider_string *str; + DBUG_ENTER("spider_mbase_handler::simple_action"); + switch (simple_action) + { + case SPIDER_SIMPLE_RECORDS: + DBUG_PRINT("info",("spider simple records")); + str = &mysql_share->show_records[pos]; + break; +#ifdef HA_HAS_CHECKSUM_EXTENDED + case SPIDER_SIMPLE_CHECKSUM_TABLE: + DBUG_PRINT("info",("spider simple checksum_table")); + str = &spider->result_list.sqls[link_idx]; + str->length(0); + if (str->reserve( + SPIDER_SQL_CHECKSUM_TABLE_LEN + + mysql_share->db_nm_max_length + + SPIDER_SQL_DOT_LEN + + mysql_share->table_nm_max_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + + ((spider->action_flags & T_QUICK) ? SPIDER_SQL_SQL_QUICK_LEN : 0) + + ((spider->action_flags & T_EXTEND) ? SPIDER_SQL_SQL_EXTENDED_LEN : 0) + )) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_CHECKSUM_TABLE_STR, + SPIDER_SQL_CHECKSUM_TABLE_LEN); + mysql_share->append_table_name(str, pos); + if (spider->action_flags & T_QUICK) + { + str->q_append(SPIDER_SQL_SQL_QUICK_STR, SPIDER_SQL_SQL_QUICK_LEN); + } + if (spider->action_flags & T_EXTEND) + { + str->q_append(SPIDER_SQL_SQL_EXTENDED_STR, + SPIDER_SQL_SQL_EXTENDED_LEN); + } + break; +#endif + default: + DBUG_ASSERT(0); + break; + } 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]; @@ -12883,8 +12991,8 @@ int spider_mbase_handler::show_records( ( spider_db_query( conn, - mysql_share->show_records[pos].ptr(), - mysql_share->show_records[pos].length(), + str->ptr(), + str->length(), -1, &spider->need_mons[link_idx]) && (error_num = spider_db_errorno(conn)) @@ -12917,8 +13025,8 @@ int spider_mbase_handler::show_records( share); if (spider_db_query( conn, - mysql_share->show_records[pos].ptr(), - mysql_share->show_records[pos].length(), + str->ptr(), + str->length(), -1, &spider->need_mons[link_idx]) ) { @@ -12960,10 +13068,22 @@ int spider_mbase_handler::show_records( 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_records( - 1, - spider->table_rows - ); + switch (simple_action) + { + case SPIDER_SIMPLE_RECORDS: + DBUG_PRINT("info",("spider simple records")); + error_num = res->fetch_table_records(1, spider->table_rows); + break; +#ifdef HA_HAS_CHECKSUM_EXTENDED + case SPIDER_SIMPLE_CHECKSUM_TABLE: + DBUG_PRINT("info",("spider simple checksum_table")); + error_num = res->fetch_table_checksum(spider); + break; +#endif + default: + DBUG_ASSERT(0); + break; + } res->free_result(); delete res; if (error_num) @@ -12971,10 +13091,34 @@ int spider_mbase_handler::show_records( DBUG_PRINT("info", ("spider error_num=%d 7", error_num)); DBUG_RETURN(error_num); } + DBUG_RETURN(0); +} + +int spider_mbase_handler::show_records( + int link_idx +) { + int error_num; + DBUG_ENTER("spider_mbase_handler::show_records"); + error_num = simple_action(SPIDER_SIMPLE_RECORDS, link_idx); + if (error_num) + { + DBUG_PRINT("info", ("spider error_num=%d", error_num)); + DBUG_RETURN(error_num); + } spider->trx->direct_aggregate_count++; DBUG_RETURN(0); } +#ifdef HA_HAS_CHECKSUM_EXTENDED +int spider_mbase_handler::checksum_table( + int link_idx +) { + DBUG_ENTER("spider_mbase_handler::checksum_table"); + DBUG_RETURN(simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE, link_idx)); + DBUG_RETURN(0); +} +#endif + int spider_mbase_handler::show_last_insert_id( int link_idx, ulonglong &last_insert_id diff --git a/storage/spider/spd_db_mysql.h b/storage/spider/spd_db_mysql.h index 968e2f37848..4fa2a3cb52d 100644 --- a/storage/spider/spd_db_mysql.h +++ b/storage/spider/spd_db_mysql.h @@ -320,10 +320,20 @@ public: time_t &update_time, time_t &check_time ); + int fetch_simple_action( + uint simple_action, + uint position, + void *param + ); int fetch_table_records( int mode, ha_rows &records ); +#ifdef HA_HAS_CHECKSUM_EXTENDED + int fetch_table_checksum( + ha_spider *spider + ); +#endif int fetch_table_cardinality( int mode, TABLE *table, @@ -703,6 +713,9 @@ public: spider_string *str ); #endif +#ifdef HA_HAS_CHECKSUM_EXTENDED + bool checksum_support(); +#endif protected: int create_table_names_str(); void free_table_names_str(); @@ -1487,9 +1500,18 @@ public: int link_idx, int crd_mode ); + int simple_action( + uint simple_action, + int link_idx + ); int show_records( int link_idx ); +#ifdef HA_HAS_CHECKSUM_EXTENDED + int checksum_table( + int link_idx + ); +#endif int show_last_insert_id( int link_idx, ulonglong &last_insert_id diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc index 63e8a10634e..88e28b0139c 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -1418,7 +1418,7 @@ int spider_db_oracle::connect( this->connect_retry_interval = connect_retry_interval; if ((error_num = spider_create_conn_thread(conn))) DBUG_RETURN(error_num); - spider_bg_conn_simple_action(conn, SPIDER_BG_SIMPLE_CONNECT, TRUE, NULL, + spider_bg_conn_simple_action(conn, SPIDER_SIMPLE_CONNECT, TRUE, NULL, 0, NULL); if (stored_error_num) @@ -1509,7 +1509,7 @@ void spider_db_oracle::disconnect() DBUG_PRINT("info",("spider this=%p", this)); if (!conn->bg_init) DBUG_VOID_RETURN; - spider_bg_conn_simple_action(conn, SPIDER_BG_SIMPLE_DISCONNECT, TRUE, NULL, + spider_bg_conn_simple_action(conn, SPIDER_SIMPLE_DISCONNECT, TRUE, NULL, 0, NULL); DBUG_VOID_RETURN; } diff --git a/storage/spider/spd_malloc.cc b/storage/spider/spd_malloc.cc index e7a6e710cbc..c8f1d61a5f5 100644 --- a/storage/spider/spd_malloc.cc +++ b/storage/spider/spd_malloc.cc @@ -1,4 +1,5 @@ -/* Copyright (C) 2012-2017 Kentoku Shiba +/* Copyright (C) 2012-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1126,6 +1127,7 @@ void spider_string::q_append( ) { DBUG_ENTER("spider_string::q_append"); DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(str.alloced_length() >= str.length() + data_len); str.q_append(data, data_len); DBUG_VOID_RETURN; } diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index f48db0f03c1..a07e8140a4e 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -4417,6 +4417,9 @@ SPIDER_SHARE *spider_create_share( uchar *tmp_cardinality_upd, *tmp_table_mon_mutex_bitmap; char buf[MAX_FIELD_WIDTH], *buf_pos; char link_idx_str[SPIDER_SQL_INT_LEN]; +#ifdef HA_HAS_CHECKSUM_EXTENDED + bool checksum_support = TRUE; +#endif DBUG_ENTER("spider_create_share"); length = (uint) strlen(table_name); bitmap_size = spider_bitmap_size(table_share->fields); @@ -4575,8 +4578,25 @@ SPIDER_SHARE *spider_create_share( { goto error_init_dbton; } +#ifdef HA_HAS_CHECKSUM_EXTENDED + if ( + spider_dbton[roop_count].db_access_type == SPIDER_DB_ACCESS_TYPE_SQL && + !share->dbton_share[roop_count]->checksum_support() + ) { + checksum_support = FALSE; + } +#endif } } +#ifdef HA_HAS_CHECKSUM_EXTENDED + if (checksum_support) + { + share->additional_table_flags |= + HA_HAS_CHECKSUM_EXTENDED | + HA_HAS_OLD_CHECKSUM | + HA_HAS_NEW_CHECKSUM; + } +#endif DBUG_RETURN(share); /* |