函数buf_page_create

/********************************************************************//**
Initializes a page to the buffer buf_pool. The page is usually not read
from a file even if it cannot be found in the buffer buf_pool. This is one
of the functions which perform to a block a state transition NOT_USED =>
FILE_PAGE (the other is buf_page_get_gen).
@return    pointer to the block, page bufferfixed */
UNIV_INTERN
buf_block_t*
buf_page_create(
/*============*/
    ulint    space,    /*!< in: space id */
    ulint    offset,    /*!< in: offset of the page within space in units of
            a page */
    ulint    zip_size,/*!< in: compressed page size, or 0 */
    mtr_t*    mtr)    /*!< in: mini-transaction handle */
{
    buf_frame_t*    frame;
    buf_block_t*    block;
    ulint        fold;
    buf_block_t*    free_block    = NULL;
    buf_pool_t*    buf_pool     = buf_pool_get(space, offset);

    ut_ad(mtr);
    ut_ad(mtr->state == MTR_ACTIVE);
    ut_ad(space || !zip_size);

    free_block = buf_LRU_get_free_block(buf_pool); //这里

    fold = buf_page_address_fold(space, offset);

    buf_pool_mutex_enter(buf_pool);

    block = (buf_block_t*) buf_page_hash_get_low(
        buf_pool, space, offset, fold);

    if (block
        && buf_page_in_file(&block->page)
        && !buf_pool_watch_is_sentinel(buf_pool, &block->page)) {
#ifdef UNIV_IBUF_COUNT_DEBUG
        ut_a(ibuf_count_get(space, offset) == 0);
#endif
#if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
        block->page.file_page_was_freed = FALSE;
#endif /* UNIV_DEBUG_FILE_ACCESSES || UNIV_DEBUG */

        /* Page can be found in buf_pool */
        buf_pool_mutex_exit(buf_pool);

        buf_block_free(free_block);

        return(buf_page_get_with_no_latch(space, zip_size,
                          offset, mtr));
    }

    /* If we get here, the page was not in buf_pool: init it there */

#ifdef UNIV_DEBUG
    if (buf_debug_prints) {
        fprintf(stderr, "Creating space %lu page %lu to buffer\n",
            (ulong) space, (ulong) offset);
    }
#endif /* UNIV_DEBUG */

    block = free_block;

    mutex_enter(&block->mutex);

    buf_page_init(buf_pool, space, offset, fold, zip_size, block);

    /* The block must be put to the LRU list */
    buf_LRU_add_block(&block->page, FALSE);

    buf_block_buf_fix_inc(block, __FILE__, __LINE__);
    buf_pool->stat.n_pages_created++;

    if (zip_size) {
        void*    data;
        ibool    lru;

        /* Prevent race conditions during buf_buddy_alloc(),
        which may release and reacquire buf_pool->mutex,
        by IO-fixing and X-latching the block. */

        buf_page_set_io_fix(&block->page, BUF_IO_READ);
        rw_lock_x_lock(&block->lock);
        mutex_exit(&block->mutex);
        /* buf_pool->mutex may be released and reacquired by
        buf_buddy_alloc().  Thus, we must release block->mutex
        in order not to break the latching order in
        the reacquisition of buf_pool->mutex.  We also must
        defer this operation until after the block descriptor
        has been added to buf_pool->LRU and buf_pool->page_hash. */
        data = buf_buddy_alloc(buf_pool, zip_size, &lru);
        mutex_enter(&block->mutex);
        block->page.zip.data = data;

        /* To maintain the invariant
        block->in_unzip_LRU_list
        == buf_page_belongs_to_unzip_LRU(&block->page)
        we have to add this block to unzip_LRU after
        block->page.zip.data is set. */
        ut_ad(buf_page_belongs_to_unzip_LRU(&block->page));
        buf_unzip_LRU_add_block(block, FALSE);

        buf_page_set_io_fix(&block->page, BUF_IO_NONE);
        rw_lock_x_unlock(&block->lock);
    }

    buf_pool_mutex_exit(buf_pool);

    mtr_memo_push(mtr, block, MTR_MEMO_BUF_FIX);

    buf_page_set_accessed(&block->page);

    mutex_exit(&block->mutex);

    /* Delete possible entries for the page from the insert buffer:
    such can exist if the page belonged to an index which was dropped */

    ibuf_merge_or_delete_for_page(NULL, space, offset, zip_size, TRUE);

    /* Flush pages from the end of the LRU list if necessary */
    buf_flush_free_margin(buf_pool);

    frame = block->frame;

    memset(frame + FIL_PAGE_PREV, 0xff, 4);
    memset(frame + FIL_PAGE_NEXT, 0xff, 4);
    mach_write_to_2(frame + FIL_PAGE_TYPE, FIL_PAGE_TYPE_ALLOCATED);

    /* Reset to zero the file flush lsn field in the page; if the first
    page of an ibdata file is ‘created‘ in this function into the buffer
    pool then we lose the original contents of the file flush lsn stamp.
    Then InnoDB could in a crash recovery print a big, false, corruption
    warning if the stamp contains an lsn bigger than the ib_logfile lsn. */

    memset(frame + FIL_PAGE_FILE_FLUSH_LSN, 0, 8);

#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
    ut_a(++buf_dbg_counter % 5771 || buf_validate());
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
#ifdef UNIV_IBUF_COUNT_DEBUG
    ut_a(ibuf_count_get(buf_block_get_space(block),
                buf_block_get_page_no(block)) == 0);
#endif
    return(block);
}
时间: 2024-10-05 04:00:27

