Innodb redo log之flush list

来源:互联网 发布:python 爬虫 抓取文字 编辑:程序博客网 时间:2024/05/05 04:41
Innodb redo log之flush list


Innodb维护一个flush list链表,保存所有的脏页。脏页按照第一次修改的时间顺序进行排序。
在mtr_commit中将redo从mtr->log中刷到redo log buffer中后,产生LSN后,通过判断LSN决定是否将该页放到flush list中。


mtr_commit
mtr_log_reserve_and_write
   mtr->end_lsn = log_reserve_and_write_fast(first_data, len, &mtr->start_lsn);
   if (mtr->end_lsn) {
mtr_add_dirtied_pages_to_flush_list(mtr);
return;
}




函数解析:
mtr_add_dirtied_pages_to_flush_list(mtr_t* mtr) /*!< in/out: mtr */


1、 通过log_sys->log_flush_order_mutex确保每次只有一个脏页顺序插入flush list
2、 如果没有脏页,不需要申请log_sys->log_flush_order_mutex
3、 通过mtr_memo_note_modifications将脏页插入到flush list


if (mtr->made_dirty) {
log_flush_order_mutex_enter();
}
log_release();//释放log_sys->mutex,让其他可以进行log操作


if (mtr->modifications) {
mtr_memo_note_modifications(mtr);//见下面函数解析
}
//插入flush list后释放log_sys->log_flush_order_mutex
if (mtr->made_dirty) {
log_flush_order_mutex_exit();
}



mtr_memo_note_modifications
    for (const dyn_block_t* block = dyn_array_get_last_block(&mtr->memo); block; block = dyn_array_get_prev_block(&mtr->memo, block)) {
const mtr_memo_slot_t*start = reinterpret_cast<mtr_memo_slot_t*>(dyn_block_get_data(block));
mtr_memo_slot_t*slot= reinterpret_cast<mtr_memo_slot_t*>(dyn_block_get_data(block) + dyn_block_get_used(block));

    while (slot-- != start) {
if (slot->object != NULL) {
mtr_memo_slot_note_modification(mtr, slot);
}
}
}
这部分待研究。。。




mtr_memo_slot_note_modification(mtr, slot);
|--buf_flush_note_modification(block, mtr);
   |--block->page.newest_modification = mtr->end_lsn;
        |3--if (!block->page.oldest_modification) {
               buf_flush_insert_into_flush_list(buf_pool, block, mtr->start_lsn);
            } else {
                do nothing;
}

buf_flush_insert_into_flush_list(buf_pool, block, mtr->start_lsn);//lsn=mtr->start_lsn
    block->page.oldest_modification = lsn;
UT_LIST_ADD_FIRST(list, buf_pool->flush_list, &block->page);

1、page的内存结构对象有newest_modification和oldest_modification
2、page.newest_modification = mtr->end_lsn;page.oldest_modification=mtr->start_lsn
3、根据oldest_modification将脏页插入到flush list头部
4、!block->page.oldest_modification表示第一次修改该页。只有第一次修改时才插入到flush list。否则do nothing
0 0
原创粉丝点击