mysql lock_rec_insert_check_and_lock 設置斷點調試

LOCK_MAX_DEPTH_IN_DEADLOCK_CHECK  死鎖檢測等待圖中wait-for-graph定義深度搜索的次數,如果搜索200次就認定爲死鎖。

 lock queue: 鎖隊列

設置斷點函數  lock_rec_insert_check_and_lock   

insert into 操作函數調用過程

#0  btr_cur_ins_lock_and_undo (flags=0, cursor=0x7ffff408aac0, entry=0x7ffa90016b48, thr=0x7ffa90016578, mtr=0x7ffff408a5d0, inherit=0x7ffff408a4d0)
    at /root/mysql-5.5.31/storage/innobase/btr/btr0cur.c:1109
#1  0x00000000009f9b33 in btr_cur_optimistic_insert (flags=0, cursor=0x7ffff408aac0, entry=0x7ffa90016b48, rec=0x7ffff408aab8, big_rec=0x7ffff408aab0, n_ext=0, thr=0x7ffa90016578,
    mtr=0x7ffff408a5d0) at /root/mysql-5.5.31/storage/innobase/btr/btr0cur.c:1321
#2  0x0000000000af2a1d in row_ins_index_entry_low (mode=2, index=0x7ffa900135f8, entry=0x7ffa90016b48, n_ext=0, thr=0x7ffa90016578) at /root/mysql-5.5.31/storage/innobase/row/row0ins.c:2160
#3  0x0000000000af2deb in row_ins_index_entry (index=0x7ffa900135f8, entry=0x7ffa90016b48, n_ext=0, foreign=1, thr=0x7ffa90016578) at /root/mysql-5.5.31/storage/innobase/row/row0ins.c:2254
#4  0x0000000000af3184 in row_ins_index_entry_step (node=0x7ffa900162b0, thr=0x7ffa90016578) at /root/mysql-5.5.31/storage/innobase/row/row0ins.c:2342
#5  0x0000000000af3448 in row_ins (node=0x7ffa900162b0, thr=0x7ffa90016578) at /root/mysql-5.5.31/storage/innobase/row/row0ins.c:2474
#6  0x0000000000af374d in row_ins_step (thr=0x7ffa90016578) at /root/mysql-5.5.31/storage/innobase/row/row0ins.c:2591
#7  0x0000000000980a0f in row_insert_for_mysql (mysql_rec=0x7ffa90012400 "\374\016", prebuilt=0x7ffa90015b88) at /root/mysql-5.5.31/storage/innobase/row/row0mysql.c:1245
#8  0x0000000000957f75 in ha_innobase::write_row (this=0x7ffa900109b0, record=0x7ffa90012400 "\374\016") at /root/mysql-5.5.31/storage/innobase/handler/ha_innodb.cc:5201
#9  0x0000000000768778 in handler::ha_write_row (this=0x7ffa900109b0, buf=0x7ffa90012400 "\374\016") at /root/mysql-5.5.31/sql/handler.cc:5188
#10 0x00000000005dfa42 in write_record (thd=0x2ff3f100, table=0x7ffa900100d0, info=0x7ffff408afe0) at /root/mysql-5.5.31/sql/sql_insert.cc:1734
#11 0x00000000005ddb69 in mysql_insert (thd=0x2ff3f100, table_list=0x7ffa78004d68, fields=..., values_list=..., update_fields=..., update_values=..., duplic=DUP_ERROR, ignore=false)
    at /root/mysql-5.5.31/sql/sql_insert.cc:931
#12 0x00000000005f76c5 in mysql_execute_command (thd=0x2ff3f100) at /root/mysql-5.5.31/sql/sql_parse.cc:2915
#13 0x00000000005fee0b in mysql_parse (thd=0x2ff3f100, rawbuf=0x7ffa78004c30 "insert into test_record_lock values(14,'hah','ha')", length=50, parser_state=0x7ffff408c6f0)
    at /root/mysql-5.5.31/sql/sql_parse.cc:5627
#14 0x00000000005f2eb3 in dispatch_command (command=COM_QUERY, thd=0x2ff3f100, packet=0x2ffc1dc1 "insert into test_record_lock values(14,'hah','ha')", packet_length=50)
    at /root/mysql-5.5.31/sql/sql_parse.cc:1037
