{"id":1018,"date":"2022-03-26T15:25:05","date_gmt":"2022-03-26T07:25:05","guid":{"rendered":"https:\/\/www.buyao007.icu\/?p=1018"},"modified":"2022-03-26T15:25:07","modified_gmt":"2022-03-26T07:25:07","slug":"11-innodb%e6%a0%b8%e5%bf%83%e7%89%b9%e6%80%a7-%e4%ba%8b%e5%8a%a1%e6%94%af%e6%8c%81%ef%bf%bc","status":"publish","type":"post","link":"https:\/\/www.buyao007.icu\/?p=1018","title":{"rendered":"11. InnoDB\u6838\u5fc3\u7279\u6027\u2014\u4e8b\u52a1\u652f\u6301\ufffc"},"content":{"rendered":"\n<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6\u7fa4\u67b6\u6784\u4e0e\u81ea\u52a8\u5316\u8fd0\u7ef4\uff0c\u66fe\u8d1f\u8d23\u56fd\u5185\u67d0\u5927\u578b\u535a\u5ba2\u7f51\u7ad9\u8fd0\u7ef4\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">1.\u4e8b\u52a1\u4ecb\u7ecd<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4e8b\u52a1\uff1aTransaction\uff08\u4ea4\u6613\uff09\u3002\u4f34\u968f\u7740\u4ea4\u6613\u7c7b\u7684\u4e1a\u52a1\u51fa\u73b0\u7684\u6982\u5ff5\uff08\u5de5\u4f5c\u6a21\u5f0f\uff09\r\n\u4ea4\u6613\uff1f\r\n\t\t\u7269\u6362\u7269\uff0c\u7b49\u4ef7\u4ea4\u6362\r\n\t\t\u8d27\u5e01\u6362\u7269\uff0c\u7b49\u4ef7\u4ea4\u6362\r\n\t\t\u865a\u62df\u8d27\u5e01\u6362\u7269\uff08\u865a\u62df\u7269\u54c1\uff09\uff0c\u7b49\u4ef7\u4ea4\u6362\r\n\u73b0\u5b9e\u751f\u6d3b\u4e2d\u600e\u4e48\u4fdd\u8bc1\u4ea4\u6613\u548c\u8c10\uff0c\u6709\u6cd5\u5f8b\u9053\u5fb7\u7b49\u89c4\u5219\u7ea6\u675f\r\n\u6570\u636e\u5e93\u4e2d\u4e3a\u4e86\u4fdd\u8bc1\u7ebf\u4e0a\u4ea4\u6613\u7684\u548c\u8c10\uff0c\u52a0\u5165\u4e86\u4e8b\u52a1\u5de5\u4f5c\u673a\u5236\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">2.\u4e8b\u52a1ACID\u7279\u6027\u7b80\u4ecb<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>A\uff1aatomicity\u539f\u5b50\u6027<\/strong>\r\n\u4e00\u4e2a\u4e8b\u52a1\u662f\u4e00\u4e2a\u5b8c\u6574\u6574\u4f53\uff0c\u4e0d\u53ef\u518d\u5206\r\n\u4e00\u4e2a\u4e8b\u52a1\u4e2d\u6240\u6709\u7684DML\u8bed\u53e5\u8981\u4e48\u5168\u6267\u884c\u6210\u529f\uff0c\u8981\u4e48\u5168\u5931\u8d25\r\n<strong>C:consistency\u4e00\u81f4\u6027<\/strong>\r\n\u4e8b\u52a1\u5de5\u4f5c\u524d\u4e2d\u540e\uff0c\u6570\u636e\u6700\u7ec8\u4e00\u81f4\r\n\u53ea\u8981\u4e8b\u52a1\u63d0\u4ea4\u6210\u529f\uff0c\u6570\u636e\u4fdd\u8bc1\u6700\u7ec8\u4e00\u81f4\r\n<strong>I:isolation\u9694\u79bb\u6027<\/strong>\r\n\u4e8b\u52a1\u548c\u4e8b\u52a1\u5de5\u4f5c\u8fc7\u7a0b\u4e2d\u662f\u4e92\u4e0d\u5f71\u54cd\u7684\r\n<strong>D:durability\u6301\u4e45\u6027<\/strong>\r\n\u5df2\u7ecf\u63d0\u4ea4\u7684\u4e8b\u52a1\uff0c\u4fdd\u8bc1\u843d\u76d8\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">3.\u4e8b\u52a1\u7684\u751f\u547d\u5468\u671f<\/h2>\n\n\n\n<p><strong><em>1.\u6807\u51c6\u4e8b\u52a1\u63a7\u5236\u8bed\u53e5<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>begin \u5f00\u542f\u4e8b\u52a1\r\ncommit \u63d0\u4ea4\u4e8b\u52a1\uff0c\u4e8b\u52a1\u7ed3\u675f##\u63d0\u4ea4\u540e\u4e0d\u80fd\u4f7f\u7528roolback\u8fdb\u884c\u56de\u5f52\r\nroolback \u56de\u6eda\u4e8b\u52a1\uff0c\u4e8b\u52a1\u7ed3\u675f\r<\/code><\/pre>\n\n\n\n<p><strong><em>2.\u81ea\u52a8\u63d0\u4ea4\u673a\u5236<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>autocommit#\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6267\u884c\u4e00\u4e2a\u8bed\u53e5\u63d0\u4ea4\u4e00\u6b21\r\n\u67e5\u8be2\u662f\u5426\u5f00\u542f\u81ea\u52a8\u63d0\u4ea4mysql> select @@autocommit\uff1b\r<\/code><\/pre>\n\n\n\n<p><strong><em>3.\u9690\u5f0f\u63d0\u4ea4<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6267\u884c\u4e86begin\u4e4b\u540e\uff0c\u518d\u6b21\u6267\u884cbegin\u4f1a\u81ea\u52a8\u63d0\u4ea4\r\n\u8fd8\u6709\u4ee5\u4e0b\u4e5f\u4f1a\u89e6\u53d1\u81ea\u52a8\u63d0\u4ea4\r\nDDL\u8bed\u53e5\uff1a\uff08ALTER\u3001CREATE\u3001DROP\uff09\r\nDCL\u8bed\u53e5\uff1a\uff08GRANTE\u3001REVOKE\u548cSET PASSWORD\uff09\r\n\u9501\u5b9a\u8bed\u53e5\uff1a\uff08LOCK TABLES\u548cUNLOCK TABLES\uff09\r\n\u5bfc\u81f4\u9690\u5f0f\u63d0\u4ea4\u7684\u8bed\u53e5\u793a\u4f8b\uff1a\r\nTruncate table\r\nLoad data infile\r\nSelect for update\r<\/code><\/pre>\n\n\n\n<p><strong><em>4.\u9690\u5f0f\u56de\u6eda<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4f1a\u8bdd\u7a97\u53e3\u88ab\u5173\u95ed\r\n\u6570\u636e\u5e93\u5173\u95ed\r\n\u51fa\u73b0\u4e8b\u52a1\u51b2\u7a81\uff08\u6b7b\u9501\uff09\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">4.\u4e8b\u52a1\u7684\u9694\u79bb\u7ea7\u522b<\/h2>\n\n\n\n<p><strong><em>1.\u4f5c\u7528<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5b9e\u73b0\u4e8b\u52a1\u5de5\u4f5c\u671f\u95f4\u7684\u201c\u8bfb\"\u7684\u9694\u79bb\r\n\u8bfb?----\u300b\u6570\u636e\u9875\u7684\u8bfb\r<\/code><\/pre>\n\n\n\n<p><strong><em>2.\u7ea7\u522b\u7c7b\u578b<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql> select @atransaction_isolation;\r\n#RU : READ-UNCOMMITTED \u8bfb\u672a\u63d0\u4ea4\r\n\u53ef\u4ee5\u8bfb\u53d6\u5230\u4e8b\u52a1\u672a\u63d0\u4ea4\u7684\u6570\u636e\u3002\u5e76\u53d1\u9ad8\uff0c\u4f46\u9694\u79bb\u6027\u5dee\uff0c\u4f1a\u51fa\u73b0\u810f\u8bfb\uff08\u5f53\u524d\u5185\u5b58\u8bfb\uff09\uff0c\u4e0d\u53ef\u91cd\u590d\u8bfb\uff0c\u5e7b\u8bfb\u95ee\u9898\r\n#RC : READ-COMMITTED\u8bfb\u5df2\u63d0\u4ea4(\u53ef\u4ee5\u7528):\r\n\u53ef\u4ee5\u8bfb\u53d6\u5230\u4e8b\u52a1\u5df2\u63d0\u4ea4\u7684\u6570\u636e\u3002\u5e76\u53d1\u8f83\u9ad8\uff0c\u9694\u79bb\u6027\u4e00\u822c\uff0c\u4e0d\u4f1a\u51fa\u73b0\u810f\u8bfb\u95ee\u9898\uff0c\u4f46\u662f\u4f1a\u51fa\u73b0\u4e0d\u53ef\u91cd\u590d\u8bfb\uff0c\u5e7b\u8bfb\u95ee\u9898\r\n#RR :REPEATABLE-READ\u53ef\u91cd\u590d\u8bfb\uff08\u9ed8\u8ba4\uff09:\r\n\u9632\u6b62\u810f\u8bfb\uff08\u5f53\u524d\u5185\u5b58\u8bfb\uff09\uff0c\u5e76\u53d1\u4e00\u822c\uff0c\u9632\u6b62\u4e0d\u53ef\u91cd\u590d\u8bfb\uff0c\u4f1a\u51fa\u73b0\u5e7b\u8bfb\u95ee\u9898\r\n#SR : SERIALIZABLE\u53ef\u4e32\u884c\u5316\r\n\u9694\u79bb\u6027\u6700\u597d\uff0c\u4f46\u6ca1\u6709\u5e76\u53d1\r\n\u7ed3\u8bba:\u9694\u79bb\u6027\u8d8a\u9ad8\uff0c\u4e8b\u52a1\u7684\u5e76\u53d1\u5ea6\u5c31\u8d8a\u5dee\u3002\r<\/code><\/pre>\n\n\n\n<p><strong><em>3.\u8bbe\u7f6e\u4e8b\u52a1\u7684\u7ea7\u522b\u7c7b\u578b<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u67e5\u8be2\r\nmysql> select @@transaction_isolation;\r\n\u4fee\u6539\r\nmysql> set global   transaction_isolation='READ-COMMITTED';\r\n\u5f53\u7136\u4e5f\u53ef\u4ee5\u5199\u5230\u914d\u7f6e\u6587\u4ef6\u91cc\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">5.\u4e8b\u52a1\u7684\u810f\u8bfb\u3001\u4e0d\u53ef\u91cd\u590d\u8bfb\u3001\u5e7b\u8bfb\u89e3\u91ca<\/h2>\n\n\n\n<p><strong><em>1.\u810f\u8bfb<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u9996\u5148\u5c06\u4e8b\u52a1\u7684\u9694\u79bb\u7ea7\u522b\u8c03\u6574\u4e3aru\u72b6\u6001\r\nmysql> set global   transaction_isolation='READ-UNCOMMITTED';\r\nmysql> set global autocommit=0;\r\n\u6253\u5f00\u4e24\u4e2amysql\u7a97\u53e3\r\n\u66f4\u65b0\u8868\u4e2d\u7684\u6570\u636e\uff0c\u672a\u63d0\u4ea4\u4e8b\u52a1\u3002\u4f46\u662f\u53e6\u4e00\u4e2a\u7a97\u53e3\u4e5f\u770b\u5230\u4e86\u672a\u63d0\u4ea4\u7684\u4e8b\u52a1\uff0c\u8fd9\u5c31\u662f\u810f\u8bfb\r<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"377\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-97.png\" alt=\"\" class=\"wp-image-1019\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-97.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-97-300x131.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-97-768x335.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<p><strong><em>2.\u4e0d\u53ef\u91cd\u590d\u8bfb<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u9996\u5148\u5c06\u4e8b\u52a1\u7684\u9694\u79bb\u7ea7\u522b\u8c03\u6574\u4e3arc\u72b6\u6001\r\nmysql> set global   transaction_isolation='READ-COMMITTED';\r\nmysql> set global autocommit=0;\r\n\u6253\u5f00\u4e24\u4e2amysql\u7a97\u53e3\r\nA\u7a97\u53e3\u6267\u884cupdate\u64cd\u4f5c\u672a\u63d0\u4ea4\u524dB\u7a97\u53e3\u67e5\u8be2\u4e0d\u5230\u66f4\u65b0\u7684\u6570\u636e\uff0c\u907f\u514d\u4e86\u810f\u8bfb\r<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"346\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-98.png\" alt=\"\" class=\"wp-image-1020\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-98.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-98-300x120.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-98-768x307.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><figcaption>\u4f46\u662fA\u7a97\u53e3\u518d\u6b21\u6267\u884c\u66f4\u65b0\u64cd\u4f5c,commit\u4e4b\u540e\uff0cB\u7a97\u53e3\u5728\u540c\u4e00\u4e8b\u7269\u4e2d\u80fd\u67e5\u8be2\u5230\u66f4\u65b0\u540e\u7684\u6570\u636e\uff0c\u5bfc\u81f4\u4e24\u6b21\u67e5\u8be2\u7ed3\u679c\u4e0d\u4e00\u81f4\uff0c\u8fd9\u5c31\u662f\u4e0d\u53ef\u91cd\u590d\u8bfb<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"365\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-99.png\" alt=\"\" class=\"wp-image-1021\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-99.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-99-300x127.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-99-768x324.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<p><strong><em>3.\u5e7b\u8bfb<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5e7b\u8bfb\u548c\u4e0d\u53ef\u91cd\u590d\u8bfb\u6709\u4e00\u5ff5\u4e4b\u5dee\r\n\u5e7b\u8bfb\u662fA\u7a97\u53e3\u6267\u884c\u66f4\u65b0\u64cd\u4f5c\u540e\uff0c\u5f53\u524d\u4e8b\u52a1\u8fd8\u672a\u7ed3\u675f\uff0c\u4f46\u662fB\u7a97\u53e3\u65b0\u63d2\u5165\u4e86\u4e00\u6761\u6570\u636e\uff0cA\u7a97\u53e3\u5728\u67e5\u8be2\u7684\u65f6\u5019\u67e5\u5230\u4e86B\u63d2\u5165\u7684\u6570\u636e\uff0cA\u5c31\u8ba4\u4e3a\u4e0a\u9762\u6267\u884c\u7684\u66f4\u65b0\u51fa\u73b0\u4e86\u95ee\u9898\uff0c\u8fd9\u5c31\u662f\u51fa\u73b0\u4e86\u5e7b\u8bfb\r<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"376\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-100.png\" alt=\"\" class=\"wp-image-1022\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-100.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-100-300x130.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-100-768x334.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">6.\u4e8b\u52a1\u7684\u5de5\u4f5c\u6d41\u7a0b\u539f\u7406\uff08ACID\u7279\u6027\u5982\u4f55\u4fdd\u8bc1\uff09<\/h2>\n\n\n\n<p><strong><em>1.\u540d\u8bcd\u4ecb\u7ecd<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u91cd\u505a\u65e5\u5fd7\uff08redo log\uff09<\/strong>\r\n\u78c1\u76d8\uff1aib_loggile0-N,\u53c2\u6570innodb_log_file_size\u548cinnodb_log_files_in_group\r\n\u5185\u5b58\uff1ainnodb_log_buffer\u53c2\u6570innodb_log_buffer_size\r\n<strong>\u8868\u6570\u636e<\/strong>\r\n\u78c1\u76d8\uff1a\u72ec\u7acb\u8868\u7a7a\u95f4xxx.ibd segment extents pages\r\n\u5185\u5b58\uff1ainnodb_buffer_pool  innodb_buffer_pool_size\r\n<strong>\u65e5\u5fd7\u5e8f\u5217\u53f7<\/strong>\r\n\u4e00\u4e2a\u987a\u5e8f\u9012\u589e\u7684\u6570\u5b57\uff0c\u8bb0\u5f55\u6570\u636e\u9875\u53d8\u5316\u7684\u7248\u672c\uff0credo\u65e5\u5fd7\u7684\u53d8\u5316\u91cf\uff08\u5b57\u8282\uff09\r\n\u90a3\u4e9b\u5bf9\u8c61\u6709\u65e5\u5fd7\u5e8f\u5217\u53f7\r\nRedo buffer\uff1aLog sequence number          111786856\r\nRedo log\uff1aLog flushed up to            111786856\r\n\u6570\u636e\u9875\uff1aLast checkpoint at           111786856\r\n\u67e5\u8be2\u65b9\u5f0f\r\nmysql> show engine innodb status \\G\r\n<strong>WAL\uff08write ahead log\uff09\u65e5\u5fd7\u5148\u884c<\/strong>\r\ncommit\u63d0\u4ea4\u4e8b\u52a1\u65f6\uff0c\u4fdd\u8bc1\u65e5\u5fd7\u5148\u5199\u78c1\u76d8\uff0c\u6570\u636e\u540e\u5199\r\n<strong>\u810f\u9875\uff08dirty page\uff09<\/strong>\r\n\u5728\u5185\u5b58\u4e2d\u4fee\u6539\u7684\u6570\u636e\u9875\uff0c\u6ca1\u5199\u5230\u78c1\u76d8\u7684\u53eb\u810f\u9875\r\n<strong>\u68c0\u67e5\u70b9\uff08checkpoint\uff09<\/strong>\r\n\u5c06\u810f\u9875\u5237\u65b0\u5230\u78c1\u76d8\u7684\u52a8\u4f5c\r\n<strong>DB_TRX_ID<\/strong>\r\n\u4e8b\u52a1\u7f16\u53f7 \u5b58\u50a8\u5728\u6570\u636e\u9875\u5934\u90e8\r\n<strong>DB_ROLL_PTR<\/strong>\r\n\u56de\u6eda\u6307\u9488 \u5b58\u50a8\u5728\u6570\u636e\u9875\u5934\u90e8\r<\/code><\/pre>\n\n\n\n<p><strong><em>2.\u4e8b\u52a1\u7684\u5de5\u4f5c\u6d41\u7a0b\u539f\u7406<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4e8b\u52a1\u4e3e\u4f8b:\r\nbegin;\r\nupdate t1 set A=2 where A=1;\r\ncommit;\r<\/code><\/pre>\n\n\n\n<p>1 redo log\u91cd\u505a\u65e5\u5fd7\u5982\u4f55\u5e94\u7528:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1.\u7528\u6237\u53d1\u8d77update\u4e8b\u52a1\u8bed\u53e5\uff0c\u5c06\u78c1\u76d8\u6570\u636e\u9875(page100,A=1,LSN=1000\uff09\u52a0\u8f7d\u5230\u5185\u5b58(buffer pool)\u7f13\u51b2\u533a\u3002\r\n2\uff0c\u5728\u5185\u5b58\u4e2d\u53d1\u751f\u6570\u636e\u9875\u4fee\u6539(A-1\u6539\u6210A=2)\uff0c\u5f62\u6210\u810f\u9875\uff0c\u66f4\u6539\u4e2d\u6570\u636e\u9875\u7684\u53d8\u5316\uff0c\u8bb0\u5f55\u5230redo buffer\u4e2d\uff0c\u52a0\u5165100\u4e2a\u5b57\u8282\u65e5\u5fd7\u3002LSI1-100+1=-200\u3002\r\n3.\u5f53commit\u8bed\u53e5\u6267\u884c\u65f6\uff0c\u57fa\u4e8eWAL\u673a\u5236\uff0c\u7b49\u5230redo buffer\u4e2d\u7684\u65e5\u5fd7\u5b8c\u5168\u843d\u76d8\u5230ib_logfilell\u4e2d\uff0ccommit\u6b63\u5f0f\u5b8c\u6210\u3002\r\n4. ib_logfileN\u4e2d\u8bb0\u5f55\u4e86\u4e00\u6761\u65e5\u5fd7\u3002\u5185\u5bb9: page100\u6570\u636e\u9875\u53d8\u5316+LSN=2000\u3002\r\n\r\n##\u60c5\u666f:\u5f53\u6b64\u65f6\uff0credo\u843d\u5730\u4e86\uff0c\u6570\u636e\u9875\u6ca1\u6709\u843d\u5730\uff0c\u5b95\u673a\u4e86\u3002\r\n1.MySQL CR\uff08\u81ea\u52a8\u6545\u969c\u6062\u590d\uff09\u5de5\u4f5c\u6a21\u5f0f\uff0c\u542f\u52a8\u6570\u636e\u5e93\u65f6\uff0c\u81ea\u52a8\u68c0\u67e5redo\u7684LSN\u548c\u6570\u636e\u9875LSN\u3002\r\n2\uff0e\u5982\u679c\u53d1\u73b0redoLSN>\u6570\u636e\u9875\u7684LSN \uff0c\u52a0\u8f7d\u539f\u59cb\u6570\u636e\u9875+\u53d8\u5316redo\u6307\u5b9a\u5185\u5b58\u3002\u4f7f\u7528redo\u91cd\u6784\u810f\u9875\uff08\u524d\u6eda\uff09\u3002\r\n3\uff0e\u5982\u679c\u786e\u8ba4\u6b64\u6b21\u4e8b\u52a1\u5df2\u7ecf\u63d0\u4ea4(commit\u6807\u7b7e\uff09\uff0c\u7acb\u5373\u89e6\u53d1CKPT\u52a8\u4f5c\uff0c\u5c06\u810f\u9875\u5237\u5199\u5230\u78c1\u76d8\u4e0a\u3002\r\n\r\n##\u8865\u5145\u4e00\u70b9:\r\nMySQL\u6709\u4e00\u79cd\u673a\u5236\uff0c\u6279\u91cf\u5237\u5199redo\u7684\u673a\u5236\u3002\u4f1a\u5728A\u4e8b\u52a1commit\u65f6\uff0c\u987a\u4fbf\u5c06redo buffer\u4e2d\u7684\u672a\u63d0\u4ea4\u7684redo\u65e5\u5fd7\u4e5f\u4e00\u5e76\u5267\u5230\u78c1\u76d8\r\n\u4e3a\u4e86\u533a\u5206\u4e0d\u540c\u72b6\u6001\u7684redo\uff0c\u65e5\u5fd7\u8bb0\u5f55\u65f6\uff0c\u4f1a\u6807\u8bb0\u662f\u5426COMMIT\u3002\r\n##redo\u4fdd\u8bc1\u4e86ACID\u54ea\u4e9b\u7279\u6027?\r\n\u4e3b\u8981\u662fD\u7684\u7279\u6027,\u53e6\u5916A\u3001C\u4e5f\u6709\u95f4\u63a5\u5173\u8054\u3002\r<\/code><\/pre>\n\n\n\n<p>2 undo log\u56de\u6eda\u65e5\u5fd7\u5982\u4f55\u5e94\u7528:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\uff0e\u4e8b\u52a1\u53d1\u751f\u6570\u636e\u9875\u4fee\u6539\u4e4b\u524d\uff0c\u4f1a\u7533\u8bf7\u4e00\u4e2aundo\u4e8b\u52a1\u64cd\u4f5c\uff0c\u4fdd\u5b58\u4e8b\u52a1\u56de\u6eda\u65e5\u5fd7\uff08\u9006\u5411\u64cd\u4f5c\u7684\u903b\u8f91\u65e5\u5fd7)\u3002\r\n2. undo\u5199\u5b8c\u4e4b\u540e\uff0c\u4e8b\u52a1\u4fee\u6539\u6570\u636e\u9875\u5934\u90e8\uff08\u4f1a\u8bb0\u5f55DB_TRX_ID+DB_ROLLl_PTR)\uff0c\u8fd9\u4e2a\u4fe1\u606f\u4e5f\u4f1a\u88ab\u8bb0\u5f55\u7684redo\u3002\r\n\u60c5\u666f1:\r\n\u5f53\u6267\u884crollback\u547d\u4ee4\u65f6\u3002\u6839\u636e\u6570\u636e\u9875\u7684DB_TRX_ID+DB_ROLL_PTR\u4fe1\u606f\uff0c\u627e\u5230undo\u65e5\u5fd7\uff0c\u8fdb\u884c\u56de\u6eda\u3002\r\n\r\n\u60c5\u666f2:\r\nbegin;\r\nupdate t1 set A=2 where A=1;\r\n\u5b95\u673a\u3002\r\n\r\n\u5047\u8bbe:undo\u6709, redo\u6ca1\u6709\r\n\u542f\u52a8\u6570\u636e\u5e93\u65f6\uff0c\u68c0\u67e5redo\u548c\u6570\u636e\u9875\u7684LSN\u53f7\u7801\u3002\u53d1\u73b0\u662f\u4e00\u81f4\u7684\u3002\r\n\u6240\u4ee5\u4e0d\u9700\u8981\u8fdb\u884credo\u7684\u524d\u6eda\uff0c\u6b64\u65f6\u4e5f\u4e0d\u9700\u8981\u56de\u6eda\u3002undo\u4fe1\u606f\u76f4\u63a5\u88ab\u6807\u8bb0\u4e3a\u53ef\u8986\u76d6\u72b6\u6001\u3002\r\n\r\n\u5047\u8bbe: undo\u6709\uff0credo\u4e5f\u6709(\u6ca1\u6709commit\u6807\u7b7e\u3002\uff09\r\n1.MySQL CR(\u81ea\u52a8\u6545\u969c\u6062\u590d\u3009\u5de5\u4f5c\u6a21\u5f0f\uff0c\u542f\u52a8\u6570\u636e\u5e93\u65f6\uff0c\u81ea\u52a8\u68c0\u67e5redo\u7684LSN\u548c\u6570\u636e\u9875LSN\u3002\r\n2\uff0e\u5982\u679c\u53d1\u73b0redoLSN>\u6570\u636e\u9875\u7684LSN\uff0c\u52a0\u8f7d\u539f\u59cb\u6570\u636e\u9875+\u53d8\u5316redo\u6307\u5b9a\u5185\u5b58\u3002\u4f7f\u7528redo\u91cd\u6784\u810f\u9875\uff08\u524d\u6eda\uff09\u3002\r\n3.\u5982\u679c\u786e\u8ba4\u6b64\u6b21\u4e8b\u52a1\u6ca1\u6709commit\u6807\u8bb0\uff0c\u7acb\u5373\u89e6\u53d1\u56de\u6eda\u64cd\u4f5c\uff0c\u6839\u636eDB_TRX_TO+OB_ROLL_PTR\u4fe1\u606f\uff0c\u627e\u5230und\u56de\u6eda\u65e5\u5fd7\uff0c\u5b9e\u73b0\u56de\u6eda\u3002\r\n\u4ee5\u4e0a\u6d41\u7a0b\u88ab\u79f0\u4e4b\u4e3aInnoOB\u7684\u6838\u5fc3\u7279\u6027:\u81ea\u52a8\u6545\u969c\u6062\u590d(Crash Recovery)\u3002\u5148\u524d\u6eda\u518d\u56de\u6eda\uff0c\u5148\u5e94\u7528redo\u518d\u5e94\u7528undo\u3002\r\n\r\n##undo\u5728ACID\u4e2d\u4fdd\u8bc1\u4e86\u5565?\r\n\u4e3b\u8981\u4fdd\u8bc1\u4e8b\u52a1\u7684A\u7684\u7279\u6027,\u540c\u65f6C\u548cI\u7684\u7279\u6027\u4e5f\u6709\u5173\u7cfb\u3002\r<\/code><\/pre>\n\n\n\n<p><strong><em>3.\u4e8b\u52a1\u4e2d\u7684C\u7279\u6027\u600e\u4e48\u4fdd\u8bc1?<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>InnoDB crash recovery:\u6570\u636e\u5e93\u610f\u5916\u5b95\u673a\u65f6\u523b\uff0c\u901a\u8fc7redo\u524d\u6eda+undo\u56de\u6eda\u4fdd\u8bc1\u6570\u636e\u7684\u6700\u7ec8\u4e00\u81f4\u3002\r\nInnoDB doublewrite buffer:\u9ed8\u8ba4\u5b58\u50a8\u5728ibdataN\u4e2d\u3002\u89e3\u51b3\u6570\u636e\u9875\u5199\u5165\u4e0d\u5b8c\u6574\r\nmysqld process crash in the middle of a page write\uff0cInd0B can find a good copy of the page from the doblewrite buffer during crash recvery.\r\nDWB\u4e00\u51712M\u3002\u5206\u4e24\u6b21\uff0c\u6bcf\u6b211M\u5199\u5165\r<\/code><\/pre>\n\n\n\n<p><strong><em>4.\u4e8b\u52a1\u4e2d\u7684I\u7279\u6027\u600e\u4e48\u4fdd\u8bc1?<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u9694\u79bb\u7ea7\u522b:\u8bfb\u9694\u79bb\u6027\r\nRU :\u810f\u8bfb\u3001\u4e0d\u753a\u91cd\u590d\u8bfb\u3001\u5e7b\u8bfb\r\nRC :\u4e2a\u53ef\u91cd\u590d\u8bfb\u3001\u5e7b\u8bfb\r\nRR :\u6709\u53ef\u80fd\u4f1a\u51fa\u73b0\u5e7b\u8bfb\u3002\r\nSR(SE) :\u4e8b\u52a1\u4e32\u884c\u5de5\u4f5c\u3002\r\n#\u9501\u673a\u5236:\u5199\u7684\u9694\u79bbI\r\n\u4f5c\u7528:\u4fdd\u62a4\u5e76\u53d1\u8bbf\u95ee\u8d44\u6e90\u3002\r\n\u4fdd\u62a4\u7684\u8d44\u6e90\u5206\u7c7b:\r\nlatch(\u95e8\u9501) : rwlock\u3001mutex\uff0c\u4e3b\u8981\u4fdd\u62a4\u5185\u5b58\u8d44\u6e90\r\nMDL: Metadata_lock,\u5143\u6570\u636e(DDL\u64cd\u4f5c)\r\ntable_lock:\u8868\u7ea7\u522b\r\n\t\tlock table t1 read ;\r\n\t\tmysqldump\u3001XBK (PBK):\u5907\u4efd\u975eInnoDB\u6570\u636e\u65f6\uff0c\u89e6\u53d1FTWRL\u5168\u5c40\u9501\u8868(Global)\u3002\r\n\t\t\u884c\u9501\u5347\u7ea7\u4e3a\u8868\u9501\u3002\r\nrow lock: InnoDB\u9ed8\u8ba4\u9501\u7c92\u5ea6\uff0c\u52a0\u9501\u65b9\u5f0f\u90fd\u662f\u5728\u7d22\u5f15\u52a0\u9501\u7684\u3002\r\nrecord lock :\u8bb0\u5f55\u9501\uff0c\u5728\u805a\u7c07\u7d22\u5f15\u9501\u5b9a\u3002RC\u7ea7\u522b\u53ea\u6709record lock\u3002\r\ngap lock:\u95f4\u9699\u9501\uff0c\u5728\u8f85\u52a9\u7d22\u5f15\u95f4\u9699\u52a0\u9501\u3002RR\u7ea7\u522b\u5b58\u5728\u3002\u9632\u6b62\u5e7b\u8bfb\u3002\r\nnext lock:\u4e0b\u4e00\u952e\u9501\uff0cGAP+Record\u3002RR\u7ea7\u522b\u5b58\u5728\u3002\u9632\u6b62\u5e7b\u8bfb\u3002\r<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":246,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"_links":{"self":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1018"}],"collection":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1018"}],"version-history":[{"count":1,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1018\/revisions"}],"predecessor-version":[{"id":1023,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1018\/revisions\/1023"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/media\/246"}],"wp:attachment":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}