申请一个段

/**********************************************************************//**
Creates a new segment.
@return the block where the segment header is placed, x-latched, NULL
if could not create segment because of lack of space */
UNIV_INTERN
buf_block_t*
fseg_create_general(
/*================*/
    ulint    space,    /*!< in: space id */
    ulint    page,    /*!< in: page where the segment header is placed: if
            this is != 0, the page must belong to another segment,
            if this is 0, a new page will be allocated and it
            will belong to the created segment */
    ulint    byte_offset, /*!< in: byte offset of the created segment header
            on the page */
    ibool    has_done_reservation, /*!< in: TRUE if the caller has already
            done the reservation for the pages with
            fsp_reserve_free_extents (at least 2 extents: one for
            the inode and the other for the segment) then there is
            no need to do the check for this individual
            operation */
    mtr_t*    mtr)    /*!< in: mtr */
{
    ulint        flags;
    ulint        zip_size;
    fsp_header_t*    space_header;
    fseg_inode_t*    inode; //typedef byte fseg_inode_t;
    ib_id_t        seg_id;
    buf_block_t*    block    = ; /* remove warning */
    fseg_header_t*    header    = ; /* remove warning */
    rw_lock_t*    latch;
    ibool        success;
    ulint        n_reserved;
    ulint        i;

    ut_ad(mtr);
    ut_ad(byte_offset + FSEG_HEADER_SIZE
          <= UNIV_PAGE_SIZE - FIL_PAGE_DATA_END);

    latch = fil_space_get_latch(space, &flags);
    zip_size = dict_table_flags_to_zip_size(flags);

    ) {
        block = buf_page_get(space, zip_size, page, RW_X_LATCH, mtr);
        header = byte_offset + buf_block_get_frame(block);
    }

    ut_ad(!mutex_own(&kernel_mutex)
          || mtr_memo_contains(mtr, latch, MTR_MEMO_X_LOCK));

    mtr_x_lock(latch, mtr);

    ) {
        /* This thread did not own the latch before this call: free
        excess pages from the insert buffer free list */

        if (space == IBUF_SPACE_ID) {
            ibuf_free_excess_pages();
        }
    }

    if (!has_done_reservation) {
        success = fsp_reserve_free_extents(&n_reserved, space, ,
                           FSP_NORMAL, mtr);
        if (!success) {
            return(NULL);
        }
    }

    space_header = fsp_get_space_header(space, zip_size, mtr);//详见

    inode = fsp_alloc_seg_inode(space_header, mtr);//申请inode entry 详见    if (inode == NULL) {

        goto funct_exit;
    }

    /* Read the next segment id from space header and increment the
    value in space header */

    seg_id = mach_read_from_8(space_header + FSP_SEG_ID);//设置下一下seg id

    mlog_write_ull(space_header + FSP_SEG_ID, seg_id + , mtr);
            *     *#define FSEG_FULL (12 + 2 * FLST_BASE_NODE_SIZE)        *     */
    mlog_write_ull(inode + FSEG_ID, seg_id, mtr);
    mlog_write_ulint(inode + FSEG_NOT_FULL_N_USED, , MLOG_4BYTES, mtr);

    flst_init(inode + FSEG_FREE, mtr); //初始化inode中的seg list 详见
    flst_init(inode + FSEG_NOT_FULL, mtr);
    flst_init(inode + FSEG_FULL, mtr);

    mlog_write_ulint(inode + FSEG_MAGIC_N, FSEG_MAGIC_N_VALUE,
             MLOG_4BYTES, mtr);

    //#define FSEG_FRAG_ARR_N_SLOTS (FSP_EXTENT_SIZE / 2) 64/2=32
    ; i < FSEG_FRAG_ARR_N_SLOTS; i++) {
        fseg_set_nth_frag_page_no(inode, i, FIL_NULL, mtr); //设置frag 碎片 详见
    }

    ) {
        block = fseg_alloc_free_page_low(space, zip_size,
                         inode, , FSP_UP, mtr, mtr);

        if (block == NULL) {

            fsp_free_seg_inode(space, zip_size, inode, mtr);

            goto funct_exit;
        }

        ut_ad(rw_lock_get_x_lock_count(&block->);

        header = byte_offset + buf_block_get_frame(block);
        mlog_write_ulint(buf_block_get_frame(block) + FIL_PAGE_TYPE,
                 FIL_PAGE_TYPE_SYS, MLOG_2BYTES, mtr);
    }
        //设置fset_header信息
    mlog_write_ulint(header + FSEG_HDR_OFFSET,page_offset(inode), MLOG_2BYTES, mtr);

    mlog_write_ulint(header + FSEG_HDR_PAGE_NO,page_get_page_no(page_align(inode)),MLOG_4BYTES, mtr);

    mlog_write_ulint(header + FSEG_HDR_SPACE, space, MLOG_4BYTES, mtr);

funct_exit:
    if (!has_done_reservation) {

        fil_space_release_free_extents(space, n_reserved);
    }

    return(block);
}

函数fseg_create_general的更多相关文章

  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. 关于maven参数过滤

    一.maven通过设置过滤器,可以使maven在编译打包时实现参数过滤的功能(详细配置说明略) <filters> <filter>../antx.properties< ...

  2. CentOS7安装性能监控系统

    目录 系统描述. 开发环境. 开始之前. 安装influxdb数据库. 安装collectd 安装Grafana FAQ       influxdb的web界面没反应.   系统描述 想打造 New ...

  3. C语言-创建链表及排序

    #include <stdio.h> #define NEWNODE (Node *)malloc(sizeof(Node)) typedef struct mynode{ int num ...

  4. php-fpm.conf 文件详解

    pid string PID文件的位置. 默认为空. error_log string 错误日志的位置. 默认: 安装路径#INSTALL_PREFIX#/log/php-fpm.log. log_l ...

  5. 【MongoDB】开启认证权限

    1. mongodb.conf : 添加 auth=true 2. use admin (3.0+ 使用 createUser ;<3.0版本  http://www.cnblogs.com/g ...

  6. 使用Yeoman搭建 AngularJS 应用 (11) —— 让我们搭建一个网页应用

    原文地址:http://yeoman.io/codelab/prepare-production.html 让我们发布这个应用 优化产品的文件 为了创建应用的产品版本,我们想做如下的事情 检查你的代码 ...

  7. CSRF防范策略研究

    目录 0x1:检查网页的来源 0x2:检查内置的隐藏变量 0x3:用POST不用GET 检查网页的来源应该怎么做呢?首先我们应该检查$_SERVER[“HTTP_REFERER”]的值与来源网页的网址 ...

  8. 结构型—桥接(Bridge)模式

    1.意图: 将抽象部分(抽象接口)与它的实现部分(代码实现)分离,使它们都可以独立地变化. 理解:抽象部分是对外展现的接口(api),而实现部分是针对抽象接口提供的不同版本的功能实现,使两者独立变化指 ...

  9. Tornado,展示一下模板渲染

    按网上一步一步走一下. 感觉模板和DJANGO的差不多,但更灵活,不限制PYTHON的使用. 前端和后端,这模板使用的规则在哪里呢? import os.path import tornado.htt ...

  10. Linux---弹球游戏

    ReadMe: 弹球游戏按键说明(注意大小写): Q End Up Game 游戏停止 P Play Again  再玩一次 f 速度x轴方向减速 s 速度x轴方向加速 F 速度y轴方向减速 S 速度 ...