Commit 332e805e authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-12266: Refactor trx_rseg_header_create()

parent 428e0289
...@@ -71,17 +71,15 @@ UNIV_INLINE ...@@ -71,17 +71,15 @@ UNIV_INLINE
ulint ulint
trx_rsegf_undo_find_free(const trx_rsegf_t* rsegf); trx_rsegf_undo_find_free(const trx_rsegf_t* rsegf);
/** Creates a rollback segment header. /** Create a rollback segment header.
This function is called only when a new rollback segment is created in @param[in] space system, undo, or temporary tablespace
the database.
@param[in] space space id
@param[in] rseg_id rollback segment identifier @param[in] rseg_id rollback segment identifier
@param[in,out] sys_header the TRX_SYS page (NULL for temporary rseg) @param[in,out] sys_header the TRX_SYS page (NULL for temporary rseg)
@param[in,out] mtr mini-transaction @param[in,out] mtr mini-transaction
@return page number of the created segment, FIL_NULL if fail */ @return page number of the created segment, FIL_NULL if fail */
ulint ulint
trx_rseg_header_create( trx_rseg_header_create(
ulint space, const fil_space_t* space,
ulint rseg_id, ulint rseg_id,
buf_block_t* sys_header, buf_block_t* sys_header,
mtr_t* mtr); mtr_t* mtr);
......
...@@ -1073,7 +1073,9 @@ srv_undo_tablespaces_init(bool create_new_db) ...@@ -1073,7 +1073,9 @@ srv_undo_tablespaces_init(bool create_new_db)
undo::Truncate::add_space_to_trunc_list(*it); undo::Truncate::add_space_to_trunc_list(*it);
fsp_header_init(fil_space_get(*it), fil_space_t* space = fil_space_get(*it);
fsp_header_init(space,
SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES,
&mtr); &mtr);
...@@ -1081,7 +1083,7 @@ srv_undo_tablespaces_init(bool create_new_db) ...@@ -1081,7 +1083,7 @@ srv_undo_tablespaces_init(bool create_new_db)
if (trx_sysf_rseg_get_space(sys_header, i) if (trx_sysf_rseg_get_space(sys_header, i)
== *it) { == *it) {
trx_rseg_header_create( trx_rseg_header_create(
*it, i, sys_header, &mtr); space, i, sys_header, &mtr);
} }
} }
......
...@@ -261,17 +261,15 @@ void trx_rseg_format_upgrade(trx_rsegf_t* rseg_header, mtr_t* mtr) ...@@ -261,17 +261,15 @@ void trx_rseg_format_upgrade(trx_rsegf_t* rseg_header, mtr_t* mtr)
mlog_log_string(b, len, mtr); mlog_log_string(b, len, mtr);
} }
/** Creates a rollback segment header. /** Create a rollback segment header.
This function is called only when a new rollback segment is created in @param[in] space system, undo, or temporary tablespace
the database.
@param[in] space space id
@param[in] rseg_id rollback segment identifier @param[in] rseg_id rollback segment identifier
@param[in,out] sys_header the TRX_SYS page (NULL for temporary rseg) @param[in,out] sys_header the TRX_SYS page (NULL for temporary rseg)
@param[in,out] mtr mini-transaction @param[in,out] mtr mini-transaction
@return page number of the created segment, FIL_NULL if fail */ @return page number of the created segment, FIL_NULL if fail */
ulint ulint
trx_rseg_header_create( trx_rseg_header_create(
ulint space, const fil_space_t* space,
ulint rseg_id, ulint rseg_id,
buf_block_t* sys_header, buf_block_t* sys_header,
mtr_t* mtr) mtr_t* mtr)
...@@ -280,13 +278,12 @@ trx_rseg_header_create( ...@@ -280,13 +278,12 @@ trx_rseg_header_create(
trx_rsegf_t* rsegf; trx_rsegf_t* rsegf;
buf_block_t* block; buf_block_t* block;
ut_ad(mtr); ut_ad(mtr_memo_contains(mtr, &space->latch, MTR_MEMO_X_LOCK));
ut_ad(mtr_memo_contains(mtr, fil_space_get_latch(space, NULL), ut_ad(!sys_header == (space == fil_system.temp_space));
MTR_MEMO_X_LOCK));
ut_ad(!sys_header == (space == SRV_TMP_SPACE_ID));
/* Allocate a new file segment for the rollback segment */ /* Allocate a new file segment for the rollback segment */
block = fseg_create(space, 0, TRX_RSEG + TRX_RSEG_FSEG_HEADER, mtr); block = fseg_create(space->id, 0, TRX_RSEG + TRX_RSEG_FSEG_HEADER,
mtr);
if (block == NULL) { if (block == NULL) {
/* No space left */ /* No space left */
...@@ -299,7 +296,7 @@ trx_rseg_header_create( ...@@ -299,7 +296,7 @@ trx_rseg_header_create(
page_no = block->page.id.page_no(); page_no = block->page.id.page_no();
/* Get the rollback segment file page */ /* Get the rollback segment file page */
rsegf = trx_rsegf_get_new(space, page_no, mtr); rsegf = trx_rsegf_get_new(space->id, page_no, mtr);
mlog_write_ulint(rsegf + TRX_RSEG_FORMAT, 0, MLOG_4BYTES, mtr); mlog_write_ulint(rsegf + TRX_RSEG_FORMAT, 0, MLOG_4BYTES, mtr);
...@@ -322,7 +319,7 @@ trx_rseg_header_create( ...@@ -322,7 +319,7 @@ trx_rseg_header_create(
+ TRX_SYS_RSEG_SPACE + TRX_SYS_RSEG_SPACE
+ rseg_id * TRX_SYS_RSEG_SLOT_SIZE + rseg_id * TRX_SYS_RSEG_SLOT_SIZE
+ sys_header->frame, + sys_header->frame,
space, MLOG_4BYTES, mtr); space->id, MLOG_4BYTES, mtr);
mlog_write_ulint(TRX_SYS + TRX_SYS_RSEGS mlog_write_ulint(TRX_SYS + TRX_SYS_RSEGS
+ TRX_SYS_RSEG_PAGE_NO + TRX_SYS_RSEG_PAGE_NO
+ rseg_id * TRX_SYS_RSEG_SLOT_SIZE + rseg_id * TRX_SYS_RSEG_SLOT_SIZE
...@@ -603,17 +600,14 @@ trx_rseg_create(ulint space_id) ...@@ -603,17 +600,14 @@ trx_rseg_create(ulint space_id)
/* To obey the latching order, acquire the file space /* To obey the latching order, acquire the file space
x-latch before the trx_sys.mutex. */ x-latch before the trx_sys.mutex. */
#ifdef UNIV_DEBUG const fil_space_t* space = mtr_x_lock_space(space_id, &mtr);
const fil_space_t* space =
#endif /* UNIV_DEBUG */
mtr_x_lock_space(space_id, &mtr);
ut_ad(space->purpose == FIL_TYPE_TABLESPACE); ut_ad(space->purpose == FIL_TYPE_TABLESPACE);
if (buf_block_t* sys_header = trx_sysf_get(&mtr)) { if (buf_block_t* sys_header = trx_sysf_get(&mtr)) {
ulint rseg_id = trx_sys_rseg_find_free(sys_header); ulint rseg_id = trx_sys_rseg_find_free(sys_header);
ulint page_no = rseg_id == ULINT_UNDEFINED ulint page_no = rseg_id == ULINT_UNDEFINED
? FIL_NULL ? FIL_NULL
: trx_rseg_header_create(space_id, rseg_id, sys_header, : trx_rseg_header_create(space, rseg_id, sys_header,
&mtr); &mtr);
if (page_no != FIL_NULL) { if (page_no != FIL_NULL) {
ut_ad(trx_sysf_rseg_get_space(sys_header, rseg_id) ut_ad(trx_sysf_rseg_get_space(sys_header, rseg_id)
...@@ -643,7 +637,7 @@ trx_temp_rseg_create() ...@@ -643,7 +637,7 @@ trx_temp_rseg_create()
mtr_x_lock(&fil_system.temp_space->latch, &mtr); mtr_x_lock(&fil_system.temp_space->latch, &mtr);
ulint page_no = trx_rseg_header_create( ulint page_no = trx_rseg_header_create(
SRV_TMP_SPACE_ID, i, NULL, &mtr); fil_system.temp_space, i, NULL, &mtr);
trx_rseg_t* rseg = trx_rseg_mem_create( trx_rseg_t* rseg = trx_rseg_mem_create(
i, SRV_TMP_SPACE_ID, page_no); i, SRV_TMP_SPACE_ID, page_no);
ut_ad(!rseg->is_persistent()); ut_ad(!rseg->is_persistent());
......
...@@ -200,7 +200,8 @@ trx_sysf_create( ...@@ -200,7 +200,8 @@ trx_sysf_create(
/* Create the first rollback segment in the SYSTEM tablespace */ /* Create the first rollback segment in the SYSTEM tablespace */
slot_no = trx_sys_rseg_find_free(block); slot_no = trx_sys_rseg_find_free(block);
page_no = trx_rseg_header_create(TRX_SYS_SPACE, slot_no, block, mtr); page_no = trx_rseg_header_create(fil_system.sys_space, slot_no, block,
mtr);
ut_a(slot_no == TRX_SYS_SYSTEM_RSEG_ID); ut_a(slot_no == TRX_SYS_SYSTEM_RSEG_ID);
ut_a(page_no == FSP_FIRST_RSEG_PAGE_NO); ut_a(page_no == FSP_FIRST_RSEG_PAGE_NO);
......
...@@ -1728,7 +1728,7 @@ trx_undo_truncate_tablespace( ...@@ -1728,7 +1728,7 @@ trx_undo_truncate_tablespace(
trx_rseg_t* rseg = undo_trunc->get_ith_rseg(i); trx_rseg_t* rseg = undo_trunc->get_ith_rseg(i);
rseg->page_no = trx_rseg_header_create( rseg->page_no = trx_rseg_header_create(
space->id, rseg->id, sys_header, &mtr); space, rseg->id, sys_header, &mtr);
rseg_header = trx_rsegf_get_new(space->id, rseg->page_no, rseg_header = trx_rsegf_get_new(space->id, rseg->page_no,
&mtr); &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