/**********************************************************************//**
Puts new extents to the free list if there are free extents above the free
limit. If an extent happens to contain an extent descriptor page, the extent
is put to the FSP_FREE_FRAG list with the page marked as used. */
static
void
fsp_fill_free_list(
/*===============*/
    ibool        init_space,    /*!< in: TRUE if this is a single-table
                    tablespace and we are only initing
                    the tablespace's first extent
                    descriptor page and ibuf bitmap page;
                    then we do not allocate more extents */
    ulint        space,        /*!< in: space */
    fsp_header_t*    header,        /*!< in/out: space header */
    mtr_t*        mtr)        /*!< in/out: mini-transaction */
{
    ulint    limit;
    ulint    size;
    ulint    zip_size;
    xdes_t*    descr;
    ulint    count        = ;
    ulint    frag_n_used;
    ulint    actual_increase;
    ulint    i;
    mtr_t    ibuf_mtr;

    ut_ad(header && mtr);
    ut_ad(page_offset(header) == FSP_HEADER_OFFSET);

    /* Check if we can fill free list from above the free list limit */
    size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
    limit = mtr_read_ulint(header + FSP_FREE_LIMIT, MLOG_4BYTES, mtr);

    zip_size = dict_table_flags_to_zip_size(
        mach_read_from_4(FSP_SPACE_FLAGS + header));
    ut_a(ut_is_2pow(zip_size));
    ut_a(zip_size <= UNIV_PAGE_SIZE);
    ut_a(!zip_size || zip_size >= PAGE_ZIP_MIN_SIZE);

     && srv_auto_extend_last_data_file
        && size < limit + FSP_EXTENT_SIZE * FSP_FREE_ADD) {

        /* Try to increase the last data file size */
        fsp_try_extend_data_file(&actual_increase, space, header, mtr);
        size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
    }

     && !init_space
        && size < limit + FSP_EXTENT_SIZE * FSP_FREE_ADD) {

        /* Try to increase the .ibd file size */
        fsp_try_extend_data_file(&actual_increase, space, header, mtr);
        size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
    }

    i = limit;

    /**     *还是先暂时分配4个page     *     *#define    FSP_FREE_ADD        4     *#define FSP_EXTENT_SIZE 64     *init_space 为false,所以第一个条件不执行     *fsp_init_file_page初始化后,limit为0     *while( (0+64 < size)&& 0<4){     init_xdes = (0%16328)=0         count=1     }     while( (16328<size) &&1<4 ){     init_xdes=16328%16328=0         count=2          }     ..     while(65312<size && 3<4)       init_xdex=65312%16328=0    count=4     }     结束while循环

     最终header + FSP_FREE_LIMIT 为 65312+64

*/
    ) || ((i + FSP_EXTENT_SIZE <= size) && (count < FSP_FREE_ADD))) {

        ibool    init_xdes;
        if (zip_size) {
            init_xdes = ut_2pow_remainder(i, zip_size) == ;
        } else {
            init_xdes = ut_2pow_remainder(i, UNIV_PAGE_SIZE) == ;
        }

        mlog_write_ulint(header + FSP_FREE_LIMIT, i + FSP_EXTENT_SIZE,MLOG_4BYTES, mtr);

        /* Update the free limit info in the log system and make
        a checkpoint */
        ) {
            ut_a(!zip_size);
            log_fsp_current_free_limit_set_and_checkpoint(
                (i + FSP_EXTENT_SIZE)
                / (( * ) / UNIV_PAGE_SIZE));
        }

        if (UNIV_UNLIKELY(init_xdes)) {

            buf_block_t*    block;

            /* We are going to initialize a new descriptor page
            and a new ibuf bitmap page: the prior contents of the
            pages should be ignored. */

            ) {                /**                 *从free-list,unzip-lru,common-lru取出block                 *初始化block                 */
                block = buf_page_create(space, i, zip_size, mtr);//详见
                buf_page_get(space, zip_size, i,RW_X_LATCH, mtr);
                buf_block_dbg_add_level(block,SYNC_FSP_PAGE);
                                //初始化blck一些属性
                fsp_init_file_page(block, mtr);

                
                mlog_write_ulint(buf_block_get_frame(block)+ FIL_PAGE_TYPE,FIL_PAGE_TYPE_XDES,MLOG_2BYTES, mtr);
            }

            /* Initialize the ibuf bitmap page in a separate
            mini-transaction because it is low in the latching
            order, and we must be able to release its latch
            before returning from the fsp routine */

            mtr_start(&ibuf_mtr);

            block = buf_page_create(space,
                            i + FSP_IBUF_BITMAP_OFFSET,
                            zip_size, &ibuf_mtr);
            buf_page_get(space, zip_size,
                     i + FSP_IBUF_BITMAP_OFFSET,
                     RW_X_LATCH, &ibuf_mtr);
            buf_block_dbg_add_level(block, SYNC_FSP_PAGE);

            fsp_init_file_page(block, &ibuf_mtr);

            ibuf_bitmap_page_init(block, &ibuf_mtr);

            mtr_commit(&ibuf_mtr);
        }
                /**         *1)根据偏移量i,计算出des page的page_no         *  1.1)如果page_no非0,则要根据offset在buf_pool->page_hash找到一个block,条件为page->offset == i         *  1.2)如果page_no为0,继续         *2)在xdes page中定位哪xdes entry的起始地址         */
        descr = xdes_get_descriptor_with_space_hdr(header, space, i,mtr);//详见
        xdes_init(descr, mtr);

        if (UNIV_UNLIKELY(init_xdes)) {

            /* The first page in the extent is a descriptor page
            and the second is an ibuf bitmap page: mark them
            used */

            xdes_set_bit(descr, XDES_FREE_BIT, , FALSE, mtr);
            xdes_set_bit(descr, XDES_FREE_BIT, FSP_IBUF_BITMAP_OFFSET, FALSE, mtr);
            xdes_set_state(descr, XDES_FREE_FRAG, mtr);

            flst_add_last(header + FSP_FREE_FRAG,descr + XDES_FLST_NODE, mtr);
            frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED,MLOG_4BYTES, mtr);
            mlog_write_ulint(header + FSP_FRAG_N_USED,frag_n_used + , MLOG_4BYTES, mtr);
        } else {
            flst_add_last(header + FSP_FREE,descr + XDES_FLST_NODE, mtr);
            count++;
        }

        i += FSP_EXTENT_SIZE;
    }
}

