innodb_flush_logs_at_trx_commit源码行为

来源:互联网 发布:淘宝描述不符赔偿 编辑:程序博客网 时间:2024/06/15 18:02
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 ofinnodb_flush_log_at_trx_commit. */staticvoidtrx_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秒算法进行刷新的。

 

0 0
原创粉丝点击