MySQL kernel: innodb dynamic array internal implementation [group chart] _ MySQL

Source: Internet
Author: User
MySQL kernel: innodb dynamic array internal implementation [group chart] the files involved in the dynamic array are three files of the innodb storage engine: dyn0dyn. h, dyn0dyn. ic, and dyn0dyn. c.

This is a basic component function and serves as a dynamic virtual linear array. The basic element of the array is byte. The dynamic array dyn is mainly used to store mtr lock information and logs. Dyn uses a memory heap if the block needs to split nodes. The data field length of each blok block storage data is fixed (the default value is 512), but it may not be used up completely. If the size of the data item to be stored is greater than that of the data block, the data item is split. this is mainly used for log buffering.

2. Data structure

Typedef struct dyn_block_struct dyn_block_t;
Typedef dyn_block_t dyn_array_t;
# DefineDYN_ARRAY_DATA_SIZE 512
Struct dyn_block_struct {
Mem_heap_t * heap;
Ulint used;
Byte data [DYN_ARRAY_DATA_SIZE];
UT_LIST_BASE_NODE_T (dyn_block_t) base;
UT_LIST_NODE_T (dyn_block_t) list;
# Ifdef UNIV_DEBUG
Ulint buf_end;
Ulint magic_n;
# Endif
};
// The following two definitions are public macros. for details, see ut0lst. h.
# Define UT_LIST_BASE_NODE_T (TYPE)
Struct {
Ulintcount;/* count of nodes in list */
TYPE * start;/* pointer to list start, NULL if empty */
TYPE * end;/* pointer to list end, NULL if empty */
}
# Define UT_LIST_NODE_T (TYPE)
Struct {
TYPE * prev;/* pointer to the previous node,
NULL if start of list */
TYPE * next;/* pointer to next node, NULL if end of list */
}

Field explanation:

1) heap

Literally, heap indicates the memory heap. From the above struct, we can see that dyn_array_t is dyn_block_struct. The date field in this struct is used to store data. used displays the number of bytes that have been used. if we want to store a data with the size of x at this time, the data cannot be stored at this time, therefore, we need to assign a new block node. Then, where the memory required for the allocation structure comes from, it is allocated from the heap in the first node.

Here, we still need some idea. Although the data structure uses the same dyn_block_struct, the first node is called arr, indicating that it is the head node of dynamic data. Other nodes are called block nodes.

Let's take a look at how the dyn function was first created:

UNIV_INLINE
Dyn_array_t *
Dyn_array_create (
/* = */
/* Out: initialized dyn array */
Dyn_array_t * arr)/* in: pointer to a memory buffer
Size sizeof (dyn_array_t )*/
{
Ut_ad (arr );
Ut_ad (DYN_ARRAY_DATA_SIZE <DYN_BLOCK_FULL_FLAG );
Arr-> heap = NULL;
Arr-> used = 0;
# Ifdef UNIV_DEBUG
Arr-> buf_end = 0;
Arr-> magic_n = DYN_BLOCK_MAGIC_N;
# Endif
Return (arr );
}

The ud_ad is a red judgment, which is equivalent to assert. This is not a table for the time being. This function is called when mtr is created and an arr pointer has been allocated during the call.

In the dyn_array_create function, the system sets the heap field to NULL and Used to 0. Buf_end and magic_n are used for debugging. Each struct definition corresponds to a unique magic_n value. In this way, you can quickly track problems during debugging.

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.