/******************************************************************//**
Returns a free block from the buf_pool. The block is taken off the
free list. If it is empty, blocks are moved from the end of the
LRU list to the free list.
@return    the free control block, in state BUF_BLOCK_READY_FOR_USE */
UNIV_INTERN
buf_block_t*
buf_LRU_get_free_block(
/*===================*/
    buf_pool_t*    buf_pool)    /*!< in/out: buffer pool instance */
{
    buf_block_t*    block        = NULL;
    ibool        freed;
    ulint        n_iterations    = ;
    ibool        mon_value_was    = FALSE;
    ibool        started_monitor    = FALSE;
loop:
    buf_pool_mutex_enter(buf_pool);

    if (!recv_recovery_on && UT_LIST_GET_LEN(buf_pool->free)
        + UT_LIST_GET_LEN(buf_pool->LRU) < buf_pool->curr_size / ) {
        ut_print_timestamp(stderr);

        fprintf(stderr,
            "  InnoDB: ERROR: over 95 percent of the buffer pool"
            " is occupied by\n"
            "InnoDB: lock heaps or the adaptive hash index!"
            " Check that your\n"
            "InnoDB: transactions do not set too many row locks.\n"
            "InnoDB: Your buffer pool size is %lu MB."
            " Maybe you should make\n"
            "InnoDB: the buffer pool bigger?\n"
            "InnoDB: We intentionally generate a seg fault"
            " to print a stack trace\n"
            "InnoDB: on Linux!\n",
            (ulong) (buf_pool->curr_size
                 / ( *  / UNIV_PAGE_SIZE)));

        ut_error;

    } else if (!recv_recovery_on
           && (UT_LIST_GET_LEN(buf_pool->free)
               + UT_LIST_GET_LEN(buf_pool->LRU))
           < buf_pool->curr_size / ) {

        if (!buf_lru_switched_on_innodb_mon) {

            /* Over 67 % of the buffer pool is occupied by lock
            heaps or the adaptive hash index. This may be a memory
            leak! */

            ut_print_timestamp(stderr);
            fprintf(stderr,
                "  InnoDB: WARNING: over 67 percent of"
                " the buffer pool is occupied by\n"
                "InnoDB: lock heaps or the adaptive"
                " hash index! Check that your\n"
                "InnoDB: transactions do not set too many"
                " row locks.\n"
                "InnoDB: Your buffer pool size is %lu MB."
                " Maybe you should make\n"
                "InnoDB: the buffer pool bigger?\n"
                "InnoDB: Starting the InnoDB Monitor to print"
                " diagnostics, including\n"
                "InnoDB: lock heap and hash index sizes.\n",
                (ulong) (buf_pool->curr_size
                     / ( *  / UNIV_PAGE_SIZE)));

            buf_lru_switched_on_innodb_mon = TRUE;
            srv_print_innodb_monitor = TRUE;
            os_event_set(srv_lock_timeout_thread_event);
        }
    } else if (buf_lru_switched_on_innodb_mon) {

        /* Switch off the InnoDB Monitor; this is a simple way
        to stop the monitor if the situation becomes less urgent,
        but may also surprise users if the user also switched on the
        monitor! */

        buf_lru_switched_on_innodb_mon = FALSE;
        srv_print_innodb_monitor = FALSE;
    }

    /* If there is a block in the free list, take it */
    block = buf_LRU_get_free_only(buf_pool); //这里
    buf_pool_mutex_exit(buf_pool);

    if (block) {
        ut_ad(buf_pool_from_block(block) == buf_pool);
        memset(&block->page.zip, , sizeof block->page.zip);

        if (started_monitor) {
            srv_print_innodb_monitor = mon_value_was;
        }

        return(block);
    }

    /* If no block was in the free list, search from the end of the LRU
    list and try to free a block there */

    freed = buf_LRU_search_and_free_block(buf_pool, n_iterations); //从lru中取一块 这里) {
        goto loop;
    }

    ) {
        ut_print_timestamp(stderr);
        fprintf(stderr,
            "  InnoDB: Warning: difficult to find free blocks in\n"
            "InnoDB: the buffer pool (%lu search iterations)!"
            " Consider\n"
            "InnoDB: increasing the buffer pool size.\n"
            "InnoDB: It is also possible that"
            " in your Unix version\n"
            "InnoDB: fsync is very slow, or"
            " completely frozen inside\n"
            "InnoDB: the OS kernel. Then upgrading to"
            " a newer version\n"
            "InnoDB: of your operating system may help."
            " Look at the\n"
            "InnoDB: number of fsyncs in diagnostic info below.\n"
            "InnoDB: Pending flushes (fsync) log: %lu;"
            " buffer pool: %lu\n"
            "InnoDB: %lu OS file reads, %lu OS file writes,"
            " %lu OS fsyncs\n"
            "InnoDB: Starting InnoDB Monitor to print further\n"
            "InnoDB: diagnostics to the standard output.\n",
            (ulong) n_iterations,
            (ulong) fil_n_pending_log_flushes,
            (ulong) fil_n_pending_tablespace_flushes,
            (ulong) os_n_file_reads, (ulong) os_n_file_writes,
            (ulong) os_n_fsyncs);

        mon_value_was = srv_print_innodb_monitor;
        started_monitor = TRUE;
        srv_print_innodb_monitor = TRUE;
        os_event_set(srv_lock_timeout_thread_event);
    }

    /* No free block was found: try to flush the LRU list */

    buf_flush_free_margin(buf_pool);
    ++srv_buf_pool_wait_free;

    os_aio_simulated_wake_handler_threads();

    buf_pool_mutex_enter(buf_pool);

    ) {
        /* We have written pages in an LRU flush. To make the insert
        buffer more efficient, we try to move these pages to the free
        list. */

        buf_pool_mutex_exit(buf_pool);

        buf_LRU_try_free_flushed_blocks(buf_pool);
    } else {
        buf_pool_mutex_exit(buf_pool);
    }

    ) {

        os_thread_sleep();
    }

    n_iterations++;

    goto loop;
}