函数fsp_fill_free_list的更多相关文章

  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. 在当前iframe中, 获取Iframe的id

    window.frameElement   返回嵌入当前window对象的元素(比如 <iframe> 或者 <object>),如果当前window对象已经是顶层窗口,则返回 ...

  2. ab压力测试工具-批量压测脚本

    ab(Apache benchmark)是一款常用的压力测试工具.简单易用,ab的命令行一次只能支持一次测试.如果想要批量执行不同的测试方式,并自动对指标进行分析,那么单靠手工一条一条命令运行ab,估 ...

  3. HDU 1715 大菲波数(JAVA, 简单题,大数)

    题目 //BigInteger 和 BigDecimal 是在java.math包中已有的类,前者表示整数,后者表示浮点数 import java.io.*; import java.util.*; ...

  4. POJ 2484

    A Funny Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3861   Accepted: 2311 Desc ...

  5. KMP模板,最小循环节

    (可以转载,但请注明出处!) 下面是有关学习KMP的参考网站 http://blog.csdn.net/yaochunnian/article/details/7059486 http://blog. ...

  6. SQL技术内幕-5 比较特殊 insert into 数据的写法

    ---比较特殊,第一次看到这种写法,记录下来 create table Student --学生成绩表 ( id int, --主键 Grade int, --班级 Score int --分数 ) ...

  7. Android——横屏和竖屏的切换,以及明文密码的显示

    查看API文档: android.content.pm.ActivityInfo    在手机的使用中,我们要根据不同的需求来改变屏幕的显示方向,一般在浏览信息时是竖屏,在玩游戏的时候就要切换到横屏. ...

  8. POJ2402/UVA 12050 Palindrome Numbers 数学思维

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...

  9. vim使用详解

    1 插入类命令 i               // 在当前字符前插入 I               // 在当前行首插入 a               // 在当前字符后写入 A         ...

  10. Fatal error: cannot allocate memory for the buffer pool

    mysql有时候会被系统kill掉,原因是内存不够了,一般都是Ubuntu出现的,因为Ubuntu吃内存,你们又给的不多.. 咋解决呢? 重启服务器是可以的,起码暂时可以了, 可以考虑加内存,或者增加 ...