Innodb change buffer passive merge, innodbbuffermerge

Source: Internet
Author: User

Innodb change buffer passive merge, innodbbuffermerge
Passive merge scenario 1: insufficient secondary index page space: ibuf0ibuf. cc: ibuf_insert_low

1. When a cache insert operation is attempted, if the estimated space of the secondary index page is insufficient, the index may be split, and the location of the page no in the ibuf tree to be cached is located, A maximum of 8 pages can be accessed by merge. The merge mode is asynchronous, that is, an asynchronous request to read index pages is initiated.

Note:

Buffered: records cached on the current secondary index page

Entry_size: the size of the second-level index record to be inserted.

Page_dir_calc_reserved_space (1): slot size of the record to be inserted

Ibuf_index_page_calc_free_from_bits (zip_size, bits): size of the remaining space on the secondary 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 position of the ibuf record to be inserted in the ibuf tree

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 secondary index page is inserted. When a secondary index is inserted, if the secondary index page is split, the page information recorded by the ibuf tree will be partially valid. Therefore, bitmap needs to be determined each time it is inserted.

2. How can I interpret merge's 8 pages?

The value of IBUF_MAX_N_PAGES_MERGED is 8.

The number of Merge pages is the minimum value of 8 and 1/4 of the current buffer pool size.

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 eight pages of merge?

An incremental 8 pages... are these 8 pages indexed or ibuftree pages?

First, locate the position of the previous record to be inserted, and push eight records forward based on the previous record. The space id and page no in these eight records need to be marked by the secondary index page of 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 functionreturns

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 may have changed the tablespace size

Const ulint * page_nos: read page number Array

Ulint n_stored: number of page number array elements

Note:

Read array pages into memory and merge pages

Issues read requests for pages which theibuf module wants to read in, in order to contract the insert buffer tree. Technically, this function is 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 when 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 the page has been read from the disk, point to pagex-latched

Space: space id of index page

Page_no: page number of index page

Zip_size: compressed page size

Update_ibuf_bitmap: usually set to true. If you have deleted or are deleting tablespace, set false.

Note:

When a secondary index page reads data from the disk to the buffer pool, this function is used to delete all operations related to this page, merge, and entries in the insert buffer. If this page is not read but is created in the buffer pool, delete the Operation Records cached by this page.

Passive merge scenario 2: The insert buffer is too large: ibuf0ibuf. cc: ibuf_insert_low

If the insert buffer size is too large, contract insert buffer will discard this cache.

1. ibuf-> size greater than ibuf-> max_size + 10 (Unit page): execute a synchronous ibuf merge (ibuf_contract). The page no of merge is the page no of the randomly located records, up to 8 merge pages at a time, and discard this cache

2. ibuf_max_size = 25% * bufferpool size. The percentage is controlled by innodb_change_buffer_max_size and can be dynamically adjusted.

...

If (ibuf-> size> = ibuf-> max_size + IBUF_CONTRACT_DO_NOT_INSERT ){

/* Insert buffer is now too big, contract it but do 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 3: insert operations may produce ibuf btree split: ibuf0ibuf. cc: ibuf_insert_low

Note:

1. When ibuf-> size <ibuf-> max_size (IBUF_CONTRACT_ON_INSERT_NON_SYNC = 0), no operation is performed.

2. When ibuf-> size> = ibuf-> max_size + 5, ibuf_contract (true) synchronizes ibuf merge at random positions.

3. When ibuf-> max_size <ibuf-> size <= ibuf-> max_size + 5, ibuf_contract (false), asynchronous merge, and random location.

4. Merge should have 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 Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.