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(-) (limited to 'storage/spider') 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