Skip to content
Permalink
Browse files
MDEV-12266: Add fil_system.sys_space, temp_space
Add fil_system_t::sys_space, fil_system_t::temp_space.
These will replace lookups for TRX_SYS_SPACE or SRV_TMP_SPACE_ID.

mtr_t::m_undo_space, mtr_t::m_sys_space: Remove.

mtr_t::set_sys_modified(): Remove.

fil_space_get_type(), fil_space_get_n_reserved_extents(): Remove.

fsp_header_get_tablespace_size(), fsp_header_inc_size():
Merge to the only caller, innobase_start_or_create_for_mysql().
  • Loading branch information
dr-m committed Mar 29, 2018
1 parent 600c85e commit 2ac8b1a
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 366 deletions.
@@ -2779,11 +2779,11 @@ xb_load_single_table_tablespace(

/* by opening the tablespace we forcing node and space objects
in the cache to be populated with fields from space header */
fil_space_open(space->name);
space->open();

if (srv_operation == SRV_OPERATION_RESTORE_DELTA
|| xb_close_files) {
fil_space_close(space->name);
space->close();
}
}

@@ -393,28 +393,6 @@ fil_space_get_latch(
return(&(space->latch));
}

/** Gets the type of a file space.
@param[in] id tablespace identifier
@return file type */
fil_type_t
fil_space_get_type(
ulint id)
{
fil_space_t* space;

ut_ad(fil_system.is_initialised());

mutex_enter(&fil_system.mutex);

space = fil_space_get_by_id(id);

ut_a(space);

mutex_exit(&fil_system.mutex);

return(space->purpose);
}

