Skip to content

Commit

Permalink
MDEV-12266: Cleanup DISCARD TABLESPACE
Browse files Browse the repository at this point in the history
fil_discard_tablespace(): Merge to row_discard_tablespace()
which was the only caller.
  • Loading branch information
dr-m committed Mar 29, 2018
1 parent f8d1bd0 commit e2bf76c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 102 deletions.
1 change: 1 addition & 0 deletions mysql-test/suite/innodb/t/alter_missing_tablespace.test
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
48 changes: 0 additions & 48 deletions storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
20 changes: 0 additions & 20 deletions storage/innobase/include/fil0fil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 29 additions & 34 deletions storage/innobase/row/row0mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*********************************************************************//**
Expand Down

0 comments on commit e2bf76c

Please sign in to comment.