Skip to content

Commit

Permalink
MDEV-21174: Replace mlog_memset() with mtr_t::memset()
Browse files Browse the repository at this point in the history
Passing buf_block_t helps us avoid calling
mlog_write_initial_log_record_fast() and page_get_page_no(),
and allows us to implement more debug checks, such as
that on ROW_FORMAT=COMPRESSED index pages, only the page header
may be modified by MLOG_MEMSET records.

fseg_n_reserved_pages(): Add a buf_block_t parameter.
  • Loading branch information
dr-m committed Dec 3, 2019
1 parent caea64d commit 8783925
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 219 deletions.
87 changes: 38 additions & 49 deletions storage/innobase/btr/btr0btr.cc
Expand Up @@ -607,42 +607,35 @@ btr_get_size(
mtr_t* mtr) /*!< in/out: mini-transaction where index
is s-latched */
{
fseg_header_t* seg_header;
page_t* root;
ulint n=0;
ulint dummy;

ut_ad(srv_read_only_mode
|| mtr_memo_contains(mtr, dict_index_get_lock(index),
MTR_MEMO_S_LOCK));
ut_ad(flag == BTR_N_LEAF_PAGES || flag == BTR_TOTAL_SIZE);

if (index->page == FIL_NULL
|| dict_index_is_online_ddl(index)
|| !index->is_committed()) {
|| !index->is_committed()
|| !index->table->space) {
return(ULINT_UNDEFINED);
}

root = btr_root_get(index, mtr);

if (root) {
if (flag == BTR_N_LEAF_PAGES) {
seg_header = root + PAGE_HEADER + PAGE_BTR_SEG_LEAF;

fseg_n_reserved_pages(seg_header, &n, mtr);

} else if (flag == BTR_TOTAL_SIZE) {
seg_header = root + PAGE_HEADER + PAGE_BTR_SEG_TOP;

n = fseg_n_reserved_pages(seg_header, &dummy, mtr);

seg_header = root + PAGE_HEADER + PAGE_BTR_SEG_LEAF;

n += fseg_n_reserved_pages(seg_header, &dummy, mtr);
} else {
ut_error;
}
buf_block_t* root = btr_root_block_get(index, RW_SX_LATCH, mtr);
if (!root) {
return ULINT_UNDEFINED;
}
mtr_x_lock_space(index->table->space, mtr);
if (flag == BTR_N_LEAF_PAGES) {
fseg_n_reserved_pages(*root, PAGE_HEADER + PAGE_BTR_SEG_LEAF
+ root->frame, &n, mtr);
} else {
n = ULINT_UNDEFINED;
ulint dummy;
n = fseg_n_reserved_pages(*root, PAGE_HEADER + PAGE_BTR_SEG_TOP
+ root->frame, &dummy, mtr);
n += fseg_n_reserved_pages(*root,
PAGE_HEADER + PAGE_BTR_SEG_LEAF
+ root->frame, &dummy, mtr);
}

return(n);
Expand All @@ -662,9 +655,6 @@ btr_get_size_and_reserved(
mtr_t* mtr) /*!< in/out: mini-transaction where index
is s-latched */
{
fseg_header_t* seg_header;
page_t* root;
ulint n=ULINT_UNDEFINED;
ulint dummy;

ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(index),
Expand All @@ -674,26 +664,26 @@ btr_get_size_and_reserved(

if (index->page == FIL_NULL
|| dict_index_is_online_ddl(index)
|| !index->is_committed()) {
|| !index->is_committed()
|| !index->table->space) {
return(ULINT_UNDEFINED);
}

root = btr_root_get(index, mtr);
buf_block_t* root = btr_root_block_get(index, RW_SX_LATCH, mtr);
*used = 0;
if (!root) {
return ULINT_UNDEFINED;
}

if (root) {

seg_header = root + PAGE_HEADER + PAGE_BTR_SEG_LEAF;

n = fseg_n_reserved_pages(seg_header, used, mtr);

if (flag == BTR_TOTAL_SIZE) {
seg_header = root + PAGE_HEADER + PAGE_BTR_SEG_TOP;

n += fseg_n_reserved_pages(seg_header, &dummy, mtr);
*used += dummy;
mtr_x_lock_space(index->table->space, mtr);

}
ulint n = fseg_n_reserved_pages(*root, PAGE_HEADER + PAGE_BTR_SEG_LEAF
+ root->frame, used, mtr);
if (flag == BTR_TOTAL_SIZE) {
n += fseg_n_reserved_pages(*root,
PAGE_HEADER + PAGE_BTR_SEG_TOP
+ root->frame, &dummy, mtr);
*used += dummy;
}

return(n);
Expand Down Expand Up @@ -1148,7 +1138,7 @@ btr_create(
/* Set the next node and previous node fields */
compile_time_assert(FIL_PAGE_NEXT == FIL_PAGE_PREV + 4);
compile_time_assert(FIL_NULL == 0xffffffff);
mlog_memset(block, FIL_PAGE_PREV, 8, 0xff, mtr);
mtr->memset(block, FIL_PAGE_PREV, 8, 0xff);

/* We reset the free bits for the page in a separate
mini-transaction to allow creation of several trees in the
Expand Down Expand Up @@ -1847,8 +1837,8 @@ void btr_set_instant(buf_block_t* root, const dict_index_t& index, mtr_t* mtr)
}

if (index.table->instant) {
mlog_memset(root, infimum - root->frame, 8, 0, mtr);
mlog_memset(root, supremum - root->frame, 7, 0, mtr);
mtr->memset(root, infimum - root->frame, 8, 0);
mtr->memset(root, supremum - root->frame, 7, 0);
mtr->write<1,mtr_t::OPT>(*root, &supremum[7],
index.n_core_null_bytes);
}
Expand Down Expand Up @@ -1939,7 +1929,7 @@ btr_root_raise_and_insert(
} else {
compile_time_assert(FIL_PAGE_NEXT == FIL_PAGE_PREV + 4);
compile_time_assert(FIL_NULL == 0xffffffff);
mlog_memset(new_block, FIL_PAGE_PREV, 8, 0xff, mtr);
mtr->memset(new_block, FIL_PAGE_PREV, 8, 0xff);
if (UNIV_LIKELY_NULL(new_page_zip)) {
static_assert(FIL_PAGE_PREV % 8 == 0, "alignment");
memset_aligned<8>(new_page_zip->data + FIL_PAGE_PREV,
Expand Down Expand Up @@ -1988,8 +1978,7 @@ btr_root_raise_and_insert(
memset_aligned<8>(p, 0, 8);
page_zip_write_header(root_page_zip, p, 8, mtr);
} else if (mach_read_from_8(p)) {
mlog_memset(root, PAGE_HEADER + PAGE_MAX_TRX_ID, 8, 0,
mtr);
mtr->memset(root, PAGE_HEADER + PAGE_MAX_TRX_ID, 8, 0);
}
} else {
/* PAGE_ROOT_AUTO_INC is only present in the clustered index
Expand All @@ -2002,8 +1991,8 @@ btr_root_raise_and_insert(
memset_aligned<8>(p, 0, 8);
page_zip_write_header(new_page_zip, p, 8, mtr);
} else if (mach_read_from_8(p)) {
mlog_memset(new_block, PAGE_HEADER + PAGE_MAX_TRX_ID,
8, 0, mtr);
mtr->memset(new_block, PAGE_HEADER + PAGE_MAX_TRX_ID,
8, 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/btr/btr0bulk.cc
Expand Up @@ -113,7 +113,7 @@ PageBulk::init()
compile_time_assert(FIL_PAGE_NEXT
== FIL_PAGE_PREV + 4);
compile_time_assert(FIL_NULL == 0xffffffff);
mlog_memset(new_block, FIL_PAGE_PREV, 8, 0xff, &m_mtr);
m_mtr.memset(new_block, FIL_PAGE_PREV, 8, 0xff);
m_mtr.write<2,mtr_t::OPT>(*new_block,
PAGE_HEADER + PAGE_LEVEL
+ new_page, m_level);
Expand Down
16 changes: 7 additions & 9 deletions storage/innobase/btr/btr0cur.cc
Expand Up @@ -7744,8 +7744,7 @@ btr_store_big_rec_extern_fields(
compile_time_assert(FIL_PAGE_NEXT
== FIL_PAGE_PREV + 4);
compile_time_assert(FIL_NULL == 0xffffffff);
mlog_memset(block, FIL_PAGE_PREV, 8, 0xff,
&mtr);
mtr.memset(block, FIL_PAGE_PREV, 8, 0xff);
/* Write a back pointer to the record
into the otherwise unused area. This
information could be useful in
Expand Down Expand Up @@ -7779,11 +7778,10 @@ btr_store_big_rec_extern_fields(
&mtr);
/* Zero out the unused part of the page. */
if (c_stream.avail_out) {
mlog_memset(block,
page_zip_get_size(page_zip)
- c_stream.avail_out,
c_stream.avail_out,
0, &mtr);
mtr.memset(block,
page_zip_get_size(page_zip)
- c_stream.avail_out,
c_stream.avail_out, 0);
}
/* Copy the page to compressed storage,
because it will be flushed to disk
Expand Down Expand Up @@ -7866,8 +7864,8 @@ btr_store_big_rec_extern_fields(
+ FIL_PAGE_DATA + block->frame,
store_len);
compile_time_assert(FIL_NULL == 0xffffffff);
mlog_memset(block, BTR_BLOB_HDR_NEXT_PAGE_NO
+ FIL_PAGE_DATA, 4, 0xff, &mtr);
mtr.memset(block, BTR_BLOB_HDR_NEXT_PAGE_NO
+ FIL_PAGE_DATA, 4, 0xff);

extern_len -= store_len;

Expand Down
6 changes: 3 additions & 3 deletions storage/innobase/dict/dict0crea.cc
Expand Up @@ -899,12 +899,12 @@ dict_create_index_tree_in_mem(
}

/** Drop the index tree associated with a row in SYS_INDEXES table.
@param[in,out] rec SYS_INDEXES record
@param[in,out] pcur persistent cursor on rec
@param[in,out] trx dictionary transaction
@param[in,out] mtr mini-transaction */
void dict_drop_index_tree(rec_t* rec, btr_pcur_t* pcur, trx_t* trx, mtr_t* mtr)
void dict_drop_index_tree(btr_pcur_t* pcur, trx_t* trx, mtr_t* mtr)
{
rec_t* rec = btr_pcur_get_rec(pcur);
byte* ptr;
ulint len;

Expand All @@ -925,7 +925,7 @@ void dict_drop_index_tree(rec_t* rec, btr_pcur_t* pcur, trx_t* trx, mtr_t* mtr)
}

compile_time_assert(FIL_NULL == 0xffffffff);
mlog_memset(ptr, 4, 0xff, mtr);
mtr->memset(btr_pcur_get_block(pcur), page_offset(ptr), 4, 0xff);

ptr = rec_get_nth_field_old(
rec, DICT_FLD__SYS_INDEXES__SPACE, &len);
Expand Down
53 changes: 24 additions & 29 deletions storage/innobase/fsp/fsp0fsp.cc
Expand Up @@ -257,7 +257,8 @@ Inits an extent descriptor to the free and clean state. */
inline void xdes_init(const buf_block_t &block, xdes_t *descr, mtr_t *mtr)
{
ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_SX_FIX));
mlog_memset(descr + XDES_BITMAP, XDES_SIZE - XDES_BITMAP, 0xff, mtr);
mtr->memset(&block, uint16_t(descr - block.frame) + XDES_BITMAP,
XDES_SIZE - XDES_BITMAP, 0xff);
xdes_set_state(block, descr, XDES_FREE, mtr);
}

Expand Down Expand Up @@ -1574,7 +1575,7 @@ static void fsp_free_seg_inode(
static
fseg_inode_t*
fseg_inode_try_get(
fseg_header_t* header,
const fseg_header_t* header,
ulint space,
ulint zip_size,
mtr_t* mtr,
Expand Down Expand Up @@ -1611,7 +1612,7 @@ fseg_inode_try_get(
static
fseg_inode_t*
fseg_inode_get(
fseg_header_t* header,
const fseg_header_t* header,
ulint space,
ulint zip_size,
mtr_t* mtr,
Expand Down Expand Up @@ -1820,8 +1821,8 @@ fseg_create(
mtr->write<4>(*iblock, inode + FSEG_MAGIC_N, FSEG_MAGIC_N_VALUE);
compile_time_assert(FSEG_FRAG_SLOT_SIZE == 4);
compile_time_assert(FIL_NULL == 0xffffffff);
mlog_memset(iblock, uint16_t(inode - iblock->frame) + FSEG_FRAG_ARR,
FSEG_FRAG_SLOT_SIZE * FSEG_FRAG_ARR_N_SLOTS, 0xff, mtr);
mtr->memset(iblock, uint16_t(inode - iblock->frame) + FSEG_FRAG_ARR,
FSEG_FRAG_SLOT_SIZE * FSEG_FRAG_ARR_N_SLOTS, 0xff);

if (page == 0) {
block = fseg_alloc_free_page_low(space,
Expand Down Expand Up @@ -1895,30 +1896,22 @@ fseg_n_reserved_pages_low(
return(ret);
}

/**********************************************************************//**
Calculates the number of pages reserved by a segment, and how many pages are
currently used.
/** Calculate the number of pages reserved by a segment,
and how many pages are currently used.
@param[in] block buffer block containing the file segment header
@param[in] header file segment header
@param[out] used number of pages that are used (not more than reserved)
@param[in,out] mtr mini-transaction
@return number of reserved pages */
ulint
fseg_n_reserved_pages(
/*==================*/
fseg_header_t* header, /*!< in: segment header */
ulint* used, /*!< out: number of pages used (<= reserved) */
mtr_t* mtr) /*!< in/out: mini-transaction */
ulint fseg_n_reserved_pages(const buf_block_t &block,
const fseg_header_t *header, ulint *used,
mtr_t *mtr)
{
ulint ret;
fseg_inode_t* inode;
ulint space_id;
fil_space_t* space;

space_id = page_get_space_id(page_align(header));
space = mtr_x_lock_space(space_id, mtr);

inode = fseg_inode_get(header, space_id, space->zip_size(), mtr);

ret = fseg_n_reserved_pages_low(inode, used, mtr);

return(ret);
ut_ad(page_align(header) == block.frame);
return fseg_n_reserved_pages_low(fseg_inode_get(header,
block.page.id.space(),
block.zip_size(), mtr),
used, mtr);
}

/** Tries to fill the free list of a segment with consecutive free extents.
Expand Down Expand Up @@ -2588,6 +2581,7 @@ fseg_free_page_low(
ut_ad(mach_read_from_4(seg_inode + FSEG_MAGIC_N)
== FSEG_MAGIC_N_VALUE);
ut_ad(!((page_offset(seg_inode) - FSEG_ARR_OFFSET) % FSEG_INODE_SIZE));
ut_ad(iblock->frame == page_align(seg_inode));
ut_d(space->modify_check(*mtr));
#ifdef BTR_CUR_HASH_ADAPT
/* Drop search system page hash index if the page is found in
Expand Down Expand Up @@ -2621,8 +2615,9 @@ fseg_free_page_low(
}

compile_time_assert(FIL_NULL == 0xffffffff);
mlog_memset(seg_inode + FSEG_FRAG_ARR
+ i * FSEG_FRAG_SLOT_SIZE, 4, 0xff, mtr);
mtr->memset(iblock, uint16_t(seg_inode - iblock->frame)
+ FSEG_FRAG_ARR
+ i * FSEG_FRAG_SLOT_SIZE, 4, 0xff);
break;
}

Expand Down
10 changes: 6 additions & 4 deletions storage/innobase/ibuf/ibuf0ibuf.cc
Expand Up @@ -411,15 +411,16 @@ ibuf_init_at_db_start(void)
{
page_t* root;
ulint n_used;
page_t* header_page;

ut_ad(!ibuf.index);
mtr_t mtr;
mtr.start();
compile_time_assert(IBUF_SPACE_ID == TRX_SYS_SPACE);
compile_time_assert(IBUF_SPACE_ID == 0);
mtr_x_lock_space(fil_system.sys_space, &mtr);
header_page = ibuf_header_page_get(&mtr);
buf_block_t* header_page = buf_page_get(
page_id_t(IBUF_SPACE_ID, FSP_IBUF_HEADER_PAGE_NO),
0, RW_X_LATCH, &mtr);

if (!header_page) {
mtr.commit();
Expand All @@ -443,8 +444,9 @@ ibuf_init_at_db_start(void)

mutex_enter(&ibuf_mutex);

fseg_n_reserved_pages(header_page + IBUF_HEADER + IBUF_TREE_SEG_HEADER,
&n_used, &mtr);
fseg_n_reserved_pages(*header_page,
IBUF_HEADER + IBUF_TREE_SEG_HEADER
+ header_page->frame, &n_used, &mtr);

ut_ad(n_used >= 2);

Expand Down
3 changes: 1 addition & 2 deletions storage/innobase/include/dict0crea.h
Expand Up @@ -97,11 +97,10 @@ dict_create_index_tree(
const trx_t* trx); /*!< in: InnoDB transaction handle */

/** Drop the index tree associated with a row in SYS_INDEXES table.
@param[in,out] rec SYS_INDEXES record
@param[in,out] pcur persistent cursor on rec
@param[in,out] trx dictionary transaction
@param[in,out] mtr mini-transaction */
void dict_drop_index_tree(rec_t* rec, btr_pcur_t* pcur, trx_t* trx, mtr_t* mtr)
void dict_drop_index_tree(btr_pcur_t* pcur, trx_t* trx, mtr_t* mtr)
MY_ATTRIBUTE((nonnull));

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

0 comments on commit 8783925

Please sign in to comment.