Commit 78d0d2cd authored by Marko Mäkelä's avatar Marko Mäkelä

Cleanup: Remove mach_read_ulint()

The function mach_read_ulint() is a wrapper for the lower-level
functions mach_read_from_1(), mach_read_from_2(), mach_read_from_8().
Invoke those functions directly, for better readability of the code.

mtr_t::read_ulint(), mtr_read_ulint(): Remove. Yes, we will lose the
ability to assert that the read is covered by the mini-transaction.
We would still check that on writes, and any writes that
wrongly bypass mini-transaction logging would likely be caught by
stress testing with Mariabackup.
parent 8a5eb414
...@@ -3343,9 +3343,9 @@ static dberr_t xb_assign_undo_space_start() ...@@ -3343,9 +3343,9 @@ static dberr_t xb_assign_undo_space_start()
+ TRX_SYS_RSEG_PAGE_NO + page) + TRX_SYS_RSEG_PAGE_NO + page)
!= FIL_NULL); != FIL_NULL);
space = mach_read_ulint(TRX_SYS + TRX_SYS_RSEGS space = mach_read_from_4(TRX_SYS + TRX_SYS_RSEGS
+ TRX_SYS_RSEG_SLOT_SIZE + TRX_SYS_RSEG_SLOT_SIZE
+ TRX_SYS_RSEG_SPACE + page, MLOG_4BYTES); + TRX_SYS_RSEG_SPACE + page);
srv_undo_space_id_start = space; srv_undo_space_id_start = space;
......
...@@ -920,7 +920,7 @@ dict_drop_index_tree( ...@@ -920,7 +920,7 @@ dict_drop_index_tree(
btr_pcur_store_position(pcur, mtr); btr_pcur_store_position(pcur, mtr);
root_page_no = mtr_read_ulint(ptr, MLOG_4BYTES, mtr); root_page_no = mach_read_from_4(ptr);
if (root_page_no == FIL_NULL) { if (root_page_no == FIL_NULL) {
/* The tree has already been freed */ /* The tree has already been freed */
...@@ -936,7 +936,7 @@ dict_drop_index_tree( ...@@ -936,7 +936,7 @@ dict_drop_index_tree(
ut_ad(len == 4); ut_ad(len == 4);
space = mtr_read_ulint(ptr, MLOG_4BYTES, mtr); space = mach_read_from_4(ptr);
ptr = rec_get_nth_field_old( ptr = rec_get_nth_field_old(
rec, DICT_FLD__SYS_INDEXES__ID, &len); rec, DICT_FLD__SYS_INDEXES__ID, &len);
......
...@@ -1484,11 +1484,10 @@ void dict_check_tablespaces_and_store_max_id() ...@@ -1484,11 +1484,10 @@ void dict_check_tablespaces_and_store_max_id()
dict_sys_lock(); dict_sys_lock();
/* Initialize the max space_id from sys header */ /* Initialize the max space_id from sys header */
mtr_start(&mtr); mtr.start();
ulint max_space_id = mtr_read_ulint( ulint max_space_id = mach_read_from_4(DICT_HDR_MAX_SPACE_ID
dict_hdr_get(&mtr) + DICT_HDR_MAX_SPACE_ID, + dict_hdr_get(&mtr));
MLOG_4BYTES, &mtr); mtr.commit();
mtr_commit(&mtr);
fil_set_max_space_id_if_bigger(max_space_id); fil_set_max_space_id_if_bigger(max_space_id);
......
...@@ -1386,8 +1386,7 @@ static void fsp_free_page(fil_space_t* space, page_no_t offset, ...@@ -1386,8 +1386,7 @@ static void fsp_free_page(fil_space_t* space, page_no_t offset,
xdes_set_bit(descr, XDES_FREE_BIT, bit, TRUE, mtr); xdes_set_bit(descr, XDES_FREE_BIT, bit, TRUE, mtr);
xdes_set_bit(descr, XDES_CLEAN_BIT, bit, TRUE, mtr); xdes_set_bit(descr, XDES_CLEAN_BIT, bit, TRUE, mtr);
frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED, MLOG_4BYTES, frag_n_used = mach_read_from_4(header + FSP_FRAG_N_USED);
mtr);
if (state == XDES_FULL_FRAG) { if (state == XDES_FULL_FRAG) {
/* The fragment was full: move it to another list */ /* The fragment was full: move it to another list */
flst_remove(header + FSP_FULL_FRAG, descr + XDES_FLST_NODE, flst_remove(header + FSP_FULL_FRAG, descr + XDES_FLST_NODE,
...@@ -2610,8 +2609,7 @@ fsp_reserve_free_extents( ...@@ -2610,8 +2609,7 @@ fsp_reserve_free_extents(
n_free_list_ext = flst_get_len(space_header + FSP_FREE); n_free_list_ext = flst_get_len(space_header + FSP_FREE);
ut_ad(space->free_len == n_free_list_ext); ut_ad(space->free_len == n_free_list_ext);
free_limit = mtr_read_ulint(space_header + FSP_FREE_LIMIT, free_limit = mach_read_from_4(space_header + FSP_FREE_LIMIT);
MLOG_4BYTES, mtr);
ut_ad(space->free_limit == free_limit); ut_ad(space->free_limit == free_limit);
/* Below we play safe when counting free extents above the free limit: /* Below we play safe when counting free extents above the free limit:
...@@ -2693,9 +2691,7 @@ fseg_mark_page_used( ...@@ -2693,9 +2691,7 @@ fseg_mark_page_used(
ut_ad(!((page_offset(seg_inode) - FSEG_ARR_OFFSET) % FSEG_INODE_SIZE)); ut_ad(!((page_offset(seg_inode) - FSEG_ARR_OFFSET) % FSEG_INODE_SIZE));
ut_ad(mach_read_from_4(seg_inode + FSEG_MAGIC_N) ut_ad(mach_read_from_4(seg_inode + FSEG_MAGIC_N)
== FSEG_MAGIC_N_VALUE); == FSEG_MAGIC_N_VALUE);
ut_ad(!memcmp(seg_inode + FSEG_ID, descr + XDES_ID, 4));
ut_ad(mtr_read_ulint(seg_inode + FSEG_ID, MLOG_4BYTES, mtr)
== mtr_read_ulint(descr + XDES_ID, MLOG_4BYTES, mtr));
if (xdes_is_free(descr, mtr)) { if (xdes_is_free(descr, mtr)) {
/* We move the extent from the free list to the /* We move the extent from the free list to the
...@@ -2712,8 +2708,7 @@ fseg_mark_page_used( ...@@ -2712,8 +2708,7 @@ fseg_mark_page_used(
/* We mark the page as used */ /* We mark the page as used */
xdes_set_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, FALSE, mtr); xdes_set_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, FALSE, mtr);
not_full_n_used = mtr_read_ulint(seg_inode + FSEG_NOT_FULL_N_USED, not_full_n_used = mach_read_from_4(seg_inode + FSEG_NOT_FULL_N_USED);
MLOG_4BYTES, mtr);
not_full_n_used++; not_full_n_used++;
mlog_write_ulint(seg_inode + FSEG_NOT_FULL_N_USED, not_full_n_used, mlog_write_ulint(seg_inode + FSEG_NOT_FULL_N_USED, not_full_n_used,
MLOG_4BYTES, mtr); MLOG_4BYTES, mtr);
...@@ -2825,8 +2820,7 @@ fseg_free_page_low( ...@@ -2825,8 +2820,7 @@ fseg_free_page_low(
<< FORCE_RECOVERY_MSG; << FORCE_RECOVERY_MSG;
} }
not_full_n_used = mtr_read_ulint(seg_inode + FSEG_NOT_FULL_N_USED, not_full_n_used = mach_read_from_4(seg_inode + FSEG_NOT_FULL_N_USED);
MLOG_4BYTES, mtr);
if (xdes_is_full(descr, mtr)) { if (xdes_is_full(descr, mtr)) {
/* The fragment is full: move it to another list */ /* The fragment is full: move it to another list */
flst_remove(seg_inode + FSEG_FULL, flst_remove(seg_inode + FSEG_FULL,
...@@ -2991,9 +2985,8 @@ fseg_free_extent( ...@@ -2991,9 +2985,8 @@ fseg_free_extent(
flst_remove(seg_inode + FSEG_NOT_FULL, flst_remove(seg_inode + FSEG_NOT_FULL,
descr + XDES_FLST_NODE, mtr); descr + XDES_FLST_NODE, mtr);
not_full_n_used = mtr_read_ulint( not_full_n_used = mach_read_from_4(FSEG_NOT_FULL_N_USED
seg_inode + FSEG_NOT_FULL_N_USED, MLOG_4BYTES, mtr); + seg_inode);
descr_n_used = xdes_get_n_used(descr, mtr); descr_n_used = xdes_get_n_used(descr, mtr);
ut_a(not_full_n_used >= descr_n_used); ut_a(not_full_n_used >= descr_n_used);
mlog_write_ulint(seg_inode + FSEG_NOT_FULL_N_USED, mlog_write_ulint(seg_inode + FSEG_NOT_FULL_N_USED,
...@@ -3234,9 +3227,7 @@ fseg_print_low( ...@@ -3234,9 +3227,7 @@ fseg_print_low(
reserved = fseg_n_reserved_pages_low(inode, &used, mtr); reserved = fseg_n_reserved_pages_low(inode, &used, mtr);
seg_id = mach_read_from_8(inode + FSEG_ID); seg_id = mach_read_from_8(inode + FSEG_ID);
n_used = mach_read_from_4(inode + FSEG_NOT_FULL_N_USED);
n_used = mtr_read_ulint(inode + FSEG_NOT_FULL_N_USED,
MLOG_4BYTES, mtr);
n_frag = fseg_get_n_frag_pages(inode, mtr); n_frag = fseg_get_n_frag_pages(inode, mtr);
n_free = flst_get_len(inode + FSEG_FREE); n_free = flst_get_len(inode + FSEG_FREE);
n_not_full = flst_get_len(inode + FSEG_NOT_FULL); n_not_full = flst_get_len(inode + FSEG_NOT_FULL);
...@@ -3275,23 +3266,12 @@ fseg_print( ...@@ -3275,23 +3266,12 @@ fseg_print(
#endif /* UNIV_BTR_PRINT */ #endif /* UNIV_BTR_PRINT */
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
/** Print the file segment header to the given output stream. std::ostream &fseg_header::to_stream(std::ostream &out) const
@param[in] out the output stream into which the object is printed.
@retval the output stream into which the object was printed. */
std::ostream&
fseg_header::to_stream(std::ostream& out) const
{ {
const ulint space = mtr_read_ulint(m_header + FSEG_HDR_SPACE, out << "[fseg_header_t: space="
MLOG_4BYTES, m_mtr); << mach_read_from_4(m_header + FSEG_HDR_SPACE)
const ulint page_no = mtr_read_ulint(m_header + FSEG_HDR_PAGE_NO, << ", page=" << mach_read_from_4(m_header + FSEG_HDR_PAGE_NO)
MLOG_4BYTES, m_mtr); << ", offset=" << mach_read_from_2(m_header + FSEG_HDR_OFFSET) << "]";
return out;
const ulint offset = mtr_read_ulint(m_header + FSEG_HDR_OFFSET,
MLOG_2BYTES, m_mtr);
out << "[fseg_header_t: space=" << space << ", page="
<< page_no << ", offset=" << offset << "]";
return(out);
} }
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
...@@ -3625,8 +3625,7 @@ fts_read_ulint( ...@@ -3625,8 +3625,7 @@ fts_read_ulint(
dfield_t* dfield = que_node_get_val(exp); dfield_t* dfield = que_node_get_val(exp);
void* data = dfield_get_data(dfield); void* data = dfield_get_data(dfield);
*value = static_cast<ulint>(mach_read_from_4( *value = mach_read_from_4(static_cast<const byte*>(data));
static_cast<const byte*>(data)));
return(TRUE); return(TRUE);
} }
......
...@@ -44,8 +44,5 @@ xdes_get_bit( ...@@ -44,8 +44,5 @@ xdes_get_bit(
ulint bit_index = index % 8; ulint bit_index = index % 8;
ulint byte_index = index / 8; ulint byte_index = index / 8;
return(ut_bit_get_nth( return ut_bit_get_nth(descr[XDES_BITMAP + byte_index], bit_index);
mach_read_ulint(descr + XDES_BITMAP + byte_index,
MLOG_1BYTE),
bit_index));
} }
/***************************************************************************** /*****************************************************************************
Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -61,9 +62,8 @@ flst_read_addr( ...@@ -61,9 +62,8 @@ flst_read_addr(
ut_ad(faddr && mtr); ut_ad(faddr && mtr);
addr.page = mtr_read_ulint(faddr + FIL_ADDR_PAGE, MLOG_4BYTES, mtr); addr.page = mach_read_from_4(faddr + FIL_ADDR_PAGE);
addr.boffset = mtr_read_ulint(faddr + FIL_ADDR_BYTE, MLOG_2BYTES, addr.boffset = mach_read_from_2(faddr + FIL_ADDR_BYTE);
mtr);
ut_a(addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA); ut_a(addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA);
ut_a(ut_align_offset(faddr, srv_page_size) >= FIL_PAGE_DATA); ut_a(ut_align_offset(faddr, srv_page_size) >= FIL_PAGE_DATA);
return(addr); return(addr);
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation. Copyright (c) 2017, 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -367,17 +367,6 @@ mach_write_ulonglong( ...@@ -367,17 +367,6 @@ mach_write_ulonglong(
#endif /* !UNIV_INNOCHECKSUM */ #endif /* !UNIV_INNOCHECKSUM */
/** Read 1 to 4 bytes from a file page buffered in the buffer pool.
@param[in] ptr pointer where to read
@param[in] type MLOG_1BYTE, MLOG_2BYTES, or MLOG_4BYTES
@return value read */
UNIV_INLINE
ulint
mach_read_ulint(
const byte* ptr,
mlog_id_t type)
MY_ATTRIBUTE((warn_unused_result));
#include "mach0data.ic" #include "mach0data.ic"
#endif #endif
/***************************************************************************** /*****************************************************************************
Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation. Copyright (c) 2017, 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -866,28 +866,3 @@ mach_write_ulonglong( ...@@ -866,28 +866,3 @@ mach_write_ulonglong(
} }
#endif /* !UNIV_INNOCHECKSUM */ #endif /* !UNIV_INNOCHECKSUM */
/** Read 1 to 4 bytes from a file page buffered in the buffer pool.
@param[in] ptr pointer where to read
@param[in] type MLOG_1BYTE, MLOG_2BYTES, or MLOG_4BYTES
@return value read */
UNIV_INLINE
ulint
mach_read_ulint(
const byte* ptr,
mlog_id_t type)
{
switch (type) {
case MLOG_1BYTE:
return(mach_read_from_1(ptr));
case MLOG_2BYTES:
return(mach_read_from_2(ptr));
case MLOG_4BYTES:
return(mach_read_from_4(ptr));
default:
break;
}
ut_error;
return(0);
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2012, Facebook Inc. Copyright (c) 2012, Facebook Inc.
Copyright (c) 2013, 2018, MariaDB Corporation. Copyright (c) 2013, 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -54,10 +54,6 @@ savepoint. */ ...@@ -54,10 +54,6 @@ savepoint. */
@return old mode */ @return old mode */
#define mtr_set_log_mode(m, d) (m)->set_log_mode((d)) #define mtr_set_log_mode(m, d) (m)->set_log_mode((d))
/** Read 1 - 4 bytes from a file page buffered in the buffer pool.
@return value read */
#define mtr_read_ulint(p, t, m) (m)->read_ulint((p), (t))
/** Release an object in the memo stack. /** Release an object in the memo stack.
@return true if released */ @return true if released */
#define mtr_memo_release(m, o, t) \ #define mtr_memo_release(m, o, t) \
...@@ -306,13 +302,6 @@ struct mtr_t { ...@@ -306,13 +302,6 @@ struct mtr_t {
bool is_named_space(const fil_space_t* space) const; bool is_named_space(const fil_space_t* space) const;
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
/** Read 1 - 4 bytes from a file page buffered in the buffer pool.
@param ptr pointer from where to read
@param type) MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES
@return value read */
inline ulint read_ulint(const byte* ptr, mlog_id_t type) const
MY_ATTRIBUTE((warn_unused_result));
/** Locks a rw-latch in S mode. /** Locks a rw-latch in S mode.
NOTE: use mtr_s_lock(). NOTE: use mtr_s_lock().
@param lock rw-lock @param lock rw-lock
......
...@@ -275,21 +275,3 @@ mtr_t::sx_lock(rw_lock_t* lock, const char* file, unsigned line) ...@@ -275,21 +275,3 @@ mtr_t::sx_lock(rw_lock_t* lock, const char* file, unsigned line)
memo_push(lock, MTR_MEMO_SX_LOCK); memo_push(lock, MTR_MEMO_SX_LOCK);
} }
/**
Reads 1 - 4 bytes from a file page buffered in the buffer pool.
@return value read */
ulint
mtr_t::read_ulint(const byte* ptr, mlog_id_t type) const
{
ut_ad(is_active());
ut_ad(memo_contains_page_flagged(
ptr,
MTR_MEMO_PAGE_S_FIX
| MTR_MEMO_PAGE_X_FIX
| MTR_MEMO_PAGE_SX_FIX));
return(mach_read_ulint(ptr, type));
}
...@@ -466,17 +466,12 @@ class AbstractCallback ...@@ -466,17 +466,12 @@ class AbstractCallback
UT_DELETE_ARRAY(m_xdes); UT_DELETE_ARRAY(m_xdes);
m_xdes = NULL; m_xdes = NULL;
ulint state; if (mach_read_from_4(XDES_ARR_OFFSET + XDES_STATE + page)
const xdes_t* xdesc = page + XDES_ARR_OFFSET; != XDES_FREE) {
state = mach_read_ulint(xdesc + XDES_STATE, MLOG_4BYTES);
if (state != XDES_FREE) {
const ulint physical_size = m_zip_size const ulint physical_size = m_zip_size
? m_zip_size : srv_page_size; ? m_zip_size : srv_page_size;
m_xdes = UT_NEW_ARRAY_NOKEY(xdes_t, m_xdes = UT_NEW_ARRAY_NOKEY(xdes_t, physical_size);
physical_size);
/* Trigger OOM */ /* Trigger OOM */
DBUG_EXECUTE_IF( DBUG_EXECUTE_IF(
......
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