我一直认为mysql的logfile,就是data文件下那几个ib_logfile就是在硬盘上的,但是今天看到关于innodb_flush_log_at_trx_commit参数的解释后迷茫了,其中一段解释如下:
With a value of 2, the contents of the InnoDB log buffer are written to the log file after each transaction commit and the log file is flushed to disk approximately once per second. Once-per-second flushing is not 100% guaranteed to happen every second, due to process scheduling issues. Because the flush to disk operation only occurs approximately once per second, you can lose up to a second of transactions in an operating system crash or a power outage.
很奇怪,这里的意思我感觉是:logfile是驻留在内存中(或文件系统缓存中?),设为2后先从log buffer写入logfile,再从缓存中的logfile写入disk上的logfile? logfile

解决方案 »

  1.   

    难道不应该是log buffer直接flush到disk上的logfile吗,怎么看官网解释中间还多了一层
      

  2.   

    楼主这个链接解释得挺清楚的:
    http://blog.csdn.net/liqfyiyi/article/details/51137764
    写只是写到操作系统的内存中,刷才是持久化到磁盘。设置为2会在事务提交的时候写到操作系统的内容,但是刷新还是每秒的。断电的时候也可能丢失超过一秒的事务。
      

  3.   

    回复楼上:
    以上英文片段是官网5.6版本的原文。
    在查阅了大量中英文资料比对后,我暂时作如下结论:
    在官网正确的前提下,'log buffer are written to the log file'是指调用write()方法将redo log buffer写入OS文件系统缓存,‘log file is flushed to disk’是指调用fsync()方法将文件系统缓存写入disk,这意味这段里边的log file是指的文件系统缓存里的log file,在disk上的log file块文件则直接用disk盖过去了。
    这意味着mysql的写日志还会考虑文件系统缓存这一层,也可能是因为oracle和sqlserver源码不公开,这部分直接被大家忽略了而已。
      

  4.   

    这个我也一直没弄懂
    我的理解似乎是 myql 接管了磁盘高速缓存
    Linux 不太清楚,Windows 的磁盘有高速缓存这个东东,写文件是写这个,然后从这个真正写入磁盘(物理写入)
      

  5.   

    刚才又翻了下文档,我前面说的应该不对,应该是 mysql 自己的 bufferThe innodb_flush_method options for Unix-like systems include: 
    fsync: InnoDB uses the fsync() system call to flush both the data and log files. fsync is the default setting. The innodb_flush_method options for Windows systems include: 
    async_unbuffered: InnoDB uses Windows asynchronous I/O and non-buffered I/O. async_unbuffered is the default setting on Windows systems. ----------------- 这个说明默认是用操作系统的 flush,那么 mysql 的那个 buffer 跟操作系统的 flush 时的 buffer 就无关了
      

  6.   

    上午我总结了一篇博客,暂时计划这么理解:http://www.cnblogs.com/leohahah/p/8176553.html