innodb_flush_log_at_trx_commit 参数

innodb_flush_log_at_trx_commit 三种取值 0 、1、2 对性能有很大影响,现在从源码瞧瞧是如何实现定义。涉及的文件以及函数调用如下:

innobase/srv/srv0srv.c中srv_master_thread()

innodbase/trx/trx0trx.c 中 trx_commit_off_kernel() ( 查看log_write_up_to()函数调用)

关键代码

/* Depending on the my.cnf options, we may now write the log
        buffer to the log files, making the transaction durable if
        the OS does not crash. We may also flush the log files to
        disk, making the transaction durable also at an OS crash or a
        power outage.

        The idea in InnoDB's group commit is that a group of
        transactions gather behind a trx doing a physical disk write
        to log files, and when that physical write has been completed,
        one of those transactions does a write which commits the whole
        group. Note that this group commit will only bring benefit if
        there are > 2 users in the database. Then at least 2 users can
        gather behind one doing the physical log write to disk.

        If we are calling trx_commit() under prepare_commit_mutex, we
        will delay possible log write and flush to a separate function
        trx_commit_complete_for_mysql(), which is only called when the
        thread has released the mutex. This is to make the
        group commit algorithm to work. Otherwise, the prepare_commit
        mutex would serialize all commits and prevent a group of
        transactions from gathering. */

        if (trx->flush_log_later) {
            /* Do nothing yet */
            trx->must_flush_log_later = TRUE;
        } else if (srv_flush_log_at_trx_commit == 0) {
            /* Do nothing */
        } else if (srv_flush_log_at_trx_commit == 1) {
            if (srv_unix_file_flush_method == SRV_UNIX_NOSYNC) {
                /* Write the log but do not flush it to disk */

                log_write_up_to(lsn, LOG_WAIT_ONE_GROUP,
                        FALSE);

            } else {
                /* Write the log to the log files AND flush
                them to disk */

                log_write_up_to(lsn, LOG_WAIT_ONE_GROUP, TRUE);
            }

        } else if (srv_flush_log_at_trx_commit == 2) {

            /* Write the log but do not flush it to disk */

            log_write_up_to(lsn, LOG_WAIT_ONE_GROUP, FALSE);
        } else {
            ut_error;
        }

        trx->commit_lsn = lsn;

  log_write_up_to定义在innobase/include/log0log.h中

/******************************************************//**
This function is called, e.g., when a transaction wants to commit. It checks
that the log has been written to the log file up to the last log entry written
by the transaction. If there is a flush running, it waits and checks if the
flush flushed enough. If not, starts a new flush. */
UNIV_INTERN
void
log_write_up_to(
/*============*/
    ib_uint64_t    lsn,    /*!< in: log sequence number up to which
                the log should be written,
                IB_ULONGLONG_MAX if not specified */
    ulint        wait,    /*!< in: LOG_NO_WAIT, LOG_WAIT_ONE_GROUP,
                or LOG_WAIT_ALL_GROUPS */
    ibool        flush_to_disk);
                /*!< in: TRUE if we want the written log
                also to be flushed to disk */
/****************************************************************//**

wait 参数三种变量值:

log_no_wait:不等待  

log_wait_one_group:等待刷新到一个日志组

log_wait_all_group:等待刷新到所有日志组


 实现 innobase/log/log0log.c中


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值