mysql master thread 工作内容
伪代码:
void master_thread(){ goto loop; loop://主循环begin for(int i=0;i<10;i++){ thread_sleep(1); //休眠1秒 do log_buffer flush to disk; //将日志缓冲刷新到磁盘文件 if (last_one_second_io < 5%*innodb_io_capacity)//如果前一秒的io操作次数小于(5%的磁盘io吞吐量参数innodb_io_capacity),合并(5%的磁盘io吞吐量参数)个插入缓冲inser_buffer do merge 5%*innodb_io_capacity insert_buffer; if (buf_get_modified_ratio_pct > innodb_max_dirty_pages_pct)//如果当前缓冲区的脏页比例超过配置文件innodb_max_dirty_pages_pct参数值,将innodb_io_capacity个脏页刷新到磁盘文件 do buffer_pool (100%*innodb_io_capacity) dirty_page flush to disk; else enable adaptive flush do buffer pool flush desired amount dirty page //??? if (no user activity) goto background loop; } if (last_ten_second_io < innodb_io_capacity) //前10秒的io操作次数小于innodb_io_capacity(就是前面for循环) do buffer_pool 100%*innodb_io_capacity dirty_page flush to disk; //将innodb_io_capacity个脏页刷新到磁盘文件 do merge at most 5%*innodb_io_capacity insert_buffer; //合并最多5%*innodb_io_capacity个插入缓冲inser_buffer do log_buffer flush to disk; //将日志缓冲刷新到磁盘文件 do full purge; //删除无用undo页 if (buf_get_modified_ratio_pct > 70%) //如果当前缓冲内存的脏页比例超过70% do buffer_pool 100%*innodb_io_capacity dirty_page flush to disk; //将innodb_io_capacity个脏页刷新到磁盘文件 else do buffer_pool 10%*innodb_io_capacity dirty_page flush to disk; //将10%*innodb_io_capacity个脏页刷新到磁盘文件 do fuzzy checkpoint; goto loop; //主循环end background loop: //后台循环begin do full purge; //删除无用undo页 do merge 100%*innodb_io_capacity insert_buffer; //合并innodb_io_capacity个插入缓冲inser_buffer if (not idle) //如果不是空置的,跳回主循环 goto loop; else goto flush loop;//后台循环end 跳到刷新循环 flush loop://刷新循环begin do buffer_pool 100%*innodb_io_capacity dirty_page flush to disk; //将innodb_io_capacity个脏页刷新到磁盘文件 if (buf_get_modified_ratio_pct > innodb_max_dirty_pages_pct) { goto flush loop;//跳到刷新循环 } goto suspend loop; //刷新循环end 跳到暂停循环 suspend loop://暂停循环begin suspend_thread();//开启挂起线程 waiting event; //等待事件触发 goto loop;//暂停循环end 跳到主循环 }