#15 0x00000000005f21ba in do_command (thd=0x2ff3f100) at /root/mysql-5.5.31/sql/sql_parse.cc:773
#16 0x00000000006d79ad in do_handle_one_connection (thd_arg=0x2ffcd4f0) at /root/mysql-5.5.31/sql/sql_connect.cc:853
#17 0x00000000006d74b9 in handle_one_connection (arg=0x2ffcd4f0) at /root/mysql-5.5.31/sql/sql_connect.cc:772
#18 0x0000003597007851 in start_thread () from /lib64/libpthread.so.0
#19 0x00000035968e890d in clone () from /lib64/libc.so.6

  lock_rec_insert_check_and_lock函數說明:

  1. /*********************************************************************//** 
  2. Checks if locks of other transactions prevent an immediate insert of 
  3. a record. If they do, first tests if the query thread should anyway 
  4. be suspended for some reason; if not, then puts the transaction and 
  5. the query thread to the lock wait state and inserts a waiting request 
  6. for a gap x-lock to the lock queue. 
  7. @return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
       鎖檢查入口

  lock_rec_insert_check_and_lock:

              thr_get_trx():                   query thread 獲得事務

               page_rec_get_next_const():   get 獲得下一條記錄 

                                    page_rec_is_comp():   判斷獲得的記錄格式是否compact ,如果是,則返回true

               page_rec_get_heap_no(const rec_t*  rec):  返回記錄的heap number,堆值

               lock_mutex_enter_kernel():  進入  mutex_kernel 

                                   pfs_mutex_enter_func(mutex_t*  mutex,const char* file_name,ulint line)

                //當插入一個記錄入索引的時候,這表必須有IX-lock或我們必須建立一個index,在這種情況下,表至少有s-locked。下面lock_table_has函數判斷

              lock_table_has() :check 一個事務是否有指定的表鎖或更強的鎖 返回lock 或null

                                  lock_mode_stronger_or_eq() :判斷 相同事務在同一表上是否還有更高粒度的lock

                                                                      lock_get_mode(const lock_t*  lock)   :   返回lock mode

           lock_rec_get_first(block,next_rec_heap_no): 在記錄上首先get explicit lock(顯式鎖),返回first lock ,沒有則返回null

                                    lock_rec_get_first_on_page():  get 獲得page中的第一個record lock記錄鎖,從指針指向的page獲得

                                                                     buf_block_get_space(block): get 獲得block 的space id

                                                                     buf_block_get_page_no(block):  get the page number of a block                                        /innobase/include/buf0buf.ic:743

                                                                    buf_block_get_lock_hash_val(block):  get 獲得指針指向page頁的 hash value 哈希值。 this can be used in searches in the lock hash table。                                                hash_get_nth_cell()    在哈希表中獲得nth cell.

            lock_mutex_exit_kernel():  退出

             dict_index_is_clust(const dict_index_t*  index):  檢查索引是不是聚簇索引,聚簇索引返回非0,其他索引返回0    /include/dict0dict.ic 250


btr_cur_ins_lock_and_undo:




btr_cur_optimistic_insert()         

             rec_get_converted_size(): 當a data tuple轉換爲physical record(物理記錄)時,返回data tuple的大小

                                dtuple_check_typed(tuple): 檢查數據元組是否typed。如果typed 返回true。

                                                             dtuple_get_n_fields(tuple) :獲得數組元組中字段數量,返回filed數量。

           mem_heap_create(size+(4+rec_offs_header_size+dtuple_get_n_fields(tuple))* sizeof *offsets):

         rec_convert_dtuple_to_rec():

         rec_get_offsets():

        

 

row_ins_index_entry_low():         /row/row0ins.c 

tries to insert an index entry to an index.if the index is clustered and a record with the same unique key is found,the other record is necessarily marked deleted by a

commited transaction,or a unique key  violation error occurs.the delete marked  record is then updated to an existing record.if the index is secondary, and a record with exactly the same filed is found,the other record is  necessarily marked deleted. it is then unmarked.otherwise ,the entry is just inserted to the index.

 嘗試插入索引項達到索引。

 row_ins_index_entry():      插入索引項到索引,

row_ins_index_entry_step():  插入一個索引項到表

row_ins()  插入一行到表.

row_insert_for_mysql():插入一行到mysql

ha_innodbase::write_row()  寫入行

handler::ha_write_row():server 層控制行寫入,提供引擎層藉口

write_record() :

mysql_insert(): insert 插入的入口函數,此處可以設斷點,瞭解insert操作

mysql_execute_command(): sql 命令具體執行調用

mysql_parse(): sql 語法解析

dispatch_command() :客戶端請求如何轉發處理命令

do_command(): 客戶端請求命令

do_handler_one_connection() :監聽到請求,處理請求。

handle_one_connection() :處理監聽,監聽客戶端請求





發佈了193 篇原創文章 · 獲贊 30 · 訪問量 49萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章