gpt4 book ai didi

mysql - 为什么MySQL在选项为O_DIRECT的情况下仍然使用fsync()来刷新数据?

转载 作者:可可西里 更新时间:2023-11-01 06:48:29 25 4
gpt4 key购买 nike

http://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_flush_method

根据上面的文章描述,如果我们选择选项O_DIRECT,则描述如下:

O_DIRECT: InnoDB uses O_DIRECT (or directio() on Solaris) to open thedata files, and uses fsync() to flush both the data and log files.

由于选项 O_DIRECT 意味着没有\最小化数据将缓存在操作系统页面缓存中,但是 fsync() 用于将数据从页面缓存刷新到设备,所以我的问题是为什么 MySQL 仍然使用 fsync() 刷新选项为 O_DIRECT 时的数据?

最佳答案

其实在documentation you linked里面加了说明在 O_DIRECT 选项描述之后的段落中(突出显示是我的):

O_DIRECT_NO_FSYNC: InnoDB uses O_DIRECT during flushing I/O, but skips the fsync() system call afterward. This setting is suitable for some types of file systems but not others. For example, it is not suitable for XFS. If you are not sure whether the file system you use requires an fsync(), for example to preserve all file metadata, use O_DIRECT instead. This option was introduced in MySQL 5.6.7 (Bug #11754304, Bug #45892).

MySQL 错误 #45892包含附加信息:

Some testing by Domas has shown that some filesystems (XFS) do not sync metadata without the fsync. If the metadata would change, then you need to still use fsync (or O_SYNC for file open).

For example, if a file grows while O_DIRECT is enabled it will still write to the new part of the file, however since the metadata doesn't reflect the new size of the file the tail portion can be lost in the event of a crash.

Solution:

Continue to use fsync when important metadata changes or use O_SYNC in addition to O_DIRECT.

总结一下:不对某些文件系统使用 fsync() 会导致 MySQL 失败。但是,MySQL 从 v5.6.7 开始提供选项,通过添加 O_DIRECT_NO_FSYNC 选项来配置 MySQL(好吧,innodb)以适应您自己的操作系统在这方面的能力。

关于mysql - 为什么MySQL在选项为O_DIRECT的情况下仍然使用fsync()来刷新数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41440492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com