Mysql之CheckPoint、LSN、redo log的刷新关系

CheckPoint:为了刷新buffer pool的数据page到磁盘中,使得持久化数据page之前相应的redo log可以失效掉,以此节约出空间可以被覆盖,也同时加快了crash时redo log恢复的速度即从检查点恢复即可。

              检查点之前的数据已持久化到磁盘中,持久化到磁盘的相应redo log也可以覆盖掉。

lsn的redo log和检查点的关系 如下(log部分):

mysql> show engine innodb status \G
*************************** 1. row ***************************
  Type: InnoDB
  Name:
Status:
=====================================
200326  8:17:20 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 36 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 59 1_second, 59 sleeps, 5 10_second, 9 background, 9 flush
srv_master_thread log flush and writes: 61
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 7, signal count 7
Mutex spin waits 1, rounds 1, OS waits 0
RW-shared spins 7, rounds 210, OS waits 7
RW-excl spins 0, rounds 0, OS waits 0
Spin rounds per wait: 1.00 mutex, 30.00 RW-shared, 0.00 RW-excl
------------
TRANSACTIONS
------------
Trx id counter 120D
Purge done for trx's n:o < 120D undo n:o < 0
History list length 13
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 120B, not started
MySQL thread id 1, OS thread handle 0xb40, query id 40 localhost 127.0.0.1 root
show engine innodb status
--------
FILE I/O
--------
I/O thread 0 state: wait Windows aio (insert buffer thread)
I/O thread 1 state: wait Windows aio (log thread)
I/O thread 2 state: wait Windows aio (read thread)
I/O thread 3 state: wait Windows aio (read thread)
I/O thread 4 state: wait Windows aio (read thread)
I/O thread 5 state: wait Windows aio (read thread)
I/O thread 6 state: wait Windows aio (write thread)
I/O thread 7 state: wait Windows aio (write thread)
I/O thread 8 state: wait Windows aio (write thread)
I/O thread 9 state: wait Windows aio (write thread)
Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,
 ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
288 OS file reads, 51 OS file writes, 28 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
 insert 0, delete mark 0, delete 0
discarded operations:
 insert 0, delete mark 0, delete 0
Hash table size 199321, node heap has 0 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
--- 
Log sequence number 1929193   #当前最新的lsn号,最后提交的mtr事务产生的lsn
Log flushed up to   1929193   #最新刷到redo log文件中的mtr事务产生的lsn号,redo log持久化了
                               代表着这之前的事务都可以重做
#一般还会有Pages flushed,我这里执行该语句没有产生Pages flushed,待分析原因!
Pages flushed up to ***  #buffer pool缓存数据的page已持久化到磁盘 时的lsn号,此时之前的数据都
                          持久到磁盘了,位于检查点之后 和 刷新到redo log之前

Last checkpoint at  1929193  #检查点的lsn号,此时之前的事务对应的buffer pool缓存数据的page已
                             持久化到磁盘中,所以当前lsn号之前的redo log文件内容都可以被覆盖掉 
                             不需要用来准备恢复数据了,
                             #从Log flushed up to到Last checkpoint at之间的redo log文件的
                             内容才是 用来做crash 时的恢复数据操作

0 pending log writes, 0 pending chkp writes
23 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 103022592; in additional pool allocated 0
Dictionary memory allocated 39803
Buffer pool size   6144
Free buffers       5863
Database pages     281
Old database pages 0
Modified db pages  0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 277, created 4, written 28
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 281, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread id 352, state: waiting for server activity
Number of rows inserted 0, updated 104, deleted 0, read 208
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================

1 row in set (0.03 sec)

从缓冲池刷新脏页到磁盘上:

--I/O吞吐量,从缓冲区刷新脏页时,每秒刷新的页的数量为innodb_io_capacity
--每秒刷新的页的数量上限为innodb_io_capacity_max数量,性能不足时 可调整
--默认:200个脏页
mysql> show variables like '%innodb_io%';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| innodb_io_capacity | 200   |
+--------------------+-------+
1 row in set (0.00 sec)
--脏页占缓冲池75%时,会刷新脏页
--默认:75%
mysql> show variables like 'innodb_max_dirty_pages_pct';
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| innodb_max_dirty_pages_pct | 75    |
+----------------------------+-------+
1 row in set (0.00 sec)
--自适应刷新,无需等innodb_max_dirty_pages_pct的75%到了再刷新脏页,自行根据redo log的产生速度
会优先刷新部分脏页
--默认:开启
mysql> show variables like 'innodb_adaptive_flushing';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| innodb_adaptive_flushing | ON    |
+--------------------------+-------+
1 row in set (0.00 sec)

 

 

你可能感兴趣的:(mysql)