InnoDB undo log物理结构的初始化( 三 )


2、初始化和E信息
/* Initialize max size field */mlog_write_ulint(rsegf + TRX_RSEG_MAX_SIZE, max_size,MLOG_4BYTES, mtr);/* Initialize the history list */mlog_write_ulint(rsegf + TRX_RSEG_HISTORY_SIZE, 0, MLOG_4BYTES, mtr);flst_init(rsegf + TRX_RSEG_HISTORY, mtr);
3、初始化每个undo所在的page no
for (i = 0; i < TRX_RSEG_N_SLOTS; i++) { //TRX_RSEG_N_SLOTS 为1024 初始化每个槽 值为 4字节指向 undo segment header的page notrx_rsegf_set_nth_undo(rsegf, i, FIL_NULL, mtr);}
初始化的情况下我们看到指向的page no都是,说明没有分配任何实际的undo。
4、整个初始化完成后将space id和page no 写回到中 。
sys_header = trx_sysf_get(mtr); //获取 5号 block指针 跳过FIL_PAGE_DATA 38U trx_sysf_rseg_set_space(sys_header, rseg_slot_no, space, mtr); //设置spacetrx_sysf_rseg_set_page_no(sys_header, rseg_slot_no, page_no, mtr); //设置 no
/* Transaction rollback segment header *//*-------------------------------------------------------------*/#define TRX_RSEG_MAX_SIZE0/* Maximum allowed size for rollbacksegment in pages */#define TRX_RSEG_HISTORY_SIZE4/* Number of file pages occupiedby the logs in the history list */ //history 链表大小#define TRX_RSEG_HISTORY8/* The update undo logs for committedtransactions */ //链表头base node他们通常调用include/fut0lst.ic中的函数进行更改#define TRX_RSEG_FSEG_HEADER(8 + FLST_BASE_NODE_SIZE)/* Header for the file segment wherethis page is placed */#define TRX_RSEG_UNDO_SLOTS (8 + FLST_BASE_NODE_SIZE + FSEG_HEADER_SIZE)/* Undo log segment slots */ ///*-------------------------------------------------------------*/
作为 base node的,我们可以看到定义如下:
/* We define the field offsets of a base node for the list */#define FLST_LEN0/* 32-bit list length field */#define FLST_FIRST4/* 6-byte address of the first elementof the list; undefined if empty list */#define FLST_LAST(4 + FIL_ADDR_SIZE) /* 6-byte address of thelast element of the list; undefinedif empty list */#define FIL_ADDR_PAGE0/* first in address is the page offset */#define FIL_ADDR_BYTE4/* then comes 2-byte byte offset within page*/#endif /* !UNIV_INNOCHECKSUM */#define FIL_ADDR_SIZE6/* address size is 6 bytes */
多了一个长度
到这里128已经初始化完成,并且,每个都包含1024个 undoslots 。
四、整个过程初始化完成后的分布图
为了让图更加美观和好理解,我这里使用的是ces=2的情况下作图,也就是只有2个 undo 的情况 。其实4个也是同样的道理,因为slot是轮询在表空间分配的 。
undo phy5.jpg
最终,我们看到初始化完成后undoslot指向的都是,及没有指向,当实际分配的时候这些slot就会指向我们的undo。
同时我们可以看看到底包含哪些类型块,使用自制的小工具读取如下:
./myblock undo001 -d|morecurrent read blocks is : 0 --This Block is file space header blocks!current read blocks is : 1 --This Block is insert buffer bitmapblocks!current read blocks is : 2 --This Block is inode blocks!current read blocks is : 3 --This Block is systemblocks!current read blocks is : 4 --This Block is systemblocks!current read blocks is : 5 --This Block is systemblocks!current read blocks is : 6 --This Block is systemblocks!current read blocks is : 7 --This Block is systemblocks!current read blocks is : 8 --This Block is systemblocks!current read blocks is : 9 --This Block is systemblocks!current read blocks is : 10 --This Block is systemblocks!current read blocks is : 11 --This Block is systemblocks!current read blocks is : 12 --This Block is systemblocks!current read blocks is : 13 --This Block is systemblocks!current read blocks is : 14 --This Block is systemblocks!current read blocks is : 15 --This Block is systemblocks!current read blocks is : 16 --This Block is systemblocks!current read blocks is : 17 --This Block is systemblocks!current read blocks is : 18 --This Block is systemblocks!current read blocks is : 19 --This Block is systemblocks!current read blocks is : 20 --This Block is systemblocks!current read blocks is : 21 --This Block is systemblocks!current read blocks is : 22 --This Block is systemblocks!current read blocks is : 23 --This Block is systemblocks!current read blocks is : 24 --This Block is systemblocks!current read blocks is : 25 --This Block is systemblocks!current read blocks is : 26 --This Block is systemblocks!current read blocks is : 27 --This Block is undo blocks!current read blocks is : 28 --This Block is undo blocks!current read blocks is : 29 --This Block is undo blocks!current read blocks is : 30 --This Block is undo blocks!current read blocks is : 31 --This Block is undo blocks!current read blocks is : 32 --This Block is undo blocks!current read blocks is : 33 --This Block is undo blocks!current read blocks is : 34 --This Block is undo blocks!current read blocks is : 35 --This Block is undo blocks!current read blocks is : 36 --This Block is undo blocks!current read blocks is : 37 --This Block is undo blocks!current read blocks is : 38 --This Block is new allocate blocks!current read blocks is : 39 --This Block is new allocate blocks!current read blocks is : 40 --This Block is new allocate blocks!current read blocks is : 41 --This Block is new allocate blocks!current read blocks is : 42 --This Block is new allocate blocks!