函数fsp_alloc_free_page

/**********************************************************************//**
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_get_descriptor_with_space_hdr(header, space, hint, mtr);

    if (descr && (xdes_get_state(descr, mtr) == XDES_FREE_FRAG)) {
        /* Ok, we can take this extent */
    } else {
        /* Else take the first extent in free_frag list */
        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 = 0;
    }

    /* 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, ((byte*)descr) - 500, 1000);
        putc(‘\n‘, stderr);

        ut_error;
    }

    page_no = xdes_get_offset(descr) + free;

    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 != 0);
        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));
}
时间: 2024-12-18 22:11:26

函数fsp_alloc_free_page的相关文章

MySQL &middot;InnoDB 文件系统之文件物理结构

从上层的角度来看,InnoDB层的文件,除了redo日志外,基本上具有相当统一的结构,都是固定block大小,普遍使用的btree结构来管理数据.只是针对不同的block的应用场景会分配不同的页类型.通常默认情况下,每个block的大小为 UNIV_PAGE_SIZE,在不做任何配置时值为16kb,你还可以选择在安装实例时指定一个块的block大小.对于压缩表,可以在建表时指定block size,但在内存中表现的解压页依旧为统一的页大小. 从物理文件的分类来看,有日志文件.主系统表空间文件ib

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