MySQL:Innodb DB_ROLL_PTR指针解析
生活随笔
收集整理的這篇文章主要介紹了
MySQL:Innodb DB_ROLL_PTR指针解析
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
源碼版本5.7.22
此處簡單記錄一下DB_ROLL_PTR指針解析的方法,水平有限,如果有誤請諒解。
一、引入
我們知道每一條記錄在聚集索引上都有如下的分布:
- rowid(主鍵)+DB_TRX_ID+DB_ROLL_PTR+其他字段
這樣格式其中DB_TRX_ID+DB_ROLL_PTR作為MVCC的關(guān)鍵信息存儲下來,其中DB_TRX_ID在存儲上占用6字節(jié),DB_ROLL_PTR在存儲上占用7字節(jié)。那么DB_ROLL_PTR是如何解析到undo上的呢,這也是一位朋友問的問題。
下面是trx0types.h中對這部分的定義
/** Row identifier (DB_ROW_ID, DATA_ROW_ID) */ typedef ib_id_t row_id_t; /** Transaction identifier (DB_TRX_ID, DATA_TRX_ID) */ typedef ib_id_t trx_id_t; /** Rollback pointer (DB_ROLL_PTR, DATA_ROLL_PTR) */ typedef ib_id_t roll_ptr_t;而ib_id_t實(shí)際上都是64位非負(fù)整數(shù)
typedef unsigned __int64 ib_uint64_t;二、函數(shù)流程
我大概看了一下流程如下:
trx_undo_prev_version_build //Build a previous version of a clustered index record->roll_ptr = row_get_rec_roll_ptr(rec, index, offsets); //獲取rollback 指針->rec_trx_id = row_get_rec_trx_id(rec, index, offsets); //獲取TRX_ID->trx_undo_get_undo_rec(roll_ptr, rec_trx_id, heap, is_redo_rseg,index->table->name, &undo_rec))//此處獲取前版本,獲取后放到undo_rec中->trx_undo_get_undo_rec_low(roll_ptr, heap, is_redo_rseg); //undo_rec作為傳出參數(shù)。傳出訪問到的undo->trx_undo_decode_roll_ptr //做roll_ptr的解析工作獲取segment id\page no\offset->開MTR獲取latch準(zhǔn)備拷貝->拷貝trx_undo_rec_copy->提交MTR實(shí)際上解析工具由trx_undo_decode_roll_ptr 完成。
三、實(shí)際解析
其實(shí)解析挺簡單,都是寫死了的。
/***********************************************************************//** Decodes a roll pointer. */ //從高位到低位依次是 第1位是否是insert //第2到8位是segmentid//第9到40位為page no //第41位到56位為OFFSET UNIV_INLINE void trx_undo_decode_roll_ptr( /*=====================*/roll_ptr_t roll_ptr, /*!< in: roll pointer */ibool* is_insert, /*!< out: TRUE if insert undo log */ulint* rseg_id, /*!< out: rollback segment id */ulint* page_no, /*!< out: page number */ulint* offset) /*!< out: offset of the undoentry within page */ { #if DATA_ROLL_PTR_LEN != 7 # error "DATA_ROLL_PTR_LEN != 7" #endif #if TRUE != 1 # error "TRUE != 1" #endifut_ad(roll_ptr < (1ULL << 56));*offset = (ulint) roll_ptr & 0xFFFF; //獲取低16位 為OFFSETroll_ptr >>= 16; //右移16位*page_no = (ulint) roll_ptr & 0xFFFFFFFF;//獲取32位為 page noroll_ptr >>= 32;//右移32位*rseg_id = (ulint) roll_ptr & 0x7F;//獲取7位為segment idroll_ptr >>= 7;//右移7位*is_insert = (ibool) roll_ptr; /* TRUE==1 *///最后一位 }參考注釋。自行理解。
作者微信號碼:gp_22389860
總結(jié)
以上是生活随笔為你收集整理的MySQL:Innodb DB_ROLL_PTR指针解析的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: go设计模式之代理模式
- 下一篇: Linux/windows下nginx的