InnoDB source code analysis-transaction log (1), innodb source code
Original article, reprinted please indicate the original link (http://www.cnblogs.com/wingsless/p/5705314.html)
In the previous article "InnoDB WAL learning" (http://www.cnblogs.com/wingsless/p/5203064.html), I analyzed what WAL is, the timing of triggering, recently just in the view of the redo log source code, let's talk about this again.
1. Log write time
Everyone knows this parameter: innodb_flush_log_at_trx_commit, which is used to control the time when the content in the redo buffer is written into the log. Generally, this parameter is divided into two parts: redo buffer writing to log file; OS cache/buffer flushing into disk. I drew a simple example:
I am a little confused after drawing this image, because there is another parameter: innodb_flush_method. We usually choose O_DIRECT. What is the relationship between this parameter and the above parameter? From the parameter perspective, it seems that this parameter specifies how to flush. If so, what will the above figure look like?
Ii. Some ghosts in the Linux Kernel
So I borrowed a book about the Linux kernel. From this book, I probably know that O_DIRECT is a file opening method, that is, the process directly obtains the file content without going through the system cache. Then I read the MySQL documentation, which clearly tells me that after I use O_DIRECT, the data file will be opened in O_DIRECT mode, but I still need to use fsync () the function fl data and logs back to the disk. In fact, I think there are some problems with the name of this parameter. This parameter does not only specify the flush method, but also includes the method for opening a file. You can draw a picture like this:
This is the supplemental version of the figure above.
InnoDB is still very fun. Recently I have been sorting out the source code Study Notes and transaction logs. It is worth writing something here. It is not very painful to read the source code after learning these basic knowledge background.
Original article, reprinted please indicate the original link (http://www.cnblogs.com/wingsless/p/5705314.html)