innodb double buffer
来源:互联网 发布:ubuntu ikev2 搭建 编辑:程序博客网 时间:2024/05/29 18:47
原文是percona的mysql performance blog上面的:
http://www.mysqlperformanceblog.com/2006/08/04/innodb-double-write/
doublewrite: It means Innodb will write data twice when it performs table space writes – writes to log files are done only once.
当innodb进行tablespace的写操作时,会写两次。而进行redo log file的写操作时,只写一次。
innodb的tablespace中有一个double write buffer。double write buffer不同于其他的buffer是在内存中的,它是在inndob的公共tablespace ibdata文件中。double write可通过设置参数:innodb_doublewrite=0来禁用double write buffer。
很想知道double write的大小,所以看了一下源代码,找到了一下的函数:
mysql-5.1.41/storage/innodb_plugin/trx/trx0sys.c:164
/****************************************************************//**
Creates or initialializes the doublewrite buffer at a database start. */
static
void
trx_doublewrite_init(
/*=================*/
byte* doublewrite) /*!< in: pointer to the doublewrite buf
header on trx sys page */
{
trx_doublewrite = mem_alloc(sizeof(trx_doublewrite_t));
/* Since we now start to use the doublewrite buffer, no need to call
fsync() after every write to a data file */
#ifdef UNIV_DO_FLUSH
os_do_not_call_flush_at_each_write = TRUE;
#endif /* UNIV_DO_FLUSH */
mutex_create(&trx_doublewrite->mutex, SYNC_DOUBLEWRITE);
trx_doublewrite->first_free = 0;
trx_doublewrite->block1 = mach_read_from_4(
doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK1);
trx_doublewrite->block2 = mach_read_from_4(
doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK2);
trx_doublewrite->write_buf_unaligned = ut_malloc(
(1 + 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) * UNIV_PAGE_SIZE);
trx_doublewrite->write_buf = ut_align(
trx_doublewrite->write_buf_unaligned, UNIV_PAGE_SIZE);
trx_doublewrite->buf_block_arr = mem_alloc(
2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * sizeof(void*));
}
其中,TRX_SYS_DOUBLEWRITE_BLOCK_SIZE =64,所以初始化时的大小应该是129个page。
1. 为什么需要double write?
目的是为了保证出现部分写失效(partial page write)--即数据页写到一半时就出现故障--时的数据安全性。
一般情况只需要用innodb的redo log就可以保证其ACID的特性了。为什么出现partial page write 的时候,recovery不能正常进行呢?
原因在于innodb的redo log的内容格式:
Innodb并不在日志中记录整个数据页,而是使用一种称之为“physiological”日志的技术,即日志项中只包含页号、对数据进行的操作(如更新一行记录)和日志序列号等信息。
redo log这样写的优点:
能够减少写入到日志的数据量。
缺点:
必须要求数据文件内的数据页内部的一致性。
It does not matter which page version it is – it could be “current” version in which case Innodb will skip page upate operation or “former” in which case Innodb will perform update. If page is inconsistent recovery can’t proceed.
2. double write的工作原理:
你可以将doublewrite看作是在Innodb表空间内部分配的一个短期的日志文件,这一日志文件包含100个数据页。
Innodb在写出缓冲区中的数据页时采用的是一次写多个页的方式,这样多个页就可以先顺序写入到doublewrite缓冲区并调用fsync()保证这些数据被写出到磁盘。
然后数据页才被定出到它们实际的存储位置并再次调用fsync()。
故障恢复时Innodb检查doublewrite缓冲区与数据页原存储位置的内容,若数据页在doublewrite缓冲区中处于不一致状态将被简单的丢弃,若在原存储位置中不一致则从doublewrite缓冲区中还原。
检查double write和tablespace中的数据是否一致:
mysql-5.1.41/storage/innodb_plugin/trx/trx0sys.c:411
trx_sys_doublewrite_init_or_restore_pages
判断double write和tablespace中的数据page是否coruppted,通过checksum来判断的:
mysql-5.1.41/storage/innodb_plugin/buf/buf0buf.c:295
buf_page_is_corrupted
- innodb double buffer
- innodb double write buffer--struct
- innodb double write buffer--buf_dblwr_write_single_page
- innodb double write buffer--buf_dblwr_add_to_batch
- MySQL InnoDB 的 Double Write Buffer
- innodb double write buffer--刷新页
- innodb double write buffer刷单页场景
- innodb double write buffer批量刷场景
- MySQL Innodb redo log,double write,buffer pool一些关系
- innodb double write buffer--buf_dblwr_add_to_batch调用write、fsync的函数buf_dblwr_flush_buffered_writes
- Innodb buffer pool struct
- innodb insert buffer
- innodb insert buffer merging
- The InnoDB Buffer Pool
- innodb buffer pool
- InnoDB Buffer Pool 说明
- innodb buffer pool
- innodb change buffer 初识
- 事务的传播特性
- 如何申请软件设计师职称?
- Love and Time
- 如何将数据库表中数据导出?
- 发小说-香蜜沉沉玄幻类
- innodb double buffer
- 如何让 HTML 控件只读或不可用
- webkit中修改Timer的时间
- WM 模拟器常见问题如何联网、打电话、发送短信、连接GPRS、硬起等
- C# lambda
- ThinkPad键盘拆解与清理(附图详解)
- 网站怎样留住浏览用户
- 17条网站的隐患,影响你的收录排名
- Log4c学习笔记