{"id":2173,"date":"2010-06-30T11:51:24","date_gmt":"2010-06-30T03:51:24","guid":{"rendered":"http:\/\/www.orczhou.com\/?p=2173"},"modified":"2010-11-08T19:36:53","modified_gmt":"2010-11-08T11:36:53","slug":"mysql-innodb-source-code-sync-1","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2010\/06\/mysql-innodb-source-code-sync-1\/","title":{"rendered":"MySQL\/InnoDB\u6e90\u4ee3\u7801\uff1a\u7ebf\u7a0b\u5e76\u53d1\u8bbf\u95ee\u63a7\u5236"},"content":{"rendered":"<p>\u4f5c\u4e3aDBA\u5173\u5fc3\u7684\u66f4\u591a\u7684\u53ef\u80fd\u662f\u539f\u7406\u3001\u673a\u5236\uff0c\u5bf9\u4e8e\u6e90\u7801\u4e00\u822c\u5927\u5bb6\u4e5f\u4e0d\u662f\u7279\u522b\u5173\u5fc3\uff0c\u4e5f\u4e0d\u592a\u7528\u5f97\u4e0a\u3002\u800c\u4e14\u5bf9\u4e8e\u5bf9\u4e8e\u6e90\u4ee3\u7801\u7ea7\u522b\u7684\u7ec6\u8282\u4e5f\u5f88\u96be\u7528\u6587\u5b57\u8868\u8fbe\u81ea\u5df1\u7684\u7406\u89e3\uff0c\u6700\u7ec8\u7406\u89e3\u5fc5\u987b\u8fd8\u662f\u9700\u8981\u81ea\u5df1\u53bb\u770b\u770b\u6bcf\u4e00\u884c\u4ee3\u7801\u5230\u5e95\u662f\u600e\u6837\u7684\u3002\u4e5f\u8bfb\u8fc7\u300aUnderstanding.MySQL.Internals\u300b\u7684\u5927\u90e8\u5206\u7ae0\u8282\uff0c\u4f5c\u8005\u4e5f\u662f\u504f\u91cd\u4e8e\u4ece\u4ee3\u7801\u7684\u5b9e\u73b0\u76ee\u7684\uff08\u539f\u7406\u3001\u673a\u5236\uff09\u6765\u4ecb\u7ecd\u7684\uff0c\u56fd\u5185\u7684\u300aMySQL\u6838\u5fc3\u5185\u5e55\u300b\uff08\u4e2a\u4eba\u5bf9\u4e8e\u201c\u6838\u5fc3\u5185\u5e55\u201d\u8fd9\u4e2a\u8bcd\u6709\u83ab\u540d\u7684\u53cd\u611f\uff09\u7b97\u662f\u66f4\u591a\u7684\u4ece\u6e90\u7801\u5f00\u59cb\u4ecb\u7ecdMySQL\u4e86\uff0c\u53ef\u662f\u8fd9\u672c\u4e66\u4e5f\u8bb8\u662f\u6388\u4e88\u7bc7\u5e45\u7684\u9650\u5236\uff0c\u4ecb\u7ecd\u7684\u4e1c\u897f\u4e5f\u5e76\u4e0d\u591a\u3002<\/p>\n<p>\u5f00\u59cb\u5199\u8fd9\u7bc7\u6587\u7ae0\uff0c\u4e0d\u80fd\u671f\u5f85\u81ea\u5df1\u80fd\u5199\u591a\u5c11\uff0c\u4e5f\u4e0d\u80fd\u671f\u5f85\u81ea\u5df1\u80fd\u7814\u7a76\u591a\u5c11\uff0c\u4e0d\u8fc7\u81f3\u5c11\u8d70\u51fa\u4e86\u81ea\u5df1\u63a2\u7d22\u7684\u7b2c\u4e00\u6b65\u3002\u6587\u7ae0\u7684\u5b97\u65e8\u4e0d\u5728\u4e8e\u80fd\u591f\u591a\u4e48\u7ec6\u81f4\u7684\u5206\u6790MySQL\u7684\u6e90\u4ee3\u7801\uff0c\u800c\u662f\u5e0c\u671b\u80fd\u7ed9\u81ea\u5df1\uff0c\u80fd\u7ed9\u4ed6\u4eba\u6253\u5f00\u8d70\u5411\u6e90\u4ee3\u7801\u7684\u7b2c\u4e00\u9053\u95e8\u3002<\/p>\n<p>\u6211\u662fBNU\u6570\u5b66\u7cfb\u6bd5\u4e1a\u7684\uff0c\u5bf9C\u8bed\u8a00\u77e5\u9053\u751a\u5c11\uff0cC\u8bed\u8a00\u7684\u7ecf\u5386\u5927\u6982\u5c31\u662f\u201c\u8ba1\u7b97\u65b9\u6cd5\u201d\u8bfe\u7a0b\u4e2d\u5b9e\u73b0\u7684\u6c42\u89e3\u5404\u79cd\u65b9\u7a0b\u7684\u6487\u811a\u7a0b\u5e8f\u4e86\u3002\u6240\u4ee5\u867d\u7136\u6211\u4f1a\u6781\u529b\u907f\u514d\u9519\u8bef\uff0c\u4f46\u662f\u76f8\u4fe1\u8fd8\u662f\u4f1a\u72af\u4e00\u5806\u9519\u8bef\uff0c\u5e0c\u671b\u5404\u4f4d\u770b\u5b98\u80fd\u591f\u5bbd\u5bb9\u70b9\uff0c\u6709\u9519\u8bef\u6307\u51fa\u6765\uff0c\u6162\u6162\u6539\u6b63\u3002<\/p>\n<div class=\"myt1\">0. \u5f00\u59cb<\/div>\n<p>InnoDB\u7684\u4ee3\u7801\u901a\u8fc7\u5b8f\u5b9a\u4e49\u8003\u8651\u5f88\u591a\u5e73\u53f0\u7684\u517c\u5bb9\u95ee\u9898\uff0c\u8fd9\u91cc\u5206\u6790\u7684\u4e3b\u8981\u662f\u7c7bUnix\/Linux\u5e73\u53f0\uff08POSIX\u6807\u51c6\uff09\u7684\u4ee3\u7801\u6bb5\uff0c\u6240\u4ee5\u4e0b\u9762\u7684\u5f88\u591a\u4ee3\u7801\u6bb5\u4e5f\u662f\u5220\u9664\u76f8\u5173\u517c\u5bb9\u6027\u4ee3\u7801\u7684\u3002\u672c\u6587InnoDB\u6e90\u7801\u662fPlugin1.0.6\u7248\u672c\u3002<!--more--><\/p>\n<div class=\"myt1\">1. InnoDB\u591a\u7ebf\u7a0b\u5e76\u53d1\u8bbf\u95ee<\/div>\n<p>MySQL\u662f\u4e00\u4e2a\u591a\u7ebf\u7a0b\u7684\u5b9e\u73b0\u7684<a href=\"http:\/\/en.wikipedia.org\/wiki\/Database_management_system\">DBMS<\/a>\uff0c\u591a\u7ebf\u7a0b\u7f16\u7a0b\u9700\u8981\u89e3\u51b3\u7684\u4e00\u4e2a\u91cd\u8981\u95ee\u9898\u5c31\u662f\u7ebf\u7a0b\u95f4\u5e76\u53d1\u8bbf\u95ee\u7684\u63a7\u5236\u3002\u4e00\u822c\u67d0\u4e2a\u7ebf\u7a0b\u66f4\u6539\u9700\u8981\u66f4\u6539\u67d0\u4e2a\u5185\u5b58\u5757\uff08\u53d8\u91cf\uff09\u65f6\uff0c\u9996\u5148\u8981\u5148\u5c06\u6570\u636e\u4ece\u5185\u5b58\u8bfb\u53d6\u5230\u5bc4\u5b58\u5668\uff0c\u7136\u540e\u8ba1\u7b97\u66f4\u6539\u4e4b\uff0c\u6700\u540e\u56de\u5199\u5230\u5185\u5b58\u5757\u3002\u5982\u679c\u6709<strong>\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6<\/strong>\u5728\u4fee\u6539\u5185\u5b58\u5757\uff0c\u800c\u4e14\u8bfb\u53d6\u540c\u65f6\uff08\u201c\u540c\u65f6\u201d\u8868\u793a\u5728\u4e24\u4e2a\u7ebf\u7a0b\u4fee\u6539\u8be5\u503c\u4e4b\u524d\u8bfb\u53d6\uff09\u53d1\u751f\uff0c\u90a3\u4e48\u4e24\u4e2a\u7ebf\u7a0b\u5c06\u6709\u4e00\u4e2a\u4f1a\u4e22\u5931\u4fee\u6539\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u5e0c\u671b\u4fdd\u6301\u5185\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\u201c\u4e00\u81f4\u201d\u3001\u201c\u51c6\u786e\u201d\u65f6\uff0c\u7ebf\u7a0b\u5728\u64cd\u4f5c\u8fd9\u4e9b\u53d8\u91cf\u65f6\uff0c\u9700\u8981\u5148\u83b7\u53d6\u5bf9\u5e94\u7684\u9501\u3002\u5229\u7528\u5404\u4e2a\u53d8\u91cf\u5bf9\u5e94\u7684\u201c\u9501\u673a\u5236\u201d\u6765\u4fdd\u8bc1\u6570\u636e\u8bbf\u95ee\u7684\u5e76\u53d1\u63a7\u5236\u3002<\/p>\n<div class=\"myt1\">2. \u57fa\u672c\u539f\u7406\uff1aPosix thread<\/div>\n<p>\u591a\u7ebf\u7a0b\u5e76\u53d1\u8bbf\u95ee\u63a7\u5236\u4e2d\uff0cInnoDB\u4f7f\u7528\u6807\u51c6<a href=\"http:\/\/www.yolinux.com\/TUTORIALS\/LinuxTutorialPosixThreads.html\">POSIX\u7ebf\u7a0b\u6a21\u578b<\/a>\u4e2d\u7684mutex\uff08condition variable\uff09\u5b9e\u73b0\u57fa\u672c\u7684\u6392\u4ed6\u8bbf\u95ee\u3002\u5728\u5bf9mutex\uff08condition variable\uff09\u7684\u5c01\u88c5\u7684\u57fa\u7840\u4e0a\uff0c\u53c8\u5b9e\u73b0\u4e86\u76f8\u5e94\u7684\u8bfb\u5199\u9501\u3002<\/p>\n<div class=\"myt2\">2.1 os_fast_mutex_t VS pthread_mutex_t<\/div>\n<p>pthread_mutex_t\u5c01\u88c5\u5728os_fast_mutex_t\u4e2d\uff0ccondition variable\u5219\u5c01\u88c5\u5728\u4e86os_event_struct\u4e2d\u3002<\/p>\n<div class=\"mycode\">typedef pthread_mutex_t\tos_fast_mutex_t;<\/div>\n<p>\u5bf9\u5e94\u7684mutex\u64cd\u4f5c\u5206\u522b\u5c01\u88c5\u5728\u4e86os_fast_mutex_init \/ os_fast_mutex_lock \/ os_fast_mutex_unlock \/ os_fast_mutex_free\u4e2d\uff0c\u8fd9\u91cc\u6211\u4eec\u770b\u770bos_fast_mutex_trylock\u7684\u5c01\u88c5\u51fd\u6570\u5b9e\u73b0\uff1a<\/p>\n<pre><div class=\"mycode\">ulint os_fast_mutex_trylock(\r\n\tos_fast_mutex_t*\tfast_mutex)\r\n{\r\n#ifdef __WIN__\r\n\tEnterCriticalSection(fast_mutex);\r\n\treturn(0);\r\n#else\r\n\treturn((ulint) pthread_mutex_trylock(fast_mutex));\r\n#endif\r\n}<\/div><\/pre>\n<div class=\"myt2\">2.2 os_event_struct VS condition variable<\/div>\n<p>Condition variable\u8f83\u4e4bpthread_mutex_t\u8981\u590d\u6742\u4e00\u70b9\uff0c\u5bf9\u5e94\u7684\u5c01\u88c5\u4e5f\u66f4\u590d\u6742\u3002os_event_struct\u5c01\u88c5\u4e86condition variable\u5168\u90e8\u64cd\u4f5c\uff0c\u4e3b\u8981\u5305\u62ec\u521d\u59cb\u5316\uff0c\u9677\u5165\u7b49\u5f85\uff0c\u5e7f\u64ad\u5524\u9192\uff1aos_event_create\uff08\u521d\u59cb\u5316\uff09\/os_event_wait_low\uff08\u7b49\u5f85\uff09\/os_event_set\uff08\u5e7f\u64ad\u5524\u9192\uff09\u3002\u4e0b\u9762\u662f\u57fa\u672c\u6570\u636e\u7ed3\u6784struct os_event_struct\uff1a<\/p>\n<pre><div class=\"mycode\">struct os_event_struct {\r\n\tos_fast_mutex_t\tos_mutex;\r\n\tibool\t\tis_set;\t\t\r\n\tib_longlong\tsignal_count;\t\r\n\tpthread_cond_t\tcond_var;\t\/* condition variable is used in\r\n\t\t\t\t\twaiting for the event *\/\r\n        ......\r\n};<\/div><\/pre>\n<p>\u8fd9\u91cc\u62bd\u53d6\u4e00\u4e2a\u5e7f\u64ad\u5524\u9192\u5f00\u51fd\u6570os_event_set\u770b\u770b\uff1a<\/p>\n<pre><div class=\"mycode\">void os_event_set(\r\n\tos_event_t\tevent)\t\/*!< in: event to set *\/\r\n{\r\n\tos_fast_mutex_lock(&#038;(event->os_mutex));\r\n\tif (event->is_set) {\r\n\t\t\/* Do nothing *\/\r\n\t} else {\r\n\t\tevent->is_set = TRUE;\r\n\t\tevent->signal_count += 1;\r\n\t\tut_a(0 == <strong>pthread_cond_broadcast<\/strong>(&(event->cond_var)));\r\n\t}\r\n\tos_fast_mutex_unlock(&(event->os_mutex));\r\n}<\/div><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\u4e0a\u9762\u51fd\u6570\uff0c\u6ca1\u6709\u4ec0\u4e48\u795e\u79d8\u7684\u5730\u65b9\uff0c\u5c31\u662f\u5224\u65ad\u4e86\u4e00\u4e0b\u662f\u5426\u9700\u8981\u5e7f\u64ad\uff0c\u7136\u540e\u8c03\u7528\u4e86pthread_cond_broadcast\u51fd\u6570\u5e7f\u64ad\u3002<\/p>\n<p>\u6570\u636e\u7ed3\u6784os_fast_mutex_t\u548cos_event_t\u770b\u5230\uff0cInnoDB\u5e76\u4e0d\u662f\u90a3\u4e48\u590d\u6742\uff0c\u4f46\u662f\u9700\u8981\u5bf9Linux\uff08\u6216\u8005\u8bf4POSIX\uff09\u6709\u4e00\u5b9a\u7684\u7406\u89e3\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u7b97\u662f\u6700\u5e95\u5c42\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4e8b\u5b9e\u4e0a\uff0c\u8fd9\u4e2a\u5c01\u88c5\u8fd8\u6ca1\u7ed3\u675f\uff0cInnoDB\u5176\u4ed6\u6a21\u5757\u4e2d\u7528\u7684\u8f83\u591a\u7684\u662fmutex_struct\u548crw_lock\u7ed3\u6784\uff0cmutex_t\u662f\u5bf9os_event_t\u5c01\u88c5\uff0crw_lock\u662f\u5bf9mutex_t\u7684\u5c01\u88c5\u3002<\/p>\n<div class=\"myt1\">3. \u524d\u594f\uff1amutex_struct<\/div>\n<div class=\"myt2\">3.1 mutex_struct\u7684\u4e00\u822c\u8bf4\u660e<\/div>\n<pre><div class=\"mycode\">struct mutex_struct {\r\n\tos_event_t\tevent;\t\/* Used by sync0arr.c for the wait queue *\/\r\n\tulint\tlock_word;\t\/* This ulint is the target of the atomic\r\n\t\t\t\ttest-and-set instruction in Win32 *\/\r\n\tulint\twaiters;\t\/\/\u5982\u679c\u6709\u7ebf\u7a0b\u5728\u7b49\u5f85\uff0c\u8bbe\u7f6e\u4e3a1\r\n\tUT_LIST_NODE_T(mutex_t)\tlist; \r\n\tconst char*\tcfile_name;\/* File name where mutex created *\/\r\n\tulint\t\tcline;\t\/* Line where created *\/\r\n#ifndef UNIV_HOTBACKUP\r\n\tulong\t\tcount_os_wait; \/* count of os_wait *\/\r\n#endif \/* !UNIV_HOTBACKUP *\/\r\n};<\/div><\/pre>\n<p>mutex_struct\u76f8\u5173\u7684\u51fd\u6570\u6709\u5f88\u591a\uff0c\u4e00\u822c\u9700\u8981\u4f7f\u7528\u7684\u6709\uff1amutex_create\u3001mutex_enter\u3001mutex_exit\uff1b\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u7684\u51fd\u6570\uff1amutex_spin_wait\u3001mutex_free\u3001mutex_signal_object\u3002<\/p>\n<div class=\"myt2\">3.2 mutex_struct\u7684\u5178\u578b\u7528\u6cd5<\/div>\n<p>InnoDB\u4e2d\u4e00\u4e2a\u5178\u578b\u7684mutex_struct\u4f7f\u7528\u5982\u4e0b\uff1a<\/p>\n<pre><div class=\"mycode\">mutex_create(&rw_lock_list_mutex);\r\nmutex_enter(&rw_lock_list_mutex);\r\n...\r\n\/\/\u8fd9\u91cc\uff0c\u5bf9rw_lock_list_mutex\u6240\u4fdd\u62a4\u7684\u5bf9\u8c61\uff0c\u8fd9\u91cc\u53ef\u4ee5\u8fdb\u884c\u4e00\u81f4\u7684\u3001\u6392\u4ed6\u64cd\u4f5c\r\n...\r\nmutex_exit(&rw_lock_list_mutex);<\/div><\/pre>\n<p>mutex_create\u51fd\u6570\u76f8\u5bf9\u7b80\u5355\uff0c\u505a\u4e86\u4e00\u4e9b\u521d\u59cb\u5316\u7684\u5de5\u4f5c\u3002\u6211\u4eec\u7ee7\u7eed\u6cbf\u7740\u7ebf\u7d22\u6765\u770b\u770bmutex_enter\u7684\u5b9e\u73b0\u3002\u8fd9\u4e2a\u51fd\u6570\u5b9e\u73b0\uff1a<\/p>\n<pre><div class=\"mycode\">typedef struct mutex_struct\t\tmutex_t;\r\nvoid mutex_enter_func(\r\n\tmutex_t* mutex, const char*  file_name, ulint  line)\r\n{\r\n\tut_d(mutex->count_using++);\r\n\tif (!mutex_test_and_set(mutex)) {\r\n\t\tut_d(mutex->thread_id = os_thread_get_curr_id());\r\n\t\treturn;\t\/* Succeeded! *\/\r\n\t}\r\n\tmutex_spin_wait(mutex, file_name, line);\r\n}<\/div><\/pre>\n<p>\u4ee3\u7801\u8bf4\u660e\uff1a\u9996\u5148\uff0c\u5c1d\u8bd5\u4f7f\u7528mutex_test_and_set\uff08\u8fd9\u662f\u5bf9os_fast_mutex_trylock\u7684\u5c01\u88c5\uff09\u83b7\u5f97\u9501\uff0c\u6210\u529f\u5219\u8fd4\u56de\u3002\u5931\u8d25\uff0c\u5219\u8c03\u7528mutex_spin_wait\u9677\u5165\u201cspin lock\u7684\u65b9\u5f0f\u201d\u83b7\u53d6\u9501\u3002spin lock\u7684\u65b9\u5f0f\u662f\u6307\uff0c\u81ea\u5df1\u4e0d\u91ca\u653ecpu\u8d44\u6e90\uff0c\u800c\u662f\u81ea\u5df1\u7a7a\u5faa\u73af\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u5728\u91cd\u65b0\u5c1d\u8bd5\u83b7\u53d6\u9501\u3002<\/p>\n<div class=\"myt2\">3.3 \u7ee7\u7eed\u6df1\u5165\uff1amutex_spin_wait<\/div>\n<p>\u7ebf\u7d22\u5230\u4e86mutex_spin_wait\u4e86\uff0c\u8be5\u51fd\u6570\u662fInnoDB\u91cc\u9762\u5b9e\u73b0\u4e86spin lock\u7684\u4e3b\u8981\u90e8\u5206\u3002\u8fd9\u91cc\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u539f\u7406\uff1a\u9996\u5148\u7ebf\u7a0b\u68c0\u67e5lock_word\uff0c\u5982\u679c\u88ab\u8bbe\u7f6e0\uff08\u8868\u793a\u5f53\u524d\u5e76\u6ca1\u6709\u53d8\u91cf\u5e76\u6ca1\u6709\u88ab\u9501\u4f4f\uff09\uff0c\u5219\u76f4\u63a5\u8c03\u7528mutex_test_and_set\uff08\u5176\u5b9e\u662fos_fast_mutex_trylock\uff09\u6765\u5c1d\u8bd5\u83b7\u53d6\u9501\u3002\u5982\u679clock_word=1\u90a3\u4e48\uff0c\u5219\u8868\u793a\u5f53\u524d\u7684\u9501\u5df2\u7ecf\u88ab\u67d0\u4e2a\u7ebf\u7a0b\u83b7\u53d6\uff0c\u5219\u7ebf\u7a0b\u8fdb\u5165\u7a7a\u5faa\u73af\uff0c\u5ef6\u8fdf\u4e00\u6bb5\u65f6\u95f4\uff08spin lock\uff09\uff0c\u7b49\u5f85lock_word\u88ab\u8bbe\u7f6e\u4e3a0\u540e\uff0c\u7acb\u523b\u8c03\u7528mutex_test_and_set\u5c1d\u8bd5\u83b7\u53d6\u9501\u3002\u5982\u679clock_word\u4e00\u76f41\uff08\u9501\u4e00\u76f4\u5728\u88ab\u5360\u7528\uff09\uff0c\u90a3\u4e48\u7ebf\u7a0b\u5c06\u5728\u5ef6\u8fdfSYNC_SPIN_ROUNDS\u4e2a\u5355\u4f4d\u65f6\u95f4\u540e\uff0c\u7ebf\u7a0b\u5c06\u5c1d\u8bd5\u8c03\u7528mutex_test_and_set\u4e00\u6b21\uff08\u78b0\u8fd0\u6c14\uff09\uff0c\u5982\u679c\u4ecd\u5931\u8d25\uff0c\u8fd9\u65f6\u7ebf\u7a0b\u5c06\u9677\u5165\u7b49\u5f85\uff08\u8fd9\u65f6Condition variables\u5f00\u59cb\u767b\u4e0a\u821e\u53f0\uff09\uff0c\u5982\u679c\u5176\u4ed6\u7ebf\u7a0b\u91ca\u653e\u8be5\u9501\uff0c\u5219\u4f1a\u5c06lock_word\u88ab\u8bbe\u7f6e\u4e3a0\uff0c\u5e76\u8fdb\u884c\u4e00\u6b21\u5e7f\u64ad\uff0c\u90a3\u4e48\u524d\u9762\u9677\u5165\u7b49\u5f85\u7684\u7ebf\u7a0b\u5c06\u4f1a\u88ab\u5524\u9192\uff0c\u5e76\u91cd\u65b0\u8c03\u7528mutex_test_and_set\u5c1d\u8bd5\u83b7\u53d6\u9501\u3002<\/p>\n<p>\u4e0b\u9762\u662fmutex_spin_wait\u7684\u4e00\u4e2a\u7b80\u5355\u6d41\u7a0b\u56fe\uff1a<\/p>\n<p><a href=\"http:\/\/www.flickr.com\/photos\/26825745@N06\/4748692857\/\" title=\"mutex_spin_wait_v3 by orczhou, on Flickr\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/farm5.static.flickr.com\/4121\/4748692857_19d8c453be.jpg\" width=\"500\" height=\"449\" alt=\"mutex_spin_wait_v3\"><\/a><\/p>\n<div class=\"myt2\">3.4 \u5c0f\u7ed3mutex_struct<\/div>\n<p>\u518d\u56de\u5934\u770b\u770bmutex_struct\u7684\u4e00\u822c\u4f7f\u7528\u65b9\u6cd5\uff0c\u5148\u662fmutex_create\uff0c\u7136\u540e\u662fmutex_enter\uff0c\u6700\u540e\u662fmutex_exit\uff0c\u8be5\u51fd\u6570\u4f1a\u8c03\u7528os_event_set\u8fdb\u884c\u4e00\u6b21\u5e7f\u64ad\uff08\u5e7f\u64ad\u51fd\u6570\u672c\u8eab\u662f\u4f1a\u91ca\u653epthread_mutex_t\u7684\uff09\u3002<\/p>\n<div class=\"myt1\">4. \u4f11\u606f\u4e00\u4f1a\u513f<\/div>\n<p>\u81f3\u6b64\uff0c\u6211\u4eec\u770b\u5230\uff0cInnoDB\u4e00\u822c\u901a\u8fc7\u6570\u636e\u7ed3\u6784mutex_struct\u6765\u5b9e\u73b0\u5bf9\u5185\u5b58\u5757\uff08\u53d8\u91cf\uff09\u7684\u5b8c\u5168\u6392\u4ed6\u8bbf\u95ee\u3002\u5982\u679c\u53ea\u662f\u6392\u4ed6\u8bbf\u95ee\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6548\u7387\u8f83\u4f4e\uff0c\u56e0\u4e3a\u5f88\u591a\u65f6\u5019\uff0c\u4e0d\u9700\u8981\u6392\u4ed6\uff0c\u53ea\u9700\u8981\u5171\u4eab\u65b9\u5f0f\u8bbf\u95ee\u5c31\u53ef\u4ee5\u4e86\u3002InnoDB\u5728mutex_struct\u57fa\u7840\u4e0a\uff0c\u518d\u505a\u4e86\u4e00\u6b21\u5c01\u88c5\uff0c\u5bf9\u5e94\u7684\u6570\u636e\u7ed3\u6784\u4e3arw_lock_struct\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u8fd9\u7bc7\u6587\u7ae0\u5df2\u7ecf\u591f\u957f\u4e86&#8230;.\u6b32\u77e5\u540e\u4e8b\u5982\u4f55\uff0c\u4e14\u542c\u4e0b\u56de\u5206\u89e3\u3002<\/p>\n<p>\u5e7f\u544a\u65f6\u95f4\uff1a<a href=\"http:\/\/www.orczhou.com\/index.php\/projects\/we-are-hunting-mysql-hacker\/\">\u5de5\u4f5c\u673a\u4f1a&#8211;MySQL Hacker<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u4e3aDBA\u5173\u5fc3\u7684\u66f4\u591a\u7684\u53ef\u80fd\u662f\u539f\u7406\u3001\u673a\u5236\uff0c\u5bf9\u4e8e\u6e90\u7801\u4e00\u822c\u5927\u5bb6\u4e5f\u4e0d\u662f\u7279\u522b\u5173\u5fc3\uff0c\u4e5f\u4e0d\u592a\u7528\u5f97\u4e0a\u3002\u800c\u4e14\u5bf9\u4e8e\u5bf9\u4e8e\u6e90\u4ee3\u7801\u7ea7\u522b\u7684\u7ec6\u8282\u4e5f\u5f88\u96be\u7528\u6587\u5b57\u8868\u8fbe\u81ea\u5df1\u7684\u7406\u89e3\uff0c\u6700\u7ec8\u7406\u89e3\u5fc5\u987b\u8fd8\u662f\u9700\u8981\u81ea\u5df1\u53bb\u770b\u770b\u6bcf\u4e00\u884c\u4ee3\u7801\u5230\u5e95\u662f\u600e\u6837\u7684\u3002\u4e5f\u8bfb\u8fc7\u300aUnderstanding.MySQL.Internals\u300b\u7684\u5927\u90e8\u5206\u7ae0\u8282\uff0c\u4f5c\u8005\u4e5f\u662f\u504f\u91cd\u4e8e\u4ece\u4ee3\u7801\u7684\u5b9e\u73b0\u76ee\u7684\uff08\u539f\u7406\u3001\u673a\u5236\uff09\u6765\u4ecb\u7ecd\u7684\uff0c\u56fd\u5185\u7684\u300aMySQL\u6838\u5fc3\u5185\u5e55\u300b\uff08\u4e2a\u4eba\u5bf9\u4e8e\u201c\u6838\u5fc3\u5185\u5e55\u201d\u8fd9\u4e2a\u8bcd\u6709\u83ab\u540d\u7684\u53cd\u611f\uff09\u7b97\u662f\u66f4\u591a\u7684\u4ece\u6e90\u7801\u5f00\u59cb\u4ecb\u7ecdMySQL\u4e86\uff0c\u53ef\u662f\u8fd9\u672c\u4e66\u4e5f\u8bb8\u662f\u6388\u4e88\u7bc7\u5e45\u7684\u9650\u5236\uff0c\u4ecb\u7ecd\u7684\u4e1c\u897f\u4e5f\u5e76\u4e0d\u591a\u3002 \u5f00\u59cb\u5199\u8fd9\u7bc7\u6587\u7ae0\uff0c\u4e0d\u80fd\u671f\u5f85\u81ea\u5df1\u80fd\u5199\u591a\u5c11\uff0c\u4e5f\u4e0d\u80fd\u671f\u5f85\u81ea\u5df1\u80fd\u7814\u7a76\u591a\u5c11\uff0c\u4e0d\u8fc7\u81f3\u5c11\u8d70\u51fa\u4e86\u81ea\u5df1\u63a2\u7d22\u7684\u7b2c\u4e00\u6b65\u3002\u6587\u7ae0\u7684\u5b97\u65e8\u4e0d\u5728\u4e8e\u80fd\u591f\u591a\u4e48\u7ec6\u81f4\u7684\u5206\u6790MySQL\u7684\u6e90\u4ee3\u7801\uff0c\u800c\u662f\u5e0c\u671b\u80fd\u7ed9\u81ea\u5df1\uff0c\u80fd\u7ed9\u4ed6\u4eba\u6253\u5f00\u8d70\u5411\u6e90\u4ee3\u7801\u7684\u7b2c\u4e00\u9053\u95e8\u3002 \u6211\u662fBNU\u6570\u5b66\u7cfb\u6bd5\u4e1a\u7684\uff0c\u5bf9C\u8bed\u8a00\u77e5\u9053\u751a\u5c11\uff0cC\u8bed\u8a00\u7684\u7ecf\u5386\u5927\u6982\u5c31\u662f\u201c\u8ba1\u7b97\u65b9\u6cd5\u201d\u8bfe\u7a0b\u4e2d\u5b9e\u73b0\u7684\u6c42\u89e3\u5404\u79cd\u65b9\u7a0b\u7684\u6487\u811a\u7a0b\u5e8f\u4e86\u3002\u6240\u4ee5\u867d\u7136\u6211\u4f1a\u6781\u529b\u907f\u514d\u9519\u8bef\uff0c\u4f46\u662f\u76f8\u4fe1\u8fd8\u662f\u4f1a\u72af\u4e00\u5806\u9519\u8bef\uff0c\u5e0c\u671b\u5404\u4f4d\u770b\u5b98\u80fd\u591f\u5bbd\u5bb9\u70b9\uff0c\u6709\u9519\u8bef\u6307\u51fa\u6765\uff0c\u6162\u6162\u6539\u6b63\u3002 0. \u5f00\u59cb InnoDB\u7684\u4ee3\u7801\u901a\u8fc7\u5b8f\u5b9a\u4e49\u8003\u8651\u5f88\u591a\u5e73\u53f0\u7684\u517c\u5bb9\u95ee\u9898\uff0c\u8fd9\u91cc\u5206\u6790\u7684\u4e3b\u8981\u662f\u7c7bUnix\/Linux\u5e73\u53f0\uff08POSIX\u6807\u51c6\uff09\u7684\u4ee3\u7801\u6bb5\uff0c\u6240\u4ee5\u4e0b\u9762\u7684\u5f88\u591a\u4ee3\u7801\u6bb5\u4e5f\u662f\u5220\u9664\u76f8\u5173\u517c\u5bb9\u6027\u4ee3\u7801\u7684\u3002\u672c\u6587InnoDB\u6e90\u7801\u662fPlugin1.0.6\u7248\u672c\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","inline_featured_image":false,"_tocer_settings":[],"footnotes":""},"categories":[6,5],"tags":[120,118,58],"class_list":["post-2173","post","type-post","status-publish","format-standard","hentry","category-mysql","category-code-staff","tag-innodb","tag-mysql","tag-source-code"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=2173"}],"version-history":[{"count":28,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2173\/revisions"}],"predecessor-version":[{"id":2651,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2173\/revisions\/2651"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=2173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=2173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=2173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}