Passive merge Scenario One, Level two index page space: ibuf0ibuf.cc:: Ibuf_insert_low
1, when attempting to cache the insert operation, if the estimated two-level index page is not enough space, may cause the index splitting, then to the attempt to cache the page no in the Ibuf tree location, up to merge 8 Page,merge mode is asynchronous, that is, initiates the asynchronous Read index page request.
Description
Buffered: The current Level Two index page has cached records
Entry_size: Level Two index record size to be inserted
Page_dir_calc_reserved_space (1): Slot size for the record to be inserted
Ibuf_index_page_calc_free_from_bits (Zip_size,bits)): The remaining space size of the two-level index page to be inserted
...
/* Find out the volume of already bufferedinserts for the same index page */
min_n_recs= 0;
Buffered= ibuf_get_volume_buffered (&pcur, Space, Page_no,
OP = = Ibuf_op_delete
? &min_n_recs
: NULL, &mtr);
......
Do_merge = FALSE;
......
Open the previous record position in the Ibuf tree for the ibuf record to be inserted
Btr_pcur_open (Ibuf->index, Ibuf_entry,page_cur_le, mode, &pcur, &mtr);
......
if (op = = Ibuf_op_insert) {
Ulint bits = ibuf_bitmap_page_get_bits (
Bitmap_page,page_no, Zip_size, ibuf_bitmap_free,&bitmap_mtr);
if (buffered + entry_size + page_dir_calc_reserved_space (1)
>ibuf_index_page_calc_free_from_bits (Zip_size, bits)) {
...
Do_merge= TRUE;
Ibuf_get_merge_page_nos (FALSE,
Btr_pcur_get_rec (&pcur), &mtr,
Space_ids,space_versions,
page_nos,&n_stored);
......
}
}
......
if (Do_merge) {
buf_read_ibuf_merge_pages (False, Space_ids,space_versions,
Page_nos, n_stored);
}
Problem:
1. What does buffered mean? What is Page_dir_calc_reserved_space (1)?
The number of records that have been cached when a Level two index page is inserted into a level two index. When a level two index is inserted, the page information for the Ibuf tree species record is partially aged if the Level two index page splits. Therefore, the bitmap should be judged each time it is inserted.
2, how to interpret the merge 8 pages?
The ibuf_max_n_pages_merged value is 8.
The number of merge pages is 8 and the current buffer pool size 1/4 min
Ibuf0ibuf.cc::ibuf_get_merge_page_nos_func
Limit = Ut_min (ibuf_max_n_pages_merged, Buf_pool_get_curr_size ()/4);
while (*n_stored < limit) {
......
Page_nos[*n_stored] = prev_page_no;
......
}
3, which 8 pages of the merge?
Increment of 8 pages ... , do these 8 pages refer to an index page or a ibuftree page?
Position the previous record of the record to be inserted first, pushing 8 records forward, in turn, according to the previous record. The Space ID and page No in these 8 records are the tags of the two-level index pages that need to be merge.
1, Buf0rea.cc::buf_read_ibuf_merge_pages
Input parameters:
Bool Sync:true If the caller wantsthis function to wait for the highest address page to get read in, before this Functionr Eturns
Const ulint* Space_ids:space ID Array
Const ib_int64_t* space_versions:the Spaces Musthave This version number (timestamp), otherwise we discard the read; We usethis to cancel reads if DISCARD + IMPORT could have changed the tablespace size
Const ulint* Page_nos: page-numbered group read-in
Ulint n_stored: Number of elements in the page Count group
Description
Read the array page into memory, merge related page
Issues read requests for pages which THEIBUF module wants to read in, in order to contract the insert buffer tree. Technically, this function was like a read-ahead function
for (i = 0; i < n_stored; i++) {
......
Buf_read_page_low (&err, Sync && (i + 1 = = n_stored),
Buf_read_any_page, Space_ids[i],
Zip_size, TRUE, Space_versions[i],
Page_nos[i]);
if (sync) {
/* The I/O is already completed if wearrive from Fil_read */
if (!buf_page_io_complete (bpage)) {
return (0);
}
}
......
}
Buf0buf.cc::buf_page_io_complete: Asynchronous Read
...
if (Io_type ==buf_io_read) {
...
if (uncompressed&&!recv_no_ibuf_operations) {
Ibuf_merge_or_delete_for_page (
(buf_block_t*) bpage, Bpage->space,
Bpage->offset,buf_page_get_zip_size (bpage),
TRUE);
}
}
......
2, ibuf0ibuf.cc:: Ibuf_merge_or_delete_for_page
Input parameters:
Block: If page has been read from disk, point to pagex-latched
Space:index Page's Space ID
Page number of Page_no:index page
zip_size:compressed Page Size
Update_ibuf_bitmap: The usual condition is true. If you have or are deleting tablespace, set false
Description
When a Level two index page is read from disk to buffer pool, this function is applied to merge all operations corresponding to the page, removing the entries in insert buffer. If this page is not read, but created in buffer pool, then delete the operation record of his cache.
Passive merge scenario Two, insert buffer too large: ibuf0ibuf.cc:: Ibuf_insert_low
If the insert buffer size is too large, contract inserts buffer and discards the cache.
1, Ibuf->size greater than ibuf->max_size+10 (Unit page) to perform a synchronization ibuf merge (Ibuf_contract), the merge page no is a randomly positioned record of page no, at most one time merge 8 page, discard this cache at the same time
2, which ibuf_max_size=25%*bufferpool size, the percentage is controlled by innodb_change_buffer_max_size, can be dynamically adjusted.
...
if (ibuf->size >= ibuf->max_size +ibuf_contract_do_not_insert) {
/*insert buffer is now too big, contract it but does not try to Insert */
/* Use synchronous contract (= = TRUE) */
ibuf_contract (TRUE);
Return (Ibuf_merge (0, &n_pages, sync));
Return (Ibuf_merge_pages (N_pages,sync));
return (Db_strong_fail);
}
Passive merge scenario Three, insert operation may produce Ibuf Btree split: ibuf0ibuf.cc:: Ibuf_insert_low
Description
1, when Ibuf->size<ibuf->max_size (ibuf_contract_on_insert_non_sync=0) do not do any action
2, when ibuf->size>= ibuf->max_size+5, Ibuf_contract (true), synchronize once ibuf merge, position random
3, when ibuf->max_size< ibuf->size <= ibuf->max_size+5, Ibuf_contract (FALSE), asynchronous merge, Position random.
4, merge at least 8 pages, ut_min (ibuf_max_n_pages_merged, Buf_pool_get_curr_size ()/4);
......
if (err = = db_success && mode ==btr_modify_tree) {
Ibuf_contract_after_insert (entry_size);
if (Size < max_size +ibuf_contract_on_insert_non_sync) {
Return
}
Sync = (size >= max_size +ibuf_contract_on_insert_sync);
size = Ibuf_contract (sync);
Return (Ibuf_merge (0,&n_pages, sync));
Return (Ibuf_merge_pages (N_pages,sync));
}
......
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Change of InnoDB buffer passive merge