Mysql — InnoDB storage engine Change Buffer

Introduction to the

When a database is down, restart can restore lost data through redo log replay. But it must be clear that the redo log records physical operations on the page, such as writing ‘AAA’ records at offset 800.

Suppose you have a scenario where the innoDB storage engine is writing to a page. This one has 16K and only writes to the first 4K. At this point, there is an outage. At this point the page is corrupted and there is no point in redo log replay.

Doublewrite is designed to solve this problem.

How Doublewrite works

As the figure shows, Doublewrite consists of two parts:

  • Memory doublewrite buffer, size 2M;
  • The doublewrite buffer for the disk system tablespace is 2M.

The innoDB buffer pool does not flush dirty pages directly to disk; Instead, the dirty pages are copied to the doubleWrite Buffer in memory using the memcpy function, then written twice to the DoubleWrite Buffer in the system table space, followed by a call to fsync to synchronize the disk. Because the system tablespace doubleWrite Buffer is written sequentially, the overhead is not very high. After the above steps are complete, the doublewrite buffer in memory is written to the separate table space, where the real data is stored.

If an outage occurs when the doubleWrite buffer is written to a separate table space, a copy of the page is found in the system table space before the redo log is replayed to the separate table space.

Mysql — InnoDB storage engine AHI