Skip to content

Commit e2bf76c

Browse files
committed
MDEV-12266: Cleanup DISCARD TABLESPACE
fil_discard_tablespace(): Merge to row_discard_tablespace() which was the only caller.
1 parent f8d1bd0 commit e2bf76c

File tree

4 files changed

+30
-102
lines changed

4 files changed

+30
-102
lines changed

mysql-test/suite/innodb/t/alter_missing_tablespace.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ call mtr.add_suppression("Could not find a valid tablespace file for");
1717
call mtr.add_suppression("InnoDB: Failed to find tablespace for table `test`\.`\(t\|x\.\.d\)` in the cache");
1818
call mtr.add_suppression("InnoDB: Cannot delete tablespace [0-9]+.*not found");
1919
call mtr.add_suppression("Table .* in the InnoDB data dictionary has tablespace id .*, but tablespace with that id or name does not exist");
20+
call mtr.add_suppression("InnoDB: ALTER TABLE `test`.`t` DISCARD TABLESPACE failed to find tablespace");
2021
--enable_query_log
2122

2223
let $MYSQLD_DATADIR=`select @@datadir`;

storage/innobase/fil/fil0fil.cc

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,54 +2997,6 @@ fil_space_dec_redo_skipped_count(
29972997
}
29982998
#endif /* UNIV_DEBUG */
29992999

3000-
/*******************************************************************//**
3001-
Discards a single-table tablespace. The tablespace must be cached in the
3002-
memory cache. Discarding is like deleting a tablespace, but
3003-
3004-
1. We do not drop the table from the data dictionary;
3005-
3006-
2. We remove all insert buffer entries for the tablespace immediately;
3007-
in DROP TABLE they are only removed gradually in the background;
3008-
3009-
3. Free all the pages in use by the tablespace.
3010-
@return DB_SUCCESS or error */
3011-
dberr_t
3012-
fil_discard_tablespace(
3013-
/*===================*/
3014-
ulint id) /*!< in: space id */
3015-
{
3016-
dberr_t err;
3017-
3018-
switch (err = fil_delete_tablespace(id
3019-
#ifdef BTR_CUR_HASH_ADAPT
3020-
, true
3021-
#endif /* BTR_CUR_HASH_ADAPT */
3022-
)) {
3023-
case DB_SUCCESS:
3024-
break;
3025-
3026-
case DB_IO_ERROR:
3027-
ib::warn() << "While deleting tablespace " << id
3028-
<< " in DISCARD TABLESPACE. File rename/delete"
3029-
" failed: " << ut_strerr(err);
3030-
break;
3031-
3032-
case DB_TABLESPACE_NOT_FOUND:
3033-
ib::warn() << "Cannot delete tablespace " << id
3034-
<< " in DISCARD TABLESPACE: " << ut_strerr(err);
3035-
break;
3036-
3037-
default:
3038-
ut_error;
3039-
}
3040-
3041-
/* Remove all insert buffer entries for the tablespace */
3042-
3043-
ibuf_delete_for_discarded_space(id);
3044-
3045-
return(err);
3046-
}
3047-
30483000
/*******************************************************************//**
30493001
Allocates and builds a file name from a path, a table or tablespace name
30503002
and a suffix. The string must be freed by caller with ut_free().

storage/innobase/include/fil0fil.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -969,26 +969,6 @@ fil_close_tablespace(
969969
trx_t* trx, /*!< in/out: Transaction covering the close */
970970
ulint id); /*!< in: space id */
971971

972-
/*******************************************************************//**
973-
Discards a single-table tablespace. The tablespace must be cached in the
974-
memory cache. Discarding is like deleting a tablespace, but
975-
976-
1. We do not drop the table from the data dictionary;
977-
978-
2. We remove all insert buffer entries for the tablespace immediately;
979-
in DROP TABLE they are only removed gradually in the background;
980-
981-
3. When the user does IMPORT TABLESPACE, the tablespace will have the
982-
same id as it originally had.
983-
984-
4. Free all the pages in use by the tablespace if rename=true.
985-
@return DB_SUCCESS or error */
986-
dberr_t
987-
fil_discard_tablespace(
988-
/*===================*/
989-
ulint id) /*!< in: space id */
990-
MY_ATTRIBUTE((warn_unused_result));
991-
992972
/** Test if a tablespace file can be renamed to a new filepath by checking
993973
if that the old filepath exists and the new filepath does not exist.
994974
@param[in] space_id tablespace id

storage/innobase/row/row0mysql.cc

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,49 +3167,44 @@ row_discard_tablespace(
31673167
}
31683168

31693169
/* Discard the physical file that is used for the tablespace. */
3170-
3171-
err = fil_discard_tablespace(table->space);
3172-
3170+
err = fil_delete_tablespace(table->space
3171+
#ifdef BTR_CUR_HASH_ADAPT
3172+
, true
3173+
#endif /* BTR_CUR_HASH_ADAPT */
3174+
);
31733175
switch (err) {
3174-
case DB_SUCCESS:
31753176
case DB_IO_ERROR:
3177+
ib::warn() << "ALTER TABLE " << table->name
3178+
<< " DISCARD TABLESPACE failed to delete file";
3179+
break;
31763180
case DB_TABLESPACE_NOT_FOUND:
3177-
/* All persistent operations successful, update the
3178-
data dictionary memory cache. */
3179-
3180-
table->file_unreadable = true;
3181-
3182-
table->flags2 |= DICT_TF2_DISCARDED;
3183-
3184-
dict_table_change_id_in_cache(table, new_id);
3185-
3186-
/* Reset the root page numbers. */
3187-
3188-
for (dict_index_t* index = UT_LIST_GET_FIRST(table->indexes);
3189-
index != 0;
3190-
index = UT_LIST_GET_NEXT(indexes, index)) {
3191-
3192-
index->page = FIL_NULL;
3193-
}
3194-
3195-
/* If the tablespace did not already exist or we couldn't
3196-
write to it, we treat that as a successful DISCARD. It is
3197-
unusable anyway. */
3198-
3199-
err = DB_SUCCESS;
3181+
ib::warn() << "ALTER TABLE " << table->name
3182+
<< " DISCARD TABLESPACE failed to find tablespace";
3183+
break;
3184+
case DB_SUCCESS:
32003185
break;
3201-
32023186
default:
3203-
/* We need to rollback the disk changes, something failed. */
3187+
ut_error;
3188+
}
32043189

3205-
trx->error_state = DB_SUCCESS;
3190+
/* All persistent operations successful, update the
3191+
data dictionary memory cache. */
32063192

3207-
trx_rollback_to_savepoint(trx, NULL);
3193+
table->file_unreadable = true;
3194+
table->flags2 |= DICT_TF2_DISCARDED;
3195+
dict_table_change_id_in_cache(table, new_id);
32083196

3209-
trx->error_state = DB_SUCCESS;
3210-
}
3197+
/* Reset the root page numbers. */
32113198

3212-
return(err);
3199+
for (dict_index_t* index = UT_LIST_GET_FIRST(table->indexes);
3200+
index != 0;
3201+
index = UT_LIST_GET_NEXT(indexes, index)) {
3202+
index->page = FIL_NULL;
3203+
}
3204+
/* If the tablespace did not already exist or we couldn't
3205+
write to it, we treat that as a successful DISCARD. It is
3206+
unusable anyway. */
3207+
return DB_SUCCESS;
32133208
}
32143209

32153210
/*********************************************************************//**

0 commit comments

Comments
 (0)