当前位置:网站首页>InnoDB dirty page refresh mechanism checkpoint in MySQL

InnoDB dirty page refresh mechanism checkpoint in MySQL

2022-07-06 12:35:00 wx5caecf2ed0645


We know InnoDB use Write Ahead Log Policies to prevent downtime and data loss , When the transaction is committed , Write the redo log first , Then modify the memory data page , This produces dirty pages . Since there are redo logs to ensure data persistence , When querying, you can also directly get data from the buffer pool page , Then why flush dirty pages to disk ? If the redo log can be increased infinitely , At the same time, the buffer pool is large enough , Able to cache all data , There is no need to flush the dirty pages in the buffer pool to the disk . however , There are usually the following questions :


  • Server memory is limited , There is not enough buffer pool , Unable to cache all data
  • Redo logs increase infinitely, and the cost is too high
  • If you redo all logs during downtime, the recovery time is too long

in fact , When the database goes down , The database does not need to redo all the logs , Just execute the log after the last swipe point . This point is called Checkpoint, It solves the above problems :


  • Reduce database recovery time
  • When the buffer pool is insufficient , Flush the dirty page to disk
  • When the redo log is not available , Refresh the dirty pages

Redo logs are designed to be recyclable , When the log file is full , The corresponding data in the redo log has been refreshed to the disk, and the logs that are no longer needed can be overwritten and reused .

InnoDB The engine goes through LSN(Log Sequence Number) To mark the version ,LSN Is the end point of each log in the log space , In terms of byte offset . Every page Yes LSN,redo log Also have LSN,Checkpoint Also have LSN. By command ​​show engine innodb status​​ To observe :

       
---
LOG
---
Log sequence number 11102619599
Log flushed up to 11102618636
Last checkpoint at 11102606319
0 pending log writes, 0 pending chkp writes
15416290 log i/o's done, 12.32 log i/o's/second
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.


Checkpoint How many pages does the mechanism refresh at a time , Where to get the dirty pages , When to trigger refresh ? These are very complicated . There are two kinds of Checkpoint, Respectively :


  • Sharp Checkpoint
  • Fuzzy Checkpoint

Sharp Checkpoint It happened when the database was shut down , Brush all dirty pages back to disk . Use at run time Fuzzy Checkpoint Refresh some dirty pages . There are several ways to refresh some dirty pages :


  • Master Thread Checkpoint
  • FLUSH_LRU_LIST Checkpoint
  • Async/Sync Flush Checkpoint
  • Dirty Page too much Checkpoint

Master Thread Checkpoint

Master Thread Refresh a certain proportion of pages from the dirty page list of the buffer pool back to disk at the rate of per second or per ten seconds . This process is asynchronous , Does not block the query thread .

FLUSH_LRU_LIST Checkpoint

InnoDB Make sure that LRU The list is 100 Left and right free pages can be used . stay InnoDB1.1.X Before version , To check LRU Whether there are enough pages for the user to query the operation thread , without , Will LRU The page at the end of the list , If there are dirty pages in the eliminated pages , Will be enforced Checkpoint Brush back dirty page data to disk , Obviously this will block the user query thread . from InnoDB1.2.X Version start , This check is placed in a separate Page Cleaner Thread In the middle of , And users can use ​​innodb_lru_scan_depth​​ control LRU The number of pages available in the list , The default value is 1024.

Async/Sync Flush Checkpoint

When the redo log file is not available , You need to force some pages in the dirty page list back to disk . This ensures that redo log files can be recycled . stay InnoDB1.2.X Before the release ,Async Flush Checkpoint Will block the user query thread that finds the problem ,Sync Flush Checkpoint Will block all query threads .InnoDB1.2.X Then put it in a separate Page Cleaner Thread.

Dirty Page too much Checkpoint

When there are too many dirty pages ,InnoDB The engine will force Checkpoint. The purpose is to ensure that there are enough free pages available in the buffer pool . This can be done through parameters ​​innodb_max_dirty_pages_pct​​ To set up :

       
mysql> show variables like 'innodb_max_dirty_pages_pct';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| innodb_max_dirty_pages_pct | 90 |
+----------------------------+-------+
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.



原网站

版权声明
本文为[wx5caecf2ed0645]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131527440798.html