MySQL kernel: InnoDB dynamic array Internal implementation

Source: Internet
Author: User
Tags split

A dynamic array involves files that are three files of the InnoDB storage Engine: Dyn0dyn.h, Dyn0dyn.ic, and DYN0DYN.C.

This is a basic component feature that is used as a dynamic virtual linear array. The base element of the array is byte. Dynamic array dyn is mainly used for storing MTR lock information and log. Dyn on implementation, if the block needs to split the node, a memory heap is used. The length of the data field that stores the data for each Blok block is fixed (the default value is 512), but it is not necessarily completely exhausted. The data item is split when the size of the data item that needs to be stored is larger than the data block, which is used primarily 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
};
//下面两个是公共宏定义,见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 is the meaning of the memory heap. From the structure above, we can see that dyn_array_t is dyn_block_struct. In this structure, the field date is used to hold the data, used shows the number of bytes already in use, assuming that this time to store a size of x-length data, this time is not stored in data, so you need to allocate a new block node. Then the memory needed to allocate the structure comes from where it is allocated from the heap inside the first node.

Here, we need a little more idea. Although the data structure uses the same dyn_block_struct, we call the first node arr, indicating that this is the head node of the dynamic Data. Other nodes, we call the Block node.

Let's take a look at the first, and how the function of dyn 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 of
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);
}

One of the ud_ad is red judgment, which is equivalent to assert. We don't watch this for a while. This function is invoked when MTR is created, and a arr pointer has been allocated at the time of the call.

In the Dyn_array_create function, the system sets the heap field to null,used set to 0. Buf_end and magic_n are used when debugging, and each definition of the struct will uniquely correspond to a magic_n value. This allows for quick tracking of problems when debugging.

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.