{"id":426,"date":"2013-09-12T18:16:59","date_gmt":"2013-09-12T10:16:59","guid":{"rendered":"http:\/\/www.gpfeng.com\/?p=426"},"modified":"2013-09-12T18:34:34","modified_gmt":"2013-09-12T10:34:34","slug":"innodb-%e9%94%81%e7%b3%bb%e7%bb%9f%e5%8f%8a%e6%ad%bb%e9%94%81%e6%a3%80%e6%b5%8b%e5%ae%9e%e7%8e%b0%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"http:\/\/www.gpfeng.com\/?p=426","title":{"rendered":"InnoDB \u9501\u7cfb\u7edf\u53ca\u6b7b\u9501\u68c0\u6d4b\u5b9e\u73b0\u5206\u6790"},"content":{"rendered":"<p>\u6b7b\u9501\u68c0\u6d4b\u4e00\u822c\u91c7\u7528Wait-For-Graph\u7b97\u6cd5\uff0c\u8fd9\u4e2a\u4e0d\u662f\u975e\u5e38\u590d\u6742\u6216\u8005\u65b0\u5947\u7684\u5185\u5bb9\uff0ccs\u8bfe\u7a0b\u4e2d\u4e00\u822c\u90fd\u4f1a\u4ea4\u4ee3\uff0c\u672c\u6587\u4ece\u4ee3\u7801\u5c42\u9762\u89e3\u6790InnoDB\u9501\u7cfb\u7edf\u53ca\u6b7b\u9501\u68c0\u6d4b\u5b9e\u73b0\uff0c\u4e00\u65b9\u9762\u7ed9\u81ea\u5df1\u9605\u8bfb\u4ee3\u7801\u505a\u505a\u7b14\u8bb0\uff0c\u53e6\u4e00\u65b9\u9762\u5e0c\u671b\u4e5f\u80fd\u591f\u4e3a\u4e00\u4e9b\u6709\u7591\u60d1\u7684\u670b\u53cb\u63d0\u4f9b\u5e2e\u52a9<\/p>\n<h3>\u51e0\u4e2a\u95ee\u9898<\/h3>\n<p>1. InnoDB\u4e2d\u9501\u5728\u662f\u600e\u6837\u8868\u793a\u548c\u7ef4\u62a4\u7684<br \/>\n2. \u6b7b\u9501\u68c0\u6d4b\u53d1\u751f\u5728\u4ec0\u4e48\u65f6\u5019<br \/>\n3. InnoDB\u4e2d\u7684Wait-For-Graph\u662f\u5982\u4f55\u5b9e\u73b0\u7684<br \/>\n4. InnoDB\u901a\u5e38\u5728\u54ea\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u53d1\u751f\u6b7b\u9501<br \/>\n<!--more--><\/p>\n<h3>InnoDB\u4e2d\u7684\u9501\u5b9e\u73b0<\/h3>\n<p>InnoDB\u652f\u6301\u884c\u9501\uff0c\u6240\u6709\u4e8b\u52a1\u52a0\u7684\u884c\u9501\u901a\u8fc7\u4e00\u4e2a\u5168\u5c40\u7684hash\u8868lock_sys\u7ef4\u62a4\uff1a<\/p>\n<pre lang=\"mysql\">\r\n\/* The lock system *\/\r\nUNIV_INTERN lock_sys_t*\tlock_sys\t= NULL;\r\ntypedef struct lock_sys_struct\tlock_sys_t;\r\n\r\n\/** The lock system struct *\/\r\nstruct lock_sys_struct{\r\n\thash_table_t*\trec_hash;\t\/*!< hash table of the record locks *\/\r\n\tulint\t\trec_num;\r\n};\r\n<\/pre>\n<p>\u5728\u8fdb\u4e00\u6b65\u4ecb\u7ecd\u884c\u9501\u5b9e\u73b0\u4e4b\u524d\uff0c\u5148\u4ecb\u7ecd\u4e00\u4e0bInnoDB\u4e2d\u4e8b\u52a1\u4e0e\u9501\u76f8\u5173\u7684\u6570\u636e\u7ed3\u6784<\/p>\n<pre lang=\"mysql\">\r\nstruct trx_struct{\r\n        ...\r\n\tlock_t*\t\twait_lock;\t\/*!< if trx execution state is\r\n\t\t\t\t\tTRX_QUE_LOCK_WAIT, this points to\r\n\t\t\t\t\tthe lock request, otherwise this is\r\n\t\t\t\t\tNULL *\/\r\n\tUT_LIST_BASE_NODE_T(lock_t)\r\n\t\t\ttrx_locks;\t\/*!< locks reserved by the transaction *\/\r\n        ...\r\n}\r\n<\/pre>\n<p>\u6bcf\u4e2a\u4e8b\u52a1\u90fd\u4f1a\u7ef4\u62a4\u6267\u884c\u8fc7\u7a0b\u4e2d\u52a0\u7684\u6240\u6709\u9501\uff08trx_locks\uff0c\u53cc\u5411\u94fe\u8868\uff09\uff0c\u4ee5\u53ca\u53d1\u751f\u9501\u7b49\u5f85\u65f6\u7b49\u5f85\u7684\u9501\uff08wait_lock\uff09<br \/>\nlock_sys\u4e2d\u4fdd\u5b58\u7684\u5bf9\u8c61\u4e3alock_t\uff0c\u5b83\u53ef\u4ee5\u63cf\u8ff0\u4e00\u4e2a\u884c\u9501\u6216\u8005\u8868\u9501\uff0c\u5982\u679c\u662f\u884c\u9501\uff0c\u4f1a\u88ablock_sys\u7ef4\u62a4\uff0c\u82e5\u662f\u8868\u9501\uff0c\u4f1a\u88ab\u5bf9\u5e94\u7684dict_table_t\u7ef4\u62a4<\/p>\n<pre lang=\"mysql\">\r\ntypedef struct lock_struct\tlock_t;\r\n\/** Lock struct *\/\r\nstruct lock_struct {\r\n\ttrx_t*\t\ttrx;\t\t\/*!< transaction owning the\r\n\t\t\t\t\tlock *\/\r\n\tUT_LIST_NODE_T(lock_t)\r\n\t\t\ttrx_locks;\t\/*!< list of the locks of the\r\n\t\t\t\t\ttransaction *\/\r\n\tulint\t\ttype_mode;\t\/*!< lock type, mode, LOCK_GAP or\r\n\t\t\t\t\tLOCK_REC_NOT_GAP,\r\n\t\t\t\t\tLOCK_INSERT_INTENTION,\r\n\t\t\t\t\twait flag, ORed *\/\r\n\thash_node_t\thash;\t\t\/*!< hash chain node for a record\r\n\t\t\t\t\tlock *\/\r\n\tdict_index_t*\tindex;\t\t\/*!< index for a record lock *\/\r\n\tunion {\r\n\t\tlock_table_t\ttab_lock;\/*!< table lock *\/\r\n\t\tlock_rec_t\trec_lock;\/*!< record lock *\/\r\n\t} un_member;\t\t\t\/*!< lock details *\/\r\n};\r\n<\/pre>\n<p>\u4e0d\u8bba\u884c\u9501\u8fd8\u662f\u8868\u9501\uff0c\u90fd\u8bb0\u5f55\u4e86\u6240\u5c5e\u7684\u4e8b\u52a1\uff0c\u9501\u521b\u5efa\u540e\u4f1a\u901a\u8fc7trx_locks\uff08next\u548cprev\u6307\u9488\uff09\u6dfb\u52a0\u5230\u6240\u5c5e\u4e8b\u52a1\u5df2\u83b7\u5f97\u9501\u94fe\u8868\u4e2d\uff08trx_struct.trx_locks\uff09\uff0c\u5982\u679c\u521b\u5efa\u7684\u9501\u4e3a\u884c\u9501\uff0c\u4f1a\u4f7f\u7528\uff08space_no, page_no\uff09\u7ecf\u8fc7hash\u51fd\u6570\u8ba1\u7b97\u540e\u6dfb\u52a0\u5230lock_sys\u4e2d\uff08lock_rec_create\uff09\uff0cInnoDB hash\u7b97\u6cd5\u89e3\u51b3\u51b2\u7a81\u7684\u65b9\u5f0f\u662f\u62c9\u94fe\u6cd5\uff0c\u56e0\u6b64\u6709\u4e00\u4e2ahash_node_t hash\uff08next\u6307\u9488\uff09\u6307\u5411\u540c\u4e00\u4e2a\u6876\u4e2d\u7684\u4e0b\u4e00\u4e2a\u5143\u7d20\uff0c\u540c\u4e00\u4e2a\u6876\u4e2d\u6dfb\u52a0\u5143\u7d20\u662f\u52a0\u5728\u62c9\u94fe\u5c3e\u90e8\uff08\u4f4d\u4e8e\u540c\u4e00\u4e2a\u6876\u4e2d\u76f8\u540crow\uff0c\u5148\u52a0\u5165\u7684\u9501\u4e0d\u9700\u8981\u7b49\u5f85\u540e\u52a0\u5165\u7684\u9501\uff09\uff1b\u5982\u679c\u521b\u5efa\u7684\u9501\u4e3a\u8868\u9501\uff0c\u5c06\u5176\u52a0\u5165\u5230\u5bf9\u5e94dict_table_t\u7684\u8868\u9501\u94fe\u8868\u5c3e\u90e8\uff08lock_table_create\uff09<\/p>\n<h3>\u884c\u9501\u4e0e\u8868\u9501<\/h3>\n<p>InnoDB\u4e2d\u4e00\u4e2a\u4e8b\u52a1\u4e2d\u7684\u884c\u9501\u662f\u6309\u7167page\u548c\u9501\u7c7b\u578b\u7ec4\u7ec7\uff0c\u76f8\u540c\u7684\u9501\u7c7b\u578b\uff0c\u9501\u4e00\u884c\u548c\u9501\u8fd9\u884c\u6240\u5728page\u4e2d\u6240\u6709\u884c\u7684\u5b58\u50a8\u4ee3\u4ef7\u662f\u4e00\u6837\u7684\uff0clock_rec_struct\u4e2d\u7684\u6210\u5458nbits\u540e\u9762\u6709\u4e00\u4e2abitmap\uff0cbitmap\u5360\u7528\u7684\u5b58\u50a8\u7a7a\u95f4\u4e3a\uff1a(1 + (nbits-1)\/8)bytes\uff0c\u5373\uff1alock_rec_struct\u5360\u7528\u7684\u5b9e\u9645\u5b58\u50a8\u7a7a\u95f4\u4e3a\uff1asizeof(lock_rec_struct) + 1 + (nbits-1)\/8\uff0cbitmap\u4e2d\u7684\u6bcf\u4e00\u4f4d\u6807\u8bc6\u5bf9\u5e94\u7684\u884c\u662f\u5426\u52a0\u9501<\/p>\n<pre lang=\"mysql\">\r\n\/** Record lock for a page *\/\r\ntypedef struct lock_rec_struct\t\tlock_rec_t;\r\n\/** Record lock for a page *\/\r\nstruct lock_rec_struct {\r\n\tulint\tspace;\t\t\t\/*!< space id *\/\r\n\tulint\tpage_no;\t\t\/*!< page number *\/\r\n\tulint\tn_bits;\t\t\t\/*!< number of bits in the lock\r\n\t\t\t\t\tbitmap; NOTE: the lock bitmap is\r\n\t\t\t\t\tplaced immediately after the\r\n\t\t\t\t\tlock struct *\/\r\n};\r\n<\/pre>\n<p>lock_table_t\u8868\u9501\uff0c\u4fdd\u5b58\u4e86\u5bf9\u5e94\u7684table\u548ctable\u4e0a\u8868\u9501\u94fe\u63a5locks\uff08prev\u548cnext\u6307\u9488\uff09<\/p>\n<pre lang=\"mysql\">\r\n\/** A table lock *\/\r\ntypedef struct lock_table_struct\tlock_table_t;\r\n\/** A table lock *\/\r\nstruct lock_table_struct {\r\n\tdict_table_t*\ttable;\t\t\/*!< database table in dictionary\r\n\t\t\t\t\tcache *\/\r\n\tUT_LIST_NODE_T(lock_t)\r\n\t\t\tlocks;\t\t\/*!< list of locks on the same\r\n\t\t\t\t\ttable *\/\r\n};\r\n<\/pre>\n<p>\u8bf4\u660e\uff1alock_t\u8868\u793a\u4e00\u4e2a\u9501\uff0c\u8868\u9501\u6216\u8005\u884c\u9501\uff0c\u5176\u4e2d\u7684trx_locks\u6210\u5458\u4f1a\u88ab\u94fe\u63a5\u5230trx_struct\u4e2d\u7684\u5df2\u52a0\u9501\u94fe\u8868trx_struct.trx_locks\u4e2d\uff0c\u800clock_table_t\u4e2d\u7684locks\u6210\u5458\u662f\u9700\u8981\u94fe\u63a5\u5230\u5bf9\u5e94table\u540e\u9762\uff0c\u4f5c\u7528\u4e0d\u540c\u4f46\u5bb9\u6613\u6df7\u6dc6\uff1b\u5728\u672c\u4eba\u770b\u6765\uff0clock_t\u4e2d\u7684hash\u548cindex\u6210\u5458\u653e\u5230lock_rec_t\u7ed3\u6784\u4f53\u4e2d\u66f4\u52a0\u5408\u9002\uff0c\u53ef\u80fd\u662f\u57fa\u4e8elock_t\u662f\u884c\u9501\u7684\u53ef\u80fd\u6027\u66f4\u5927\u7684\u524d\u63d0\u8003\u8651\u7684<\/p>\n<p>\u80cc\u666f\u77e5\u8bc6\u4ecb\u7ecd\u7684\u5dee\u4e0d\u591a\u4e86\uff0c\u95ee\u98981\u56de\u7b54\u5b8c\u6bd5\uff0c\u8fdb\u5165\u7b2c\u4e8c\u4e2a\u95ee\u9898<\/p>\n<h3>\u6b7b\u9501\u68c0\u6d4b\u53d1\u751f\u5728\u4ec0\u4e48\u65f6\u5019<\/h3>\n<p>\u6b7b\u9501\u68c0\u6d4b\u53d1\u751f\u5728\u52a0\u9501\u8bf7\u6c42\u65e0\u6cd5\u7acb\u5373\u6ee1\u8db3\u9700\u8981\u8fdb\u5165\u6240\u7b49\u5f85\u65f6\uff0clock_deadlock_occurs\u88ab\u4e24\u4e2a\u51fd\u6570\u9501\u8c03\u7528\uff1a<br \/>\nlock_rec_enqueue_waiting<br \/>\nlock_table_enqueue_waiting<\/p>\n<h3>Wait-For-Graph\u5728InnoDB\u4e2d\u7684\u5b9e\u73b0<\/h3>\n<p>InnoDB\u5728\u5b9e\u73b0Wait-For-Graph\u65f6\u57fa\u4e8e\u6027\u80fd\u65b9\u9762\u7684\u8003\u8651\uff0c\u5b9a\u4e49\u4e86\u4e24\u4e2a\u53d8\u91cf\uff1a<\/p>\n<p><strong>LOCK_MAX_DEPTH_IN_DEADLOCK_CHECK<\/strong>(\u9ed8\u8ba4200)\uff1a\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u7684\u5c42\u6570\u8d85\u8fc7\u6b64\u503c\uff0c\u5373\u8ba4\u4e3a\u53d1\u751f\u6b7b\u9501\uff0c\u56de\u6eda\u5f53\u524d\u4e8b\u52a1<br \/>\n<strong>LOCK_MAX_N_STEPS_IN_DEADLOCK_CHECK<\/strong>(\u9ed8\u8ba41000000)\uff1alock_deadlock_recursive\u9012\u5f52\u8c03\u7528\u7684\u6b21\u6570\u8d85\u8fc7\u6b64\u503c\uff0c\u5373\u8ba4\u4e3a\u53d1\u751f\u6b7b\u9501\uff0c\u56de\u6eda\u5f53\u524d\u4e8b\u52a1<\/p>\n<h4>lock_deadlock_recursive\u51fd\u6570\u5b9a\u4e49<\/h4>\n<pre lang=\"mysql\">\r\nstatic ulint lock_deadlock_recursive(\r\n\/*====================*\/\r\n\ttrx_t*\tstart,\t\t\/*!< in: recursion starting point *\/\r\n\ttrx_t*\ttrx,\t\t\/*!< in: a transaction waiting for a lock *\/\r\n\tlock_t*\twait_lock,\t\/*!< in: lock that is waiting to be granted *\/\r\n\tulint*\tcost,\t\t\/*!< in\/out: number of calculation steps thus\r\n\t\t\t\tfar: if this exceeds LOCK_MAX_N_STEPS_...\r\n\t\t\t\twe return LOCK_EXCEED_MAX_DEPTH *\/\r\n\tulint\tdepth)\t\t\/*!< in: recursion depth: if this exceeds\r\n\t\t\t\tLOCK_MAX_DEPTH_IN_DEADLOCK_CHECK, we\r\n\t\t\t\treturn LOCK_EXCEED_MAX_DEPTH *\/\r\n<\/pre>\n<p>lock_deadlock_recursive\u662f\u4e00\u4e2a\u9012\u5f52\u51fd\u6570\uff0cstart\u662fWait-For-Graph\u7684\u8d77\u70b9\uff0ctrx\u662f\u5f53\u524d\u904d\u5386\u8282\u70b9\uff0cwait_lock\u662ftrx\u9700\u8981\u7b49\u5f85\u7684\u9501\uff0c*cost\u5728\u6bcf\u6b21\u8fdb\u5165lock_deadlock_recursive\u4f1a\u589e\u52a01\uff0cdepth\u5728\u9012\u5f52\u8c03\u7528lock_deadlock_recursive\u8fdb\u5165Wait-For-Graph\u4e0b\u4e00\u4e2a\u8282\u70b9\u65f6\u589e\u52a01<\/p>\n<h4>lock_deadlock_recursive\u6267\u884c\u903b\u8f91<\/h4>\n<pre lang=\"mysql\">\r\n    \/\/ trx-sys\u4e2d\u6240\u6709\u4e8b\u52a1trx->deadlock_mark\u5728lock_deadlock_occurs\u4e2d\u88ab\u7f6e\u4e3a0\r\n    if (trx->deadlock_mark == 1) {\r\n        \/* We have already exhaustively searched the subtree starting from this trx *\/\r\n        return(0);\r\n    }\r\n\r\n    \/\/ cost \u589e\u52a01\r\n    *cost = *cost + 1;\r\n\r\n    \/\/ \u7b49\u5f85\u7684\u9501\u4e3a\u884c\u9501\uff0c\u627e\u5230lock_sys\u4e2d\u76f8\u540c\u884c\u4e0a\u7684\u7b2c\u4e00\u4e2a\u9501\r\n    if (lock_get_type_low(wait_lock) == LOCK_REC) {\r\n        \r\n        space = wait_lock->un_member.rec_lock.space;\r\n        page_no = wait_lock->un_member.rec_lock.page_no;\r\n        lock = lock_rec_get_first_on_page_addr(space, page_no);\r\n\r\n        \/* Position the iterator on the first matching record lock. *\/\r\n        while (lock != NULL\r\n               && lock != wait_lock\r\n               && !lock_rec_get_nth_bit(lock, heap_no)) {\r\n\r\n            lock = lock_rec_get_next_on_page(lock);\r\n        }\r\n        \/\/ \u627e\u5230\u81ea\u8eab\uff0c\u4e0d\u9700\u8981\u7ee7\u7eed\u627elock_sys\u4e2d\u76f8\u540c\u884c\u4e0a\u7684\u4e0b\u4e00\u4e2a\u9501\r\n        if (lock == wait_lock) {\r\n            lock = NULL;\r\n        }\r\n    } else {  \/\/ \u7b49\u5f85\u7684\u9501\u4e3a\u8868\u9501\r\n        lock = wait_lock;\r\n    }\r\n\r\n    \/* Look at the locks ahead of wait_lock in the lock queue *\/\r\n    for (;;) {\r\n        \/\/ lock\u4e3a\u8868\u9501\uff0c\u5b9a\u4f4d\u5230table\u5bf9\u5e94\u8868\u9501\u94fe\u8868\u4e2dlock\u524d\u4e00\u4e2a\u8868\u9501\r\n        \/* Get previous table lock. *\/\r\n        if (heap_no == ULINT_UNDEFINED) {\r\n            lock = UT_LIST_GET_PREV(un_member.tab_lock.locks, lock);\r\n        }\r\n        \/\/ \u6ca1\u6709\u627e\u5230\u524d\u4e00\u4e2a\u8868\u9501\uff0c\u5373lock\u4e3a\u6700\u540e\u4e00\u4e2a\u8868\u9501\u8bf7\u6c42\uff0c\u4e0d\u4f1a\u9020\u6210\u6b7b\u9501\uff0c\u8fd4\u56deFALSE\r\n\t\/\/ \u6216\u8005\uff0clock_sys\u4e2d\u627e\u5230\u76f8\u540c\u884c\u4e0a\u7b2c\u4e00\u4e2a\u9501lock == wait_lock\uff0c\u4e0d\u4f1a\u9020\u6210\u6b7b\u9501\uff0c\u8fd4\u56deFALSE\r\n\t\/\/ \u6b7b\u9501\u68c0\u6d4b\u65f6\uff0c\u4e0d\u9700\u8981\u5173\u5fc3\u662f\u5426\u4e0e\u4e4b\u540e\u52a0\u7684\u9501\u6709\u51b2\u7a81\uff0cWait-For-Graph\u8282\u70b9\u4e4b\u95f4\u662f\u5355\u5411\u5173\u7cfb\r\n        if (lock == NULL) {\r\n            \/* We can mark this subtree as searched *\/\r\n            trx->deadlock_mark = 1;\r\n            return(FALSE);\r\n        }\r\n        \/\/ Wait-For-Graph\u4e2d\u627e\u5230\u4e86\u4e00\u6761\u8fb9\uff0c\u9700\u8981\u68c0\u67e5\u662f\u5426\u6b7b\u9501\r\n        if (lock_has_to_wait(wait_lock, lock)) {\r\n            \/\/ \u5224\u65ad\u662f\u5426\u8c03\u7528\u5c42\u6b21\u592a\u6df1\uff0c\u6216\u8005\u8c03\u7528\u6b21\u6570\u8fc7\u591a\r\n            ibool    too_far\r\n                = depth > LOCK_MAX_DEPTH_IN_DEADLOCK_CHECK\r\n                || *cost > LOCK_MAX_N_STEPS_IN_DEADLOCK_CHECK;\r\n\r\n            lock_trx = lock->trx;\r\n            \/\/ Wait-For-Graph\u4e2d\u627e\u5230\u4e86\u56de\u8def\uff0c\u51fa\u73b0\u6b7b\u9501\uff01\r\n            if (lock_trx == start) {\r\n                \/\/ \u5224\u65ad\u4e8b\u52a1\u6743\u91cd\uff0c\u82e5start\u6743\u91cd\u8f83\u5c0f\uff0c\u8fd4\u56deLOCK_VICTIM_IS_START\uff0cstart\u5c06\u88ab\u56de\u6eda\r\n                if (trx_weight_ge(wait_lock->trx, start)) {\r\n                        return(LOCK_VICTIM_IS_START);\r\n                }\r\n                \/\/ wait_lock->trx\u6743\u91cd\u8f83\u5c0f\uff0c\u9700\u8981\u56de\u6eda\uff0c\u8fd4\u56deLOCK_VICTIM_IS_OTHER\r\n                lock_deadlock_found = TRUE;\r\n                wait_lock->trx->was_chosen_as_deadlock_victim = TRUE;\r\n                lock_cancel_waiting_and_release(wait_lock);\r\n\r\n                return(LOCK_VICTIM_IS_OTHER);\r\n            }\r\n            \/\/ \u8c03\u7528\u5c42\u6b21\u592a\u6df1\uff0c\u6216\u8005\u8c03\u7528\u6b21\u6570\u8fc7\u591a\uff0c\u8fd4\u56deLOCK_EXCEED_MAX_DEPTH\r\n            if (too_far) {\r\n                return(LOCK_EXCEED_MAX_DEPTH);\r\n            }\r\n            \/\/ \u76ee\u524d\u8fd8\u6ca1\u6709\u51fa\u73b0\u6b7b\u9501\uff0c\u7ee7\u7eed\u5728Wait-For-Graph\u5bfb\u627e\u53ef\u80fd\u7684\u8fb9\r\n            if (lock_trx->que_state == TRX_QUE_LOCK_WAIT) {\r\n\r\n                ret = lock_deadlock_recursive(start, lock_trx, lock_trx->wait_lock, cost, depth + 1);\r\n\t\t\/\/ \u53ea\u6709\u5f53\u68c0\u6d4b\u51fa\u6b7b\u9501\u6216\u8005\u53d1\u73b0\u8c03\u7528\u5c42\u6b21(\u6b21\u6570)\u8fc7\u6df1(\u8fc7\u591a)\u624d\u8fd4\u56de\uff0c\u5426\u5219\u4e3aWait-For-Graph\u9009\u62e9\u4e0b\u4e00\u4e2a\u8282\u70b9\r\n                if (ret != 0) {\r\n                    return(ret);\r\n                }\r\n            }\r\n        }\r\n\t\/\/ wait_lock\u4e0elock\u6ca1\u6709\u51b2\u7a81\uff0c\u7ee7\u7eed\u627elock_sys\u4e2d\u76f8\u540c\u884c\u4e0a\u7684\u4e0b\u4e00\u4e2a\u9501\r\n        \/* Get the next record lock to check. *\/\r\n        if (heap_no != ULINT_UNDEFINED) {\r\n            do {\r\n                lock = lock_rec_get_next_on_page(lock);\r\n            } while (lock != NULL && lock != wait_lock && !lock_rec_get_nth_bit(lock, heap_no));\r\n            \/\/ \u627e\u5230\u81ea\u8eab\uff0c\u4e0d\u9700\u8981\u7ee7\u7eed\u627elock_sys\u4e2d\u76f8\u540c\u884c\u4e0a\u7684\u4e0b\u4e00\u4e2a\u9501\r\n            if (lock == wait_lock) {\r\n                lock = NULL;\r\n            }\r\n        }\r\n    }\/* end of the 'for (;;)'-loop *\/\r\n<\/pre>\n<h4>lock_deadlock_recursive\u8fd4\u56de\u503c\u7684\u5904\u7406<\/h4>\n<p>1. LOCK_VICTIM_IS_OTHER\uff0c\u53d1\u751f\u6b7b\u9501\uff0c\u9700\u8981\u56de\u6eda\u5176\u5b83\u4e8b\u52a1\uff0c\u4f46\u53ef\u80fd\u591a\u4e2a\u4e8b\u52a1\u4e0e\u5f53\u524d\u4e8b\u52a1\u53d1\u751f\u6b7b\u9501\uff0c\u56e0\u6b64\u9700\u8981\u518d\u6b21\u8c03\u7528lock_deadlock_recursive<br \/>\n2. LOCK_EXCEED_MAX_DEPTH\uff0c\u8c03\u7528\u5c42\u6b21(\u6b21\u6570)\u8fc7\u6df1(\u8fc7\u591a)\uff0c\u56de\u6eda\u5f53\u524d\u4e8b\u52a1<br \/>\n3. LOCK_VICTIM_IS_START\uff0c\u53d1\u751f\u6b7b\u9501\uff0c\u9700\u8981\u56de\u6eda\u5f53\u524d\u4e8b\u52a1<\/p>\n<h3>InnoDB\u901a\u5e38\u5728\u54ea\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u53d1\u751f\u6b7b\u9501<\/h3>\n<p>\u56de\u987e\u4e00\u4e0bcs\u8bfe\u672c\u4e0a\u5173\u4e8e\u53d1\u751f\u6b7b\u9501\u7684\u51e0\u4e2a\u6761\u4ef6\uff1a<br \/>\n1. \u8d44\u6e90\u4e92\u65a5\uff1b2. \u8bf7\u6c42\u4fdd\u6301\uff1b3. \u4e0d\u5265\u593a\uff1b4. \u5faa\u73af\u7b49\u5f85<\/p>\n<p>\u5bf9\u4e8eDB\u800c\u8a00\uff0c\u5bfc\u81f4\u6b7b\u9501\u610f\u5473\u7740\u53d1\u751f\u4e86\u5faa\u73af\u7b49\u5f85\uff0c\u5728InnoDB\u4e2d\u7531\u4e8e\u884c\u9501\u7684\u5f15\u5165\uff0c\u6bd4\u8f83\u5bb9\u6613\u53d1\u751f\u6b7b\u9501\uff0c\u4e0b\u9762\u603b\u7ed3\u4e00\u4e9b\u53d1\u751f\u6b7b\u9501\u7684\u60c5\u51b5\uff08\u4e0d\u5168\uff09\uff1a<br \/>\n1. \u540c\u4e00\u7d22\u5f15\u4e0a\uff0c\u4e24\u4e2asession\u76f8\u53cd\u7684\u987a\u5e8f\u52a0\u9501\u591a\u884c\u8bb0\u5f55<br \/>\n2. Primary key\u548cSecondary index\uff0c\u901a\u8fc7primary key\u627e\u5230\u8bb0\u5f55\uff0c\u66f4\u65b0Secondary index\u5b57\u6bb5\u4e0e\u901a\u8fc7Secondary index\u66f4\u65b0\u8bb0\u5f55<br \/>\n3. UPDATE\/DELETE\u901a\u8fc7\u4e0d\u540c\u7684\u4e8c\u7ea7\u7d22\u5f15\u66f4\u65b0\u591a\u6761\u8bb0\u5f55\uff0c\u53ef\u80fd\u9020\u6210\u5728Primary key\u4e0a\u4e0d\u540c\u7684\u52a0\u9501\u987a\u5e8f\uff0c\u53ef\u4ee5\u53c2\u8003<a href=\"http:\/\/www.gpfeng.com\/?p=406\">\u4e4b\u524d\u4e00\u7bc7\u535a\u5ba2<\/a><br \/>\n4. \u6b22\u8fce\u8865\u5145...<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6b7b\u9501\u68c0\u6d4b\u4e00\u822c\u91c7\u7528Wait-For-Graph\u7b97\u6cd5\uff0c\u8fd9\u4e2a\u4e0d\u662f\u975e\u5e38\u590d\u6742\u6216\u8005\u65b0\u5947\u7684\u5185\u5bb9\uff0ccs\u8bfe\u7a0b\u4e2d\u4e00\u822c\u90fd\u4f1a\u4ea4\u4ee3\uff0c\u672c\u6587 &hellip; <a href=\"http:\/\/www.gpfeng.com\/?p=426\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">InnoDB \u9501\u7cfb\u7edf\u53ca\u6b7b\u9501\u68c0\u6d4b\u5b9e\u73b0\u5206\u6790<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3tPZp-6S","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/426"}],"collection":[{"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=426"}],"version-history":[{"count":5,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/426\/revisions"}],"predecessor-version":[{"id":429,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/426\/revisions\/429"}],"wp:attachment":[{"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=426"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}