In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to understand the innodb_flush_method of MySQL". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand the innodb_flush_method of MySQL".
The official document is described as follows:
By default, InnoDB uses the fsync () system call to flush both the data and log files. If
Innodb_flush_method option is set to O_DSYNC, InnoDB uses O_SYNC to open and flush the
Log files, and fsync () to flush the data files. If O_DIRECT is specified (available on some GNU/
Linux versions, FreeBSD, and Solaris), InnoDBuses O_DIRECT (or directio () on Solaris) to
Open the data files, and uses fsync () to flush both the data and log files. Note that InnoDB uses
Fsync () instead of fdatasync (), and it does not use O_DSYNC by default because there have
Been problems with it on many varieties of Unix.
Innodb_flush_method
General 3 valu
1 、 fdatasync
2 、 O_DSYNC
3 、 O_DIRECT
Normal access mode
User mode cache-"kernel state cache -" disk
According to MYSQL's description,
1 、 fdatasync
InnoDB uses the fsync () system call to flush both the data and log files.
Note that InnoDB uses fsync () instead of fdatasync ()
Although MYSQL can use fdatasync as an argument, it is actually the fsync () function of the calling system
We can look at the description of the FSYNC () function under LINUX.
Fsync () transfers ("flushes") all modified in-core data of (i.e., modified buffer cache pages for) the file referred to by the
File descriptor fd to the disk device (or other permanent storage device) so that all changed information can be retrieved even
After the system crashed or was rebooted. This includes writing through or flushing a disk cache if present. The call blocks
Until the device reports that the transfer has completed. It also flushes metadata information associated with the file (see
Stat (2)).
To put it simply, this parameter is used to synchronize all thread-modified files, while the open file is recorded in the PCB in the process, and it matches through the file descriptor.
In the LINUX kernel / usr/src/linux-headers-3.19.0-25-generic/include/linux/sched.h
Has the following PCB structure
Struct task_struct {}
There is a files_struct structure, and the file descriptor is the pointer to such a structure
So as long as the MYSQL thread refreshes, the data of his files must be synchronized to disk.
2 、 O_DSYNC
InnoDB uses O_SYNC to open and flush the log files, and fsync () to flush the data files
When set to this option, the way O_SYNC is used when the MYSQL thread opens LOGFILE, while fsync () is still used for data files
We know that a file is read and opened using LINUX
The open () function, and there is such an option
O_SYNC The file is opened for synchronous I. Any write (2) s on the resulting file descriptor will block the calling process
Until the data has been physically written to the underlying hardware.
He describes that if a file is opened in this way, any process that attempts to modify the file descriptor will be blocked before the data is written from the kernel state cache to the physical disk. This ensures that the log file
Maximum security
3 、 O_DIRECT
If O_DIRECT is specified (available on some GNU/Linux versions, FreeBSD, and Solaris), InnoDB
Uses O_DIRECT (or directio () on Solaris) to open the data files, and uses
Fsync () to flush both the data and log files.
Use this option MYSQL to open the data file using O_DIRECT, while fsync () will eventually synchronize all data and log files.
Let's also look at the description of O_DIRECT in the open () function.
O_DIRECT (Since Linux 2.4.10)
Try to minimize cache effects of the I/O to and from this file. In general this will degrade performance, but it is use-
Ful in special situations, such as when applications do their own caching. File I/O is done directly to/from user-space
Buffers. The O_DIRECT flag on its own makes an effort to transfer data synchronously, but does not give the guarantees
Of the O_SYNC flag that data and necessary metadata are transferred. To guarantee synchronous I/O, O_SYNC must be used
In addition to O_DIRECT.
Using this option generally degrades performance, but in certain cases, such as the application has its own caching mechanism. The O_DIRECT logo comes directly from the cache in the user mode for a large number of
Data writing is advantageous because he bypasses kernel state caching, but he does not synchronize METADATA (here time-taking is understood as INODE cache, that is, basic information of files such as open time, modification time, etc.)
So to complete the synchronization, you must call O_SYNC at the same time.
So we also understand why we call FSYNC () when using O_DIRECT. We know that FSYNC () is fully synchronized, and the traditional FDATASYNC () on LINUX is out of sync with METADATA.
Such as INODE cache, process description cache. But he can bypass caching for a large amount of data and improve performance, and the only thing that needs to be synchronized is DATAFILE's METADAT.
MYSQL has its own buffer, so it's better to use O_DIRECT.
Thank you for reading, the above is the content of "how to understand the innodb_flush_method of MySQL", after the study of this article, I believe you have a deeper understanding of how to understand the innodb_flush_method of MySQL, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.