{"id":10008062,"date":"2023-07-10T11:58:53","date_gmt":"2023-07-10T03:58:53","guid":{"rendered":"https:\/\/ityet.com\/?p=10008062"},"modified":"2023-07-10T11:58:53","modified_gmt":"2023-07-10T03:58:53","slug":"tidb%e7%ae%80%e8%bf%b0%e5%8f%8atikv%e7%9a%84%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e4%b8%8e%e5%ad%98%e5%82%a8-%e4%ba%ac%e4%b8%9c%e7%89%a9%e6%b5%81%e6%8a%80%e6%9c%af%e5%9b%a2%e9%98%9f","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008062","title":{"rendered":"TiDB\u7b80\u8ff0\u53caTiKV\u7684\u6570\u636e\u7ed3\u6784\u4e0e\u5b58\u50a8 | \u4eac\u4e1c\u7269\u6d41\u6280\u672f\u56e2\u961f"},"content":{"rendered":"<h2>1 \u6982\u8ff0<\/h2>\n<p>TiDB \u662f PingCAP \u516c\u53f8\u81ea\u4e3b\u8bbe\u8ba1\u3001\u7814\u53d1\u7684\u5f00\u6e90\u5206\u5e03\u5f0f\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u662f\u4e00\u6b3e\u540c\u65f6\u652f\u6301\u5728\u7ebf\u4e8b\u52a1\u5904\u7406\u4e0e\u5728\u7ebf\u5206\u6790\u5904\u7406 (Hybrid Transactional and Analytical Processing, HTAP) \u7684\u878d\u5408\u578b\u5206\u5e03\u5f0f\u6570\u636e\u5e93\u4ea7\u54c1\uff0c\u5177\u5907\u6c34\u5e73\u6269\u5bb9\u6216\u8005\u7f29\u5bb9\u3001\u91d1\u878d\u7ea7\u9ad8\u53ef\u7528\u3001\u5b9e\u65f6 HTAP\u3001\u4e91\u539f\u751f\u7684\u5206\u5e03\u5f0f\u6570\u636e\u5e93\u3001\u517c\u5bb9 MySQL 5.7 \u534f\u8bae\u548c MySQL \u751f\u6001\u7b49\u91cd\u8981\u7279\u6027\u3002\u76ee\u6807\u662f\u4e3a\u7528\u6237\u63d0\u4f9b\u4e00\u7ad9\u5f0f OLTP (Online Transactional Processing)\u3001OLAP (Online Analytical Processing)\u3001HTAP \u89e3\u51b3\u65b9\u6848\u3002TiDB \u9002\u5408\u9ad8\u53ef\u7528\u3001\u5f3a\u4e00\u81f4\u8981\u6c42\u8f83\u9ad8\u3001\u6570\u636e\u89c4\u6a21\u8f83\u5927\u7b49\u5404\u79cd\u5e94\u7528\u573a\u666f\u3002<\/p>\n<p>\u603b\u7ed3\u4e00\u4e0b\uff0cTidb\u662f\u4e2a\u9ad8\u5ea6\u517c\u5bb9MySQL\u7684\u5206\u5e03\u5f0f\u6570\u636e\u5e93\uff0c\u5e76\u62e5\u6709\u4ee5\u4e0b\u51e0\u4e2a\u7279\u6027\uff1a<\/p>\n<ul>\n<li>\u9ad8\u5ea6\u517c\u5bb9 MySQL\uff1a\u638c\u63e1MySQL\uff0c\u5c31\u53ef\u4ee5\u96f6\u57fa\u7840\u4f7f\u7528TIDB<\/li>\n<li>\u6c34\u5e73\u5f39\u6027\u6269\u5c55\uff1a\u81ea\u9002\u5e94\u6269\u5c55\uff0c\u57fa\u4e8eRaft\u534f\u8bae<\/li>\n<li>\u5206\u5e03\u5f0f\u4e8b\u52a1\uff1a\u60b2\u89c2\u9501\u3001\u4e50\u89c2\u9501\u3001\u56e0\u679c\u4e00\u81f4\u6027<\/li>\n<li>\u771f\u6b63\u91d1\u878d\u7ea7\u9ad8\u53ef\u7528\uff1a\u57fa\u4e8eRaft\u534f\u8bae<\/li>\n<li>\u4e00\u7ad9\u5f0f HTAP \u89e3\u51b3\u65b9\u6848\uff1a\u5355\u4e2a\u6570\u636e\u5e93\u540c\u65f6\u652f\u6301 OLTP \u548c OLAP\uff0c\u8fdb\u884c\u5b9e\u65f6\u667a\u80fd\u5904\u7406\u7684\u80fd\u529b<\/li>\n<\/ul>\n<p>\u5176\u4e2dTiDB\u7684\u6838\u5fc3\u7279\u6027\u662f\uff1a\u6c34\u5e73\u6269\u5c55\u3001\u9ad8\u53ef\u7528\u3002<\/p>\n<p>\u672c\u6587\u4e3b\u8981\u4eceTiDB\u7684\u5404\u7c7b\u7ec4\u4ef6\u4e3a\u8d77\u70b9\uff0c\u4e86\u89e3\u5b83\u7684\u57fa\u7840\u67b6\u6784\uff0c\u5e76\u91cd\u70b9\u5206\u6790\u5b83\u5728\u5b58\u50a8\u67b6\u6784\u65b9\u9762\u7684\u8bbe\u8ba1\uff0c\u63a2\u7a76\u5176\u5982\u4f55\u7ec4\u7ec7\u6570\u636e\uff0cTable\u4e2d\u7684\u6bcf\u884c\u8bb0\u5f55\u662f\u5982\u4f55\u5728\u5185\u5b58\u548c\u78c1\u76d8\u4e2d\u8fdb\u884c\u5b58\u50a8\u7684\u3002<\/p>\n<h2>2 \u7ec4\u4ef6<\/h2>\n<p>\u5148\u770b\u4e00\u5f20Tidb\u7684\u67b6\u6784\u56fe\uff0c\u91cc\u9762\u5305\u542b TiDB\u3001Storage(TiKV\u3001TiFlash)\u3001TiSpark\u3001PD\u3002\u5176\u4e2d\u7684TiDB\u3001TiKV\u3001PD\u662f\u6838\u5fc3\u7ec4\u4ef6\uff1bTIFlash\u3001TiSpark\u662f\u4e3a\u4e86\u89e3\u51b3\u590d\u6742OLAP\u7684\u7ec4\u4ef6\u3002  <br \/>TiDB\u662fMysql\u8bed\u6cd5\u7684\u4ea4\u4e92\u5165\u53e3\uff0cTiSpark\u662fsparkSAL\u7684\u4ea4\u4e92\u5165\u53e3\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043990860\" alt=\"\" title=\"\" loading=\"lazy\">[]()<\/p>\n<h3>2.1 TiDB Server<\/h3>\n<p>SQL \u5c42\uff0c\u5bf9\u5916\u66b4\u9732 MySQL \u534f\u8bae\u7684\u8fde\u63a5 endpoint\uff0c\u8d1f\u8d23\u63a5\u53d7\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\uff0c\u6267\u884c SQL \u89e3\u6790\u548c\u4f18\u5316\uff0c\u6700\u7ec8\u751f\u6210\u5206\u5e03\u5f0f\u6267\u884c\u8ba1\u5212\u3002<\/p>\n<p>TiDB \u5c42\u672c\u8eab\u662f\u65e0\u72b6\u6001\u7684\uff0c\u5b9e\u8df5\u4e2d\u53ef\u4ee5\u542f\u52a8\u591a\u4e2a TiDB \u5b9e\u4f8b\uff0c\u901a\u8fc7\u8d1f\u8f7d\u5747\u8861\u7ec4\u4ef6\uff08\u5982 LVS\u3001HAProxy \u6216 F5\uff09\u5bf9\u5916\u63d0\u4f9b\u7edf\u4e00\u7684\u63a5\u5165\u5730\u5740\uff0c\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u53ef\u4ee5\u5747\u5300\u5730\u5206\u644a\u5728\u591a\u4e2a TiDB \u5b9e\u4f8b\u4e0a\u4ee5\u8fbe\u5230\u8d1f\u8f7d\u5747\u8861\u7684\u6548\u679c\u3002TiDB Server \u672c\u8eab\u5e76\u4e0d\u5b58\u50a8\u6570\u636e\uff0c\u53ea\u662f\u89e3\u6790 SQL\uff0c\u5c06\u5b9e\u9645\u7684\u6570\u636e\u8bfb\u53d6\u8bf7\u6c42\u8f6c\u53d1\u7ed9\u5e95\u5c42\u7684\u5b58\u50a8\u8282\u70b9 TiKV\uff08\u6216 TiFlash\uff09\u3002<\/p>\n<h3>2.2 PD (Placement Driver) Server<\/h3>\n<p>\u6574\u4e2a TiDB \u96c6\u7fa4\u7684\u5143\u4fe1\u606f\u7ba1\u7406\u6a21\u5757\uff0c\u8d1f\u8d23\u5b58\u50a8\u6bcf\u4e2a TiKV \u8282\u70b9\u5b9e\u65f6\u7684\u6570\u636e\u5206\u5e03\u60c5\u51b5\u548c\u96c6\u7fa4\u7684\u6574\u4f53\u62d3\u6251\u7ed3\u6784\uff0c\u63d0\u4f9b TiDB Dashboard \u7ba1\u63a7\u754c\u9762\uff0c\u5e76\u4e3a\u5206\u5e03\u5f0f\u4e8b\u52a1\u5206\u914d\u4e8b\u52a1 ID\u3002<\/p>\n<p>PD \u4e0d\u4ec5\u5b58\u50a8\u5143\u4fe1\u606f\uff0c\u540c\u65f6\u8fd8\u4f1a\u6839\u636e TiKV \u8282\u70b9\u5b9e\u65f6\u4e0a\u62a5\u7684\u6570\u636e\u5206\u5e03\u72b6\u6001\uff0c\u4e0b\u53d1\u6570\u636e\u8c03\u5ea6\u547d\u4ee4\u7ed9\u5177\u4f53\u7684 TiKV \u8282\u70b9\uff0c\u53ef\u4ee5\u8bf4\u662f\u6574\u4e2a\u96c6\u7fa4\u7684\u201c\u5927\u8111\u201d\u3002\u6b64\u5916\uff0cPD \u672c\u8eab\u4e5f\u662f\u7531\u81f3\u5c11 3 \u4e2a\u8282\u70b9\u6784\u6210\uff0c\u62e5\u6709\u9ad8\u53ef\u7528\u7684\u80fd\u529b\u3002\u5efa\u8bae\u90e8\u7f72\u5947\u6570\u4e2a PD \u8282\u70b9\u3002<\/p>\n<h3>2.3 \u5b58\u50a8\u8282\u70b9<\/h3>\n<h4>2.3.1 TiKV Server<\/h4>\n<p>\u8d1f\u8d23\u5b58\u50a8\u6570\u636e\uff0c\u4ece\u5916\u90e8\u770b TiKV \u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u7684\u63d0\u4f9b\u4e8b\u52a1\u7684 Key-Value \u5b58\u50a8\u5f15\u64ce\u3002<\/p>\n<p>\u5b58\u50a8\u6570\u636e\u7684\u57fa\u672c\u5355\u4f4d\u662f Region\uff0c\u6bcf\u4e2a Region \u8d1f\u8d23\u5b58\u50a8\u4e00\u4e2a Key Range\uff08\u4ece StartKey \u5230 EndKey \u7684\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09\u7684\u6570\u636e\uff0c\u6bcf\u4e2a TiKV \u8282\u70b9\u4f1a\u8d1f\u8d23\u591a\u4e2a Region\u3002<\/p>\n<p>TiKV \u7684 API \u5728 KV \u952e\u503c\u5bf9\u5c42\u9762\u63d0\u4f9b\u5bf9\u5206\u5e03\u5f0f\u4e8b\u52a1\u7684\u539f\u751f\u652f\u6301\uff0c\u9ed8\u8ba4\u63d0\u4f9b\u4e86 SI (Snapshot Isolation) \u7684\u9694\u79bb\u7ea7\u522b\uff0c\u8fd9\u4e5f\u662f TiDB \u5728 SQL \u5c42\u9762\u652f\u6301\u5206\u5e03\u5f0f\u4e8b\u52a1\u7684\u6838\u5fc3\u3002<\/p>\n<p>TiDB \u7684 SQL \u5c42\u505a\u5b8c SQL \u89e3\u6790\u540e\uff0c\u4f1a\u5c06 SQL \u7684\u6267\u884c\u8ba1\u5212\u8f6c\u6362\u4e3a\u5bf9 TiKV API \u7684\u5b9e\u9645\u8c03\u7528\u3002\u6240\u4ee5\uff0c\u6570\u636e\u90fd\u5b58\u50a8\u5728 TiKV \u4e2d\u3002\u53e6\u5916\uff0cTiKV \u4e2d\u7684\u6570\u636e\u90fd\u4f1a\u81ea\u52a8\u7ef4\u62a4\u591a\u526f\u672c\uff08\u9ed8\u8ba4\u4e3a\u4e09\u526f\u672c\uff09\uff0c\u5929\u7136\u652f\u6301\u9ad8\u53ef\u7528\u548c\u81ea\u52a8\u6545\u969c\u8f6c\u79fb\u3002<\/p>\n<h4>2.3.2 TiFlash<\/h4>\n<p>TiFlash \u662f\u4e00\u7c7b\u7279\u6b8a\u7684\u5b58\u50a8\u8282\u70b9\u3002\u548c\u666e\u901a TiKV \u8282\u70b9\u4e0d\u4e00\u6837\u7684\u662f\uff0c\u5728 TiFlash \u5185\u90e8\uff0c\u6570\u636e\u662f\u4ee5\u5217\u5f0f\u7684\u5f62\u5f0f\u8fdb\u884c\u5b58\u50a8\uff0c\u4e3b\u8981\u7684\u529f\u80fd\u662f\u4e3a\u5206\u6790\u578b\u7684\u573a\u666f\u52a0\u901f\u3002\u5047\u5982\u4f7f\u7528\u573a\u666f\u4e3a\u6d77\u91cf\u6570\u636e\uff0c\u4e14\u9700\u8981\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\uff0c\u53ef\u4ee5\u5728\u6570\u636e\u8868\u57fa\u7840\u4e0a\u521b\u5efaTiFlash\u5b58\u50a8\u7ed3\u6784\u7684\u6620\u5c04\u8868\uff0c\u4ee5\u63d0\u9ad8\u67e5\u8be2\u901f\u5ea6\u3002<\/p>\n<p>\u4ee5\u4e0a\u7ec4\u4ef6\u4e92\u76f8\u914d\u5408\uff0c\u652f\u6491\u7740Tidb\u5b8c\u6210\u6d77\u91cf\u6570\u636e\u5b58\u50a8\u3001\u540c\u65f6\u517c\u987e\u9ad8\u53ef\u7528\u3001\u4e8b\u52a1\u3001\u4f18\u79c0\u7684\u8bfb\u5199\u6027\u80fd\u3002<\/p>\n<h2>3 \u5b58\u50a8\u67b6\u6784<\/h2>\n<h3>3.1 TiKV\u7684\u6a21\u578b<\/h3>\n<p>\u524d\u6587\u6240\u63cf\u8ff0\u7684Tidb\u67b6\u6784\u4e2d\uff0c\u5176\u4f5c\u4e3a\u5b58\u50a8\u8282\u70b9\u7684\u6709\u4e24\u4e2a\u670d\u52a1\uff0cTiKV\u548cTiFlash\u3002\u5176\u4e2dTiFlash\u4e3a\u5217\u5f0f\u5b58\u50a8\u7684\u5f62\u5f0f\u5b9e\u73b0\u7684\uff0c\u53ef\u4ee5\u53c2\u8003ClickHouse\u7684\u67b6\u6784\u601d\u8def\uff0c\u4e8c\u8005\u5177\u6709\u76f8\u4f3c\u6027\u3002\u672c\u7ae0\u8282\u4e3b\u8981\u8ba8\u8bbaTiKV\u7684\u5b9e\u73b0\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043990861\" alt=\"\" title=\"\" loading=\"lazy\">[]()<\/p>\n<p>\u5728\u4e0a\u56fe\u4e2d\uff0cTiKV node\u6240\u63cf\u8ff0\u7684\u5c31\u662fOLTP\u573a\u666f\u4e0bTidb\u7684\u5b58\u50a8\u7ec4\u4ef6\uff0c\u800cTiFlash\u5219\u662f\u5e94\u5bf9\u7684LOAP\u573a\u666f\u3002TiKV\u9009\u62e9\u7684\u662fKey-Value\u6a21\u578b\uff0c\u4f5c\u4e3a\u6570\u636e\u7684\u5b58\u50a8\u6a21\u578b\uff0c\u5e76\u63d0\u4f9b\u6709\u5e8f\u904d\u5386\u65b9\u6cd5\u8fdb\u884c\u8bfb\u53d6\u3002<\/p>\n<p>TiKV\u6570\u636e\u5b58\u50a8\u6709\u4e24\u4e2a\u5173\u952e\u70b9\uff1a<\/p>\n<ol>\n<li>\u662f\u4e00\u4e2a\u5de8\u5927\u7684Map\uff08\u53ef\u4ee5\u53c2\u8003HashMap\uff09\uff0c\u4e5f\u5c31\u662f\u5b58\u50a8\u7684\u662fKey-Value Pairs\uff08\u952e\u503c\u5bf9\uff09\u3002<\/li>\n<li>\u8fd9\u4e2aMap\u4e2d\u7684Key-Value pair\u6309\u7167Key\u7684\u4e8c\u8fdb\u5236\u987a\u5e8f\u6709\u5e8f\uff0c\u4e5f\u5c31\u662f\u53ef\u4ee5Seek\u5230\u67d0\u4e00\u4e2aKey\u7684\u4f4d\u7f6e\uff0c\u7136\u540e\u4e0d\u65ad\u5730\u8c03\u7528Next\u65b9\u6cd5\uff0c\u4ee5\u9012\u589e\u7684\u987a\u5e8f\u83b7\u53d6\u6bd4\u8fd9\u4e2aKey\u5927\u7684Key-Value\u3002<\/li>\n<\/ol>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u91cc\u63cf\u8ff0\u7684TiKV\u7684KV\u5b58\u50a8\u6a21\u578b\uff0c\u4e0eSQL\u4e2d\u7684Table\u65e0\u5173\uff0c\u4e0d\u8981\u6709\u4efb\u4f55\u4ee3\u5165\u3002<\/p>\n<p>\u5728\u56fe\u4e2dTiKV node\u5185\u90e8\uff0c\u6709store\u3001Region\u7684\u6982\u5ff5\uff0c\u8fd9\u662f\u9ad8\u53ef\u7528\u7684\u89e3\u51b3\u65b9\u6848\uff0cTiDB\u91c7\u7528\u4e86Raft\u7b97\u6cd5\u5b9e\u73b0\uff0c\u8fd9\u91cc\u7ec6\u5206\u6790\u3002<\/p>\n<h3>3.2 TiKV\u7684\u884c\u5b58\u50a8\u7ed3\u6784<\/h3>\n<p>\u5728\u4f7f\u7528Tidb\u65f6\uff0c\u4f9d\u7136\u4ee5\u4f20\u7edf\u201c\u8868\u201d\u7684\u6982\u5ff5\u8fdb\u884c\u8bfb\u5199\uff0c\u5728\u5173\u7cfb\u578b\u6570\u636e\u5e93\u4e2d\uff0c\u4e00\u4e2a\u8868\u53ef\u80fd\u6709\u5f88\u591a\u5217\u3002\u800cTidb\u662f\u4ee5Key-Value\u5f62\u5f0f\u6784\u9020\u6570\u636e\u7684\uff0c\u56e0\u6b64\u9700\u8981\u8003\u8651\uff0c\u5c06\u4e00\u884c\u8bb0\u5f55\u4e2d\uff0c\u5404\u5217\u6570\u636e\u6620\u5c04\u6210\u4e00\u4e2akey-value\u952e\u503c\u5bf9\u3002<\/p>\n<p>\u9996\u5148\uff0c\u5728OLTP\u573a\u666f\uff0c\u6709\u5927\u91cf\u9488\u5bf9\u5355\u884c\u6216\u8005\u591a\u884c\u7684\u589e\u3001\u5220\u3001\u6539\u3001\u67e5\u64cd\u4f5c\uff0c\u8981\u6c42\u6570\u636e\u5e93\u5177\u5907\u5feb\u901f\u8bfb\u53d6\u4e00\u884c\u6570\u636e\u7684\u80fd\u529b\u3002\u56e0\u6b64\uff0c\u5bf9\u5e94\u7684 Key \u6700\u597d\u6709\u4e00\u4e2a\u552f\u4e00 ID\uff08\u663e\u793a\u6216\u9690\u5f0f\u7684 ID\uff09\uff0c\u4ee5\u65b9\u4fbf\u5feb\u901f\u5b9a\u4f4d\u3002<\/p>\n<p>\u5176\u6b21\uff0c\u5f88\u591a OLAP \u578b\u67e5\u8be2\u9700\u8981\u8fdb\u884c\u5168\u8868\u626b\u63cf\u3002\u5982\u679c\u80fd\u591f\u5c06\u4e00\u4e2a\u8868\u4e2d\u6240\u6709\u884c\u7684 Key \u7f16\u7801\u5230\u4e00\u4e2a\u533a\u95f4\u5185\uff0c\u5c31\u53ef\u4ee5\u901a\u8fc7\u8303\u56f4\u67e5\u8be2\u9ad8\u6548\u5b8c\u6210\u5168\u8868\u626b\u63cf\u7684\u4efb\u52a1\u3002<\/p>\n<h4>3.2.1 \u8868\u6570\u636e\u7684KV\u6620\u5c04<\/h4>\n<p>Tidb\u4e2d\u8868\u6570\u636e\u4e0eKey-Value\u7684\u6620\u5c04\u5173\u7cfb\uff0c\u8bbe\u8ba1\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u4e3a\u4e86\u4fdd\u8bc1\u540c\u4e00\u4e2a\u8868\u7684\u6570\u636e\u4f1a\u653e\u5728\u4e00\u8d77\uff0c\u65b9\u4fbf\u67e5\u627e\uff0cTiDB\u4f1a\u4e3a\u6bcf\u4e2a\u8868\u5206\u914d\u4e00\u4e2a\u8868ID\uff0c\u7528TableID\u8868\u793a\uff0c\u6574\u6570\u3001\u5168\u5c40\u552f\u4e00\u3002<\/li>\n<li>TiDB\u4f1a\u4e3a\u6bcf\u884c\u6570\u636e\u5206\u914d\u4e00\u4e2a\u884cID\uff0c\u7528RowID\u8868\u793a\uff0c\u6574\u6570\u3001\u8868\u5185\u552f\u4e00\u3002\u5982\u679c\u8868\u6709\u4e3b\u952e\uff0c\u5219\u884cID\u7b49\u4e8e\u4e3b\u952e\u3002<\/li>\n<\/ul>\n<p>\u57fa\u4e8e\u4ee5\u4e0a\u89c4\u5219\uff0c\u751f\u6210\u7684Key-Value\u952e\u503c\u5bf9\u4e3a\uff1a<\/p>\n<pre><code>Key\uff1a  tablePrefix{TableID}_recordPrefixSep{RowID} \nValue: [col1,col2,col3,col4]<\/code><\/pre>\n<p>\u5176\u4e2d tablePrefix \u548c recordPrefixSep \u90fd\u662f\u7279\u5b9a\u7684\u5b57\u7b26\u4e32\u5e38\u91cf\uff0c\u7528\u4e8e\u5728 Key \u7a7a\u95f4\u5185\u533a\u5206\u5176\u4ed6\u6570\u636e\u3002<\/p>\n<p>\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u662f\u5b8c\u5168\u57fa\u4e8eRowID\u5f62\u6210\u7684Key\uff0c\u53ef\u4ee5\u7c7b\u6bd4MySQL\u7684\u805a\u96c6\u7d22\u5f15\u3002<\/p>\n<h4>3.2.2 \u7d22\u5f15\u6570\u636e\u7684KV\u6620\u5c04<\/h4>\n<p>\u5bf9\u4e8e\u666e\u901a\u7d22\u5f15\uff0c\u5728MySQL\u4e2d\u662f\u6709\u975e\u805a\u96c6\u7d22\u5f15\u6982\u5ff5\u7684\uff0c\u5c24\u5176innodb\u4e2d\uff0c\u901a\u8fc7B+Tree\u5f62\u5f0f\uff0c\u5b50\u8282\u70b9\u8bb0\u5f55\u4e3b\u952e\u4fe1\u606f\uff0c\u518d\u901a\u8fc7\u56de\u8868\u65b9\u5f0f\u5f97\u5230\u7ed3\u679c\u6570\u636e\u3002<\/p>\n<p>\u5728Tidb\u4e2d\u662f\u652f\u6301\u521b\u5efa\u7d22\u5f15\u7684\uff0c\u90a3\u4e48\u7d22\u5f15\u4fe1\u606f\u5982\u4f55\u5b58\u50a8\uff1f \u5b83\u540c\u65f6\u652f\u6301\u4e3b\u952e\u548c\u4e8c\u7ea7\u7d22\u5f15\uff08\u5305\u62ec\u552f\u4e00\u7d22\u5f15\u548c\u975e\u552f\u4e00\u7d22\u5f15\uff09\uff0c\u4e14\u4e0e\u8868\u6570\u636e\u6620\u5c04\u65b9\u5f0f\u7c7b\u4f3c\u3002<\/p>\n<p>\u8bbe\u8ba1\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>Tidb\u4e3a\u8868\u4e2d\u6bcf\u4e2a\u7d22\u5f15\uff0c\u5206\u914d\u4e86\u4e00\u4e2a\u7d22\u5f15ID\uff0c\u7528IndexID\u8868\u793a\u3002<\/li>\n<li>\u5bf9\u4e8e\u4e3b\u952e\u548c\u552f\u4e00\u7d22\u5f15\uff0c\u9700\u8981\u6839\u636e\u952e\u503c\u5feb\u901f\u5b9a\u4f4d\u5230RowID\uff0c\u8fd9\u4e2a\u4f1a\u5b58\u50a8\u5230value\u4e2d<\/li>\n<\/ul>\n<p>\u56e0\u6b64\u751f\u6210\u7684key-value\u952e\u503c\u5bf9\u4e3a\uff1a<\/p>\n<pre><code>Key\uff1atablePrefix{TableID}_indexPrefixSep{IndexID}_indexedColumnsValue\nValue: RowID<\/code><\/pre>\n<p>\u7531\u4e8e\u8bbe\u8ba1\u7684key\u4e2d\u5b58\u5728indexedColumnsValue\uff0c\u4e5f\u5c31\u662f\u67e5\u8be2\u7684\u5b57\u6bb5\u503c\uff0c\u56e0\u6b64\u53ef\u4ee5\u76f4\u63a5\u547d\u4e2d\u6216\u6a21\u7cca\u68c0\u7d22\u5230\u3002\u518d\u901a\u8fc7value\u4e2d\u7684RowID\uff0c\u53bb\u8868\u6570\u636e\u6620\u5c04\u4e2d\uff0c\u68c0\u7d22\u5230RowID\u5bf9\u5e94\u7684\u884c\u8bb0\u5f55\u3002<\/p>\n<p>\u5bf9\u4e8e\u666e\u901a\u7d22\u5f15\uff0c\u4e00\u4e2a\u952e\u503c\u53ef\u80fd\u5bf9\u5e94\u591a\u884c\uff0c\u9700\u8981\u6839\u636e\u952e\u503c\u8303\u56f4\u67e5\u8be2\u5bf9\u5e94\u7684RowID\u3002<\/p>\n<pre><code>Key:   tablePrefix{TableID}_indexPrefixSep{IndexID}_indexedColumnsValue_{RowID}\nValue: null<\/code><\/pre>\n<p>\u6839\u636e\u5b57\u6bb5\u503c\uff0c\u53ef\u4ee5\u68c0\u7d22\u5230\u5177\u6709\u76f8\u5173\u6027\u7684key\u7684\u5217\u8868\uff0c\u5728\u6839\u636ekey\u4e2d\u5305\u542b\u7684RowID\uff0c\u518d\u62ff\u5230\u884c\u8bb0\u5f55\u3002<\/p>\n<h4>3.2.3 \u6620\u5c04\u4e2d\u7684\u5e38\u91cf\u5b57\u7b26\u4e32<\/h4>\n<p>\u4e0a\u8ff0\u6240\u6709\u7f16\u7801\u89c4\u5219\u4e2d\u7684 tablePrefix\u3001recordPrefixSep \u548c indexPrefixSep \u90fd\u662f\u5b57\u7b26\u4e32\u5e38\u91cf\uff0c\u7528\u4e8e\u5728 Key \u7a7a\u95f4\u5185\u533a\u5206\u5176\u4ed6\u6570\u636e\uff0c\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n<pre><code>tablePrefix     = []byte{'t'}\nrecordPrefixSep = []byte{'r'}\nindexPrefixSep  = []byte{'i'}<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u6620\u5c04\u5173\u7cfb\u4e2d\uff0c\u4e00\u4e2a\u8868\u5185\u6240\u6709\u7684\u884c\u90fd\u6709\u76f8\u540c\u7684 Key \u524d\u7f00\uff0c\u4e00\u4e2a\u7d22\u5f15\u7684\u6240\u6709\u6570\u636e\u4e5f\u90fd\u6709\u76f8\u540c\u7684\u524d\u7f00\u3002\u8fd9\u6837\u5177\u6709\u76f8\u540c\u7684\u524d\u7f00\u7684\u6570\u636e\uff0c\u5728 TiKV \u7684 Key \u7a7a\u95f4\u5185\uff0c\u662f\u6392\u5217\u5728\u4e00\u8d77\u7684\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u53ea\u9700\u8981\u8bbe\u8ba1\u51fa\u7a33\u5b9a\u7684\u540e\u7f00\uff0c\u5219\u53ef\u4ee5\u4fdd\u8bc1\u8868\u6570\u636e\u6216\u7d22\u5f15\u6570\u636e\uff0c\u6709\u5e8f\u7684\u5b58\u50a8\u5728TiKV\u4e2d\u3002\u800c\u6709\u5e8f\u5e26\u6765\u7684\u4ef7\u503c\u5c31\u662f\u80fd\u591f\u9ad8\u6548\u7684\u8bfb\u53d6\u3002<\/p>\n<h4>3.2.4 \u4e3e\u4f8b<\/h4>\n<p>\u5047\u8bbe\u6570\u636e\u5e93\u7684\u4e00\u5f20\u8868\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre><code>CREATE TABLE User (\n    ID int,\n    Name varchar(20),\n    Role varchar(20),\n    Age int,\n    PRIMARY KEY (ID),\n    KEY idxAge (Age)\n);<\/code><\/pre>\n<p>\u8868\u4e2d\u67093\u884c\u8bb0\u5f55\uff1a<\/p>\n<pre><code>1, &quot;TiDB&quot;, &quot;SQL Layer&quot;, 10\n2, &quot;TiKV&quot;, &quot;KV Engine&quot;, 20\n3, &quot;PD&quot;, &quot;Manager&quot;, 30\n4, &quot;TiFlash&quot;, &quot;OLAP&quot;, 30<\/code><\/pre>\n<p>\u8fd9\u5f20\u8868\u4e2d\u6709\u4e00\u4e2a\u4e3b\u952eID\u3001\u4e00\u4e2a\u666e\u901a\u7d22\u5f15idxAge\uff0c\u5bf9\u5e94\u7684\u662f\u5217Age.<\/p>\n<p>\u5047\u8bbe\u8be5\u8868\u7684TableID=10\uff0c\u5219\u5176\u8868\u6570\u636e\u7684\u5b58\u50a8\u5982\u4e0b\uff1a<\/p>\n<pre><code>t10_r1 --&gt; [&quot;TiDB&quot;, &quot;SQL Layer&quot;, 10]\nt10_r2 --&gt; [&quot;TiKV&quot;, &quot;KV Engine&quot;, 20]\nt10_r3 --&gt; [&quot;PD&quot;, &quot;Manager&quot;, 30]\nt10_r4 --&gt; [&quot;TiFlash&quot;, &quot;OLAP&quot;, 30]<\/code><\/pre>\n<p>\u5176\u666e\u901a\u7d22\u5f15idxAge\u7684\u5b58\u50a8\u5982\u4e0b\uff1a<\/p>\n<pre><code>t10_i1_10_1 --&gt; null\nt10_i1_20_2 --&gt; null\nt10_i1_30_3 --&gt; null\nt10_i1_30_4 --&gt; null<\/code><\/pre>\n<h3>3.3 SQL\u4e0eKV\u6620\u5c04<\/h3>\n<p>TiDB \u7684 SQL \u5c42\uff0c\u5373 TiDB Server\uff0c\u8d1f\u8d23\u5c06 SQL \u7ffb\u8bd1\u6210 Key-Value \u64cd\u4f5c\uff0c\u5c06\u5176\u8f6c\u53d1\u7ed9\u5171\u7528\u7684\u5206\u5e03\u5f0f Key-Value \u5b58\u50a8\u5c42 TiKV\uff0c\u7136\u540e\u7ec4\u88c5 TiKV \u8fd4\u56de\u7684\u7ed3\u679c\uff0c\u6700\u7ec8\u5c06\u67e5\u8be2\u7ed3\u679c\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<p>\u4e3e\u4f8b\uff0c\u201cselect count(*) from user where name=\u2019tidb\u2019;\u201d\u8fd9\u6837\u7684SQL\u8bed\u53e5\uff0c\u5728Tidb\u4e2d\u8fdb\u884c\u68c0\u7d22\uff0c\u6d41\u7a0b\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u6839\u636e\u8868\u540d\u3001\u6240\u6709\u7684RowID\uff0c\u7ed3\u5408\u8868\u6570\u636e\u7684Key\u7f16\u7801\u89c4\u5219\uff0c\u6784\u9020\u51fa\u4e00\u4e2a[StartKey,endKey)\u7684\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\u3002<\/li>\n<li>\u6839\u636e[StartKey,endKey)\u8fd9\u4e2a\u533a\u95f4\u5185\u7684\u503c\uff0c\u5230TiKV\u4e2d\u8bfb\u53d6\u6570\u636e<\/li>\n<li>\u5f97\u5230\u6bcf\u4e00\u884c\u8bb0\u5f55\u540e\uff0c\u8fc7\u6ee4\u51faname=\u2019tidb\u2019\u7684\u6570\u636e<\/li>\n<li>\u5c06\u7ed3\u679c\u8fdb\u884c\u7edf\u8ba1\uff0c\u8ba1\u7b97\u51facount(*)\u7684\u7ed3\u679c\uff0c\u8fdb\u884c\u8fd4\u56de\u3002<\/li>\n<\/ol>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043990862\" alt=\"\" title=\"\" loading=\"lazy\">[]()<\/p>\n<p>\u5728\u5206\u5e03\u5f0f\u73af\u5883\u4e0b\uff0c\u4e3a\u4e86\u63d0\u9ad8\u68c0\u7d22\u6548\u7387\uff0c\u5b9e\u9645\u8fd0\u884c\u8fc7\u7a0b\u4e2d\uff0c\u4e0a\u8ff0\u6d41\u7a0b\u662f\u4f1a\u5c06name=\u2019tidb\u2019\u548ccount( <strong><em>)\u4e0b\u63a8\u5230\u96c6\u7fa4\u7684\u6bcf\u4e2a\u8282\u70b9\u4e2d\uff0c\u51cf\u5c11\u65e0\u5f02\u8bae\u7684\u7f51\u7edc\u4f20\u8f93\uff0c\u6bcf\u4e2a\u8282\u70b9\u6700\u7ec8\u5c06count(<\/strong> <\/em>)\u7684\u7ed3\u679c\uff0c\u518d\u7531SQL\u5c42\u5c06\u7ed3\u679c\u7d2f\u52a0\u6c42\u548c\u3002<\/p>\n<h2>4 RockDB \u6301\u4e45\u5316<\/h2>\n<h3>4.1 \u6982\u8ff0<\/h3>\n<p>\u524d\u6587\u6240\u63cf\u8ff0\u7684Key-Value Pairs\u53ea\u662f\u5b58\u50a8\u6a21\u578b\uff0c\u662f\u5b58\u5728\u4e8e\u5185\u5b58\u4e2d\u7684\uff0c\u4efb\u4f55\u6301\u4e45\u5316\u7684\u5b58\u50a8\u5f15\u64ce\uff0c\u6570\u636e\u7ec8\u5f52\u8981\u4fdd\u5b58\u5728\u78c1\u76d8\u4e0a\u3002TiKV \u6ca1\u6709\u9009\u62e9\u76f4\u63a5\u5411\u78c1\u76d8\u4e0a\u5199\u6570\u636e\uff0c\u800c\u662f\u628a\u6570\u636e\u4fdd\u5b58\u5728 RocksDB \u4e2d\uff0c\u5177\u4f53\u7684\u6570\u636e\u843d\u5730\u7531 RocksDB \u8d1f\u8d23\u3002<\/p>\n<p>\u8fd9\u4e2a\u9009\u62e9\u7684\u539f\u56e0\u662f\u5f00\u53d1\u4e00\u4e2a\u5355\u673a\u5b58\u50a8\u5f15\u64ce\u5de5\u4f5c\u91cf\u5f88\u5927\uff0c\u7279\u522b\u662f\u8981\u505a\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684\u5355\u673a\u5f15\u64ce\uff0c\u9700\u8981\u505a\u5404\u79cd\u7ec6\u81f4\u7684\u4f18\u5316\uff0c\u800c RocksDB \u662f\u7531 Facebook \u5f00\u6e90\u7684\u4e00\u4e2a\u975e\u5e38\u4f18\u79c0\u7684\u5355\u673a KV \u5b58\u50a8\u5f15\u64ce\uff0c\u53ef\u4ee5\u6ee1\u8db3 TiKV \u5bf9\u5355\u673a\u5f15\u64ce\u7684\u5404\u79cd\u8981\u6c42\u3002\u8fd9\u91cc\u53ef\u4ee5\u7b80\u5355\u7684\u8ba4\u4e3a RocksDB \u662f\u4e00\u4e2a\u5355\u673a\u7684\u6301\u4e45\u5316 Key-Value Map\u3002<\/p>\n<h3>4.2 RocksDB<\/h3>\n<p>TiKV Node\u7684\u5185\u90e8\u88ab\u5212\u5206\u6210\u591a\u4e2aRegion\uff0c\u8fd9\u4e9bRegion\u4f5c\u4e3a\u6570\u636e\u5207\u7247\uff0c\u662f\u6570\u636e\u4e00\u81f4\u6027\u7684\u57fa\u7840\uff0c\u800cTiKV\u7684\u6301\u4e45\u5316\u5355\u5143\u5219\u662fRegion\uff0c\u4e5f\u5c31\u662f\u6bcf\u4e2aRegion\u90fd\u4f1a\u88ab\u5b58\u50a8\u5728RocksDB\u5b9e\u4f8b\u4e2d\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043990863\" alt=\"\" title=\"\" loading=\"lazy\">[]()<\/p>\n<p>\u4ee5Region\u4e3a\u5355\u5143\uff0c\u662f\u57fa\u4e8e\u987a\u5e8fI\/O\u7684\u6027\u80fd\u8003\u8651\u7684\u3002\u800cTiKV\u662f\u5982\u4f55\u6709\u6548\u7684\u7ec4\u7ec7Region\u5185\u7684\u6570\u636e\uff0c\u4fdd\u8bc1\u5206\u7247\u5747\u5300\u3001\u6709\u5e8f\uff0c\u8fd9\u91cc\u9762\u7528\u5230\u4e86LSM-Tree\uff0c\u5982\u679c\u6709HBase\u7ecf\u9a8c\u4e00\u5b9a\u4e0d\u6a21\u5f0f\u3002<\/p>\n<h4>4.2.1 LSM-Tree\u7ed3\u6784<\/h4>\n<p>LSM-Tree\uff08log structured merge-tree\uff09\u5b57\u9762\u610f\u601d\u662f\u201c\u65e5\u5fd7\u7ed3\u6784\u7684\u5408\u5e76\u6811\u201d\uff0cLSM-Tree\u7684\u7ed3\u6784\u662f\u6a2a\u8de8\u78c1\u76d8\u548c\u5185\u5b58\u7684\u3002\u5b83\u5c06\u5b58\u50a8\u4ecb\u8d28\u6839\u636e\u529f\u80fd\uff0c\u5212\u5206\u78c1\u76d8\u7684WAL(write ahead log)\u3001\u5185\u5b58\u7684MemTable\u3001\u78c1\u76d8\u7684SST\u6587\u4ef6\uff1b\u5176\u4e2dSST\u6587\u4ef6\u53c8\u5206\u4e3a\u591a\u5c42\uff0c\u6bcf\u4e00\u5c42\u6570\u636e\u8fbe\u5230\u9608\u503c\u540e\uff0c\u4f1a\u6311\u9009\u4e00\u90e8\u5206SST\u5408\u5e76\u5230\u4e0b\u4e00\u5c42\uff0c\u6bcf\u4e00\u5c42\u7684\u6570\u636e\u662f\u4e0a\u4e00\u5c42\u768410\u500d\uff0c\u56e0\u6b6490%\u7684\u6570\u636e\u4f1a\u5b58\u50a8\u5728\u6700\u540e\u4e00\u5c42\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043990864\" alt=\"\" title=\"\" loading=\"lazy\">[]()<\/p>\n<p>WAL\uff1a\u662f\u9884\u5199Log\u7684\u5b9e\u73b0\uff0c\u5f53\u8fdb\u884c\u5199\u64cd\u4f5c\u65f6\uff0c\u4f1a\u5c06\u6570\u636e\u901a\u8fc7WAL\u65b9\u5f0f\u5907\u4efd\u5230\u78c1\u76d8\u4e2d\uff0c\u9632\u6b62\u5185\u5b58\u65ad\u7535\u800c\u4e22\u5931\u3002<\/p>\n<p>Memory-Table\uff1a\u662f\u5728\u5185\u5b58\u4e2d\u7684\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4ee5\u4fdd\u5b58\u6700\u8fd1\u7684\u4e00\u4e9b\u66f4\u65b0\u64cd\u4f5c\uff1bmemory-table\u53ef\u4ee5\u4f7f\u7528\u8df3\u8dc3\u8868\u6216\u8005\u641c\u7d22\u6811\u7b49\u6570\u636e\u7ed3\u6784\u6765\u7ec4\u7ec7\u6570\u636e\uff0c\u4ee5\u4fdd\u6301\u6570\u636e\u7684\u6709\u5e8f\u6027\u3002\u5f53memory-table\u8fbe\u5230\u4e00\u5b9a\u7684\u6570\u636e\u91cf\u540e\uff0cmemory-table\u4f1a\u8f6c\u5316\u6210\u4e3aimmutable memory-table\uff0c\u540c\u65f6\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684memory-table\u6765\u5904\u7406\u65b0\u7684\u6570\u636e\u3002<\/p>\n<p>Immutable Memory-Table\uff1aimmutable memory-table\u5728\u5185\u5b58\u4e2d\u662f\u4e0d\u53ef\u4fee\u6539\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u662f\u5c06memory-table\u8f6c\u53d8\u4e3aSSTable\u7684\u4e00\u79cd\u4e2d\u95f4\u72b6\u6001\u3002\u76ee\u7684\u662f\u4e3a\u4e86\u5728\u8f6c\u5b58\u8fc7\u7a0b\u4e2d\u4e0d\u963b\u585e\u5199\u64cd\u4f5c\u3002\u5199\u64cd\u4f5c\u53ef\u4ee5\u7531\u65b0\u7684memory-table\u5904\u7406\uff0c\u800c\u4e0d\u7528\u56e0\u4e3a\u9501\u4f4fmemory-table\u800c\u7b49\u5f85\u3002<\/p>\n<p>SST\u6216SSTable\uff1a\u6709\u5e8f\u952e\u503c\u5bf9\u96c6\u5408\uff0c\u662fLSM\u6811\u7ec4\u5728\u78c1\u76d8\u4e2d\u7684\u6570\u636e\u7684\u7ed3\u6784\u3002\u5982\u679cSSTable\u6bd4\u8f83\u5927\u7684\u65f6\u5019\uff0c\u8fd8\u53ef\u4ee5\u6839\u636e\u952e\u7684\u503c\u5efa\u7acb\u4e00\u4e2a\u7d22\u5f15\u6765\u52a0\u901fSSTable\u7684\u67e5\u8be2\u3002SSTable\u4f1a\u5b58\u5728\u591a\u4e2a\uff0c\u5e76\u4e14\u6309Level\u8bbe\u8ba1\uff0c\u6bcf\u4e00\u5c42\u7ea7\u4f1a\u5b58\u5728\u591a\u4e2aSSTable\u6587\u4ef6\u3002<\/p>\n<h4>4.2.2 LSM-Tree\u6267\u884c\u8fc7\u7a0b<\/h4>\n<p>\u5199\u5165\u8fc7\u7a0b<\/p>\n<ol>\n<li>\u9996\u5148\u4f1a\u68c0\u67e5\u6bcf\u4e2a\u533a\u57df\u7684\u5b58\u50a8\u662f\u5426\u8fbe\u5230\u9608\u503c\uff0c\u672a\u8fbe\u5230\u4f1a\u76f4\u63a5\u5199\u5165\uff1b<\/li>\n<li>\u5982\u679cImmutable Memory-Table\u5b58\u5728\uff0c\u4f1a\u7b49\u5f85\u5176\u538b\u7f29\u8fc7\u7a0b\u3002<\/li>\n<li>\u5982\u679cMemory-Table\u5df2\u7ecf\u5199\u6ee1\uff0cImmutable Memory-Table \u4e0d\u5b58\u5728\uff0c\u5219\u5c06\u5f53\u524dMemory-Table\u8bbe\u7f6e\u4e3aImmutable Memory-Table\uff0c\u751f\u6210\u65b0\u7684Memory-Table\uff0c\u518d\u89e6\u53d1\u538b\u7f29\uff0c\u968f\u540e\u8fdb\u884c\u5199\u5165\u3002<\/li>\n<li>\u5199\u7684\u8fc7\u7a0b\u4f1a\u5148\u5199\u5165WAL\uff0c\u6210\u529f\u540e\u624d\u4f1a\u5199Memory-Table\uff0c\u6b64\u523b\u5199\u5165\u624d\u5b8c\u6210\u3002<\/li>\n<\/ol>\n<p>\u6570\u636e\u5b58\u5728\u7684\u4f4d\u7f6e\uff0c\u6309\u987a\u5e8f\u4f1a\u4f9d\u6b21\u7ecf\u5386WAL\u3001Memory-Table\u3001Immutable Memory-Table\u3001SSTable\u3002\u5176\u4e2dSSTable\u662f\u6570\u636e\u6700\u7ec8\u6301\u4e45\u5316\u7684\u4f4d\u7f6e\u3002\u800c\u4e8b\u52a1\u6027\u5199\u5165\u53ea\u9700\u8981\u7ecf\u5386WAL\u548cMemory-Table\u5373\u53ef\u5b8c\u6210\u3002<\/p>\n<p>\u67e5\u627e\u8fc7\u7a0b<\/p>\n<p>1.\u6839\u636e\u76ee\u6807key\uff0c\u9010\u7ea7\u4f9d\u6b21\u5728Memory-Table\u3001Immutable Memory-Table\u3001SSTable\u4e2d\u67e5\u627e  <br \/>2.\u5176\u4e2dSSTable\u4f1a\u5206\u4e3a\u51e0\u4e2a\u7ea7\u522b\uff0c\u4e5f\u662f\u6309Level\u4e2d\u8fdb\u884c\u67e5\u627e\u3002<\/p>\n<ul>\n<li>Level-0\u7ea7\u522b\uff0cRocksDB\u4f1a\u91c7\u7528\u904d\u5386\u7684\u65b9\u5f0f\uff0c\u6240\u6709\u4e3a\u4e86\u67e5\u627e\u6548\u7387\uff0c\u4f1a\u63a7\u5236Level-0\u7684\u6587\u4ef6\u4e2a\u6570\u3002<\/li>\n<li>\u800cLevel-1\u53ca\u4ee5\u4e0a\u5c42\u7ea7\u7684SSTable\uff0c\u6570\u636e\u4e0d\u4f1a\u5b58\u5728\u4ea4\u53e0\uff0c\u4e14\u7531\u4e8e\u5b58\u50a8\u6709\u5e8f\uff0c\u4f1a\u91c7\u7528\u4e8c\u5206\u67e5\u627e\u63d0\u9ad8\u6548\u7387\u3002<\/li>\n<\/ul>\n<p>RocksDB\u4e3a\u4e86\u63d0\u9ad8\u67e5\u627e\u6548\u7387\uff0c\u6bcf\u4e2aMemory-Table\u548cSSTable\u90fd\u4f1a\u6709\u76f8\u5e94\u7684Bloom Filter\u6765\u52a0\u5feb\u5224\u65adKey\u662f\u5426\u53ef\u80fd\u5728\u5176\u4e2d\uff0c\u4ee5\u51cf\u5c11\u67e5\u627e\u6b21\u6570\u3002<\/p>\n<p>\u5220\u9664\u548c\u66f4\u65b0\u8fc7\u7a0b<\/p>\n<p>\u5f53\u6709\u5220\u9664\u64cd\u4f5c\u65f6\uff0c\u5e76\u4e0d\u9700\u8981\u50cfB+\u6811\u4e00\u6837\uff0c\u5728\u78c1\u76d8\u4e2d\u7684\u627e\u5230\u76f8\u5e94\u7684\u6570\u636e\u540e\u518d\u5220\u9664\u3002<\/p>\n<ol>\n<li>\u9996\u5148\u4f1a\u5728\u901a\u8fc7\u67e5\u627e\u6d41\u7a0b\uff0c\u5728Memory-Table\u3001Immuatble Memory-Table\u4e2d\u8fdb\u884c\u67e5\u627e\u3002<\/li>\n<li>\u5982\u679c\u627e\u5230\u5219\u5bf9\u7ed3\u679c\u6807\u8bb0\u4e3a\u201c\u5220\u9664\u201d\u3002<\/li>\n<li>\u5426\u5219\u4f1a\u5728\u7ed3\u5c3e\u8ffd\u52a0\u4e00\u4e2a\u8282\u70b9\uff0c\u5e76\u6807\u8bb0\u4e3a\u201c\u5220\u9664\u201d  <br \/>\u5728\u771f\u6b63\u5220\u9664\u524d\uff0c\u672a\u6765\u7684\u67e5\u8be2\u64cd\u4f5c\uff0c\u90fd\u4f1a\u5148\u627e\u5230\u8fd9\u4e2a\u88ab\u6807\u8bb0\u4e3a\u201c\u5220\u9664\u201d\u7684\u8bb0\u5f55\u3002<\/li>\n<li>\u4e4b\u540e\u4f1a\u5728\u67d0\u4e00\u65f6\u523b\uff0c\u901a\u8fc7\u538b\u7f29\u8fc7\u7a0b\u771f\u6b63\u5220\u9664\u5b83\u3002<\/li>\n<\/ol>\n<p>\u66f4\u65b0\u64cd\u4f5c\u548c\u5220\u9664\u64cd\u4f5c\u7c7b\u4f3c\uff0c\u90fd\u662f\u53ea\u64cd\u4f5c\u5185\u5b58\u533a\u57df\u7684\u7ed3\u6784\uff0c\u5199\u5165\u4e00\u4e2a\u6807\u5fd7\uff0c\u968f\u540e\u771f\u6b63\u7684\u66f4\u65b0\u64cd\u4f5c\u88ab\u5ef6\u8fdf\u5728\u5408\u5e76\u65f6\u4e00\u5e76\u5b8c\u6210\u3002\u7531\u4e8e\u64cd\u4f5c\u662f\u53d1\u751f\u5728\u5185\u5b58\u4e2d\uff0c\u5176\u8bfb\u5199\u6027\u80fd\u4e5f\u80fd\u4fdd\u969c\u3002<\/p>\n<h3>4.3 RockDB \u7684\u4f18\u7f3a\u70b9<\/h3>\n<p>\u4f18\u70b9<\/p>\n<ol>\n<li>\u5c06\u6570\u636e\u62c6\u5206\u4e3a\u51e0\u767eM\u5927\u5c0f\u7684\u5757\uff0c\u7136\u540e\u987a\u5e8f\u5199\u5165<\/li>\n<li>\u9996\u6b21\u5199\u5165\u7684\u76ee\u7684\u5730\u662f\u5185\u5b58\uff0c\u91c7\u7528WAL\u8bbe\u8ba1\u601d\u8def\uff0c\u52a0\u4e0a\u987a\u5e8f\u5199\uff0c\u63d0\u9ad8\u5199\u5165\u7684\u80fd\u529b\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u8fd1\u4f3c\u5e38\u6570<\/li>\n<li>\u652f\u6301\u4e8b\u52a1\uff0c\u4f46L0\u5c42\u7684\u6570\u636e\uff0ckey\u7684\u533a\u95f4\u6709\u91cd\u53e0\uff0c\u652f\u6301\u8f83\u5dee<\/li>\n<\/ol>\n<p>\u7f3a\u70b9<\/p>\n<ol>\n<li>\u8bfb\u5199\u653e\u5927\u4e25\u91cd<\/li>\n<li>\u5e94\u5bf9\u7a81\u53d1\u6d41\u91cf\u7684\u65f6\u5019\uff0c\u524a\u5cf0\u80fd\u529b\u4e0d\u8db3<\/li>\n<li>\u538b\u7f29\u7387\u6709\u9650<\/li>\n<li>\u7d22\u5f15\u6548\u7387\u8f83\u4f4e<\/li>\n<li>\u538b\u7f29\u8fc7\u7a0b\u6bd4\u8f83\u6d88\u8017\u7cfb\u7edf\u8d44\u6e90\uff0c\u540c\u65f6\u5bf9\u8bfb\u5199\u5f71\u54cd\u8f83\u5927<\/li>\n<\/ol>\n<h2>5 \u603b\u7ed3<\/h2>\n<p>\u4ee5\u4e0a\u9488\u5bf9TiDB\u7684\u6574\u4f53\u67b6\u6784\u8fdb\u884c\u5efa\u5355\u4ecb\u7ecd\uff0c\u5e76\u7740\u91cd\u63cf\u8ff0\u4e86TiKV\u662f\u5982\u4f55\u7ec4\u7ec7\u6570\u636e\u3001\u5982\u4f55\u5b58\u50a8\u6570\u636e\u3002\u5c06\u5176Key-Value\u7684\u8bbe\u8ba1\u601d\u8def\uff0c\u4e0eMySQL\u7684\u7d22\u5f15\u7ed3\u6784\u8fdb\u884c\u5bf9\u6bd4\uff0c\u8bc6\u522b\u76f8\u4f3c\u4e0e\u5dee\u5f02\u3002TiDB\u4f9d\u8d56RockDB\u5b9e\u73b0\u4e86\u6301\u4e45\u5316\uff0c\u5176\u4e2d\u7684Lsm-Tree\uff0c\u4f5c\u4e3aB+Tree\u7684\u6539\u8fdb\u7ed3\u6784\uff0c\u5176\u5173\u6ce8\u4e2d\u5fc3\u662f\u201c\u5982\u4f55\u5728\u9891\u7e41\u7684\u6570\u636e\u6539\u52a8\u4e0b\u4fdd\u6301\u7cfb\u7edf\u8bfb\u53d6\u901f\u5ea6\u7684\u7a33\u5b9a\u6027\u201d\uff0c\u4ee5\u987a\u5e8f\u5199\u78c1\u76d8\u4f5c\u4e3a\u76ee\u6807\uff0c\u5047\u8bbe\u9891\u7e41\u5730\u5bf9\u6570\u636e\u8fdb\u884c\u6574\u7406\uff0c\u529b\u6c42\u6570\u636e\u7684\u987a\u5e8f\u6027\uff0c\u5e26\u6765\u8bfb\u6027\u80fd\u7684\u7a33\u5b9a\uff0c\u540c\u65f6\u4e5f\u5e26\u6765\u4e86\u4e00\u5b9a\u7a0b\u5ea6\u7684\u8bfb\u5199\u653e\u5927\u95ee\u9898\u3002<\/p>\n<blockquote>\n<p>\u4f5c\u8005\uff1a\u4eac\u4e1c\u7269\u6d41 \u803f\u5b8f\u5b87<\/p>\n<p>\u6765\u6e90\uff1a\u4eac\u4e1c\u4e91\u5f00\u53d1\u8005\u793e\u533a \u81ea\u733f\u5176\u8bf4Tech<\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043990858\">https:\/\/segmentfault.com\/a\/1190000043990858<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1 \u6982\u8ff0 TiDB \u662f PingCAP \u516c\u53f8\u81ea\u4e3b\u8bbe\u8ba1\u3001\u7814\u53d1\u7684\u5f00\u6e90\u5206\u5e03\u5f0f\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u662f\u4e00\u6b3e\u540c\u65f6\u652f\u6301\u5728\u7ebf\u4e8b\u52a1\u5904\u7406 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008062","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008062"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008062\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}