//在mtr_commit時,将髒頁添加到flush list頭部。
mtr_commit
if (mtr->modifications && mtr->n_log_recs) {
mtr_log_reserve_and_write(mtr);->
mtr_add_dirtied_pages_to_flush_list(mtr);->
}
mtr_add_dirtied_pages_to_flush_list
log_flush_order_mutex_enter();
mutex_exit(&(log_sys->mutex));
mtr_memo_note_modifications(mtr);-> buf_flush_note_modification(block, mtr);->
mutex_enter(&block->mutex);
buf_flush_list_mutex_enter(buf_pool);
block->page.oldest_modification = mtr->start_lsn;
if (!block->page.oldest_modification) {
UT_LIST_ADD_FIRST(list, buf_pool->flush_list, &block->page);
}
buf_flush_list_mutex_exit(buf_pool);
mutex_exit(&block->mutex);
log_flush_order_mutex_exit();
1、 先申請log_sys->log_flush_order_mutex
2、 申請完就釋放log_sys->mutex。為了減少log_sys->mutex的持有時間,減少競争,采用先申請log_flush_order_mutex來保證髒頁插入flush list的順序。
3、 申請頁的mutex、申請flush listmutex
4、 得到髒頁的oldest_modification,以便在真正刷時寫入到頁内
5、 如果該髒頁已經在flushlist裡面,則不需要插入,否則将髒頁插入到flush list