Open lihongjie0209 opened 4 years ago
As you may know, a transactional engine writes transactional logs (name you may see: “redo logs”, write-ahead logs or WAL etc), to be able to perform a crash recovery in the case of database crash or server power outage. To maintain somehow the time for recovery (we all expect that database will start quick), the engine has to limit how many changes are in logs. For this a transactional engine performs a “checkpoint,” which basically synchronizes changes in memory with corresponding changes in logs – so old log records can be deleted. Often it results in writing changed database pages from memory to a permanent storage.
checkpoint的一个重要原因是 redolog 容量有限, 不可能一直记录下去, 把redolog中的记录的操作落盘到tablespace, 那么旧的redolog就可以删除了
InnoDB implements a checkpoint mechanism known as fuzzy checkpointing. InnoDB flushes modified database pages from the buffer pool in small batches. There is no need to flush the buffer pool in one single batch, which would disrupt processing of user SQL statements during the checkpointing process.
During crash recovery, InnoDB looks for a checkpoint label written to the log files. It knows that all modifications to the database before the label are present in the disk image of the database. Then InnoDB scans the log files forward from the checkpoint, applying the logged modifications to the database.
原理: