InnoDB---UNDO日誌與回滾
事務通過trx_rsegs_t與系統表空間和臨時表空間等物理儲存聯絡起來的方式如下:
/** Rollback segments assigned to a transaction for undo logging. */
struct trx_rsegs_t {
/** undo log ptr holding reference to a rollback segment that resides in
system/undo tablespace used for undo logging of tables that needs to be recovered on crash. */
trx_undo_ptr_tm_redo;//系統的UNDO表空間
/** undo log ptr holding reference to a rollback segment that resides in
temp tablespace used for undo logging of tables that doesn't need to be recovered on crash. */
trx_undo_ptr_tm_noredo; //系統的臨時表空間
};
系統表空間和臨時表空間等物理儲存與UNDO日誌之間的關係如下:
/** Represents an instance of rollback segment along with its state variables.*/
struct trx_undo_ptr_t {
//標識分配給事務的回滾段,這樣把事務和回滾段建立起聯絡來。然後通過trx_rsegs_t與系統表空間和臨時表空間等物理儲存聯絡起來
trx_undo_t*insert_undo;/*!< pointer to the insert undo log, or NULL if no inserts performed yet *///事務指向insert undo log
trx_undo_t*update_undo;/*!< pointer to the update undo log, or ULL if no update performed yet *///
};
而回滾段的資訊又如下:
/** The rollback segment memory object */
struct trx_rseg_t {
ulintid;//回滾段的標識
...
ulintspace;//回滾段的頭資訊在表空間中的位置,表空間標識
ulintpage_no; //回滾段的頭資訊在表空間中的位置,頁號
page_size_tpage_size; /** page size of the relevant tablespace */
ulintmax_size; /** maximum allowed size in pages */
ulintcurr_size; /** current size in pages */
...
/** 執行UPDATE操作產生的UODO日誌,包括先刪除後插入的過程中產生的UODO資訊,事務完成,資訊依然被保留,用於MVCC機制下的一致性讀 */
/** List of update undo logs */
UT_LIST_BASE_NODE_T(trx_undo_t)update_undo_list;
/** List of update undo log segments cached for fast reuse */
UT_LIST_BASE_NODE_T(trx_undo_t)update_undo_cached;
/* 執行INSERT操作產生的UODO日誌,這些資訊是臨時的,事務結束後就被清理 */
/** List of insert undo logs */
UT_LIST_BASE_NODE_T(trx_undo_t) insert_undo_list;
/** List of insert undo log segments cached for fast reuse */
UT_LIST_BASE_NODE_T(trx_undo_t) insert_undo_cached;
...
};