本文主要是介绍innodb_flush_log_at_timeout,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文档解释
innodb_flush_log_at_timeoutProperty Value
System Variable innodb_flush_log_at_timeout
Scope Global
Dynamic Yes
Type integer
Default Value 1
Minimum Value 1
Maximum Value 2700Write 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吗?
这篇关于innodb_flush_log_at_timeout的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!