InnoDB purge thread

background

mysql purge线程为数据库清理线程,关系到数据的更新。

Write in front

The main content of this article comes from WeChat public account, the original Gao Peng. This article will extract part of the original text.

link

Source version 8.0.21\

problem


 1. del flag记录是否能够及时清理
 2. 为什么History list length持续不为0,是否代表del flag记录没有清理
 3. purge线程触发的规则是什么

purge thread

一般来讲我们理解的purge线程可以做如下的工作:

清理del flag标签的记录
清理undo的历史版本
如果需要进行undo tablespace截断。
其包含一个协调线程和多个工作线程由如下参数设置:

innodb_purge_threads=4   #默认值
这代表1个协调线程和3个工作线程。协调线程也会充当一个工作线程角色。
协调线程循环检测变化

如下调入:
srv_purge_coordinator_thread
 ->srv_purge_coordinator_suspend
判断如下:
(rseg_history_len <= trx_sys->rseg_history_len) { 
//如果当前history_len大于等于上一次循环的的history_len
      ret =os_event_wait_time_low(slot->event, SRV_PURGE_MAX_TIMEOUT, sig_count); 
//等待10毫秒后进行处理或者等待被唤醒

唤醒的条件是有事务提交或者回滚

    /* Tell server some activity has happened, since the trx
    does changes something. Background utility threads like
    master thread, purge thread or page_cleaner thread might
    have some work to do. */
    srv_active_wake_master_thread();
但是需要注意的是如果长期没有新的事务进行提交,那么可能进入永久堵塞状态而不是每10毫秒醒来,直到唤醒

if (ret == OS_SYNC_TIME_EXCEEDED) { //如果是等待超时
      if (rseg_history_len == trx_sys->rseg_history_len &&
          trx_sys->rseg_history_len < 5000) { //如果上次的history_len和本次history_len相同且小于5000那么需要等待唤醒
        stop = true; //设置为true,进行无限期等待,直到唤醒
      }

Excerpted here, I found that the full text is all dry goods
推荐读者移步到原文阅读,以下摘录原文的结论。

After the transaction is submitted, the coordination thread determines whether the del flag can be cleaned up. If it can be cleaned up, it will be distributed to the worker thread for cleaning up. This is an asynchronous process. If there are more data changes, this process may be slower and you can see The thread related to purge is under pressure, but it is still timely.

The purge thread will always be backlogged for a period of time to clean up the history list length. If it is a small transaction (the page modified each time is less than the setting of innodb_purge_batch_size), then 128 such small transactions are needed to clean up once, if it is a large transaction then modify If the setting exceeds (innodb_purge_batch_size*innodb_purge_rseg_truncate_frequency), it will be cleaned up once, but no matter how this indicator continues to be non-zero, it is normal. If it is larger, it may mean that there are either large queries, or each thread of purge is working at full capacity.

Purge's coordination thread will wake up every time a transaction is committed to determine whether there is a transaction that needs to be cleaned up. If there is no transaction for a long time, it will wait for the first 10ms, and enter a long-term blocking waiting state after the timeout.

5.7.26 Default parameter values
Insert picture description here

This article explains that the main technical content comes from the sharing of Internet technology giants, as well as some self-processing (only for the role of annotations). If related questions, please leave a message after the confirmation, the implementation of infringement will be deleted

Guess you like

Origin blog.csdn.net/baidu_34007305/article/details/110552231