Commit e2bf76cb authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-12266: Cleanup DISCARD TABLESPACE

fil_discard_tablespace(): Merge to row_discard_tablespace()
which was the only caller.
parent f8d1bd01
......@@ -17,6 +17,7 @@ call mtr.add_suppression("Could not find a valid tablespace file for");
call mtr.add_suppression("InnoDB: Failed to find tablespace for table `test`\.`\(t\|x\.\.d\)` in the cache");
call mtr.add_suppression("InnoDB: Cannot delete tablespace [0-9]+.*not found");
call mtr.add_suppression("Table .* in the InnoDB data dictionary has tablespace id .*, but tablespace with that id or name does not exist");
call mtr.add_suppression("InnoDB: ALTER TABLE `test`.`t` DISCARD TABLESPACE failed to find tablespace");
--enable_query_log
let $MYSQLD_DATADIR=`select @@datadir`;
......
......@@ -2997,54 +2997,6 @@ fil_space_dec_redo_skipped_count(
}
#endif /* UNIV_DEBUG */
/*******************************************************************//**
Discards a single-table tablespace. The tablespace must be cached in the
memory cache. Discarding is like deleting a tablespace, but
1. We do not drop the table from the data dictionary;
2. We remove all insert buffer entries for the tablespace immediately;
in DROP TABLE they are only removed gradually in the background;
3. Free all the pages in use by the tablespace.
@return DB_SUCCESS or error */
dberr_t
fil_discard_tablespace(
/*===================*/
ulint id) /*!< in: space id */
{
dberr_t err;
switch (err = fil_delete_tablespace(id
#ifdef BTR_CUR_HASH_ADAPT
, true
#endif /* BTR_CUR_HASH_ADAPT */
)) {
case DB_SUCCESS:
break;
case DB_IO_ERROR:
ib::warn() << "While deleting tablespace " << id
<< " in DISCARD TABLESPACE. File rename/delete"
" failed: " << ut_strerr(err);
break;
case DB_TABLESPACE_NOT_FOUND:
ib::warn() << "Cannot delete tablespace " << id
<< " in DISCARD TABLESPACE: " << ut_strerr(err);
break;
default:
ut_error;
}
/* Remove all insert buffer entries for the tablespace */
ibuf_delete_for_discarded_space(id);
return(err);
}
/*******************************************************************//**
Allocates and builds a file name from a path, a table or tablespace name
and a suffix. The string must be freed by caller with ut_free().
......
......@@ -969,26 +969,6 @@ fil_close_tablespace(
trx_t* trx, /*!< in/out: Transaction covering the close */
ulint id); /*!< in: space id */
/*******************************************************************//**
Discards a single-table tablespace. The tablespace must be cached in the
memory cache. Discarding is like deleting a tablespace, but
1. We do not drop the table from the data dictionary;
2. We remove all insert buffer entries for the tablespace immediately;
in DROP TABLE they are only removed gradually in the background;
3. When the user does IMPORT TABLESPACE, the tablespace will have the
same id as it originally had.
4. Free all the pages in use by the tablespace if rename=true.
@return DB_SUCCESS or error */
dberr_t
fil_discard_tablespace(
/*===================*/
ulint id) /*!< in: space id */
MY_ATTRIBUTE((warn_unused_result));
/** Test if a tablespace file can be renamed to a new filepath by checking
if that the old filepath exists and the new filepath does not exist.
@param[in] space_id tablespace id
......
......@@ -3167,49 +3167,44 @@ row_discard_tablespace(
}
/* Discard the physical file that is used for the tablespace. */
err = fil_discard_tablespace(table->space);
err = fil_delete_tablespace(table->space
#ifdef BTR_CUR_HASH_ADAPT
, true
#endif /* BTR_CUR_HASH_ADAPT */
);
switch (err) {
case DB_SUCCESS:
case DB_IO_ERROR:
ib::warn() << "ALTER TABLE " << table->name
<< " DISCARD TABLESPACE failed to delete file";
break;
case DB_TABLESPACE_NOT_FOUND:
/* All persistent operations successful, update the
data dictionary memory cache. */
table->file_unreadable = true;
table->flags2 |= DICT_TF2_DISCARDED;
dict_table_change_id_in_cache(table, new_id);
/* Reset the root page numbers. */
for (dict_index_t* index = UT_LIST_GET_FIRST(table->indexes);
index != 0;
index = UT_LIST_GET_NEXT(indexes, index)) {
index->page = FIL_NULL;
}
/* If the tablespace did not already exist or we couldn't
write to it, we treat that as a successful DISCARD. It is
unusable anyway. */
err = DB_SUCCESS;
ib::warn() << "ALTER TABLE " << table->name
<< " DISCARD TABLESPACE failed to find tablespace";
break;
case DB_SUCCESS:
break;
default:
/* We need to rollback the disk changes, something failed. */
ut_error;
}
trx->error_state = DB_SUCCESS;
/* All persistent operations successful, update the
data dictionary memory cache. */
trx_rollback_to_savepoint(trx, NULL);
table->file_unreadable = true;
table->flags2 |= DICT_TF2_DISCARDED;
dict_table_change_id_in_cache(table, new_id);
trx->error_state = DB_SUCCESS;
}
/* Reset the root page numbers. */
return(err);
for (dict_index_t* index = UT_LIST_GET_FIRST(table->indexes);
index != 0;
index = UT_LIST_GET_NEXT(indexes, index)) {
index->page = FIL_NULL;
}
/* If the tablespace did not already exist or we couldn't
write to it, we treat that as a successful DISCARD. It is
unusable anyway. */
return DB_SUCCESS;
}
/*********************************************************************//**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment