mysql lock_rec_insert_check_and_lock 设置断点调试

来源:互联网 发布:高颜值包装 知乎 编辑:程序博客网 时间:2024/06/05 19:54

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() :处理监听,监听客户端请求





0 0
原创粉丝点击