rollback segment

/* Transaction rollback segment header */ /*-------------------------------------------------------------*/ #define TRX_RSEG_MAX_SIZE 0 /* Maximum allowed size for rollback segment in pages */ #define TRX_RSEG_HISTORY_SIZE 4 /* Number of file pages occupied by the logs in the history list */ #define TRX_RSEG_HISTORY 8 /* The update undo logs for committed transactions */ #define TRX_RSEG_FSEG_HEADER (8 + FLST_BASE_NODE_SIZE) /* Header for the file segment where this page is placed */ #define TRX_RSEG_UNDO_SLOTS (8 + FLST_BASE_NODE_SIZE + FSEG_HEADER_SIZE) /* Undo log segment slots */ /* Number of undo log slots in a rollback segment file copy */ #define TRX_RSEG_N_SLOTS (UNIV_PAGE_SIZE / 16) /* Maximum number of transactions supported by a single rollback segment */ #define TRX_RSEG_MAX_N_TRXS (TRX_RSEG_N_SLOTS / 2) /* The rollback segment memory object */ struct trx_rseg_struct{ /*--------------------------------------------------------*/ ulint id; /*!< rollback segment id == the index of its slot in the trx system file copy */ mutex_t mutex; /*!< mutex protecting the fields in this struct except id, which is constant */ ulint space; /*!< space where the rollback segment is header is placed */ ulint zip_size;/* compressed page size of space in bytes, or 0 for uncompressed spaces */ ulint page_no;/* page number of the rollback segment header */ ulint max_size;/* maximum allowed size in pages */ ulint curr_size;/* current size in pages */ /*--------------------------------------------------------*/ /* Fields for update undo logs */ UT_LIST_BASE_NODE_T(trx_undo_t) update_undo_list; /* List of update undo logs */ UT_LIST_BASE_NODE_T(trx_undo_t) update_undo_cached; /* List of update undo log segments cached for fast reuse */ /*--------------------------------------------------------*/ /* Fields for insert undo logs */ UT_LIST_BASE_NODE_T(trx_undo_t) insert_undo_list; /* List of insert undo logs */ UT_LIST_BASE_NODE_T(trx_undo_t) insert_undo_cached; /* List of insert undo log segments cached for fast reuse */ /*--------------------------------------------------------*/ ulint last_page_no; /*!< Page number of the last not yet purged log header in the history list; FIL_NULL if all list purged */ ulint last_offset; /*!< Byte offset of the last not yet purged log header */ trx_id_t last_trx_no; /*!< Transaction number of the last not yet purged log */ ibool last_del_marks; /*!< TRUE if the last not yet purged log needs purging */ /*--------------------------------------------------------*/ UT_LIST_NODE_T(trx_rseg_t) rseg_list; /* the list of the rollback segment memory objects */ }; /** The offset of the undo log page header on pages of the undo log */ #define TRX_UNDO_PAGE_HDR FSEG_PAGE_DATA /*-------------------------------------------------------------*/ /** 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 */ /*-------------------------------------------------------------*/ #define TRX_UNDO_PAGE_HDR_SIZE (6 + FLST_NODE_SIZE) /*!< Size of the transaction undo log page header, in bytes */ /* 一个 undo log record主要有下面几部分 1。2 bytes for the pointer to the next undo log record,当不存在时,预留这部分空间 2。1 byte for some general parameters to the undo log #define TRX_UNDO_INSERT_REC 11 /* fresh insert into clustered index */ #define TRX_UNDO_UPD_EXIST_REC 12 /* update of a non-delete-marked record */ #define TRX_UNDO_UPD_DEL_REC 13 /* update of a delete marked record to a not delete marked record; also the fields of the record can change */ #define TRX_UNDO_DEL_MARK_REC 14 /* delete marking of a record; fields do not change */ #define TRX_UNDO_CMPL_INFO_MULT 16 /* compilation info is multiplied by this and ORed to the type above */ 3。undo_no 4。table id 5。1 byte for the state of the info bits 6。trx id 7。Store then the fields required to uniquely determine the record which will be modified in the clustered index 8。Save to the undo log the old values of the columns to be updated 9。In the case of a delete marking, and also in the case of an update where any ordering field of any index changes, store the values of all columns which occur as ordering fields in any index. This info is used in the purge of old versions where we use it to build and search the delete marked index records, to look if we can remove them from the index tree. 10。Write pointers to the previous and the next undo log records */ /** Transaction undo log memory object; this is protected by the undo_mutex in the corresponding transaction object */ struct trx_undo_struct{ /*-----------------------------*/ ulint id; /*!< undo log slot number within the rollback segment */ ulint type; /*!< TRX_UNDO_INSERT or TRX_UNDO_UPDATE */ ulint state; /*!< state of the corresponding undo log segment */ ibool del_marks; /*!< relevant only in an update undo log: this is TRUE if the transaction may have delete marked records, because of a delete of a row or an update of an indexed field; purge is then necessary; also TRUE if the transaction has updated an externally stored field */ trx_id_t trx_id; /*!< id of the trx assigned to the undo log */ XID xid; /*!< X/Open XA transaction identification */ ibool dict_operation; /*!< TRUE if a dict operation trx */ table_id_t table_id; /*!< if a dict operation, then the table id */ trx_rseg_t* rseg; /*!< rseg where the undo log belongs */ /*-----------------------------*/ ulint space; /*!< space id where the undo log placed */ ulint zip_size; /*!< compressed page size of space in bytes, or 0 for uncompressed */ ulint hdr_page_no; /*!< page number of the header page in the undo log */ ulint hdr_offset; /*!< header offset of the undo log on the page */ ulint last_page_no; /*!< page number of the last page in the undo log; this may differ from top_page_no during a rollback */ ulint size; /*!< current size in pages */ /*-----------------------------*/ ulint empty; /*!< TRUE if the stack of undo log records is currently empty */ ulint top_page_no; /*!< page number where the latest undo log record was catenated; during rollback the page from which the latest undo record was chosen */ ulint top_offset; /*!< offset of the latest undo record, i.e., the topmost element in the undo log if we think of it as a stack */ undo_no_t top_undo_no; /*!< undo number of the latest record */ buf_block_t* guess_block; /*!< guess for the buffer block where the top page might reside */ /*-----------------------------*/ UT_LIST_NODE_T(trx_undo_t) undo_list; /*!< undo log objects in the rollback segment are chained into lists */ }; /** The undo log header. There can be several undo log headers on the first page of an update undo log segment. 每一条元组都有这么一条记录头*/ /* @{ */ /*-------------------------------------------------------------*/ #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 */ /*-------------------------------------------------------------*/ /** Size of the undo log header without XID information */ #define TRX_UNDO_LOG_OLD_HDR_SIZE (34 + FLST_NODE_SIZE) //insert undo 记录的内容 /* Reserve 2 bytes for the pointer to the next undo log record */ ptr += 2; /* Store first some general parameters to the undo log */ *ptr++ = TRX_UNDO_INSERT_REC; ptr += mach_ull_write_much_compressed(ptr, trx->undo_no); ptr += mach_ull_write_much_compressed(ptr, index->table->id); /*----------------------------------------*/ /* Store then the fields required to uniquely determine the record to be inserted in the clustered index */ //update undo 记录的内容 /* Store the state of the info bits */ /* Store the values of the system columns */ /* Store then the fields required to uniquely determine the record which will be modified in the clustered index */ /* Save to the undo log the old values of the columns to be updated. 格式:总个数 | 第一个修改列的位置 | 长度 | 内容 | 第二个修改列的位置 | 。。。 */ /* In the case of a delete marking, and also in the case of an update where any ordering field of any index changes, store the values of all columns which occur as ordering fields in any index. This info is used in the purge of old versions where we use it to build and search the delete marked index records, to look if we can remove them from the index tree. Note that starting from 4.0.14 also externally stored fields can be ordering in some index. Starting from 5.2, we no longer store REC_MAX_INDEX_COL_LEN first bytes to the undo log record, but we can construct the column prefix fields in the index by fetching the first page of the BLOB that is pointed to by the clustered index. This works also in crash recovery, because all pages (including BLOBs) are recovered before anything is rolled back. */ //把对undo log的修改记录在redo log之中, //元组中记录的组成 roll_ptr = (roll_ptr_t) is_insert << 55 | (roll_ptr_t) rseg_id << 48 | (roll_ptr_t) page_no << 16 | offset;

 

 

 

 

 

 

 

 

你可能感兴趣的:(list,header,delete,insert,Parameters,transactions)