暂无图片
暂无图片
暂无图片
暂无图片
暂无图片
MySQL特性之double write
914
7页
17次
2020-05-30
免费下载
double write
InnoDB关键特性之double write - GeaoZhang - 博客园
MySQLdouble write 浅析_ITPUB博客
https://dev.mysql.com/doc/refman/8.0/en/innodb-doublewrite-buffer.html
為什麼Oracle沒有double write———Roger
Doublewrite Buffer
The doublewrite buffer is a storage area located in the system tablespace where InnoDB
writes pages that are flushed from the InnoDB buffer pool, before the pages are written to
their proper positions in the data file. Only after flushing and writing pages to the
doublewrite buffer, does InnoDB write pages to their proper positions. If there is an
operating system, storage subsystem, or mysqld process crash in the middle of a page
write, InnoDB can later find a good copy of the page from the doublewrite buffer during
crash recovery.
Although data is always 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 itself as a large sequential chunk, with a single fsync()call to the operating system.
The doublewrite buffer is enabled by default in most cases. To disable the doublewrite
buffer, set innodb_doublewrite to 0.
If system tablespace files (“ibdata files”) are located on Fusion-io devices that support
atomic writes, doublewrite buffering is automatically disabled and Fusion-io atomic writes
are used for all data files. Because the doublewrite buffer setting is global, doublewrite
buffering is also disabled for data files residing on non-Fusion-io hardware. This feature is
only supported on Fusion-io hardware and is only enabled for Fusion-io NVMFS on Linux.
To take full advantage of this feature, an innodb_flush_method setting ofO_DIRECTis
recommended.
Doublewrite Buffer
Doublewrite缓冲区是位于系统表空间中的存储区域,在将⻚⾯写⼊数据⽂件中的正确位置之
前,InnoDB写⼊从InnoDB缓冲池中刷新的⻚⾯。只有在将⻚⾯刷新并写⼊双写缓冲区后,才
InnoDB将⻚⾯写⼊正确的位置。如果在⻚⾯写⼊过程中存在操作系统,存储⼦系统或
mysqld 进程崩溃,则InnoDB可以在崩溃恢复期间从doublewrite缓冲区中找到该⻚⾯的良好
副本。
尽管数据总是写⼊两次,但双写缓冲区不需要两倍的I / O开销或两倍的I / O操作。数据作为⼀
个⼤的顺序块写⼊doublewrite缓冲区本身,只需⼀次fsync()调⽤操作系统。
在⼤多数情况下,默认情况下启⽤doublewrite缓冲区。要禁⽤双写缓冲区,请设置
innodb_doublewrite 0
如果系统表空间⽂件(“ibdata⽂件)位于⽀持原⼦写⼊的Fusion-io设备上,则会⾃动禁⽤双
写缓冲,并且Fusion-io原⼦写⼊将⽤于所有数据⽂件。由于双写缓冲区设置是全局的,因此对
于驻留在⾮Fusion-io硬件上的数据⽂件也禁⽤双写缓冲。此功能仅在Fusion-io硬件上受⽀
持,仅适⽤于Linux上的Fusion-io NVMFS。要充分利⽤此功能,建议进⾏
innodb_flush_method 设置O_DIRECT
关于IO的最⼩单位:
  1、数据库IO的最⼩单位是16KMySQL默认,oracle8K
  2、⽂件系统IO的最⼩单位是4K(也有1K的)
  3、磁盘IO的最⼩单位是512字节
因此,存在IO写⼊导致page损坏的⻛险:
doublewrite:两次写
  提⾼innodb的可靠性,⽤来解决部分写失败(partial page write⻚断裂)
1Double write解决了什么问题
  ⼀个数据⻚的⼤⼩是16K,假设在把内存中的脏⻚写到数据库的时候,写了2K突然掉电,
也就是说前2K数据是新的,后14K是旧的,那么磁盘数据库这个数据⻚就是不完整的,是⼀个
坏掉的数据⻚。redo只能加上旧、校检完整的数据⻚恢复⼀个脏块,不能修复坏掉的数据⻚,
所以这个数据就丢失了,可能会造成数据不⼀致,所以需要double write
2、使⽤情景
  当数据库正在从内存想磁盘写⼀个数据⻚是,数据库宕机,从⽽导致这个⻚只写了部分数
据,这就是部分写失效,它会导致数据丢失。这时是⽆法通过重做⽇志恢复的,因为重做⽇志
记录的是对⻚的物理修改,如果⻚本身已经损坏,重做⽇志也⽆能为⼒。
3double write⼯作流程
  doublewrite由两部分组成,⼀部分为内存中的doublewrite buffer,其⼤⼩为2MB,另⼀
部分是磁盘上共享表空间(ibdata x)中连续的128个⻚,即2个区(extent),⼤⼩也是2M
  1、当⼀系列机制触发数据缓冲池中的脏⻚刷新时,并不直接写⼊磁盘数据⽂件中,⽽是
先拷⻉⾄内存中的doublewrite buffer中;
  2、接着从两次写缓冲区分两次写⼊磁盘共享表空间中(连续存储,顺序写,性能很⾼),每
次写1MB
  3、待第⼆步完成后,再将doublewrite buffer中的脏⻚数据写⼊实际的各个表空间⽂件
(离散写)(脏⻚数据固化后,即进⾏标记对应doublewrite数据可覆盖)
4doublewrite的崩溃恢复
of 7
免费下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论