1 问题背景
前面研究了InnoDB磁盘架构之表空间,今天来研究双写缓冲区。
2 回顾
InnoDB架构如下图所示:
3 双写缓冲区
原文
The doublewrite buffer is a storage area where InnoDB writes pages flushed from the buffer pool before writing the pages to their proper positions in the InnoDB data files. If there is an operating system, storage subsystem, or unexpected mysqld process exit in the middle of a page write, InnoDB can find a good copy of the page from the doublewrite buffer during crash recovery.
双写缓冲区是一个存储区域,在InnoDB将页写到InnoDB数据文件的正确位置之前,InnoDB将页从缓冲池写到该区域(双写缓冲区)。如果在页面写入的过程中存在操作系统,存储子系统或者意外的mysqld
进程退出,InnoDB可以在崩溃恢复期间从双写缓冲区找到一个完整的页面副本。
原文
Although data is written twice, the doublewrite buffer does not require twice as much I/O overhead or twice as many I/O operations. Data is written to the doublewrite buffer in a large sequential chunk, with a single fsync() call to the operating system (except in the case that innodb_flush_method is set to O_DIRECT_NO_FSYNC).
即使数据被写了两次,双写缓冲区不需要两倍的I/O开销或者两倍的I/O操作。数据以大顺序块的形式被写进双写缓冲区中,只需fsync()
调用一次操作系统(innodb_flush_method
被设置成O_DIRECT_NO_FSYNC
的情况除外)。
原文
Prior to MySQL 8.0.20, the doublewrite buffer storage area is located in the InnoDB system tablespace. As of MySQL 8.0.20, the doublewrite buffer storage area is located in doublewrite files.
在 MySQL 8.0.20 之前,双写缓冲区存储区位于InnoDB系统表空间中。从 MySQL 8.0.20 开始,双写缓冲区存储区域位于双写文件中。
双写缓冲区详情配置见Doublewrite Buffer。