Innodb undo构架是什么
发布时间:2021-12-23 10:45:23 所属栏目:MySql教程 来源:互联网
导读:本篇内容介绍了Innodb undo结构是什么的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成! 一、大体结构 rollback segments(128) undo segments(1024) undo
本篇内容介绍了“Innodb undo结构是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成! 一、大体结构 rollback segments(128) undo segments(1024) undo log (header insert/modify 分开的) <-> undo page undo record undo record 作为undo segments的第一个undo page可以存放多个事物的undo log,因为如果这个块的undo 记录没有填满3/4则会进入 rollback segment的cache list,那么下次可以继续使用,但是如果第一个块不足以装下事物的undo 记录,那么很显然需要分配新的undo page,这种情况下一个undo page就只能包含一个事物的undo记录了。 事物每次需要分配rollback segments然后分配undo segments然后初始化好undo log header,insert和update/delete需要分配不同的undo segments,一个undo segments往往对应了一个undo log,undo log可以包含多个undo record(因为从debug来看undo log header的初始化只做了一次),对于操作的每行都会留下一个undo record作为mvcc构建历史版本的基础。 undo生成的基本单位是undo record,每行记录都会包含一个undo record,而rollback ptr指向的是undo record的偏移量,对于每行的记录都会去判断其可见性,如果需要构建前版本则通过本指针进行构建包含: 第1位是否是insert 第2到8位是undo segment id 第9到40位为page no 第41位到56位为 offset 每一个undo log包含一个trx_undo_t结构体 每一个rollback segments包含一个trx_rseg_t结构体 二、物理结构 undo page header 每一个undo page都包含 /** Transaction undo log page header offsets *//* @{ */#define TRX_UNDO_PAGE_TYPE 0 /*!< TRX_UNDO_INSERT or TRX_UNDO_UPDATE */#define TRX_UNDO_PAGE_START 2 /*!< Byte offset where the undo log records for the LATEST transaction start on this page (remember that in an update undo log, the first page can contain several undo logs) */#define TRX_UNDO_PAGE_FREE 4 /*!< On each page of the undo log this field contains the byte offset of the first free byte on the page */#define TRX_UNDO_PAGE_NODE 6 /*!< The file list node in the chain of undo log pages */ undo semgent header 第一个page 才会用 undo segment header信息 #define TRX_UNDO_STATE 0 /*!< TRX_UNDO_ACTIVE, ... */#ifndef UNIV_INNOCHECKSUM#define TRX_UNDO_LAST_LOG 2 /*!< Offset of the last undo log header on the segment header page, 0 if none */#define TRX_UNDO_FSEG_HEADER 4 /*!< Header for the file segment which the undo log segment occupies */#define TRX_UNDO_PAGE_LIST (4 + FSEG_HEADER_SIZE) /*!< Base node for the list of pages in the undo log segment; defined only on the undo log segment's first page */ 每一个undo log undo log header undo log record 相应的undo实际内容 undo log record 相应的undo实际内容 undo log header 包含 #define TRX_UNDO_TRX_ID 0 /*!< Transaction id */#define TRX_UNDO_TRX_NO 8 /*!< Transaction number of the transaction; defined only if the log is in a history list */#define TRX_UNDO_DEL_MARKS 16 /*!< Defined only in an update undo log: TRUE if the transaction may have done delete markings of records, and thus purge is necessary */#define TRX_UNDO_LOG_START 18 /*!< Offset of the first undo log record of this log on the header page; purge may remove undo log record from the log start, and therefore this is not necessarily the same as this log header end offset */#define TRX_UNDO_XID_EXISTS 20 /*!< TRUE if undo log header includes X/Open XA transaction identification XID */#define TRX_UNDO_DICT_TRANS 21 /*!< TRUE if the transaction is a table create, index create, or drop transaction: in recovery the transaction cannot be rolled back in the usual way: a 'rollback' rather means dropping the created or dropped table, if it still exists */#define TRX_UNDO_TABLE_ID 22 /*!< Id of the table if the preceding field is TRUE */#define TRX_UNDO_NEXT_LOG 30 /*!< Offset of the next undo log header on this page, 0 if none */#define TRX_UNDO_PREV_LOG 32 /*!< Offset of the previous undo log header on this page, 0 if none */#define TRX_UNDO_HISTORY_NODE 34 /*!< If the log is put to the history list, the file list node is here */ 三、分配步骤和写入 第一步为 分配rollback segments #0 get_next_redo_rseg (max_undo_logs=128, n_tablespaces=4) at /root/mysqlc/percona-server-locks-detail-5.7.22/storage/innobase/trx/trx0trx.cc:1138#1 0x0000000001c0bce8 in trx_assign_rseg_low (max_undo_logs=128, n_tablespaces=4, rseg_type=TRX_RSEG_TYPE_REDO) at /root/mysqlc/percona-server-locks-detail-5.7.22/storage/innobase/trx/trx0trx.cc:1314#2 0x0000000001c1097d in trx_set_rw_mode (trx=0x7fffd7804080) at /root/mysqlc/percona-server-locks-detail-5.7.22/storage/innobase/trx/trx0trx.cc:3352#3 0x0000000001a64013 in lock_table (flags=0, table=0x7ffeac012ae0, mode=LOCK_IX, thr=0x7ffe7c92ef48) at /root/mysqlc/percona-server-locks-detail-5.7.22/storage/innobase/lock/lock0lock.cc:4139#4 0x0000000001b7950e in row_search_mvcc (buf=0x7ffe7c92e350 "377", mode=PAGE_CUR_GE, prebuilt=0x7ffe7c92e7d0, match_mode=1, direction=0) at /root/mysqlc/percona-server-locks-detail-5.7.22/storage/innobase/row/row0sel.cc:5100#5 0x00000000019d5443 in ha_innobase::index_read (this=0x7ffe7c92de10, buf=0x7ffe7c92e350 "377", key_ptr=0x7ffe7cd57590 " |