zoukankan      html  css  js  c++  java
  • innodb_flush_logs_at_trx_commit源码行为

    1.innodb_flush_logs_at_trx_commit模式:
       该参数定义有三种值:012;默认为1
    如果innodb_flush_log_at_trx_commit设置为0,log buffer将每秒一次地写入log file中,并且log file的flush(刷到磁盘)操作同时进行.该模式下,在事务提交的时候,不会主动触发写入磁盘的操作。
    如果innodb_flush_log_at_trx_commit设置为1,每次事务提交时MySQL都会把log buffer的数据写入log file,并且flush(刷到磁盘)中去.
    如果innodb_flush_log_at_trx_commit设置为2,每次事务提交时MySQL都会把log buffer的数据写入log file.但是flush(刷到磁盘)操作并不会同时进行。该模式下,MySQL会每秒执行一次 flush(刷到磁盘)操作。
      定义位于:innobase/srv/srv0srv.c中
       UNIV_INTERN ulong    srv_flush_log_at_trx_commit = 1;
    
    定义位于:/innobase/trx0.trx.cc  
    /**********************************************************************//**
    If required, flushes the log to disk based on the value of
    innodb_flush_log_at_trx_commit. */
    static
    void
    trx_flush_log_if_needed_low(
    /*========================*/
        lsn_t    lsn)    /*!< in: lsn up to which logs are to be
                flushed. */
    {
        switch (srv_flush_log_at_trx_commit) {
        case 0:
            /* Do nothing */  这里是由master线程的每1秒和每10秒算法进行日志的刷新
            break;
        case 1:
            /* Write the log and optionally flush it to disk */
            log_write_up_to(lsn, LOG_WAIT_ONE_GROUP,
                    srv_unix_file_flush_method != SRV_UNIX_NOSYNC);
            break;
        case 2:
            /* Write the log but do not flush it to disk */
            log_write_up_to(lsn, LOG_WAIT_ONE_GROUP, FALSE);
    
            break;
        default:
            ut_error;
        }
    }
    
    innodb有2个算法分别为1秒和10秒算法:
            srv_master_sleep(); //os_thread_sleep(1000000);
            if (srv_check_activity(old_activity_count)) {
                old_activity_count = srv_get_activity_count();
                srv_master_do_active_tasks();
                        ->/* Flush logs if needed */
                            srv_main_thread_op_info = "flushing log";
                            srv_sync_log_buffer_in_background();
            } else {
                srv_master_do_idle_tasks();
                        ->    /* Flush logs if needed */
                            srv_sync_log_buffer_in_background();
            }
    当innodb_flush_log_at_trx_commit=0时候,innodb的日志刷新是由master线程中的1秒和10秒算法进行刷新的。
  • 相关阅读:
    Docker简介,安装,配置
    Centos7给 root 账户开通ssh权限
    [转载]Hyper-v 安装CentOS 7
    软件开发_六大原则
    php函数名后冒号(:)+数据类型(返回值类型限制/php新特性)
    MySQL--事务介绍
    MySQL存储引擎
    leetcode刷题笔记300题 最长上升子序列
    leetcode刷题笔记299题 猜数字游戏
    **leetcode刷题笔记四 两个有序序列的中位数**
  • 原文地址:https://www.cnblogs.com/innobase/p/4665115.html
Copyright © 2011-2022 走看看