lihongjie0209 / myblog

4 stars 0 forks source link

MySQL: redo log #166

Open lihongjie0209 opened 3 years ago

lihongjie0209 commented 3 years ago

The redo log is a write ahead log of changes applied to contents of data pages. It provides durability for all changes applied to the pages. In case of crash, it is used to recover modifications to pages that were modified but have not been flushed to disk.

Every change to content of a data page must be done through a mini transaction (so called mtr - mtr_t), which in mtr_commit() writes all its log records to the redo log.

每次对内存中的页变更都会写入redolog

lihongjie0209 commented 3 years ago

During life time of a mtr, a log of changes is collected inside an internal buffer of the mtr. It contains multiple log records, which describe changes applied to possibly different modified pages. When the mtr is committed, all the log records are written to the log buffer within a single group of the log records. Procedure:

  1. Total number of data bytes of log records is calculated.
  2. Space for the log records is reserved. Range of lsn values is assigned for a group of log records.
  3. Log records are written to the reserved space in the log buffer.
  4. Modified pages are marked as dirty and moved to flush lists. All the dirty pages are marked with the same range of lsn values.
  5. Reserved space is closed.

在commit之前先写入mtr的buff, commit的时候写入redo buff