MySQL刷髒
MySQL刷髒,也是有個協調執行緒,透過不停的迴圈執行刷髒的任務,刷髒分為了2種型別,一種是刷lru,另一種是刷flush list.
刷髒分為正常刷髒,sync flush和空閒刷髒,在正常刷髒和sync_flush 這兩種是使用的同步刷,空閒刷使用的是非同步刷,同步刷的情況忽略io_capacity的設定,空閒刷的方法是
buf_flush_lists(PCT_IO(100), LSN_MAX, &n_flushed); PCT_IO是受srv_io_capacity影響 這個函式會執行buf_flush_page,buf_flush_page是非同步的,堆疊如下 mysqld!buf_flush_page(buf_pool_t*, buf_page_t*, buf_flush_t, bool) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/buf/buf0flu.cc:1145) mysqld!buf_flush_try_neighbors(page_id_t const&, buf_flush_t, unsigned long, unsigned long) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/buf/buf0flu.cc:1461) mysqld!buf_flush_page_and_try_neighbors(buf_page_t*, buf_flush_t, unsigned long, unsigned long*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/buf/buf0flu.cc:1533) mysqld!buf_do_flush_list_batch(buf_pool_t*, unsigned long, unsigned long long) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/buf/buf0flu.cc:1787) mysqld!buf_flush_batch(buf_pool_t*, buf_flush_t, unsigned long, unsigned long long) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/buf/buf0flu.cc:1866) mysqld!buf_flush_do_batch(buf_pool_t*, buf_flush_t, unsigned long, unsigned long long, unsigned long*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/buf/buf0flu.cc:2026) mysqld!buf_flush_lists(unsigned long, unsigned long long, unsigned long*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/buf/buf0flu.cc:2132) mysqld!::buf_flush_page_cleaner_coordinator(void *) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/buf/buf0flu.cc:3355) libsystem_pthread.dylib!_pthread_start (Unknown Source:0) libsystem_pthread.dylib!thread_start (Unknown Source:0)
sync flush的作用是控制,不要讓髒頁太久,如果lsn超過了lsn_limit+ 3倍的lsn_avg_rate就要執行同步刷髒。
正常刷髒是指有活動的情況,這種情況會計算出刷髒的數量,然後執行同步刷髒
n_to_flush = page_cleaner_flush_pages_recommendation( &lsn_limit, last_pages);
這裡的同步是指,等待所有的重新整理請求都已經被處理了,等待下面這個事件
os_event_wait(page_cleaner->is_finished);
不是刷最終的刷頁是同步的,這裡的刷頁也是呼叫的buf_flush_page,非同步的io
page cleaner worker執行緒
/******************************************************************//** Worker thread of page_cleaner. @return a dummy parameter */ extern "C" os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner_worker)( /*==========================================*/ void* arg MY_ATTRIBUTE((unused))) /*!< in: a dummy parameter required by os_thread_create */ { my_thread_init(); mutex_enter(&page_cleaner->mutex); page_cleaner->n_workers++; mutex_exit(&page_cleaner->mutex); #ifdef UNIV_LINUX /* linux might be able to set different setting for each thread worth to try to set high priority for page cleaner threads */ if (buf_flush_page_cleaner_set_priority( buf_flush_page_cleaner_priority)) { ib::info() << "page_cleaner worker priority: " << buf_flush_page_cleaner_priority; } #endif /* UNIV_LINUX */ while (true) { os_event_wait(page_cleaner->is_requested); ut_d(buf_flush_page_cleaner_disabled_loop()); if (!page_cleaner->is_running) { break; } pc_flush_slot(); } mutex_enter(&page_cleaner->mutex); page_cleaner->n_workers--; mutex_exit(&page_cleaner->mutex); my_thread_end(); os_thread_exit(); OS_THREAD_DUMMY_RETURN; }
在log buffer結構體中,有個屬性,這個是控制同步刷的,使用同步io
lsn_t max_modified_age_sync; /*!< when this recommended value for lsn - buf_pool_get_oldest_modification() is exceeded, we start a synchronous preflush of pool pages */
在函式log_checkpoint_margin中,判斷如果超過這個限制,會執行一個同步io的刷頁
if (age > log->max_modified_age_sync) { /* A flush is urgent: we have to do a synchronous preflush */ advance = age - log->max_modified_age_sync; }
void buf_flush_wait_flushed( lsn_t new_oldest) { for (ulint i = 0; i < srv_buf_pool_instances; ++i) { buf_pool_t* buf_pool; lsn_t oldest; buf_pool = buf_pool_from_array(i); for (;;) { /* We don't need to wait for fsync of the flushed blocks, because anyway we need fsync to make chekpoint. So, we don't need to wait for the batch end here. */ buf_flush_list_mutex_enter(buf_pool); buf_page_t* bpage;
在for迴圈中註釋說不用在此處等待fsync,不太明白為什麼
有興趣學習原始碼的加群一起學習啊 QQ: 700072075
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25719946/viewspace-2913358/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL:刷髒相關MySql
- MySQL學習之flush(刷髒頁)MySql
- PG檢查點刷寫髒頁
- Linux的磁碟快取和刷髒頁Linux快取
- MySQL InnoDB髒頁管理MySql
- PostgreSQL的"double buffers"刷髒機制和引數SQL
- 首款刷馬桶機器人上市 髒活累活留給它就好機器人
- 簡單聊聊mysql的髒讀、不可重複讀MySql
- MySQL學習筆記 - 髒頁重新整理策略MySql筆記
- MySQL大量髒資料,如何只保留最新的一條?MySql
- mysql刷題題後感MySql
- [Mysql]日誌刷盤總結MySql
- 【Mysql】資料庫事務,髒讀、幻讀、不可重複讀MySql資料庫
- MySQL 事務隔離實驗-認識:髒讀、不可重複讀、幻讀MySql
- MySQL 表資料多久刷一次盤?MySql
- InnoDB引擎之flush髒頁
- 髒讀!幻讀!不可重複讀!mysql併發事務引發的問題MySql
- MySQL事務(4種事務隔離級別、髒寫、髒讀、不可重複讀、幻讀、當前讀、快照讀、MVCC、事務指標監控)MySqlMVC指標
- vulnhub-Lampiao髒牛提權LAMP
- 都是髒資料惹的禍
- 髒讀,幻讀,不可重複讀
- InnoDB髒頁重新整理機制
- js騷操作罵人不帶髒JS
- AI 資料標註不是“髒活累活”AI
- 髒讀、幻讀和不可重複讀
- 程式碼整潔 vs 程式碼骯髒
- 聊聊信任:衣服掉地上會髒的
- 事務四大特性理解,什麼是髒資料、髒讀、不可重複讀、幻覺讀
- 刷題
- 髒讀、幻讀和不可重複讀?為啥?
- angular髒檢查原理及虛擬碼實現Angular
- 什麼是髒讀,不可重複讀,幻讀
- 真的,刷抖音,不如刷這個專案
- 刷劍指
- Android刷機Android
- 刷題10.10
- golang刷leetcodeGolangLeetCode
- Linux 核心最新高危提權漏洞:髒管道 (Dirty Pipe)Linux