从fsp中分配32个碎片页

/**********************************************************************//**
Allocates a single free page from a space. The page is marked as used.
@retval NULL if no page could be allocated
@retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded
(init_mtr == mtr, or the page was not previously freed in mtr)
@retval block (not allocated or initialized) otherwise */
static __attribute__((nonnull, warn_unused_result))
buf_block_t*
fsp_alloc_free_page(
/*================*/
    ulint    space,    /*!< in: space id */
    ulint    zip_size,/*!< in: compressed page size in bytes
            or 0 for uncompressed pages */
    ulint    hint,    /*!< in: hint of which page would be desirable */
    mtr_t*    mtr,    /*!< in/out: mini-transaction */
    mtr_t*    init_mtr)/*!< in/out: mini-transaction in which the
            page should be initialized
            (may be the same as mtr) */
{
    fsp_header_t*    header;
    fil_addr_t    first;
    xdes_t*        descr;
    ulint        free;
    ulint        page_no;
    ulint        space_size;

    ut_ad(mtr);
    ut_ad(init_mtr);

    header = fsp_get_space_header(space, zip_size, mtr); //详见    /* Get the hinted descriptor */    /**     *descr 是XDES 页中第N个XDES Entry 的内存地址     *     */
    descr = xdes_get_descriptor_with_space_hdr(header, space, hint, mtr); //详见    /**     *这个desc的类型属于XDES_FREE_FRAG 可拿来使用     *为一个段指定空间时, 先从 FSP中的碎片区中取,若拿不至,再分配extent     *     */    if (descr && (xdes_get_state(descr, mtr) == XDES_FREE_FRAG)) { //详见      /* Ok, we can take this extent */      //descr 所在的 xdes entry 的状态属于 free_freg 碎片
    } else {
                //获得fsp header +40 的 free_frag 空闲碎片        //fsp中的free_frag类型是 flst_base_node_t,真正类型为byte
        first = flst_get_first(header + FSP_FREE_FRAG, mtr); //详见        if (fil_addr_is_null(first)) {
            /* There are no partially full fragments: allocate
            a free extent and add it to the FREE_FRAG list. NOTE
            that the allocation may have as a side-effect that an
            extent containing a descriptor page is added to the
            FREE_FRAG list. But we will allocate our page from the
            the free extent anyway. */

            descr = fsp_alloc_free_extent(space, zip_size,hint, mtr);

            if (descr == NULL) {
                /* No free space left */

                return(NULL);
            }

            xdes_set_state(descr, XDES_FREE_FRAG, mtr);
            flst_add_last(header + FSP_FREE_FRAG,
                      descr + XDES_FLST_NODE, mtr);
        } else {
            descr = xdes_lst_get_descriptor(space, zip_size,
                            first, mtr);
        }

        /* Reset the hint */
        hint = ;
    }

    /* Now we have in descr an extent with at least one free page. Look
    for a free page in the extent. */

    free = xdes_find_bit(descr, XDES_FREE_BIT, TRUE,hint % FSP_EXTENT_SIZE, mtr); //详见    if (free == ULINT_UNDEFINED) {

        ut_print_buf(stderr, ((, );
        putc('\n', stderr);

        ut_error;
    }

    page_no = xdes_get_offset(descr) + free; //计算出某一bit的page_no 详见

    space_size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);

    if (space_size <= page_no) {
        /* It must be that we are extending a single-table tablespace
        whose size is still < 64 pages */

        ut_a(space != );
        if (page_no >= FSP_EXTENT_SIZE) {
            fprintf(stderr,
                "InnoDB: Error: trying to extend a"
                " single-table tablespace %lu\n"
                "InnoDB: by single page(s) though the"
                " space size %lu. Page no %lu.\n",
                (ulong) space, (ulong) space_size,
                (ulong) page_no);
            return(NULL);
        }
        if (!fsp_try_extend_data_file_with_pages(space, page_no,
                             header, mtr)) {
            /* No disk space left */
            return(NULL);
        }
    }

    fsp_alloc_from_free_frag(header, descr, free, mtr);//详见    return(fsp_page_create(space, zip_size, page_no, mtr, init_mtr));
}

函数fsp_alloc_free_page的更多相关文章

  1. MySQL ·InnoDB 文件系统之文件物理结构

    从上层的角度来看,InnoDB层的文件,除了redo日志外,基本上具有相当统一的结构,都是固定block大小,普遍使用的btree结构来管理数据.只是针对不同的block的应用场景会分配不同的页类型. ...

  2. Python 小而美的函数

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

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

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

  4. JavaScript权威指南 - 函数

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

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

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

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

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

  7. javascript中的this与函数讲解

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

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

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

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

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

随机推荐

  1. 【开发】Dialog 对话框

    提示:Dialog 继承自 Panel,有大量的方法在 Panel 中已被定义,可以复用. Dialog API:http://www.jeasyui.net/plugins/181.html Pan ...

  2. Hyper-V 测试

    云平台的虚拟服务器,基本上没有免费的(试用时间基本上都是1个月),按月收费最低的套餐(1个CPU核心.512内存)一般都是将近100元 所以索性还是自己搭建一个技术测试环境吧 上学的时候一直用的是VM ...

  3. wifidog编译到openwrt

    首先敲一下 cd 命令,定位到自己的用户目录, 然后 mkdir openwrt 新建一个openwrt文件夹,然后开始装openwrt的编译用到的工具, sudo apt-get install g ...

  4. gdb提示Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6_5.2.x86_64

    用gdb debugc代码的时候弹出这个错误 Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6_5.2. ...

  5. C# 链表操作

    关于链表操作,在C#当中微软已经提供了一个LinkedList<T>的数据结构,通过这个类提供的一系列方法就能够实现链表操作. 这里我提供一段代码,这是在论坛里面有人提问时给出的代码,它实 ...

  6. jquery-easyui使用

    1,闲来无事用了一下jquery-easyui,首先下载下来easyui,文件夹如图 2,将themes里面的东西整体拷贝,我是整体的,省的麻烦了 3,在在自己的vs里面新建一个mvc的项目(项目自己 ...

  7. php四种基础排序算法的运行时间比较

    /** * php四种基础排序算法的运行时间比较 * @authors Jesse (jesse152@163.com) * @date 2016-08-11 07:12:14 */ //冒泡排序法 ...

  8. (转载)delphi 中如何调用sql 存储过程

    delphi 中如何调用sql 存储过程 使用TADOStoredProc组件,可以,给你举个例子好了 with ADOStoredProc1 do begin Close; Parameters.C ...

  9. MVC-登录并设置角色

    1.新建一个类,设置角色: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...

  10. dtv_driver.ko

            替换dtv_driver.ko .步骤:         shell@android:/ # get_rootfs.sh                                 ...