Skip to content

Commit

Permalink
MDEV-30170 ha_spider::delete_table() should report table not exist
Browse files Browse the repository at this point in the history
All Spider tables are recorded in the system table
mysql.spider_tables. Deleting a spider table removes the corresponding
rows from the system table, among other things. This patch makes it so
that if spider could not find any record in the system table to delete
for a given table, it should correctly report that no such Spider
table exists.
  • Loading branch information
mariadb-YuchenPei committed Jan 11, 2024
1 parent 7801c6d commit 9e9e0b9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
9 changes: 8 additions & 1 deletion storage/spider/ha_spider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11371,7 +11371,10 @@ int ha_spider::create(
if (
thd->lex->create_info.or_replace() &&
(error_num = spider_delete_tables(
table_tables, tmp_share.table_name, &dummy))
table_tables, tmp_share.table_name, &dummy)) &&
/* In this context, no key found in mysql.spider_tables means
the Spider table does not exist */
error_num != HA_ERR_KEY_NOT_FOUND
) {
goto error;
}
Expand Down Expand Up @@ -11842,6 +11845,10 @@ int ha_spider::delete_table(
(error_num = spider_delete_tables(
table_tables, name, &old_link_count))
) {
/* In this context, no key found in mysql.spider_tables means
the Spider table does not exist */
if (error_num == HA_ERR_KEY_NOT_FOUND)
error_num= HA_ERR_NO_SUCH_TABLE;
goto error;
}
spider_close_sys_table(current_thd, table_tables,
Expand Down
7 changes: 7 additions & 0 deletions storage/spider/mysql-test/spider/bugfix/r/mdev_30170.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
install soname 'ha_spider';
DROP TABLE non_existing_table;
ERROR 42S02: Unknown table 'test.non_existing_table'
create or replace table non_existing_table (c int) engine=Spider;
drop table non_existing_table;
Warnings:
Warning 1620 Plugin is busy and will be uninstalled on shutdown
8 changes: 8 additions & 0 deletions storage/spider/mysql-test/spider/bugfix/t/mdev_30170.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
install soname 'ha_spider';
--error ER_BAD_TABLE_ERROR
DROP TABLE non_existing_table;
# Test that create or replace a non existing spider table work
create or replace table non_existing_table (c int) engine=Spider;
drop table non_existing_table;
--disable_query_log
--source ../../include/clean_up_spider.inc
22 changes: 21 additions & 1 deletion storage/spider/spd_sys_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,16 @@ int spider_delete_xa_member(
DBUG_RETURN(0);
}

/**
Delete a Spider table from mysql.spider_tables.
@param table The table mysql.spider_tables
@param name The name of the Spider table to delete
@param old_link_count The number of links in the deleted table
@retval 0 Success
@retval nonzero Failure
*/
int spider_delete_tables(
TABLE *table,
const char *name,
Expand All @@ -1880,10 +1890,20 @@ int spider_delete_tables(
{
spider_store_tables_link_idx(table, roop_count);
if ((error_num = spider_check_sys_table(table, table_key)))
break;
{
/* There's a problem with finding the first record for the
spider table, likely because it does not exist. Fail */
if (roop_count == 0)
DBUG_RETURN(error_num);
/* At least one row has been deleted for the Spider table.
Success */
else
break;
}
else {
if ((error_num = spider_delete_sys_table_row(table)))
{
/* There's a problem deleting the row. Fail */
DBUG_RETURN(error_num);
}
}
Expand Down

0 comments on commit 9e9e0b9

Please sign in to comment.