函数 xdes_get_descriptor_with_space_hdr

 

获得区描述符 xdes entry 的offset

/********************************************************************//**
Gets pointer to a the extent descriptor of a page. The page where the extent
descriptor resides is x-locked. This function no longer extends the data
file.
@return pointer to the extent descriptor, NULL if the page does not
exist in the space or if the offset is >= the free limit */
UNIV_INLINE __attribute__((nonnull, warn_unused_result))
xdes_t*
xdes_get_descriptor_with_space_hdr(
/*===============================*/
    fsp_header_t*    sp_header,    /*!< in/out: space header, x-latched
                    in mtr */
    ulint        space,        /*!< in: space id */
    ulint        offset,        /*!< in: page offset; if equal
                    to the free limit, we try to
                    add new extents to the space
                    free list */
    mtr_t*        mtr)        /*!< in/out: mini-transaction */
{
    ulint    limit;
    ulint    size;
    ulint    zip_size;
    ulint    descr_page_no;
    page_t*    descr_page;

    ut_ad(mtr_memo_contains(mtr, fil_space_get_latch(space, NULL),MTR_MEMO_X_LOCK));
    ut_ad(mtr_memo_contains_page(mtr, sp_header, MTR_MEMO_PAGE_X_FIX));
    ut_ad(page_offset(sp_header) == FSP_HEADER_OFFSET);
    /* Read free limit and space size */
    limit = mach_read_from_4(sp_header + FSP_FREE_LIMIT);
    size  = mach_read_from_4(sp_header + FSP_SIZE);
    zip_size = dict_table_flags_to_zip_size(mach_read_from_4(sp_header + FSP_SPACE_FLAGS));

    if ((offset >= size) || (offset >= limit)) {
        return(NULL);
    }
    
/**
*计算出xdes entry 所在的页号,
* 0 % 16328 = 0
* 64 % 16328 = 64
* 128 % 16328 = 128
* 192 % 16328 = 192
*每个xdes页中含有256个xdes entry,每个xdesc 页是16K,给定一个offset,该值为0 可计算出它属于第几个xdes 页
*/ descr_page_no
= xdes_calc_descriptor_page(zip_size, offset);//详见 if (descr_page_no == 0) { /* It is on the space header page */ descr_page = page_align(sp_header); //详见 } else {
/**
*如果descr_page_no非0,则根据这个编号,buf_pool->page_hash中查找
*查找条件为page->offset == descr_page_no,否则继续查找
*/ buf_block_t
* block; block = buf_page_get(space, zip_size, descr_page_no,RW_X_LATCH, mtr); buf_block_dbg_add_level(block, SYNC_FSP_PAGE); descr_page = buf_block_get_frame(block); }
   //XDES_ADR_OFFSET 计算后是38+112=150字节,第index个XDES Entry入口
return(descr_page + XDES_ARR_OFFSET + XDES_SIZE * xdes_calc_descriptor_index(zip_size, offset));
}

 

#define  XDES_ARR_OFFSET        (FSP_HEADER_OFFSET + FSP_HEADER_SIZE)
#define  FSP_HEADER_OFFSET    FIL_PAGE_DATA
#define  FIL_PAGE_DATA      38    

/* File space header size */
#define  FSP_HEADER_SIZE       (32 + 5 * FLST_BASE_NODE_SIZE)
/* The physical size of a list base node in bytes */
#define  FLST_BASE_NODE_SIZE    (4 + 2 * FIL_ADDR_SIZE)
#define  FIL_ADDR_SIZE        6    /* address size is 6 bytes */

 

 

http://blog.itpub.net/15480802/viewspace-777332/

函数 xdes_get_descriptor_with_space_hdr_第1张图片

 

 

#define    XDES_SIZE                            \
    (XDES_BITMAP + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE * XDES_BITS_PER_PAGE))

    (2*6+12) + UT_BITS_IN_BYTES(64*2)
    38

#define    XDES_BITMAP        (FLST_NODE_SIZE + 12)
#define    FLST_NODE_SIZE        (2 * FIL_ADDR_SIZE) /* The physical size of a list node in bytes */
#define    FIL_ADDR_SIZE    6    /* address size is 6 bytes */

/** File space extent size (one megabyte) in pages */
#define    FSP_EXTENT_SIZE        (1 << (20 - UNIV_PAGE_SIZE_SHIFT))
#define UNIV_PAGE_SIZE_SHIFT    14

#define    XDES_BITS_PER_PAGE    2    /* How many bits are there per page */

/** Determine how many bytes (groups of 8 bits) are needed to
store the given number of bits.
@param b    in: bits
@return        number of bytes (octets) needed to represent b */
#define UT_BITS_IN_BYTES(b) (((b) + 7) / 8)

 

 

/********************************************************************//**
Calculates the descriptor index within a descriptor page.
@return    descriptor index */
UNIV_INLINE
ulint
xdes_calc_descriptor_index(
/*=======================*/
    ulint    zip_size,    /*!< in: compressed page size in bytes;
                0 for uncompressed pages */
    ulint    offset)        /*!< in: page offset */
{
    ut_ad(ut_is_2pow(zip_size));

    if (!zip_size) {
        return(ut_2pow_remainder(offset, UNIV_PAGE_SIZE)
               / FSP_EXTENT_SIZE);
    } else {
        return(ut_2pow_remainder(offset, zip_size) / FSP_EXTENT_SIZE);
    }
}

面的大小 16K=16384= 2^14
/* The universal page size of the database */
#define UNIV_PAGE_SIZE        (1 << UNIV_PAGE_SIZE_SHIFT)
/* The 2-logarithm of UNIV_PAGE_SIZE: */
#define UNIV_PAGE_SIZE_SHIFT    14

/*************************************************************//**
Calculates fast the remainder of n/m when m is a power of two.
@param n    in: numerator
@param m    in: denominator, must be a power of two
@return        the remainder of n/m 

求余数,m必须为2的幂数
*/

#define ut_2pow_remainder(n, m) ((n) & ((m) - 1))

 

 

/********************************************************************//**
Calculates the page where the descriptor of a page resides.
@return    descriptor page offset */
UNIV_INLINE
ulint
xdes_calc_descriptor_page(
/*======================*/
    ulint    zip_size,    /*!< in: compressed page size in bytes;
                0 for uncompressed pages */
    ulint    offset)        /*!< in: page offset */
{

    ut_ad(ut_is_2pow(zip_size));

    if (!zip_size) {
//计算出2^14=16384*N 不超过offset,但N为最大
return(ut_2pow_round(offset, UNIV_PAGE_SIZE)); } else { ut_ad(zip_size > XDES_ARR_OFFSET + (zip_size / FSP_EXTENT_SIZE) * XDES_SIZE); return(ut_2pow_round(offset, zip_size)); } }

 

你可能感兴趣的:(函数 xdes_get_descriptor_with_space_hdr)