简体   繁体   English

为什么MySQL InnoDB redo log block写不需要双写?

[英]Why doesn't MySQL InnoDB redo log block writing need double write?

MySQL InnoDB redo log block size is 512 bytes (maybe a sector in the disk). MySQL InnoDB 重做日志块大小为 512 字节(可能是磁盘中的一个扇区)。 I read Are disk sector writes atomic?我读了磁盘扇区写入原子吗? . . It looks like it depends on the underlying hardware to decide if a sector writing is atomic.看起来它取决于底层硬件来决定扇区写入是否是原子的。 So if it's not atomic, how can InnoDB redo log guarantees that it won't be corrupted?那么如果它不是原子的,InnoDB 重做日志如何保证它不会被破坏呢?

Say the last log block was not full in the disk, then the InnoDB engine wrote more log records to this block and flushed it to the disk.假设磁盘中最后一个日志块未满,那么 InnoDB 引擎会向该块写入更多日志记录并将其刷新到磁盘。 Sudden power loss caused only part of the block had been written into disk.突然断电导致只有部分块已写入磁盘。 By that the checksum of this block is mismatched.由于该块的校验和不匹配。 Other previous committed transactions would be lost after the server restarts.服务器重新启动后,其他先前提交的事务将丢失。

when a transcation commit, mysql will force flush the redo log block(512b) to disk, if the log block is not full, mysql will fill the blcok with zero(zero-filling) before flush to disk.当事务提交时,mysql 将强制刷新重做日志块(512b)到磁盘,如果日志块未满,mysql 将在刷新到磁盘之前用零(零填充)填充块。

if the flush action is success, the transcation commit will be success;如果刷新操作成功,则事务提交将成功; if the flush action has error, the transcation coomit will be fail;如果flush action有错误,事务coomit会失败;

so if a transcation commit is success, the transcation's redo log must has flushed to disk.因此,如果事务提交成功,则事务的重做日志必须已刷新到磁盘。

if the checksum of redo block is mismatched, it mean the redo log block flush action has error(such as power loss), the transcation of the redo log in this block must is fail.如果重做块的校验和不匹配,说明重做日志块刷新动作有错误(例如掉电),这个块中重做日志的事务肯定是失败的。

So the commited transcation will not be lost, when mysql recover from power loss, because a success transcation must flush his redo log to disk successfully.所以提交的事务不会丢失,当 mysql 从断电中恢复时,因为成功的事务必须成功地将他的重做日志刷新到磁盘。

And Last, why the redo log block size is 512 byte?最后,为什么重做日志块大小是 512 字节? because it try to use the disk atomic write(a disk sector size 512 byte) for speed up and less mismatched checksum.因为它尝试使用磁盘原子写入(磁盘扇区大小 512 字节)来加快速度并减少不匹配的校验和。 if the disk not support 512byte atomic write, it doesn't matter.如果磁盘不支持 512byte 原子写入,没关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL InnoDB:WAL、Double Write Buffer、Log Buffer、Redo Log的区别 - MySQL InnoDB: Differences between WAL, Double Write Buffer, Log Buffer, Redo Log 启用mysql binlog后,为什么仍需要innodb重做日志? - Why we still need innodb redo log when mysql binlog has been enabled? Mysql 由于 performance_schema.innodb_redo_log_files 而崩溃 - Mysql crashing due to performance_schema.innodb_redo_log_files MySql InnoDB 中的重做日志和双写缓冲区有什么区别? - What is the difference between redo log and doublewirte buffer in MySql InnoDB? 为什么 mysql "ENGINE=InnoDB" 不适用于 joomla 3 安装 - Why mysql "ENGINE=InnoDB" doesn't work with joomla 3 installation MySQL/MariaDB - 设置全局变量“innodb_flush_log_at_trx_commit = 2”不影响速度 - MySQL/MariaDB - Setting global variable “innodb_flush_log_at_trx_commit = 2” doesn't affect speed Mysql innodb 行锁不起作用 - Mysql innodb row lock doesn't work 不启用事务时innodb会记录undo log redo log吗? - Will innodb record undo log redo log when not enable transaction? 为什么撤消MySQL innodb缓冲池中的日志条目(MySQL 5.7) - Why undo log entries in MySQL innodb buffer pool (MySQL 5.7) 为什么MySQL InnoDB日志文件会产生如此大的HDD负载? - Why MySQL InnoDB log files creates such big HDD load?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM