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

MDEV-25491 preparation: Clean up tablespace destruction

fil_check_pending_ops(), fil_check_pending_io(): Remove.
These functions were actually duplicating each other ever since
commit 118e258a (MDEV-23855).

fil_space_t::check_pending_operations(): Replaces
fil_check_pending_operations() and incorporates the logic of
fil_check_pending_ops(). Avoid unnecessary lookups for the tablespace.
Just wait for the reference count to drop to zero.

fil_space_t::io(): Remove an unnecessary condition. We can (and
probably better should) refuse asynchronous reads of undo tablespaces
that are being truncated.

fil_truncate_prepare(): Remove.

trx_purge_truncate_history(): Implement the necessary steps that used
to be in fil_truncate_prepare().
parent b3d963fe
This diff is collapsed.
......@@ -517,6 +517,12 @@ struct fil_space_t final
/** Note that operations on the tablespace must stop or can resume */
inline void set_stopping(bool stopping);
/** Look up the tablespace and wait for pending operations to cease
@param id tablespace identifier
@return tablespace
@retval nullptr if no tablespace was found */
static fil_space_t *check_pending_operations(ulint id);
private:
MY_ATTRIBUTE((warn_unused_result))
/** Try to acquire a tablespace reference.
......@@ -1580,12 +1586,6 @@ dberr_t
fil_delete_tablespace(ulint id, bool if_exists= false,
std::vector<pfs_os_file_t> *detached_handles= nullptr);
/** Prepare to truncate an undo tablespace.
@param[in] space_id undo tablespace id
@return the tablespace
@retval NULL if the tablespace does not exist */
fil_space_t* fil_truncate_prepare(ulint space_id);
/** Close a single-table tablespace on failed IMPORT TABLESPACE.
The tablespace must be cached in the memory cache.
Free all pages used by the tablespace. */
......
......@@ -605,7 +605,7 @@ static void trx_purge_truncate_history()
return;
}
const fil_space_t& space = *purge_sys.truncate.current;
fil_space_t& space = *purge_sys.truncate.current;
/* Undo tablespace always are a single file. */
ut_a(UT_LIST_GET_LEN(space.chain) == 1);
fil_node_t* file = UT_LIST_GET_FIRST(space.chain);
......@@ -685,26 +685,47 @@ static void trx_purge_truncate_history()
log_free_check();
/* Adjust the tablespace metadata. */
if (!fil_truncate_prepare(space.id)) {
ib::error() << "Failed to find UNDO tablespace "
<< file->name;
return;
}
/* Re-initialize tablespace, in a single mini-transaction. */
mtr_t mtr;
const ulint size = SRV_UNDO_TABLESPACE_SIZE_IN_PAGES;
mtr.start();
mtr.x_lock_space(purge_sys.truncate.current);
mtr.x_lock_space(&space);
/* Adjust the tablespace metadata. */
mysql_mutex_lock(&fil_system.mutex);
space.set_stopping(true);
space.is_being_truncated = true;
if (space.crypt_data) {
space.reacquire();
mysql_mutex_unlock(&fil_system.mutex);
fil_space_crypt_close_tablespace(&space);
space.release();
} else {
mysql_mutex_unlock(&fil_system.mutex);
}
uint i = 60;
while (space.referenced()) {
if (!--i) {
mtr.commit();
ib::error() << "Failed to freeze"
" UNDO tablespace "
<< file->name;
return;
}
std::this_thread::sleep_for(std::chrono::seconds(1));
}
/* Associate the undo tablespace with mtr.
During mtr::commit(), InnoDB can use the undo
tablespace object to clear all freed ranges */
mtr.set_named_space(purge_sys.truncate.current);
mtr.set_named_space(&space);
mtr.trim_pages(page_id_t(space.id, size));
fsp_header_init(purge_sys.truncate.current, size, &mtr);
fsp_header_init(&space, size, &mtr);
mysql_mutex_lock(&fil_system.mutex);
purge_sys.truncate.current->size = file->size = size;
space.size = file->size = size;
mysql_mutex_unlock(&fil_system.mutex);
buf_block_t* sys_header = trx_sysf_get(&mtr);
......
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