In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The level is limited, please point out if there is any mistake.
I haven't studied Innodb's undo for a long time. Recently, I happen to have some time to prepare to learn, through a comprehensive summary of Ali kernel monthly report and my own code. The context of this article:
Code version percona 5.7.22 parameter innodb_undo_tablespaces = 4 and 4 undo tablespace parameters innodb_rollback_segments = 128are used
This article describes the use of the above parameter settings.
I. the establishment of physical files in undo tablespaces
This procedure calls the function srv_undo_tablespaces_init, and the stack frame is as follows:
# 0 srv_undo_tablespaces_init (create_new_db=true, n_conf_tablespaces=4 N_opened=0x2ef55b0) at / root/mysqlc/percona-server-locks-detail-5.7.22/storage/innobase/srv/srv0start.cc:824#1 0x0000000001bbd7e0 in innobase_start_or_create_for_mysql () at / root/mysqlc/percona-server-locks-detail-5.7.22/storage/innobase/srv/srv0start.cc:2188#2 0x00000000019ca74e in innobase_init (p=0x2f2a420) at / root/mysqlc/percona-server-locks-detail-5.7.22/storage/innobase/handler / ha_innodb.cc:4409#3 0x0000000000f7ec2a in ha_initialize_handlerton (plugin=0x2fca110) at / root/mysqlc/percona-server-locks-detail-5.7.22/sql/handler.cc:871#4 0x00000000015f9edf in plugin_initialize (plugin=0x2fca110) at / root/mysqlc/percona-server-locks-detail-5.7.22/sql/sql_plugin.cc:1252
This process mainly has the following steps:
Create files separately by calling srv_undo_tablespace_create according to the configuration of the parameter innodb_undo_tablespaces. The default size is 10M:for (I = 0; create_new_db & & I).
< n_conf_tablespaces; ++i) //n_conf_tablespaces 为innodb_undo_tablespaces的配置的个数/** Default undo tablespace size in UNIV_PAGEs count (10MB). */const ulint SRV_UNDO_TABLESPACE_SIZE_IN_PAGES = ((1024 * 1024) * 10) / UNIV_PAGE_SIZE_DEF;... err = srv_undo_tablespace_create( name, SRV_UNDO_TABLESPACE_SIZE_IN_PAGES); //建立undo文件... 本步骤会有一个注释如下: /* Create the undo spaces only if we are creating a new instance. We don't allow creating of new undo tablespaces in an existing instance (yet). This restriction exists because we check in several places for SYSTEM tablespaces to be less than the min of user defined tablespace ids. Once we implement saving the location of the undo tablespaces and their space ids this restriction will/should be lifted. */ 简单的讲就是建立undo tablespace只能在初始化实例的时候,因为space id已经固定了。 分别对4个undo tablespace调用srv_undo_tablespace_open 其主要调用fil_space_create 和 fil_node_create将新建立的undo tablespace加入Innodb的文件体系。for (i = 0; i < n_undo_tablespaces; ++i) {....err = srv_undo_tablespace_open(name, undo_tablespace_ids[i]); //打开UNDO文件 建立 file node...}分别对4个undo tablespace 进行fsp header初始化for (i = 0; i < n_undo_tablespaces; ++i) { fsp_header_init( //初始化fsp header 明显 space id 已经写入 undo_tablespace_ids[i], SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr); //SRV_UNDO_TABLESPACE_SIZE_IN_PAGES 默认的undo大小 10MB } 其中fsp_header_init部分代码如下: mlog_write_ulint(header + FSP_SPACE_ID, space_id, MLOG_4BYTES, mtr); mlog_write_ulint(header + FSP_NOT_USED, 0, MLOG_4BYTES, mtr); mlog_write_ulint(header + FSP_SIZE, size, MLOG_4BYTES, mtr); mlog_write_ulint(header + FSP_FREE_LIMIT, 0, MLOG_4BYTES, mtr); mlog_write_ulint(header + FSP_SPACE_FLAGS, space->Flags, MLOG_4BYTES, mtr); mlog_write_ulint (header + FSP_FRAG_N_USED, 0, MLOG_4BYTES, mtr); flst_init (header + FSP_FREE, mtr); flst_init (header + FSP_FREE_FRAG, mtr); flst_init (header + FSP_FULL_FRAG, mtr); flst_init (header + FSP_SEG_INODES_FULL, mtr); flst_init (header + FSP_SEG_INODES_FREE, mtr)
These are all the contents of fsp.
After completing this step, only 4 undo tablespace files with the size of 10MB have been generated and have been added to the Innodb file system, but there is no class content in it.
2. Initialization of system segment header in ibdata
This step calls trx_sys_create_sys_pages- > trx_sysf_create. In addition to initializing transaction system segment, this step will also initialize its header (ibdata page no 5) information as follows:
/ * Create the trx sys file block in a new allocated file segment * / block = fseg_create (TRX_SYS_SPACE, 0, TRX_SYS + TRX_SYS_FSEG_HEADER, mtr); / / create segment buf_block_dbg_add_level (block, SYNC_TRX_SYS_HEADER); ut_a (block- > page.id.page_no () = = TRX_SYS_PAGE_NO); page = buf_block_get_frame (block) / / get the memory location mlog_write_ulint (page + FIL_PAGE_TYPE, FIL_PAGE_TYPE_TRX_SYS, / / write block type MLOG_2BYTES, mtr); / * Start counting transaction ids from number 1 up * / mach_write_to_8 (sys_header + TRX_SYS_TRX_ID_STORE, 1); / / initialize TRX_SYS_TRX_ID_STORE / * Reset the rollback segment slots. Old versions of InnoDB define TRX_SYS_N_RSEGS as 256 (TRX_SYS_OLD_N_RSEGS) and expect that the whole array is initialized. * / ptr = TRX_SYS_RSEGS + sys_header; len = ut_max (TRX_SYS_OLD_N_RSEGS, TRX_SYS_N_RSEGS) * TRX_SYS_RSEG_SLOT_SIZE;//TRX_SYS_OLD_N_RSEGS is 256memset (ptr, 0xff, len); / / initialize all the information of slot to ff ptr + = len; ut_a (ptr
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.