函数buf_page_create的相关文章

js高阶函数

map()方法定义在JavaScript的Array中,我们调用Array的map()方法,传入我们自己的函数,就得到了一个新的Array作为结果: function pow(x) { return x * x; } var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; arr.map(pow); // [1, 4, 9, 16, 25, 36, 49, 64, 81] reduce()把一个函数作用在这个Array的[x1, x2, x3...]上,这个函数必须接收两个

Django url 标签和reverse()函数的使用(转)

原文:http://www.yihaomen.com/article/python/355.htm 使用url标签和reverse()函数,可以避免在模板和view中对url进行硬编码,这样即使url改变了,对模板和view也没有影响 起初用django 开发应用的时候,完全是在urls.py 中硬编码配置地址,在views.py中HttpResponseRedirect()也是硬编码转向地址,当然在template 中也是一样了,这样带来一个问题,如果在urls.py 中修改了某个页面的地址,

Python2.7-内置函数

具体参见:https://docs.python.org/2/library/functions.html#file 1.进制转换:bin(x), oct(x), hex(x) 把一个十进制数分别转换为2.8.16进制 2.字符转换:chr(x)将数字(255以内不报错,128以后无字符)转换为对应ASCII字符, unichr(x)将数字转换为unicode, ord(x) 将字符转数字与前两个相反, unicode(obj, [encoding, [error]]) 用encoding解码o

linux Shell函数

Shell函数类似于Shell脚本,里面存放了一系列的指令,不过Shell的函数存在于内存,而不是硬盘文件,所以速度很快,另外,Shell还能对函数进行预处理,所以函数的启动比脚本更快. 1.函数定义 1 2 3 4 function 函数名() {     语句     [return] } 关键字function表示定义一个函数,可以省略,其后是函数名,有时函数名后可以跟一个括号,符号"{"表示函数执行命令的入口,该符号也可以在函数名那一行,"}"表示函数体的结

pythonの函数学习笔记(一)

函数是可以实现一些特定功能的小方法或小程序定义函数function的方法:def function_name(arg1,arg2[,...]): statement [return value]注意事项:1.def开头,代表定义函数,def和函数名中间要敲一个空格:2.返回值不是必须的,如果没有renturn语句,则默认返回值None:3.函数名必须以下划线或字母开头,可以包含任意字母.数字或下划线的组合,区分大小写且不能是保留字: py使用名称空间的概念存储对象,这个名称空间就是对象作用的区域

条件、循环、函数定义、字符串操作练习

注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式. 对前面的代码进行优化,用for,while,if,def实现: 用循环画五角星 1 import turtle 2 3 turtle.fillcolor("red") 4 turtle.begin_fill() 5 for i in range(5): 6 turtle.forward(100) 7 turtle.right(144) 8 turtle.end_fill() 用循环画同心圆

sql常用格式化函数及字符串函数

一.常用格式化函数 1.日期转字符串 select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS') //2017-09-18 22:41:50 YYYY:年(4和更多位) MM:月份号(01-12) DD:一个月里的日(01-31) HH24:一天的小时数(00-23) MI:分钟(00-59) SS:秒(00-59) 2.字符串转日期 select to_date('2017-09-18','YYYY-MM-DD') //2017-09-

Delphi常用系统函数总结

字符串处理函数 Unit System 函数原型 function Concat(s1 [, s2,..., sn]: string): string; 说明 与 S := S1 + S2 + S3 ...; 相同. 将字符串相加. 函数原型 function Copy(S: string; Index, Count: Integer): string;说明 S : 字符串. Indexd : 从第几位开始拷贝. Count : 总共要拷贝几位. 从母字符串拷贝至另一个字符串. 函数原型 pro

python练习之map()和reduce()函数

利用map()函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字.输入:['adam', 'LISA', 'barT'],输出:['Adam', 'Lisa', 'Bart']: 1 def normalize(name): 2 name=name.lower() 3 name=name[0].upper()+name[1:] 4 return name 5 6 7 8 9 10 # 测试: 11 L1 = ['adam', 'LISA', 'barT'] 12 L2 = l