函数buf_LRU_get_free_block的更多相关文章

  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. laravel扩展xls处理maatwebsite/excel

    github地址:https://github.com/Maatwebsite/Laravel-Excel 安装: sudo composer require maatwebsite/excel 配置 ...

  2. web页面开发笔记(不断更新)

    布局: 1.左右分列2端:使用float:left+float:right,如果一边有多列的话,另一列会对齐最下面那列.所以一般把左右各设一列,一列中再细分多行. 2.div不跟随:使用clear:b ...

  3. Spark Streaming揭秘 Day14 State状态管理

    Spark Streaming揭秘 Day14 State状态管理 今天让我们进入下SparkStreaming的一个非常好用的功能,也就State相关的操作.State是SparkStreaming ...

  4. 四个基数任意次数组合相加得到一个数N,求所有可能组合

    #include <iostream> #include <vector> usingnamespace std; vector<int> vec; constin ...

  5. opencv学习笔记(02)——遍历图像(指针法)

    #include <opencv2\core\core.hpp> #include <opencv2\highgui\highgui.hpp> #include <ope ...

  6. MySQL的alter的使用

    ALTER TABLE 语句用于在已有的表中添加.修改或删除列 1.ADD [COLUMN] column name (column definitions) [FIRST or AFTER colu ...

  7. [摘] SQLPLUS Syntax

    You use the SQLPLUS command at the operating system prompt to start command-line SQL*Plus: SQLPLUS [ ...

  8. MySQL行级锁,表级锁,页级锁详解

    页级:引擎 BDB. 表级:引擎 MyISAM , 理解为锁住整个表,可以同时读,写不行 行级:引擎 INNODB , 单独的一行记录加锁 表级,直接锁定整张表,在你锁定期间,其它进程无法对该表进行写 ...

  9. OnlineJudge大集合

    什么是OJ Online Judge系统(简称OJ)是一个在线的判题系统.用户可以在线提交程序源代码,系统对源代码进行编译和执行,并通过预先设计的测试数据来检验程序源代码的正确性. 一个用户提交的程序 ...

  10. 1201: [HNOI2005]数三角形 - BZOJ

    Description Input 大三角形的所有短边可以看成由(n+1)*n/2个单位三角形的边界组成.如下图的灰色三角形所示.其中第1排有1个灰色三角形,第2排有2个灰色三角形,……,第n排有n个 ...