innodb_flush_log_at_timeout

innodb_flush_log_at_timeout


文档解释

 innodb_flush_log_at_timeout

Property    Value
System Variable innodb_flush_log_at_timeout
Scope   Global
Dynamic Yes
Type    integer
Default Value   1
Minimum Value   1
Maximum Value   2700

Write and flush the logs every N seconds. innodb_flush_log_at_timeout allows the timeout period between flushes to be increased in order to reduce flushing and avoid impacting performance of binary log group commit. The default setting for innodb_flush_log_at_timeout is once per second.

master线程刷写日志的频率。可以增大此参数设置来减少刷写次数,避免对binlog group commit带来影响。默认值是1.

代码

/********************************************************************//**
The master thread is tasked to ensure that flush of log file happens
once every second in the background. This is to ensure that not more
than one second of trxs are lost in case of crash when
innodb_flush_logs_at_trx_commit != 1 */
static
void
srv_sync_log_buffer_in_background(void)
/*===================================*/
{
    time_t  current_time = time(NULL);

    srv_main_thread_op_info = "flushing log";
    if (difftime(current_time, srv_last_log_flush_time)
        >= srv_flush_log_at_timeout) {
        log_buffer_sync_in_background(true);
        srv_last_log_flush_time = current_time;
        srv_log_writes_and_flush++;
    }
}

如果上一次刷新时间跟现在的差超过了srv_last_log_flush_time的值,则进行log_buffer_sync_in_background刷新操作

/****************************************************************//**
This functions writes the log buffer to the log file and if 'flush'
is set it forces a flush of the log file as well. This is meant to be
called from background master thread only as it does not wait for
the write (+ possible flush) to finish. */
void
log_buffer_sync_in_background(
/*==========================*/
    bool    flush)  /*!< in: flush the logs to disk */
{
    lsn_t   lsn;

    log_mutex_enter();

    lsn = log_sys->lsn;

    if (flush
        && log_sys->n_pending_flushes > 0
        && log_sys->current_flush_lsn >= lsn) {
        /* The write + flush will write enough */
        log_mutex_exit();
        return;
    }

    log_mutex_exit();

    log_write_up_to(lsn, flush);
}

当然关于master线程更多的逻辑不在此介绍了。然而还是觉得,如果在参数innodb_flush_log_at_trx_commit=1的情况下,还有必要周期性的进行log_buffer_sync吗?

猜你喜欢

转载自blog.csdn.net/sun_ashe/article/details/81319520