函数 flst_get_first

时间:2022-01-19 23:19:38
/********************************************************************//**
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)); //#define FLST_FIRST 4 flist node节点内存地址
}

/********************************************************************//**
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 = mtr_read_ulint(faddr + FIL_ADDR_PAGE, MLOG_4BYTES, mtr);
    addr.boffset = mtr_read_ulint(faddr + FIL_ADDR_BYTE, MLOG_2BYTES,
                      mtr);
    ut_a(addr.page == FIL_NULL || addr.boffset >= FIL_PAGE_DATA);
    ut_a(ut_align_offset(faddr, UNIV_PAGE_SIZE) >= FIL_PAGE_DATA);
    return(addr);
}
#define FIL_ADDR_PAGE    0
#define FIL_ADDR_BYTE    4#define FIL_PAGE_DATA   38

flst_node_t可以通过buf_ptr_get_fsp_addr来确定fil_addr_t。 flst_node_t中存有12个字节的内容,前6个字节(page:4 boffset:2)表示相对自己前一个node的fil_addr_t信息,后6个字节表示相对自己后1个node的fil_addr_t。除了flst_node_t以外,磁盘链表还有一个头信息flst_base_node_t,头信息是一个节点个数FLST_LEN(4字节) + FLST_FIRST (6字节)+ FLST_LAST(6字节)