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秒算法进行刷新的。
  • 相关阅读:
    职业规划——第1.0章、模拟面试的小记(一)
    菜鸟VUER学习记——零0章、打开新的大门
    职业规划——第0章、哇,原来需要的这么多
    经营自己,愈发强大——《软技能——代码之外的生存指南》读后感
    如何阅读一本书
    Java开发规范
    JVM堆和栈的区别
    2016年7月书单推荐
    web性能优化——代理(nginx)
    web性能优化——浏览器相关
  • 原文地址:https://www.cnblogs.com/innobase/p/4665115.html
Copyright © 2011-2022 走看看