/**********************************************************************//**
Tries to extend a data file so that it would accommodate the number of pages
given. The tablespace must be cached in the memory cache. If the space is big
enough already, does nothing.
@return    TRUE if success */
UNIV_INTERN
ibool
fil_extend_space_to_desired_size(
/*=============================*/
    ulint*    actual_size,    /*!< out: size of the space after extension;
                if we ran out of disk space this may be lower
                than the desired size */
    ulint    space_id,    /*!< in: space id */
    ulint    size_after_extend)/*!< in: desired size in pages after the
                extension; if the current space size is bigger
                than this already, the function does nothing */
{
    fil_node_t*    node;
    fil_space_t*    space;
    byte*        buf2;
    byte*        buf;
    ulint        buf_size;
    ulint        start_page_no;
    ulint        file_start_page_no;
    ulint        offset_high;
    ulint        offset_low;
    ulint        page_size;
    ibool        success        = TRUE;

    fil_mutex_enter_and_prepare_for_io(space_id);

    space = fil_space_get_by_id(space_id);
    ut_a(space);

    if (space->size >= size_after_extend) {
        /* Space already big enough */

        *actual_size = space->size;

        mutex_exit(&fil_system->mutex);

        return(TRUE);
    }

    page_size = dict_table_flags_to_zip_size(space->flags);
    if (!page_size) {
        page_size = UNIV_PAGE_SIZE;
    }

    node = UT_LIST_GET_LAST(space->chain);

    fil_node_prepare_for_io(node, fil_system, space);

    start_page_no = space->size;
    file_start_page_no = space->size - node->size;

    /* Extend at most 64 pages at a time */
    buf_size = ut_min(, size_after_extend - start_page_no) * page_size;
    buf2 = mem_alloc(buf_size + page_size);
    buf = ut_align(buf2, page_size);

    memset(buf, , buf_size);

    while (start_page_no < size_after_extend) {
        ulint    n_pages = ut_min(buf_size / page_size,
                     size_after_extend - start_page_no);

        offset_high = (start_page_no - file_start_page_no)
            / ( * (( * ) / page_size));
        offset_low  = ((start_page_no - file_start_page_no)
                   % ( * (( * ) / page_size)))
            * page_size;
#ifdef UNIV_HOTBACKUP
        success = os_file_write(node->name, node->handle, buf,
                    offset_low, offset_high,
                    page_size * n_pages);
#else
        success = os_aio(OS_FILE_WRITE, OS_AIO_SYNC,
                 node->name, node->handle, buf,
                 offset_low, offset_high,
                 page_size * n_pages,
                 NULL, NULL);
#endif
        if (success) {
            node->size += n_pages;
            space->size += n_pages;

            os_has_said_disk_full = FALSE;
        } else {
            /* Let us measure the size of the file to determine
            how much we were able to extend it */

            n_pages = ((ulint)
                   (os_file_get_size_as_iblonglong(
                       node->handle)
                    / page_size)) - node->size;

            node->size += n_pages;
            space->size += n_pages;

            break;
        }

        start_page_no += n_pages;
    }

    mem_free(buf2);

    fil_node_complete_io(node, fil_system, OS_FILE_WRITE);

    *actual_size = space->size;

#ifndef UNIV_HOTBACKUP
    ) {
        ulint pages_per_mb = ( * ) / page_size;

        /* Keep the last data file size info up to date, rounded to
        full megabytes */

        srv_data_file_sizes[srv_n_data_files - ]
            = (node->size / pages_per_mb) * pages_per_mb;
    }
#endif /* !UNIV_HOTBACKUP */

    /*
    printf("Extended %s to %lu, actual size %lu pages\n", space->name,
    size_after_extend, *actual_size); */
    mutex_exit(&fil_system->mutex);

    fil_flush(space_id);

    return(success);
}

函数fil_extend_space_to_desired_size的更多相关文章

  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. android开发修改相机扫描二维码框的高宽

    我用的是网上一个现成的例子,可以直接用,但是高宽不合适,现在主流都是大屏幕手机了,所以需要更改. 找到CameraManager 类,更改下面的方法 public Rect getFramingRec ...

  2. smarty中的母板极制_extends和block标签

    模板继承 继承是从面向对象编程而来的概念,模板继承可以让你定义一个或多个父模板,提供给子模板来进行扩展. 扩展继承意味着子模板可以覆盖部分或全部父模板的块区域. 继承结构可以是多层次的,所以你可以继承 ...

  3. AlphaToCoverage solution

    After msaa output the alpha in ps remove clip in ps in blendstate add AlphaToCoverageEnable = TRUE - ...

  4. Codeforces Round #241 (Div. 2)->B. Art Union

    B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  5. Unity3D 游戏开发应用篇——每日登陆(持久化类实现)

    上一篇中我们实现用本地文件实现了持久化类的保存,当然小型数据用PlayerPrefs存储,或者采用XML服务器持久化也行.因为我涉及的角色类和玩家类数据比较多,加上项目要求尽量少与服务器交互,所以采用 ...

  6. 如何使用yum来下载RPM包而不进行安装

    如何使用yum来下载RPM包而不进行安装 2015-03-23 13:15 theo-l译 linux.cn 字号:T | T yum是基于Red Hat的系统(如CentOS.Fedora.RHEl ...

  7. mac os 下如何清除/切换svn eclipse插件的用户

    以mac os x为例(Unix/Linux类似), 1.打开命令行窗口,即用户的根目录(用户的home目录) $ ls -al ... drwxr-xr-x   6 linxyz  staff   ...

  8. POJ 1922

    #include<iostream>cheng da cai zi 11.21 //#include<stdio.h> #include<math.h> using ...

  9. C# 委托的”四步走“

    看了一本<深入了解C#>感觉很不错,对于委托的讲解,给大家摘录了下来! 1.什么是委托 我的拙见:委托就是将方法作为参数,进行传递的 书中的记载:将某种行为“包含”在一个对象中,这个对象可 ...

  10. POJ3009Curling 2.0

    http://poj.org/problem?id=3009 题意 : 迷宫升级版,也是m*n的迷宫,0是可以走的,1是阻塞,2是初始点,3是目标位置,这个的阻塞是可以消除的,就是说只要石头撞到阻塞, ...