Skip to content

Commit

Permalink
MDEV-30920 Remove need_lock and table from spider_close_sys_table()
Browse files Browse the repository at this point in the history
  • Loading branch information
mariadb-YuchenPei committed Apr 28, 2023
1 parent aa6ba99 commit f2f5486
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 280 deletions.
65 changes: 15 additions & 50 deletions storage/spider/ha_spider.cc
Expand Up @@ -8597,7 +8597,6 @@ int ha_spider::create(
SPIDER_TRX *trx;
TABLE *table_tables = NULL;
SPIDER_Open_tables_backup open_tables_backup;
bool need_lock = FALSE;
DBUG_ENTER("ha_spider::create");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_PRINT("info",("spider name=%s", name));
Expand Down Expand Up @@ -8675,7 +8674,7 @@ int ha_spider::create(
if (
!(table_tables = spider_open_sys_table(
current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup,
&error_num))
) {
goto error;
Expand All @@ -8692,8 +8691,7 @@ int ha_spider::create(
) {
goto error;
}
spider_close_sys_table(current_thd, table_tables,
&open_tables_backup, FALSE);
spider_sys_close_table(current_thd, &open_tables_backup);
table_tables = NULL;
} else if (
sql_command == SQLCOM_ALTER_TABLE
Expand Down Expand Up @@ -8726,11 +8724,10 @@ int ha_spider::create(
) &&
memcmp(name + strlen(name) - 5, "#TMP#", 5)
) {
need_lock = TRUE;
if (
!(table_tables = spider_open_sys_table(
current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, TRUE,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup,
&error_num))
) {
goto error;
Expand All @@ -8740,8 +8737,7 @@ int ha_spider::create(
) {
goto error;
}
spider_close_sys_table(current_thd, table_tables,
&open_tables_backup, TRUE);
spider_sys_close_table(current_thd, &open_tables_backup);
table_tables = NULL;
}
}
Expand Down Expand Up @@ -8770,8 +8766,7 @@ int ha_spider::create(

error:
if (table_tables)
spider_close_sys_table(current_thd, table_tables,
&open_tables_backup, need_lock);
spider_sys_close_table(current_thd, &open_tables_backup);
if (tmp_share.lgtm_tblhnd_share)
spider_free_lgtm_tblhnd_share_alloc(tmp_share.lgtm_tblhnd_share, FALSE);
if (tmp_share.static_key_cardinality)
Expand Down Expand Up @@ -8843,7 +8838,6 @@ int ha_spider::rename_table(
SPIDER_ALTER_TABLE *alter_table_from, *alter_table_to;
SPIDER_LGTM_TBLHND_SHARE *from_lgtm_tblhnd_share, *to_lgtm_tblhnd_share;
SPIDER_Open_tables_backup open_tables_backup;
bool need_lock = FALSE;
DBUG_ENTER("ha_spider::rename_table");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_PRINT("info",("spider from=%s", from));
Expand Down Expand Up @@ -8875,7 +8869,7 @@ int ha_spider::rename_table(
if (
!(table_tables = spider_open_sys_table(
current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup,
&error_num))
) {
goto error;
Expand All @@ -8886,8 +8880,7 @@ int ha_spider::rename_table(
) {
goto error;
}
spider_close_sys_table(current_thd, table_tables,
&open_tables_backup, FALSE);
spider_sys_close_table(current_thd, &open_tables_backup);
table_tables = NULL;

/* release table mon list */
Expand Down Expand Up @@ -8929,21 +8922,10 @@ int ha_spider::rename_table(
DBUG_PRINT("info",
("spider alter_info.flags: %llu alter_info.partition_flags: %lu",
thd->lex->alter_info.flags, thd->lex->alter_info.partition_flags));
if (
(thd->lex->alter_info.partition_flags &
(
SPIDER_ALTER_PARTITION_ADD | SPIDER_ALTER_PARTITION_DROP |
SPIDER_ALTER_PARTITION_COALESCE | SPIDER_ALTER_PARTITION_REORGANIZE |
SPIDER_ALTER_PARTITION_TABLE_REORG | SPIDER_ALTER_PARTITION_REBUILD
)
)
)
need_lock = TRUE;

if (
!(table_tables = spider_open_sys_table(
current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, need_lock,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup,
&error_num))
) {
goto error;
Expand Down Expand Up @@ -8972,8 +8954,7 @@ int ha_spider::rename_table(
goto error;
}
}
spider_close_sys_table(current_thd, table_tables,
&open_tables_backup, need_lock);
spider_sys_close_table(current_thd, &open_tables_backup);
table_tables = NULL;

if (!alter_table_from->now_create)
Expand Down Expand Up @@ -9031,8 +9012,7 @@ int ha_spider::rename_table(

error:
if (table_tables)
spider_close_sys_table(current_thd, table_tables,
&open_tables_backup, need_lock);
spider_sys_close_table(current_thd, &open_tables_backup);
pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
to_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
to, to_len, to_hash_value, TRUE, FALSE, &tmp_error_num);
Expand All @@ -9052,7 +9032,6 @@ int ha_spider::delete_table(
uint sql_command = thd_sql_command(thd);
SPIDER_ALTER_TABLE *alter_table;
SPIDER_Open_tables_backup open_tables_backup;
bool need_lock = FALSE;
DBUG_ENTER("ha_spider::delete_table");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_PRINT("info",("spider name=%s", name));
Expand Down Expand Up @@ -9098,28 +9077,16 @@ int ha_spider::delete_table(
DBUG_PRINT("info",
("spider alter_info.flags: %llu alter_info.partition_flags: %lu",
thd->lex->alter_info.flags, thd->lex->alter_info.partition_flags));
if (
sql_command == SQLCOM_ALTER_TABLE &&
(thd->lex->alter_info.partition_flags &
(
SPIDER_ALTER_PARTITION_ADD | SPIDER_ALTER_PARTITION_DROP |
SPIDER_ALTER_PARTITION_COALESCE | SPIDER_ALTER_PARTITION_REORGANIZE |
SPIDER_ALTER_PARTITION_TABLE_REORG | SPIDER_ALTER_PARTITION_REBUILD
)
)
)
need_lock = TRUE;

if ((error_num = spider_sys_delete_table_sts(
current_thd, name, name_len, need_lock)))
current_thd, name, name_len)))
goto error;
if ((error_num = spider_sys_delete_table_crd(
current_thd, name, name_len, need_lock)))
current_thd, name, name_len)))
goto error;
if (
!(table_tables = spider_open_sys_table(
current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, need_lock,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup,
&error_num))
) {
goto error;
Expand All @@ -9130,8 +9097,7 @@ int ha_spider::delete_table(
) {
goto error;
}
spider_close_sys_table(current_thd, table_tables,
&open_tables_backup, need_lock);
spider_sys_close_table(current_thd, &open_tables_backup);
table_tables = NULL;

/* release table mon list */
Expand All @@ -9155,8 +9121,7 @@ int ha_spider::delete_table(

error:
if (table_tables)
spider_close_sys_table(current_thd, table_tables,
&open_tables_backup, need_lock);
spider_sys_close_table(current_thd, &open_tables_backup);
DBUG_RETURN(error_num);
}

Expand Down
8 changes: 3 additions & 5 deletions storage/spider/spd_copy_tables.cc
Expand Up @@ -355,7 +355,7 @@ int spider_udf_get_copy_tgt_tables(
!(table_tables = spider_open_sys_table(
thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup,
need_lock, &error_num))
&error_num))
) {
my_error(error_num, MYF(0));
goto error;
Expand Down Expand Up @@ -543,8 +543,7 @@ int spider_udf_get_copy_tgt_tables(
error_num = spider_sys_index_next_same(table_tables, table_key);
} while (error_num == 0);
spider_sys_index_end(table_tables);
spider_close_sys_table(thd, table_tables,
&open_tables_backup, need_lock);
spider_sys_close_table(thd, &open_tables_backup);
table_tables = NULL;

if (!copy_tables->table_conn[0])
Expand All @@ -566,8 +565,7 @@ int spider_udf_get_copy_tgt_tables(

error:
if (table_tables)
spider_close_sys_table(thd, table_tables,
&open_tables_backup, need_lock);
spider_sys_close_table(thd, &open_tables_backup);
if (table_conn)
{
spider_free_tmp_dbton_share(tmp_share);
Expand Down
48 changes: 21 additions & 27 deletions storage/spider/spd_ping_table.cc
Expand Up @@ -267,7 +267,7 @@ int spider_get_ping_table_mon(
!(table_link_mon = spider_open_sys_table(
thd, SPIDER_SYS_LINK_MON_TABLE_NAME_STR,
SPIDER_SYS_LINK_MON_TABLE_NAME_LEN, FALSE, &open_tables_backup,
need_lock, &error_num))
&error_num))
) {
my_error(error_num, MYF(0));
goto error;
Expand Down Expand Up @@ -386,8 +386,7 @@ int spider_get_ping_table_mon(
error_num = spider_sys_index_next_same(table_link_mon, table_key);
} while (error_num == 0);
spider_sys_index_end(table_link_mon);
spider_close_sys_table(thd, table_link_mon,
&open_tables_backup, need_lock);
spider_sys_close_table(thd, &open_tables_backup);
table_link_mon = NULL;
table_mon_list->list_size = list_size;

Expand All @@ -403,8 +402,7 @@ int spider_get_ping_table_mon(

error:
if (table_link_mon)
spider_close_sys_table(thd, table_link_mon,
&open_tables_backup, need_lock);
spider_sys_close_table(thd, &open_tables_backup);
table_mon = table_mon_list->first;
table_mon_list->first = NULL;
table_mon_list->current = NULL;
Expand Down Expand Up @@ -474,7 +472,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt(
if (
!(table_tables = spider_open_sys_table(
thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup, need_lock,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup,
error_num))
) {
my_error(*error_num, MYF(0));
Expand Down Expand Up @@ -512,8 +510,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt(
table_tables->file->print_error(*error_num, MYF(0));
goto error;
}
spider_close_sys_table(thd, table_tables,
&open_tables_backup, need_lock);
spider_sys_close_table(thd, &open_tables_backup);
table_tables = NULL;

if (
Expand Down Expand Up @@ -576,8 +573,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt(
error_caller_mutex_init:
error:
if (table_tables)
spider_close_sys_table(thd, table_tables,
&open_tables_backup, need_lock);
spider_sys_close_table(thd, &open_tables_backup);
free_root(&mem_root, MYF(0));
if (table_mon_list)
{
Expand Down Expand Up @@ -791,11 +787,10 @@ int spider_get_ping_table_gtid_pos(
goto error_sys_index_end;
}
#ifdef SPIDER_REQUIRE_DEFINE_FOR_SECONDARY_OPEN_TABLES_BACKUP
spider_close_sys_table(thd, table_gtid_pos,
spider_sys_close_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);
spider_sys_close_table(thd, &open_tables_backup_tables);

DBUG_RETURN(0);

Expand All @@ -806,13 +801,12 @@ int spider_get_ping_table_gtid_pos(
error_sys_index_end:
error_get_sys_table_by_idx:
#ifdef SPIDER_REQUIRE_DEFINE_FOR_SECONDARY_OPEN_TABLES_BACKUP
spider_close_sys_table(thd, table_gtid_pos,
spider_sys_close_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);
spider_sys_close_table(thd, &open_tables_backup_tables);
error_open_table_tables:
DBUG_RETURN(error_num);
}
Expand All @@ -833,7 +827,7 @@ int spider_init_ping_table_mon_cache(
!(table_link_mon = spider_open_sys_table(
thd, SPIDER_SYS_LINK_MON_TABLE_NAME_STR,
SPIDER_SYS_LINK_MON_TABLE_NAME_LEN, FALSE, &open_tables_backup,
need_lock, &error_num))
&error_num))
) {
my_error(error_num, MYF(0));
goto error_open_sys_table;
Expand Down Expand Up @@ -921,7 +915,7 @@ int spider_init_ping_table_mon_cache(
spider_mon_table_cache_version = spider_mon_table_cache_version_req;
}
pthread_mutex_unlock(&spider_mon_table_cache_mutex);
spider_close_sys_table(thd, table_link_mon, &open_tables_backup, need_lock);
spider_sys_close_table(thd, &open_tables_backup);
DBUG_RETURN(0);

error_push_dynamic:
Expand All @@ -930,7 +924,7 @@ int spider_init_ping_table_mon_cache(
spider_sys_index_end(table_link_mon);
error_sys_index_first:
pthread_mutex_unlock(&spider_mon_table_cache_mutex);
spider_close_sys_table(thd, table_link_mon, &open_tables_backup, need_lock);
spider_sys_close_table(thd, &open_tables_backup);
error_open_sys_table:
DBUG_RETURN(error_num);
}
Expand Down Expand Up @@ -1223,9 +1217,9 @@ long long spider_ping_table_body(
conv_name_length, link_idx, SPIDER_LINK_STATUS_NG);
spider_sys_update_tables_link_status(trx->thd,
conv_name.c_ptr(), conv_name_length, link_idx,
SPIDER_LINK_STATUS_NG, TRUE);
SPIDER_LINK_STATUS_NG);
spider_sys_log_tables_link_failed(trx->thd,
conv_name.c_ptr(), conv_name_length, link_idx, TRUE);
conv_name.c_ptr(), conv_name_length, link_idx);
status_changed_to_ng = TRUE;
}
/*
Expand Down Expand Up @@ -1296,9 +1290,9 @@ long long spider_ping_table_body(
conv_name_length, link_idx, SPIDER_LINK_STATUS_NG);
spider_sys_update_tables_link_status(trx->thd,
conv_name.c_ptr(), conv_name_length, link_idx,
SPIDER_LINK_STATUS_NG, TRUE);
SPIDER_LINK_STATUS_NG);
spider_sys_log_tables_link_failed(trx->thd,
conv_name.c_ptr(), conv_name_length, link_idx, TRUE);
conv_name.c_ptr(), conv_name_length, link_idx);
status_changed_to_ng = TRUE;
}
/*
Expand Down Expand Up @@ -1359,9 +1353,9 @@ long long spider_ping_table_body(
conv_name_length, link_idx, SPIDER_LINK_STATUS_NG);
spider_sys_update_tables_link_status(trx->thd,
conv_name.c_ptr(), conv_name_length, link_idx,
SPIDER_LINK_STATUS_NG, TRUE);
SPIDER_LINK_STATUS_NG);
spider_sys_log_tables_link_failed(trx->thd,
conv_name.c_ptr(), conv_name_length, link_idx, TRUE);
conv_name.c_ptr(), conv_name_length, link_idx);
status_changed_to_ng = TRUE;
}
/*
Expand Down Expand Up @@ -1715,9 +1709,9 @@ int spider_ping_table_mon_from_table(
link_idx));
share->link_statuses[link_idx] = SPIDER_LINK_STATUS_NG;
spider_sys_update_tables_link_status(thd, conv_name,
conv_name_length, link_idx, SPIDER_LINK_STATUS_NG, need_lock);
conv_name_length, link_idx, SPIDER_LINK_STATUS_NG);
spider_sys_log_tables_link_failed(thd, conv_name,
conv_name_length, link_idx, need_lock);
conv_name_length, link_idx);
}
/*
pthread_mutex_unlock(&table_mon_list->update_status_mutex);
Expand Down

0 comments on commit f2f5486

Please sign in to comment.