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

Cleanup: flst_read_addr(), fil_addr_t

fil_addr_t: Use exactly sized data types.

flst_read_addr(): Remove the unused parameter mtr.

page_offset(): Return uint16_t.
parent 29710b28
......@@ -478,8 +478,8 @@ btr_page_alloc_for_ibuf(
root = btr_root_get(index, mtr);
node_addr = flst_get_first(root + PAGE_HEADER
+ PAGE_BTR_IBUF_FREE_LIST, mtr);
node_addr = flst_get_first(PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST
+ root);
ut_a(node_addr.page != FIL_NULL);
new_block = buf_page_get(
......
......@@ -998,12 +998,12 @@ fsp_alloc_free_extent(
/* Ok, we can take this extent */
} else {
/* Take the first extent in the free list */
first = flst_get_first(header + FSP_FREE, mtr);
first = flst_get_first(header + FSP_FREE);
if (fil_addr_is_null(first)) {
fsp_fill_free_list(false, space, header, mtr);
first = flst_get_first(header + FSP_FREE, mtr);
first = flst_get_first(header + FSP_FREE);
}
if (fil_addr_is_null(first)) {
......@@ -1148,7 +1148,7 @@ fsp_alloc_free_page(
/* Ok, we can take this extent */
} else {
/* Else take the first extent in free_frag list */
first = flst_get_first(header + FSP_FREE_FRAG, mtr);
first = flst_get_first(header + FSP_FREE_FRAG);
if (fil_addr_is_null(first)) {
/* There are no partially full fragments: allocate
......@@ -1479,7 +1479,7 @@ fsp_alloc_seg_inode(
}
const page_id_t page_id(
space->id,
flst_get_first(space_header + FSP_SEG_INODES_FREE, mtr).page);
flst_get_first(space_header + FSP_SEG_INODES_FREE).page);
block = buf_page_get(page_id, space->zip_size(), RW_SX_LATCH, mtr);
buf_block_dbg_add_level(block, SYNC_FSP_PAGE);
......@@ -2019,7 +2019,7 @@ fseg_alloc_free_extent(
if (flst_get_len(inode + FSEG_FREE) > 0) {
/* Segment free list is not empty, allocate from it */
first = flst_get_first(inode + FSEG_FREE, mtr);
first = flst_get_first(inode + FSEG_FREE);
descr = xdes_lst_get_descriptor(space, first, mtr);
} else {
......@@ -2193,10 +2193,9 @@ fseg_alloc_free_page_low(
fil_addr_t first;
if (flst_get_len(seg_inode + FSEG_NOT_FULL) > 0) {
first = flst_get_first(seg_inode + FSEG_NOT_FULL,
mtr);
first = flst_get_first(seg_inode + FSEG_NOT_FULL);
} else if (flst_get_len(seg_inode + FSEG_FREE) > 0) {
first = flst_get_first(seg_inode + FSEG_FREE, mtr);
first = flst_get_first(seg_inode + FSEG_FREE);
} else {
ut_ad(!has_done_reservation);
return(NULL);
......@@ -3039,16 +3038,11 @@ fseg_get_first_extent(
ut_ad(mach_read_from_4(inode + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE);
if (flst_get_len(inode + FSEG_FULL) > 0) {
first = flst_get_first(inode + FSEG_FULL, mtr);
first = flst_get_first(inode + FSEG_FULL);
} else if (flst_get_len(inode + FSEG_NOT_FULL) > 0) {
first = flst_get_first(inode + FSEG_NOT_FULL, mtr);
first = flst_get_first(inode + FSEG_NOT_FULL);
} else if (flst_get_len(inode + FSEG_FREE) > 0) {
first = flst_get_first(inode + FSEG_FREE, mtr);
first = flst_get_first(inode + FSEG_FREE);
} else {
return(NULL);
}
......
......@@ -109,7 +109,7 @@ flst_add_last(
MTR_MEMO_PAGE_X_FIX
| MTR_MEMO_PAGE_SX_FIX));
len = flst_get_len(base);
last_addr = flst_get_last(base, mtr);
last_addr = flst_get_last(base);
buf_ptr_get_fsp_addr(node, &space, &node_addr);
......@@ -159,7 +159,7 @@ flst_add_first(
MTR_MEMO_PAGE_X_FIX
| MTR_MEMO_PAGE_SX_FIX));
len = flst_get_len(base);
first_addr = flst_get_first(base, mtr);
first_addr = flst_get_first(base);
buf_ptr_get_fsp_addr(node, &space, &node_addr);
......@@ -218,7 +218,7 @@ flst_insert_after(
buf_ptr_get_fsp_addr(node1, &space, &node1_addr);
buf_ptr_get_fsp_addr(node2, &space, &node2_addr);
node3_addr = flst_get_next_addr(node1, mtr);
node3_addr = flst_get_next_addr(node1);
/* Set prev and next fields of node2 */
flst_write_addr(node2 + FLST_PREV, node1_addr, mtr);
......@@ -281,7 +281,7 @@ flst_insert_before(
buf_ptr_get_fsp_addr(node2, &space, &node2_addr);
buf_ptr_get_fsp_addr(node3, &space, &node3_addr);
node1_addr = flst_get_prev_addr(node3, mtr);
node1_addr = flst_get_prev_addr(node3);
/* Set prev and next fields of node2 */
flst_write_addr(node2 + FLST_PREV, node1_addr, mtr);
......@@ -340,8 +340,8 @@ flst_remove(
ulint zip_size = s ? s->zip_size() : 0;
if (s) s->release();
node1_addr = flst_get_prev_addr(node2, mtr);
node3_addr = flst_get_next_addr(node2, mtr);
node1_addr = flst_get_prev_addr(node2);
node3_addr = flst_get_next_addr(node2);
if (!fil_addr_is_null(node1_addr)) {
......@@ -426,14 +426,14 @@ flst_validate(
if (s) s->release();
len = flst_get_len(base);
node_addr = flst_get_first(base, mtr1);
node_addr = flst_get_first(base);
for (i = 0; i < len; i++) {
mtr_start(&mtr2);
node = fut_get_ptr(space, zip_size,
node_addr, RW_SX_LATCH, &mtr2);
node_addr = flst_get_next_addr(node, &mtr2);
node_addr = flst_get_next_addr(node);
mtr_commit(&mtr2); /* Commit mtr2 each round to prevent buffer
becoming full */
......@@ -441,14 +441,14 @@ flst_validate(
ut_a(fil_addr_is_null(node_addr));
node_addr = flst_get_last(base, mtr1);
node_addr = flst_get_last(base);
for (i = 0; i < len; i++) {
mtr_start(&mtr2);
node = fut_get_ptr(space, zip_size,
node_addr, RW_SX_LATCH, &mtr2);
node_addr = flst_get_prev_addr(node, &mtr2);
node_addr = flst_get_prev_addr(node);
mtr_commit(&mtr2); /* Commit mtr2 each round to prevent buffer
becoming full */
......
......@@ -2013,8 +2013,8 @@ ibuf_remove_free_page(void)
mutex_exit(&ibuf_mutex);
page_no = flst_get_last(root + PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST,
&mtr2).page;
page_no = flst_get_last(PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST
+ root).page;
/* NOTE that we must release the latch on the ibuf tree root
because in fseg_free_page we access level 1 pages, and the root
......@@ -2043,8 +2043,8 @@ ibuf_remove_free_page(void)
root = ibuf_tree_root_get(&mtr);
ut_ad(page_no == flst_get_last(root + PAGE_HEADER
+ PAGE_BTR_IBUF_FREE_LIST, &mtr).page);
ut_ad(page_no == flst_get_last(PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST
+ root).page);
{
buf_block_t* block;
......
......@@ -774,7 +774,7 @@ buf_ptr_get_fsp_addr(
*space = mach_read_from_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
addr->page = mach_read_from_4(page + FIL_PAGE_OFFSET);
addr->boffset = ut_align_offset(ptr, srv_page_size);
addr->boffset = static_cast<uint16_t>(ut_align_offset(ptr, srv_page_size));
}
/**********************************************************************//**
......
......@@ -672,8 +672,10 @@ typedef byte fil_faddr_t; /*!< 'type' definition in C: an address
/** File space address */
struct fil_addr_t {
ulint page; /*!< page number within a space */
ulint boffset; /*!< byte offset within the page */
/** page number within a tablespace */
uint32_t page;
/** byte offset within the page */
uint16_t boffset;
};
/** The byte offsets on a file page for various variables @{ */
......
/*****************************************************************************
Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2018, MariaDB Corporation.
Copyright (c) 2018, 2019, MariaDB Corporation.
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
......@@ -133,42 +133,6 @@ uint32_t
flst_get_len(
const flst_base_node_t* base);
/********************************************************************//**
Gets list first node address.
@return file address */
UNIV_INLINE
fil_addr_t
flst_get_first(
/*===========*/
const flst_base_node_t* base, /*!< in: pointer to base node */
mtr_t* mtr); /*!< in: mini-transaction handle */
/********************************************************************//**
Gets list last node address.
@return file address */
UNIV_INLINE
fil_addr_t
flst_get_last(
/*==========*/
const flst_base_node_t* base, /*!< in: pointer to base node */
mtr_t* mtr); /*!< in: mini-transaction handle */
/********************************************************************//**
Gets list next node address.
@return file address */
UNIV_INLINE
fil_addr_t
flst_get_next_addr(
/*===============*/
const flst_node_t* node, /*!< in: pointer to node */
mtr_t* mtr); /*!< in: mini-transaction handle */
/********************************************************************//**
Gets list prev node address.
@return file address */
UNIV_INLINE
fil_addr_t
flst_get_prev_addr(
/*===============*/
const flst_node_t* node, /*!< in: pointer to node */
mtr_t* mtr); /*!< in: mini-transaction handle */
/********************************************************************//**
Writes a file address. */
UNIV_INLINE
void
......@@ -177,15 +141,41 @@ flst_write_addr(
fil_faddr_t* faddr, /*!< in: pointer to file faddress */
fil_addr_t addr, /*!< in: file address */
mtr_t* mtr); /*!< in: mini-transaction handle */
/********************************************************************//**
Reads a file address.
@return file address */
UNIV_INLINE
fil_addr_t
flst_read_addr(
/*===========*/
const fil_faddr_t* faddr, /*!< in: pointer to file faddress */
mtr_t* mtr); /*!< in: mini-transaction handle */
/** @return a file address */
inline fil_addr_t flst_read_addr(const fil_faddr_t *faddr)
{
fil_addr_t addr= { mach_read_from_4(faddr + FIL_ADDR_PAGE),
mach_read_from_2(faddr + FIL_ADDR_BYTE) };
ut_a(addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA);
ut_a(ut_align_offset(faddr, srv_page_size) >= FIL_PAGE_DATA);
return addr;
}
/** @return list first node address */
inline fil_addr_t flst_get_first(const flst_base_node_t *base)
{
return flst_read_addr(base + FLST_FIRST);
}
/** @return list last node address */
inline fil_addr_t flst_get_last(const flst_base_node_t *base)
{
return flst_read_addr(base + FLST_LAST);
}
/** @return list next node address */
inline fil_addr_t flst_get_next_addr(const flst_node_t* node)
{
return flst_read_addr(node + FLST_NEXT);
}
/** @return list prev node address */
inline fil_addr_t flst_get_prev_addr(const flst_node_t *node)
{
return flst_read_addr(node + FLST_PREV);
}
/********************************************************************//**
Validates a file-based list.
@return TRUE if ok */
......
......@@ -48,27 +48,6 @@ flst_write_addr(
MLOG_2BYTES, mtr);
}
/********************************************************************//**
Reads a file address.
@return file address */
UNIV_INLINE
fil_addr_t
flst_read_addr(
/*===========*/
const fil_faddr_t* faddr, /*!< in: pointer to file faddress */
mtr_t* mtr) /*!< in: mini-transaction handle */
{
fil_addr_t addr;
ut_ad(faddr && mtr);
addr.page = mach_read_from_4(faddr + FIL_ADDR_PAGE);
addr.boffset = mach_read_from_2(faddr + FIL_ADDR_BYTE);
ut_a(addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA);
ut_a(ut_align_offset(faddr, srv_page_size) >= FIL_PAGE_DATA);
return(addr);
}
/********************************************************************//**
Initializes a list base node. */
UNIV_INLINE
......@@ -99,55 +78,3 @@ flst_get_len(
{
return(mach_read_from_4(base + FLST_LEN));
}
/********************************************************************//**
Gets list first node address.
@return file address */
UNIV_INLINE
fil_addr_t
flst_get_first(
/*===========*/
const flst_base_node_t* base, /*!< in: pointer to base node */
mtr_t* mtr) /*!< in: mini-transaction handle */
{
return(flst_read_addr(base + FLST_FIRST, mtr));
}
/********************************************************************//**
Gets list last node address.
@return file address */
UNIV_INLINE
fil_addr_t
flst_get_last(
/*==========*/
const flst_base_node_t* base, /*!< in: pointer to base node */
mtr_t* mtr) /*!< in: mini-transaction handle */
{
return(flst_read_addr(base + FLST_LAST, mtr));
}
/********************************************************************//**
Gets list next node address.
@return file address */
UNIV_INLINE
fil_addr_t
flst_get_next_addr(
/*===============*/
const flst_node_t* node, /*!< in: pointer to node */
mtr_t* mtr) /*!< in: mini-transaction handle */
{
return(flst_read_addr(node + FLST_NEXT, mtr));
}
/********************************************************************//**
Gets list prev node address.
@return file address */
UNIV_INLINE
fil_addr_t
flst_get_prev_addr(
/*===============*/
const flst_node_t* node, /*!< in: pointer to node */
mtr_t* mtr) /*!< in: mini-transaction handle */
{
return(flst_read_addr(node + FLST_PREV, mtr));
}
......@@ -210,11 +210,9 @@ page_align(const void* ptr)
@param[in] ptr pointer within a page frame
@return offset from the start of the page */
MY_ATTRIBUTE((const))
inline
ulint
page_offset(const void* ptr)
inline uint16_t page_offset(const void* ptr)
{
return(ut_align_offset(ptr, srv_page_size));
return static_cast<uint16_t>(ut_align_offset(ptr, srv_page_size));
}
/** Determine whether an index page is not in ROW_FORMAT=REDUNDANT.
......
......@@ -441,8 +441,8 @@ trx_purge_truncate_rseg_history(
rseg_hdr = trx_rsegf_get(rseg.space, rseg.page_no, &mtr);
hdr_addr = trx_purge_get_log_from_hist(
flst_get_last(rseg_hdr + TRX_RSEG_HISTORY, &mtr));
hdr_addr = trx_purge_get_log_from_hist(flst_get_last(TRX_RSEG_HISTORY
+ rseg_hdr));
loop:
if (hdr_addr.page == FIL_NULL) {
func_exit:
......@@ -469,7 +469,7 @@ trx_purge_truncate_rseg_history(
}
prev_hdr_addr = trx_purge_get_log_from_hist(
flst_get_prev_addr(log_hdr + TRX_UNDO_HISTORY_NODE, &mtr));
flst_get_prev_addr(log_hdr + TRX_UNDO_HISTORY_NODE));
seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
......@@ -852,7 +852,7 @@ static void trx_purge_rseg_get_next_history_log(
(*n_pages_handled)++;
prev_log_addr = trx_purge_get_log_from_hist(
flst_get_prev_addr(log_hdr + TRX_UNDO_HISTORY_NODE, &mtr));
flst_get_prev_addr(log_hdr + TRX_UNDO_HISTORY_NODE));
const bool empty = prev_log_addr.page == FIL_NULL;
......
......@@ -506,7 +506,7 @@ trx_rseg_mem_restore(trx_rseg_t* rseg, trx_id_t& max_trx_id, mtr_t* mtr)
trx_sys.rseg_history_len += len;
fil_addr_t node_addr = trx_purge_get_log_from_hist(
flst_get_last(rseg_header + TRX_RSEG_HISTORY, mtr));
flst_get_last(rseg_header + TRX_RSEG_HISTORY));
rseg->last_page_no = node_addr.page;
rseg->last_offset = node_addr.boffset;
......
......@@ -176,7 +176,7 @@ trx_undo_get_prev_rec_from_prev_page(
undo_page = page_align(rec);
prev_page_no = flst_get_prev_addr(undo_page + TRX_UNDO_PAGE_HDR
+ TRX_UNDO_PAGE_NODE, mtr)
+ TRX_UNDO_PAGE_NODE)
.page;
if (prev_page_no == FIL_NULL) {
......@@ -284,8 +284,8 @@ trx_undo_get_next_rec_from_next_page(
}
}
next_page_no = flst_get_next_addr(undo_page + TRX_UNDO_PAGE_HDR
+ TRX_UNDO_PAGE_NODE, mtr)
next_page_no = flst_get_next_addr(TRX_UNDO_PAGE_HDR
+ TRX_UNDO_PAGE_NODE + undo_page)
.page;
if (next_page_no == FIL_NULL) {
......@@ -856,7 +856,7 @@ trx_undo_free_page(
rseg->space, page_no, false, true, mtr);
const fil_addr_t last_addr = flst_get_last(
TRX_UNDO_SEG_HDR + TRX_UNDO_PAGE_LIST + header_page, mtr);
TRX_UNDO_SEG_HDR + TRX_UNDO_PAGE_LIST + header_page);
rseg->curr_size--;
if (in_history) {
......@@ -1143,8 +1143,7 @@ trx_undo_mem_create_at_db_start(trx_rseg_t* rseg, ulint id, ulint page_no,
}
fil_addr_t last_addr = flst_get_last(
TRX_UNDO_SEG_HDR + TRX_UNDO_PAGE_LIST + undo_page,
&mtr);
TRX_UNDO_SEG_HDR + TRX_UNDO_PAGE_LIST + undo_page);
undo->last_page_no = last_addr.page;
undo->top_page_no = last_addr.page;
......
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