/********************************************************************//**
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);//获取具体buff pool实例 详见

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

    free_block = buf_LRU_get_free_block(buf_pool); //取得一块空闲block 这里

    fold = buf_page_address_fold(space, offset); //计算hash值 详见

    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)) {

        /* 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 */    block = free_block;

    mutex_enter(&block->mutex);
        /**     *初始化block,详见     *计算block中的lock_hash_val     *将block->page放入buf_pool->page_hash中     */
    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); //放入lru中,且status为old 详见

    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);
        /**     *取出block中的frame     *block结构体 详见     */
    frame = block->frame;
            */
    memset(frame + FIL_PAGE_PREV, );
    memset(frame + FIL_PAGE_NEXT, );
    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, , );

    return(block);
}

函数buf_page_create的更多相关文章

  1. Python 小而美的函数

    python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况   any any(iterable) ...

  2. 探究javascript对象和数组的异同,及函数变量缓存技巧

    javascript中最经典也最受非议的一句话就是:javascript中一切皆是对象.这篇重点要提到的,就是任何jser都不陌生的Object和Array. 有段时间曾经很诧异,到底两种数据类型用来 ...

  3. JavaScript权威指南 - 函数

    函数本身就是一段JavaScript代码,定义一次但可能被调用任意次.如果函数挂载在一个对象上,作为对象的一个属性,通常这种函数被称作对象的方法.用于初始化一个新创建的对象的函数被称作构造函数. 相对 ...

  4. C++对C的函数拓展

    一,内联函数 1.内联函数的概念 C++中的const常量可以用来代替宏常数的定义,例如:用const int a = 10来替换# define a 10.那么C++中是否有什么解决方案来替代宏代码 ...

  5. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

  6. javascript中的this与函数讲解

    前言 javascript中没有块级作用域(es6以前),javascript中作用域分为函数作用域和全局作用域.并且,大家可以认为全局作用域其实就是Window函数的函数作用域,我们编写的js代码, ...

  7. 复杂的 Hash 函数组合有意义吗?

    很久以前看到一篇文章,讲某个大网站储存用户口令时,会经过十分复杂的处理.怎么个复杂记不得了,大概就是先 Hash,结果加上一些特殊字符再 Hash,结果再加上些字符.再倒序.再怎么怎么的.再 Hash ...

  8. JS核心系列:浅谈函数的作用域

    一.作用域(scope) 所谓作用域就是:变量在声明它们的函数体以及这个函数体嵌套的任意函数体内都是有定义的. function scope(){ var foo = "global&quo ...

  9. C++中的时间函数

    C++获取时间函数众多,何时该用什么函数,拿到的是什么时间?该怎么用?很多人都会混淆. 本文是本人经历了几款游戏客户端和服务器开发后,对游戏中时间获取的一点总结. 最早学习游戏客户端时,为了获取最精确 ...

随机推荐

  1. JS实现刷新iframe的方法

    <iframe src="1.htm" name="ifrmname" id="ifrmid"></iframe> ...

  2. 《C++Primer》复习——with C++11 [3]

    1.我们的程序经常使用很多IO库,用来输入输出例如:istream(输入流)类型,提供输入操作. ostream(输出流)类型, 提供输出操作. cin, 一个istream对象,从标准输入读取数据. ...

  3. 2432: [Noi2011]兔农 - BZOJ

    Description 农夫栋栋近年收入不景气,正在他发愁如何能多赚点钱时,他听到隔壁的小朋友在讨论兔子繁殖的问题. 问题是这样的:第一个月初有一对刚出生的小兔子,经过两个月长大后,这对兔子从第三个月 ...

  4. PHP 中的BOM BUG

    对于PHP,一个小小让我不敢置信的事情很多,包括引用变量哪么迟钝,普通变量哪么牛B我己经很意外,甚至现在竟然出现了BOM头的BUG. 在PHP中,会引用很多小文件,include或require,哪么 ...

  5. Windows下JNI执行步骤

    问题描述:     java JNI使用 问题解决: JNI编写步骤: (1)编写带有native声明的方法的java类     (2)使用javac编译所写的java类,然后使用javah生成扩展名 ...

  6. 【CodeForces】【#286】Div.2

    T_T越来越水了,这次只做出A+B. A题为了代码简单直接枚举(插入位置和插入字符) //CF #286 Div.2 A #include<vector> #include<stri ...

  7. VisualSVN Server的windows 2003配置和使用方法(图文并茂)

    1.为什么要用VisualSVN Server,而不用Subversion? 回答: 因为如果直接使用Subversion,那么在Windows 系统上,要想让它随系统启动,就要封装SVN Serve ...

  8. [转]Ubuntu alternate和desktop区别

    原文地址:http://blog.csdn.net/is2120/article/details/6797621 Desktop : 刻录在光盘,从光盘运行的系统,相当于 Live CD Altern ...

  9. lintcode:三数之和

    题目 三数之和 给出一个有n个整数的数组S,在S中找到三个整数a, b, c,找到所有使得a + b + c = 0的三元组. 样例 如S = {-1 0 1 2 -1 -4}, 你需要返回的三元组集 ...

  10. Mahout学习之Mahout简介、安装、配置、入门程序测试

    一.Mahout简介 查了Mahout的中文意思——驭象的人,再看看Mahout的logo,好吧,想和小黄象happy地玩耍,得顺便陪陪这位驭象人耍耍了... 附logo: (就是他,骑在象头上的那个 ...