Mysql检查点CheckPoint、LSN、redo日志 的刷新关系

 

官方文档:https://dev.mysql.com/doc/refman/5.7/en/innodb-checkpoints.html

 

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

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

 

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

mysql> show engine innodb status \G
*************************** 1. row ***************************
  Type: InnoDB
  Name:
Status:
=====================================
2018-11-15 13:45:25 0x7fa76dd78700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 8 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 454 srv_active, 0 srv_shutdown, 11659 srv_idle
srv_master_thread log flush and writes: 12113
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 1267
OS WAIT ARRAY INFO: signal count 1116
RW-shared spins 0, rounds 378, OS waits 155
RW-excl spins 0, rounds 4980, OS waits 178
RW-sx spins 87, rounds 2610, OS waits 75
Spin rounds per wait: 378.00 RW-shared, 4980.00 RW-excl, 30.00 RW-sx
------------
TRANSACTIONS
------------
Trx id counter 40165
Purge done for trx's n:o < 40165 undo n:o < 0 state: running but idle
History list length 77
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 421832186570576, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 40160, ACTIVE 17 sec updating or deleting
mysql tables in use 1, locked 1
706 lock struct(s), heap size 106704, 354952 row lock(s), undo log entries 354952
MySQL thread id 8, OS thread handle 140356915402496, query id 13573251 192.168.56.1 flyremote updating
update test_change_buffer_table set b='b'
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (write thread)
Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
ibuf aio reads:, log i/o's:, sync i/o's:
Pending flushes (fsync) log: 0; buffer pool: 0
13987 OS file reads, 46024 OS file writes, 2684 OS fsyncs
55.71 reads/s, 16384 avg bytes/read, 289.96 writes/s, 10.57 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 25, free list len 20, seg size 46, 35 merges         
merged operations:
insert 1391, delete mark 7607, delete 0                         
discarded operations:
insert 0, delete mark 0, delete 0                               
Hash table size 26041, node heap has 0 buffer(s)
Hash table size 26041, node heap has 1375 buffer(s)
Hash table size 26041, node heap has 287 buffer(s)
Hash table size 26041, node heap has 0 buffer(s)
Hash table size 26041, node heap has 1 buffer(s)
Hash table size 26041, node heap has 0 buffer(s)
Hash table size 26041, node heap has 0 buffer(s)
Hash table size 26041, node heap has 0 buffer(s)
42571.30 hash searches/s, 29614.30 non-hash searches/s           
---
LOG
---
Log sequence number 2247327060    //当前最新的lsn号,最后提交的mtr事务产生的lsn
Log flushed up to   2246693831    //最新刷到redo log文件中的mtr事务产生的lsn号,redo log持久化了 代表着这之前的事务都可以重做
Pages flushed up to 2223747920    //buffer pool缓存数据的page已持久化到磁盘 时的lsn号,此时之前的数据都持久到磁盘了,位于检查点之后 和 刷新到redo log之前
Last checkpoint at  2197419801    //检查点的lsn号,此时之前的事务对应的buffer pool缓存数据的page已持久化到磁盘中,所以当前lsn号之前的redo log文件内容都可以被覆盖掉 不需要用来准备恢复数据了,
                                  //从Log flushed up to到Last checkpoint at之间的redo log文件的内容才是 用来做crash 时的恢复数据操作
0 pending log flushes, 0 pending chkp writes
887 log i/o's done, 2.14 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total large memory allocated 107380736
Dictionary memory allocated 382802
Buffer pool size   6400
Free buffers       1117
Database pages     3614
Old database pages 1314
Modified db pages  1144
Pending reads      0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 7124, not young 15349893
66.56 youngs/s, 78029.85 non-youngs/s
Pages read 13856, created 22298, written 43636
55.71 reads/s, 88.27 creates/s, 282.39 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 301 / 1000
Pages read ahead 53.85/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 3614, unzip_LRU len: 0
I/O sum[3312]:cur[216], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Process ID=2652, Main thread ID=140356928546560, state: sleeping
Number of rows inserted 4524249, updated 354951, deleted 0, read 374965
0.00 inserts/s, 23180.48 updates/s, 0.00 deletes/s, 23180.48 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================

 

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

--I/O吞吐量,从缓冲区刷新脏页时,每秒刷新的页的数量为innodb_io_capacity
--每秒刷新的页的数量上限为innodb_io_capacity_max数量,性能不足时 可调整
--默认:200个脏页
mysql> show variables like '%innodb_io%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| innodb_io_capacity     | 200   |
| innodb_io_capacity_max | 2000  |
+------------------------+-------+
2 rows 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.000000 |
+----------------------------+-----------+
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,基本管理,Mysql—基础功能学习)