InnoDB storage engine---checkpoint

Buffer Pool is designed to reconcile the gap between CPU and disk speed. Therefore, page operations are first completed in the Buufer Pool.

     For example, the client sends a DML, which is first changed on the page in the Buufer Pool, which will cause a problem. The "version" of the data in the Buufer Pool is "newer" than the data in the disk, and we must use the disk as the "version". The data in the Buffer Pool shall prevail (the final data will also be written to the disk), so the page in the Buffer Pool at this time is called "dirty page (dirty page)"    

    If the page does not exist in the buffer pool, the normal query route (parser, optimizer) is taken, the "result page" is placed in the LRU list of the buffer pool, and then the page is changed. Then flush it to disk.

    Checkpoint can be regarded as a kind of "pointer", the main function is to flush the dirty pages in the buffer pool to the disk, the difference is how much is flushed to the disk. The version is marked by LSN (Log Sequence Number) in InnoDB. The LSN is 8 bytes, that is, 32 bits, and each page is 16KB by default, so 2^32 * 16KB=64TB, which explains that InnoDB has the largest single table size is 64TB.

There are two types of checkpoints in innodb:
Sharp checkpoint: flushes all dirty pages in the buffer pool to disk when the data is about to be shut down, this is the default way of working (innodb_fast_shutdown=1)
fuzzy checkpoint: flush some dirty pages to disk
master thread checkpoint
flush_lru_list checkpoint
    async/sync flush checkpoint:
    Denote the LSN that has been written to the redo log as redo_lsn, and denote the latest LSN that has been flushed to disk as checkpoint_lsn, define:
    checkpoint_age = redo_lsn - checkpoint_lsn
    再定义:
    async_water_mark = 75% * total_redo_log_file_size
    sync_water_mark = 90% * total_redo_log_file_size

    checkpoint_age < async_water_mark 时不需要刷脏页到磁盘;
    async_water_mark < checkpoint_age < sync_water_mark 时刷脏页到磁盘,直到 checkpoint_age < async_water_mark ;

dirty page too much checkpoint(脏页数量过多):

                其目的是保证缓冲池中有足够多的可用页,其参数由 innodb_max_dirty_pages_pct 控制。








innodb_buffer_pool_size --> innodb_log_buffer_size --> redo log(flush disk)
checkpoint 控制  innodb_flush_log_at_trx_commit 控制




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324746448&siteId=291194637