/** Note that a tablespace has been imported.
It is initially marked as FIL_TYPE_IMPORT so that no logging is
done during the import process when the space ID is stamped to each page.
@@ -1373,6 +1351,12 @@ fil_space_detach(

fil_node_close_to_free(fil_node, space);
}

if (space == fil_system.sys_space) {
fil_system.sys_space = NULL;
} else if (space == fil_system.temp_space) {
fil_system.temp_space = NULL;
}
}

/** Free a tablespace object on which fil_space_detach() was invoked.
@@ -1828,58 +1812,47 @@ fil_space_get_flags(
return(flags);
}

/** Open each fil_node_t of a named fil_space_t if not already open.
@param[in] name Tablespace name
@return true if all nodes are open */
bool
fil_space_open(
const char* name)
/** Open each file. Only invoked on fil_system.temp_space.
@return whether all files were opened */
bool fil_space_t::open()
{
ut_ad(fil_system.is_initialised());

mutex_enter(&fil_system.mutex);
ut_ad(this == fil_system.temp_space
|| srv_operation == SRV_OPERATION_BACKUP
|| srv_operation == SRV_OPERATION_RESTORE
|| srv_operation == SRV_OPERATION_RESTORE_DELTA);

fil_space_t* space = fil_space_get_by_name(name);
fil_node_t* node;

for (node = UT_LIST_GET_FIRST(space->chain);
for (fil_node_t* node = UT_LIST_GET_FIRST(chain);
node != NULL;
node = UT_LIST_GET_NEXT(chain, node)) {

if (!node->is_open()
&& !fil_node_open_file(node)) {
if (!node->is_open() && !fil_node_open_file(node)) {
mutex_exit(&fil_system.mutex);
return(false);
return false;
}
}

mutex_exit(&fil_system.mutex);

return(true);
return true;
}

/** Close each fil_node_t of a named fil_space_t if open.
@param[in] name Tablespace name */
void
fil_space_close(
const char* name)
/** Close each file. Only invoked on fil_system.temp_space. */
void fil_space_t::close()
{
if (!fil_system.is_initialised()) {
return;
}

mutex_enter(&fil_system.mutex);
ut_ad(this == fil_system.temp_space
|| srv_operation == SRV_OPERATION_BACKUP
|| srv_operation == SRV_OPERATION_RESTORE
|| srv_operation == SRV_OPERATION_RESTORE_DELTA);

fil_space_t* space = fil_space_get_by_name(name);
if (space == NULL) {
mutex_exit(&fil_system.mutex);
return;
}

for (fil_node_t* node = UT_LIST_GET_FIRST(space->chain);
for (fil_node_t* node = UT_LIST_GET_FIRST(chain);
node != NULL;
node = UT_LIST_GET_NEXT(chain, node)) {

if (node->is_open()) {
fil_node_close_file(node);
}
@@ -1940,6 +1913,8 @@ void fil_system_t::close()
ut_a(!UT_LIST_GET_LEN(LRU));
ut_a(!UT_LIST_GET_LEN(unflushed_spaces));
ut_a(!UT_LIST_GET_LEN(space_list));
ut_ad(!sys_space);
ut_ad(!temp_space);

if (is_initialised()) {
m_initialised = false;
@@ -4854,32 +4829,6 @@ fil_space_release_free_extents(
mutex_exit(&fil_system.mutex);
}

/*******************************************************************//**
Gets the number of reserved extents. If the database is silent, this number
should be zero. */
ulint
fil_space_get_n_reserved_extents(
/*=============================*/
ulint id) /*!< in: space id */
{
fil_space_t* space;
ulint n;

ut_ad(fil_system.is_initialised());

mutex_enter(&fil_system.mutex);

space = fil_space_get_by_id(id);

ut_a(space);

n = space->n_reserved_extents;

mutex_exit(&fil_system.mutex);

return(n);
}

/*============================ FILE I/O ================================*/

/********************************************************************//**
@@ -5498,6 +5447,10 @@ struct Check {
Check check;
ut_list_validate(space->chain, check);
ut_a(space->size == check.size);
ut_ad(space->id != TRX_SYS_SPACE
|| space == fil_system.sys_space);
ut_ad(space->id != SRV_TMP_SPACE_ID
|| space == fil_system.temp_space);
return(check.n_open);
}
};
@@ -812,63 +812,6 @@ fsp_header_get_space_id(
return(id);
}

/**********************************************************************//**
Increases the space size field of a space. */
void
fsp_header_inc_size(
/*================*/
ulint space_id, /*!< in: space id */
ulint size_inc, /*!< in: size increment in pages */
mtr_t* mtr) /*!< in/out: mini-transaction */
{
fsp_header_t* header;
ulint size;

ut_ad(mtr);

fil_space_t* space = mtr_x_lock_space(space_id, mtr);
ut_d(fsp_space_modify_check(space, mtr));

header = fsp_get_space_header(
space, page_size_t(space->flags), mtr);

size = mach_read_from_4(header + FSP_SIZE);
ut_ad(size == space->size_in_header);

size += size_inc;

mlog_write_ulint(header + FSP_SIZE, size, MLOG_4BYTES, mtr);
space->size_in_header = size;
}

/**********************************************************************//**
Gets the size of the system tablespace from the tablespace header. If
we do not have an auto-extending data file, this should be equal to
the size of the data files. If there is an auto-extending data file,
this can be smaller.
@return size in pages */
ulint
fsp_header_get_tablespace_size(void)
/*================================*/
{
fsp_header_t* header;
ulint size;
mtr_t mtr;

mtr_start(&mtr);

fil_space_t* space = mtr_x_lock_space(TRX_SYS_SPACE, &mtr);

header = fsp_get_space_header(space, univ_page_size, &mtr);

size = mach_read_from_4(header + FSP_SIZE);
ut_ad(space->size_in_header == size);

mtr_commit(&mtr);

return(size);
}

/** Try to extend a single-table tablespace so that a page would fit in the
data file.
@param[in,out] space tablespace
@@ -912,15 +912,19 @@ SysTablespace::open_or_create(
it->close();
it->m_exists = true;

if (it == begin) {
/* First data file. */

/* Create the tablespace entry for the multi-file
tablespace in the tablespace manager. */
space = fil_space_create(
name(), space_id(), flags(), is_temp
? FIL_TYPE_TEMPORARY : FIL_TYPE_TABLESPACE,
NULL);
if (it != begin) {
} else if (is_temp) {
ut_ad(!fil_system.temp_space);
ut_ad(space_id() == SRV_TMP_SPACE_ID);
space = fil_system.temp_space = fil_space_create(
name(), SRV_TMP_SPACE_ID, flags(),
FIL_TYPE_TEMPORARY, NULL);
} else {
ut_ad(!fil_system.sys_space);
ut_ad(space_id() == TRX_SYS_SPACE);
space = fil_system.sys_space = fil_space_create(
name(), TRX_SYS_SPACE, flags(),
FIL_TYPE_TABLESPACE, NULL);
}

ut_a(fil_validate());
@@ -3489,9 +3489,12 @@ innobase_space_shutdown()
{
DBUG_ENTER("innobase_space_shutdown");

if (fil_system.temp_space) {
fil_system.temp_space->close();
}

srv_sys_space.shutdown();
if (srv_tmp_space.get_sanity_check_status()) {
fil_space_close(srv_tmp_space.name());
srv_tmp_space.delete_files();
}
srv_tmp_space.shutdown();
@@ -522,7 +522,9 @@ ibuf_init_at_db_start(void)

mtr_start(&mtr);

mtr_x_lock_space(IBUF_SPACE_ID, &mtr);
compile_time_assert(IBUF_SPACE_ID == TRX_SYS_SPACE);
compile_time_assert(IBUF_SPACE_ID == 0);
mtr_x_lock(&fil_system.sys_space->latch, &mtr);

mutex_enter(&ibuf_mutex);

@@ -1151,7 +1153,8 @@ ibuf_page_low(
return(FALSE);
}

ut_ad(fil_space_get_type(IBUF_SPACE_ID) == FIL_TYPE_TABLESPACE);
compile_time_assert(IBUF_SPACE_ID == 0);
ut_ad(fil_system.sys_space->purpose == FIL_TYPE_TABLESPACE);

#ifdef UNIV_DEBUG
if (!x_latch) {
@@ -2028,11 +2031,9 @@ ibuf_add_free_page(void)
page_t* bitmap_page;

mtr_start(&mtr);
fil_space_t* space = mtr.set_sys_modified();

/* Acquire the fsp latch before the ibuf header, obeying the latching
order */
mtr_x_lock(&space->latch, &mtr);
mtr_x_lock(&fil_system.sys_space->latch, &mtr);
header_page = ibuf_header_page_get(&mtr);

/* Allocate a new page: NOTE that if the page has been a part of a
@@ -2078,13 +2079,11 @@ ibuf_add_free_page(void)
(level 2 page) */

const page_id_t page_id(IBUF_SPACE_ID, block->page.id.page_no());
const page_size_t page_size(space->flags);

bitmap_page = ibuf_bitmap_get_map_page(page_id, page_size, &mtr);
bitmap_page = ibuf_bitmap_get_map_page(page_id, univ_page_size, &mtr);

mutex_exit(&ibuf_mutex);

ibuf_bitmap_page_set_bits(bitmap_page, page_id, page_size,
ibuf_bitmap_page_set_bits(bitmap_page, page_id, univ_page_size,
IBUF_BITMAP_IBUF, TRUE, &mtr);

ibuf_mtr_commit(&mtr);
@@ -2110,13 +2109,10 @@ ibuf_remove_free_page(void)
log_free_check();

mtr_start(&mtr);
fil_space_t* space = mtr.set_sys_modified();
const page_size_t page_size(space->flags);

/* Acquire the fsp latch before the ibuf header, obeying the latching
order */

mtr_x_lock(&space->latch, &mtr);
mtr_x_lock(&fil_system.sys_space->latch, &mtr);
header_page = ibuf_header_page_get(&mtr);

/* Prevent pessimistic inserts to insert buffer trees for a while */
@@ -2195,12 +2191,12 @@ ibuf_remove_free_page(void)
/* Set the bit indicating that this page is no more an ibuf tree page
(level 2 page) */

bitmap_page = ibuf_bitmap_get_map_page(page_id, page_size, &mtr);
bitmap_page = ibuf_bitmap_get_map_page(page_id, univ_page_size, &mtr);

mutex_exit(&ibuf_mutex);

ibuf_bitmap_page_set_bits(
bitmap_page, page_id, page_size, IBUF_BITMAP_IBUF, FALSE,
bitmap_page, page_id, univ_page_size, IBUF_BITMAP_IBUF, FALSE,
&mtr);

ut_d(buf_page_set_file_page_was_freed(page_id));

0 comments on commit 2ac8b1a

Please sign in to comment.