{"id":99779,"date":"2026-09-03T10:24:48","date_gmt":"2026-09-03T02:24:48","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/99779.html"},"modified":"2026-09-03T10:24:48","modified_gmt":"2026-09-03T02:24:48","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88%e8%af%b4%e6%9c%89%e5%ba%8f%e6%98%af%e5%ad%98%e5%82%a8%e5%bc%95%e6%93%8e%e7%9a%84%e5%ba%95%e5%b1%82%e7%89%a9%e7%90%86%e5%ae%9a%e5%be%8b%ef%bc%9f%e6%b7%b1","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/99779.html","title":{"rendered":"\u4e3a\u4ec0\u4e48\u8bf4\u201c\u6709\u5e8f\u201d\u662f\u5b58\u50a8\u5f15\u64ce\u7684\u5e95\u5c42\u7269\u7406\u5b9a\u5f8b\uff1f\u6df1\u5ea6\u62c6\u89e3 LevelDB\/RocksDB \u7684 C++ \u63a5\u53e3\u6a21\u578b\uff01"},"content":{"rendered":"<p>\u5982\u679c\u4f60\u4e60\u60ef\u4e86\u00a0std::unordered_map\u00a0\u6216 Redis \u8fd9\u79cd\u628a\u6570\u636e\u6563\u5217\u843d\u6876\u7684\u601d\u7ef4&#xff0c;\u521d\u6b21\u63a5\u89e6\u5de5\u4e1a\u7ea7\u5d4c\u5165\u5f0f KV \u5f15\u64ce&#xff08;\u5982 RocksDB \/ LevelDB&#xff09;\u65f6&#xff0c;\u5927\u6982\u7387\u4f1a\u88ab\u5b83\u7684\u201c\u8d8a\u6743\u201d\u884c\u4e3a\u6253\u4e2a\u63aa\u624b\u4e0d\u53ca&#xff1a;\u4f60\u660e\u660e\u4ece\u672a\u6307\u5b9a\u8fc7\u4efb\u4f55\u6392\u5e8f\u89c4\u5219&#xff0c;\u5b83\u5374\u56fa\u6267\u5730\u91cd\u6392\u4e86\u4f60\u7684\u6bcf\u4e00\u4e2a\u5b57\u8282\u3002<\/p>\n<p>\u5199\u8fdb 1 \u5230 12 \u7684\u6574\u6570\u5b57\u7b26\u4e32&#xff0c;\u8bfb\u51fa\u6765\u5374\u53d8\u6210\u4e86\u5b57\u5178\u5e8f&#xff1b;\u5982\u679c\u4f60\u76f4\u63a5\u628a\u00a0uint64_t\u00a0\u7684\u5185\u5b58\u6309 Little-Endian\u00a0reinterpret_cast\u00a0\u6254\u8fdb\u00a0Slice&#xff0c;\u539f\u672c\u5355\u8c03\u9012\u589e\u7684\u6570\u503c\u5e8f\u5217\u66f4\u4f1a\u5728\u8de8\u5b57\u8282\u7ffb\u8f6c\u5904\u88ab\u5f7b\u5e95\u641e\u788e\u3002<\/p>\n<p>\u590d\u73b0\u8fd9\u4e2a\u201c\u4e0d\u8bf7\u81ea\u6765\u201d\u7684\u6392\u5e8f&#xff0c;\u53ea\u9700\u8981\u51e0\u884c\u7eaf\u7cb9\u7684 C&#043;&#043;&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>std::unique_ptr&lt;DB&gt; db;<br \/>\nOptions options;<br \/>\noptions.create_if_missing &#061; true;<br \/>\nStatus s &#061; DB::Open(options, &#034;\/tmp\/kv&#034;, &amp;db);<\/p>\n<p>for (int i &#061; 1; i &lt;&#061; 12; &#043;&#043;i) {<br \/>\n  \/\/ \u9677\u9631\u5c31\u85cf\u5728 std::to_string(i) \u6784\u9020\u51fa\u7684 Slice \u89c6\u56fe\u4e0e\u9ed8\u8ba4\u4e09\u8def Comparator \u4e2d<br \/>\n  db-&gt;Put(WriteOptions(), std::to_string(i), &#034;v&#034;);<br \/>\n}<\/p>\n<p>std::unique_ptr&lt;Iterator&gt; it(db-&gt;NewIterator(ReadOptions()));<br \/>\nfor (it-&gt;SeekToFirst(); it-&gt;Valid(); it-&gt;Next()) {<br \/>\n  std::printf(&#034;%s &#034;, it-&gt;key().ToString().c_str());<br \/>\n}<br \/>\n\/\/ \u8f93\u51fa&#xff1a;1 10 11 12 2 3 4 5 6 7 8 9<\/p>\n<p>\u7ecf\u9a8c\u4e30\u5bcc\u7684 C&#043;&#043; \u5de5\u7a0b\u5e08\u4e00\u773c\u5c31\u80fd\u770b\u7a7f\u5e95\u5c42\u662f\u00a0memcmp\u00a0\u5b57\u8282\u5e8f\u5728\u4f5c\u795f\u2014\u2014&#039;1&#039;\u00a0(0x31) \u5929\u7136\u6392\u5728\u00a0&#039;2&#039;\u00a0(0x32) \u524d\u9762\u3002\u4f46\u771f\u6b63\u503c\u5f97\u6df1\u601d\u7684\u95ee\u9898\u4e0d\u662f\u73b0\u8c61\u672c\u8eab&#xff0c;\u800c\u662f\u67b6\u6784\u54f2\u5b66&#xff1a;\u4e3a\u4ec0\u4e48\u8fd9\u7c7b\u5f15\u64ce\u54ea\u6015\u727a\u7272\u5199\u5165\u7075\u6d3b\u6027&#xff0c;\u4e5f\u7edd\u4e0d\u63d0\u4f9b\u4efb\u4f55\u201c\u65e0\u5e8f\u201d\u9009\u9879&#xff1f;<\/p>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u6216\u8ba1\u5212\u81ea\u7814\u4e00\u4e2a\u9ad8\u6027\u80fd\u5d4c\u5165\u5f0f\u5b58\u50a8\u5f15\u64ce&#xff0c;\u641e\u61c2\u8fd9\u5957\u63a5\u53e3\u6a21\u578b\u4e0e\u80cc\u540e\u7684 C\u5951\u7ea6\u8bbe\u8ba1&#xff0c;\u5c31\u662f\u4f60\u5fc5\u987b\u8de8\u8fc7\u7684\u7b2c\u4e00\u9053\u5206\u6c34\u5cad\u3002\u8fd9\u7bc7\u5c31\u987a\u7740\u4e0a\u9762\u7684\u4ee3\u7801\u5411\u4e0b\u62c6\u89e3&#xff0c;\u9010\u5c42\u5265\u5f00\u73b0\u4ee3 C\u00a0\u5b58\u50a8\u5f15\u64ce\u5728\u63a5\u53e3\u4e0e\u5e95\u5c42\u6a21\u578b\u8bbe\u8ba1\u4e0a\u7684\u786c\u6838\u53d6\u820d\u3002<\/p>\n<hr \/>\n<h3>1. \u5148\u628a\u5b83\u5f53\u54c8\u5e0c\u8868\u7528&#xff0c;\u76f4\u5230\u8303\u56f4\u626b\u63cf\u628a\u4f60\u62e6\u4e0b\u6765<\/h3>\n<p>\u649e\u89c1\u987a\u5e8f\u4e4b\u524d&#xff0c;\u5148\u628a\u5b83\u5f53\u6700\u6734\u7d20\u7684\u4e1c\u897f\u4f7f&#xff1a;\u4e00\u4e2a\u80fd\u843d\u76d8\u7684 map\u3002\u4f60\u8111\u5b50\u91cc\u90a3\u4e2a\u00a0std::unordered_map&lt;string, string&gt;\u00a0\u7684\u6a21\u578b&#xff0c;\u5927\u534a\u662f\u5bf9\u7684\u3002\u5199\u4e00\u4e2a\u952e&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h&#xff1a;Set the database entry for &#034;key&#034; to &#034;value&#034;.<br \/>\n\/\/ If &#034;key&#034; already exists, it will be overwritten.<br \/>\nvirtual Status Put(const WriteOptions&amp; options,<br \/>\n                   ColumnFamilyHandle* column_family,<br \/>\n                   const Slice&amp; key, const Slice&amp; value) &#061; 0;<\/p>\n<p>\u6ce8\u91ca\u7b2c\u4e8c\u884c\u5c31\u662f map \u7684\u8d4b\u503c\u8bed\u4e49&#xff1a;key \u5df2\u5b58\u5728\u5c31\u8986\u76d6\u3002\u6240\u4ee5\u201c\u66f4\u65b0\u201d\u5728\u63a5\u53e3\u5c42\u6839\u672c\u6ca1\u6709\u72ec\u7acb\u7684\u52a8\u8bcd&#xff0c;\u5b83\u5c31\u662f\u518d\u00a0Put\u00a0\u4e00\u6b21\u540c\u4e00\u4e2a key\u3002\u8fd9\u4e00\u70b9\u5148\u8bb0\u4f4f&#xff0c;\u7b2c 5 \u8282\u6211\u4f1a\u544a\u8bc9\u4f60\u5b83\u5728\u5e95\u4e0b\u5176\u5b9e\u6ca1\u8986\u76d6\u4efb\u4f55\u4e1c\u897f\u2014\u2014\u53ea\u662f\u538b\u4e86\u4e00\u5c42\u65b0\u7248\u672c\u4e0a\u53bb&#xff0c;\u4f46\u90a3\u662f\u540e\u8bdd\u3002<\/p>\n<p>\u53d6\u503c\u8fd9\u4e00\u4fa7&#xff0c;\u6ce8\u610f\u5b83\u7684\u8fd4\u56de\u7ea6\u5b9a&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h&#xff1a;Returns OK on success. Returns NotFound and an empty<br \/>\n\/\/ value in &#034;*value&#034; if there is no entry for &#034;key&#034;. Returns<br \/>\n\/\/ some other non-OK status on error.<br \/>\nvirtual Status Get(const ReadOptions&amp; options,<br \/>\n                   ColumnFamilyHandle* column_family, const Slice&amp; key,<br \/>\n                   PinnableSlice* value, std::string* timestamp) &#061; 0;<\/p>\n<p>\u201c\u67e5\u4e0d\u5230\u201d\u4f1a\u7ed9\u4f60\u4e00\u4e2a\u6b63\u5e38\u7684\u00a0Status::NotFound()\u00a0\u8fd4\u56de\u503c&#xff0c;\u4ece\u4e0d\u629b\u5f02\u5e38\u3002\u8fd9\u8ddf\u00a0std::map::find\u00a0\u8fd4\u56de\u00a0end()\u00a0\u662f\u4e00\u4e2a\u54f2\u5b66\u2014\u2014\u627e\u4e0d\u5230\u662f\u67e5\u8be2\u7684\u5408\u6cd5\u7ed3\u679c\u4e4b\u4e00&#xff0c;\u4e0d\u662f\u9519\u8bef\u3002\u4f60\u73b0\u5728\u5148\u628a\u8fd9\u5f53\u98ce\u683c\u8bb0\u4e0b&#xff0c;\u7b2c 7 \u8282\u6211\u4f1a\u544a\u8bc9\u4f60&#xff0c;\u8fd9\u53f0\u5f15\u64ce\u4ece\u5934\u5230\u5c3e\u4e0d\u7528 C&#043;&#043; \u5f02\u5e38&#xff0c;\u662f\u4e00\u4e2a\u523b\u8fdb\u6574\u5957 API \u7684\u786c\u51b3\u5b9a&#xff0c;Get\u00a0\u53ea\u662f\u5176\u4e2d\u6700\u4e0d\u8d77\u773c\u7684\u4e00\u5904\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\u4f60\u624b\u91cc\u6709\u4e86\u00a0Put\/Get\/Delete\u00a0\u4e09\u4e2a\u52a8\u4f5c&#xff0c;\u5fc3\u667a\u6a21\u578b\u662f\u201c\u4e00\u4e2a\u843d\u76d8\u7684 map\u201d&#xff0c;\u591f\u7528\u3002\u76f4\u5230\u4f60\u5199\u4e0b\u8fd9\u6837\u4e00\u4e2a\u9700\u6c42&#xff1a;<\/p>\n<p>\u628a\u00a0user:1000\u00a0\u5230\u00a0user:2000\u00a0\u4e4b\u95f4\u7684\u6240\u6709\u8bb0\u5f55\u62c9\u51fa\u6765\u3002<\/p>\n<p>std::unordered_map\u00a0\u5e72\u4e0d\u4e86\u8fd9\u4ef6\u4e8b\u3002\u54c8\u5e0c\u8868\u628a key \u6253\u6563\u5230\u6876\u91cc&#xff0c;user:1000\u00a0\u548c\u00a0user:1001\u00a0\u5927\u6982\u7387\u9694\u7740\u534a\u5f20\u8868&#xff0c;\u5b83\u6ca1\u6709\u201c\u4e0b\u4e00\u4e2a key\u201d\u7684\u6982\u5ff5\u3002\u53ef\u5f00\u5934\u90a3\u6bb5\u4ee3\u7801\u91cc&#xff0c;it-&gt;Next()\u00a0\u660e\u660e\u5c31\u80fd\u4e00\u4e2a\u63a5\u4e00\u4e2a\u8d70\u4e0b\u53bb&#xff0c;\u800c\u4e14\u8d70\u51fa\u6765\u662f\u6709\u5e8f\u7684\u3002\u5b83\u51ed\u4ec0\u4e48\u80fd\u7ed9\u4f60\u533a\u95f4&#xff1f;\u00a0\u8fd9\u4e2a\u201c\u51ed\u4ec0\u4e48\u201d&#xff0c;\u5c31\u662f\u8fd9\u53f0\u5f15\u64ce\u548c\u4e00\u5f20\u54c8\u5e0c\u8868\u7684\u5206\u6c34\u5cad&#xff0c;\u7b54\u6848\u5728\u7b2c 3 \u8282\u3002\u4f46\u5728\u56de\u7b54\u5b83\u4e4b\u524d&#xff0c;\u6211\u5f97\u5148\u5e26\u4f60\u770b\u5199\u64cd\u4f5c\u2014\u2014\u56e0\u4e3a\u987a\u5e8f\u8fd9\u4ef6\u4e8b&#xff0c;\u7b2c\u4e00\u6b21\u5728\u63a5\u53e3\u4e0a\u9732\u5934\u662f\u5728\u5220\u9664\u91cc\u3002<\/p>\n<h3>2. \u5220\u9664\u53ea\u662f\u8bb0\u4e00\u7b14&#xff0c;\u66f4\u65b0\u53ea\u662f\u538b\u4e00\u5c42<\/h3>\n<p>\u5148\u770b\u6700\u666e\u901a\u7684\u5220\u9664&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h&#xff1a;Remove the database entry (if any) for &#034;key&#034;.<br \/>\n\/\/ It is not an error if &#034;key&#034; did not exist in the database.<br \/>\nvirtual Status Delete(const WriteOptions&amp; options,<br \/>\n                      ColumnFamilyHandle* column_family,<br \/>\n                      const Slice&amp; key) &#061; 0;<\/p>\n<p>\u201c\u5220\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684 key \u4e0d\u7b97\u9519\u201d\u2014\u2014\u53c8\u4e00\u6b21&#xff0c;\u63a5\u53e3\u5728\u544a\u8bc9\u4f60\u5b83\u5bf9\u201c\u9519\u8bef\u201d\u7684\u5b9a\u4e49\u5f88\u514b\u5236\u3002\u5220\u9664\u662f\u5e42\u7b49\u7684&#xff0c;\u4f60\u5220\u5341\u904d\u548c\u5220\u4e00\u904d&#xff0c;\u7ed3\u679c\u548c\u8fd4\u56de\u90fd\u4e00\u6837\u3002\u8fd9\u8ddf\u4f60\u81ea\u7814\u5f15\u64ce\u65f6\u7684\u76f4\u89c9\u53ef\u80fd\u51b2\u7a81&#xff1a;\u5f88\u591a\u4eba\u4f1a\u8ba9\u00a0Delete\u00a0\u5728 key \u4e0d\u5b58\u5728\u65f6\u8fd4\u56de\u4e00\u4e2a\u201c\u6ca1\u5220\u5230\u201d\u7684\u4fe1\u53f7&#xff0c;\u7136\u540e\u8c03\u7528\u65b9\u5230\u5904\u5224\u8fd9\u4e2a\u4fe1\u53f7\u3002\u8fd9\u53f0\u5f15\u64ce\u7684\u9009\u62e9\u662f\u2014\u2014\u4e0d\u7ed9\u4f60\u8fd9\u4e2a\u4fe1\u53f7&#xff0c;\u56e0\u4e3a\u5728\u4e00\u4e2a LSM \u7ed3\u6784\u91cc&#xff0c;\u201c\u8fd9\u4e2a key \u73b0\u5728\u5230\u5e95\u5b58\u4e0d\u5b58\u5728\u201d\u672c\u8eab\u5c31\u662f\u4e00\u6b21\u67e5\u8be2\u7684\u6210\u672c&#xff0c;Delete\u00a0\u4e0d\u60f3\u66ff\u4f60\u4ed8\u8fd9\u4e2a\u6210\u672c\u3002<\/p>\n<p>\u771f\u6b63\u4f1a\u54ac\u4f60\u7684\u662f\u5b83\u65c1\u8fb9\u90a3\u4e2a\u5144\u5f1f&#xff0c;SingleDelete\u3002\u5148\u770b\u4e00\u6bb5\u4f1a\u51fa\u4e8b\u7684\u7528\u6cd5&#xff0c;\u6211\u4eec\u8ba9\u5b83\u5f53\u573a\u574f\u6389&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>db-&gt;Put(WriteOptions(), &#034;k&#034;, &#034;v1&#034;);<br \/>\ndb-&gt;Put(WriteOptions(), &#034;k&#034;, &#034;v2&#034;);   \/\/ \u8986\u76d6&#xff0c;\u5199\u4e86\u7b2c\u4e8c\u904d<br \/>\ndb-&gt;SingleDelete(WriteOptions(), &#034;k&#034;);<\/p>\n<p>std::string val;<br \/>\nStatus s &#061; db-&gt;Get(ReadOptions(), &#034;k&#034;, &amp;val);<br \/>\n\/\/ \u4f60\u4ee5\u4e3a s.IsNotFound()\u3002\u4f46\u8fd9\u91cc\u7684\u884c\u4e3a\u662f\u3010\u672a\u5b9a\u4e49\u3011\u7684&#xff1a;<br \/>\n\/\/ val \u53ef\u80fd\u662f &#034;v1&#034;&#xff0c;\u53ef\u80fd NotFound&#xff0c;\u53d6\u51b3\u4e8e\u5e95\u5c42\u538b\u7f29\u5230\u54ea\u4e00\u6b65\u4e86\u3002<\/p>\n<p>\u6211\u7b2c\u4e00\u6b21\u7528\u00a0SingleDelete\u00a0\u5c31\u683d\u5728\u8fd9\u4e0a\u9762\u3002\u5f53\u65f6\u60f3\u5f53\u7136\u628a\u5b83\u5f53\u6210\u201c\u66f4\u5feb\u7684 Delete\u201d&#xff0c;\u5728\u4e00\u6761\u672c\u8be5\u5e42\u7b49\u7684\u5199\u8def\u5f84\u4e0a\u6df7\u7740\u7528&#xff0c;\u7070\u5ea6\u4e0a\u7ebf\u4e09\u5929\u540e\u6709\u4e00\u6279\u672c\u8be5\u6d88\u5931\u7684 key \u53c8\u8bc8\u5c38\u56de\u6765\u4e86&#xff0c;\u6392\u67e5\u5230\u6700\u540e\u662f\u538b\u7f29\u628a\u4e24\u6761\u5199\u8bb0\u5f55\u7684\u62b5\u6d88\u987a\u5e8f\u641e\u4e71\u4e86\u3002\u539f\u56e0\u5934\u6587\u4ef6\u91cc\u5199\u5f97\u6e05\u6e05\u695a\u695a&#xff0c;\u662f\u6211\u6ca1\u8bfb&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h&#xff1a;If a key is overwritten (by calling Put() multiple times),<br \/>\n\/\/ then the result of calling SingleDelete() on this key is undefined.<br \/>\n\/\/ SingleDelete() only behaves correctly if there has been only one<br \/>\n\/\/ Put() for this key since the previous call to SingleDelete().<\/p>\n<p>SingleDelete\u00a0\u7684\u5951\u7ea6\u662f&#xff1a;\u4ece\u4e0a\u4e00\u6b21 SingleDelete \u5230\u73b0\u5728&#xff0c;\u8fd9\u4e2a key \u53ea\u88ab Put \u8fc7\u6070\u597d\u4e00\u6b21\u3002\u00a0\u8fdd\u53cd\u4e86\u5c31\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u5b83\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u82db\u523b&#xff1f;\u56e0\u4e3a\u5b83\u662f\u4e00\u4e2a\u9488\u5bf9\u7279\u5b9a\u5199\u8d1f\u8f7d\u7684\u6027\u80fd\u4f18\u5316\u2014\u2014\u666e\u901a\u00a0Delete\u00a0\u4f1a\u7559\u4e0b\u4e00\u6761\u201c\u5893\u7891\u201d\u8bb0\u5f55&#xff0c;\u5f97\u7b49\u538b\u7f29\u65f6\u548c\u88ab\u5220\u7684\u90a3\u6761\u771f\u503c\u76f8\u9047\u624d\u80fd\u53cc\u53cc\u6d88\u6389&#xff1b;SingleDelete\u00a0\u627f\u8bfa\u201c\u6211\u4fdd\u8bc1\u53ea\u6709\u4e00\u6761\u771f\u503c\u201d&#xff0c;\u4e8e\u662f\u5893\u7891\u53ef\u4ee5\u7528\u66f4\u4fbf\u5b9c\u7684\u65b9\u5f0f\u62b5\u6d88\u3002\u4f60\u62ff\u8d70\u4e86\u6027\u80fd&#xff0c;\u5c31\u5f97\u66ff\u5b83\u5b88\u4f4f\u90a3\u4e2a\u524d\u63d0\u3002\u5207\u8bb0&#xff0c;\u5207\u8bb0&#xff1a;\u4e00\u4e2a key \u7684\u5199\u8def\u5f84\u4e0a\u53ea\u8981\u6709\u53ef\u80fd Put \u4e24\u6b21&#xff0c;\u5c31\u6c38\u8fdc\u522b\u5bf9\u5b83\u7528 SingleDelete\u3002\u00a0\u8fd9\u662f\u81ea\u7814\u5f15\u64ce\u6700\u5bb9\u6613\u6284\u9519\u7684\u4e00\u7c7b\u63a5\u53e3\u2014\u2014\u628a\u522b\u4eba\u4e3a\u7279\u5b9a\u524d\u63d0\u8bbe\u8ba1\u7684\u5feb\u8def\u5f84&#xff0c;\u5f53\u6210\u901a\u7528\u8def\u5f84\u4e71\u94fa\u3002<\/p>\n<p>\u5199\u64cd\u4f5c\u8fd8\u6709\u4e00\u4e2a\u4f60\u8fdf\u65e9\u8981\u63d0\u4f9b\u7684\u80fd\u529b&#xff1a;\u628a\u591a\u4e2a\u5199\u6253\u6210\u4e00\u4e2a\u539f\u5b50\u5305\u3002\u770b\u8fd9\u6bb5\u2014\u2014\u4e00\u6b21\u5220\u4e00\u4e2a key\u3001\u52a0\u4e24\u4e2a key&#xff0c;\u8981\u4e48\u5168\u6210\u3001\u8981\u4e48\u5168\u4e0d\u6210&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>WriteBatch batch;<br \/>\nbatch.Put(handles[0], Slice(&#034;key2&#034;), Slice(&#034;value2&#034;));<br \/>\nbatch.Put(handles[1], Slice(&#034;key3&#034;), Slice(&#034;value3&#034;));<br \/>\nbatch.Delete(handles[0], Slice(&#034;key&#034;));<br \/>\nStatus s &#061; db-&gt;Write(WriteOptions(), &amp;batch);<\/p>\n<p>WriteBatch\u00a0\u628a\u82e5\u5e72\u4e2a\u00a0Put\/Delete\u00a0\u6512\u6210\u4e00\u6279&#xff0c;Write\u00a0\u4e00\u6b21\u6027\u539f\u5b50\u843d\u76d8\u3002\u6709\u610f\u601d\u7684\u662f&#xff0c;\u5355\u4e2a\u00a0Put\u00a0\u5176\u5b9e\u4e5f\u662f\u8d70\u00a0Write\u00a0\u7684\u2014\u2014\u5b83\u5c31\u662f\u4e00\u4e2a\u53ea\u88c5\u4e86\u4e00\u6761\u64cd\u4f5c\u7684 batch&#xff0c;\u63a5\u53e3\u5c42\u6839\u672c\u6ca1\u6709\u7b2c\u4e8c\u6761\u5199\u8def\u5f84\u3002\u539f\u5b50\u6027\u4ece\u54ea\u6765&#xff1f;\u4ece\u90a3\u6761\u9884\u5199\u65e5\u5fd7&#xff08;WAL&#xff09;&#xff1a;\u6574\u6279\u64cd\u4f5c\u5148\u4f5c\u4e3a\u4e00\u6761\u8bb0\u5f55\u987a\u5e8f\u8ffd\u52a0\u8fdb\u65e5\u5fd7&#xff0c;\u65e5\u5fd7\u843d\u76d8\u6210\u529f\u8fd9\u6279\u624d\u7b97\u6570&#xff1b;\u4e2d\u9014\u5d29\u4e86&#xff0c;\u91cd\u542f\u65f6\u8981\u4e48\u6574\u6761\u65e5\u5fd7\u8fd8\u5728\u3001\u6574\u6279\u91cd\u653e&#xff0c;\u8981\u4e48\u6574\u6761\u6ca1\u5199\u5168\u3001\u6574\u6279\u5f53\u6ca1\u53d1\u751f\u8fc7\u3002\u4f60\u81ea\u7814\u5f15\u64ce\u7684\u539f\u5b50\u6027\u5730\u57fa&#xff0c;\u51e0\u4e4e\u4e00\u5b9a\u662f\u8fd9\u6761\u201c\u5148\u987a\u5e8f\u5199\u65e5\u5fd7\u3001\u518d\u6539\u5185\u5b58\u7ed3\u6784\u201d\u7684\u8def\u5b50\u2014\u2014\u800c\u987a\u5e8f\u5199\u65e5\u5fd7\u53c8\u662f\u4e00\u6b21\u5bf9\u78c1\u76d8\u6781\u53cb\u597d\u7684\u987a\u5e8f IO&#xff0c;\u548c\u6709\u5e8f\u7ed3\u6784\u90a3\u80a1\u201c\u628a\u968f\u673a\u63b0\u6210\u987a\u5e8f\u201d\u7684\u6c14\u8d28\u4e00\u8109\u76f8\u627f\u3002<\/p>\n<p>\u73b0\u5728\u770b\u987a\u5e8f\u7b2c\u4e00\u6b21\u9732\u5934\u7684\u5730\u65b9&#xff0c;\u533a\u95f4\u5220\u9664&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h&#xff1a;Removes the database entries in the range<br \/>\n\/\/ [&#034;begin_key&#034;, &#034;end_key&#034;), i.e., including &#034;begin_key&#034; and<br \/>\n\/\/ excluding &#034;end_key&#034;.<br \/>\n\/\/ If &#034;end_key&#034; comes before &#034;start_key&#034; according to the user&#039;s<br \/>\n\/\/ comparator, a &#096;Status::InvalidArgument&#096; is returned.<br \/>\nvirtual Status DeleteRange(const WriteOptions&amp; options,<br \/>\n                           ColumnFamilyHandle* column_family,<br \/>\n                           const Slice&amp; begin_key, const Slice&amp; end_key);<\/p>\n<p>\u4e24\u4e2a\u7ec6\u8282\u503c\u5f97\u505c\u4e00\u4e0b\u3002\u4e00\u662f\u534a\u5f00\u533a\u95f4\u00a0[begin, end)&#xff0c;\u542b\u5de6\u4e0d\u542b\u53f3\u2014\u2014\u8fd9\u662f\u6240\u6709\u533a\u95f4\u63a5\u53e3\u7684\u8001\u89c4\u77e9&#xff0c;\u548c STL \u8fed\u4ee3\u5668\u4e00\u4e2a\u7ea6\u5b9a&#xff0c;\u597d\u5904\u662f\u76f8\u90bb\u533a\u95f4\u80fd\u65e0\u7f1d\u62fc\u63a5&#xff0c;[a,b)\u00a0\u52a0\u00a0[b,c)\u00a0\u6b63\u597d\u7b49\u4e8e\u00a0[a,c)&#xff0c;\u4e0d\u91cd\u4e0d\u6f0f\u3002\u4e8c\u662f\u90a3\u53e5\u00a0if &#034;end_key&#034; comes before &#034;start_key&#034; according to the user&#039;s comparator\u2014\u2014\u201caccording to the user&#039;s comparator\u201d\u3002\u5230\u8fd9\u91cc&#xff0c;\u4f60\u5df2\u7ecf\u8eb2\u4e0d\u5f00\u90a3\u4e2a\u95ee\u9898\u4e86&#xff1a;\u8fd9\u53f0\u5f15\u64ce\u5224\u65ad\u8c01\u5728\u524d\u8c01\u5728\u540e&#xff0c;\u9760\u7684\u662f\u4e00\u4e2a\u53eb comparator \u7684\u4e1c\u897f&#xff0c;\u800c\u4e14\u662f\u201cuser&#039;s\u201d&#xff0c;\u53ef\u4ee5\u7531\u4f60\u6362\u3002\u533a\u95f4\u5220\u9664\u53ea\u662f\u7b2c\u4e00\u4e2a\u628a\u5b83\u903c\u5230\u53f0\u9762\u4e0a\u7684\u63a5\u53e3&#xff0c;\u63a5\u4e0b\u6765\u6bcf\u4e00\u4e2a\u8ddf\u201c\u8303\u56f4\u201d\u201c\u987a\u5e8f\u201d\u201c\u524d\u7f00\u201d\u6cbe\u8fb9\u7684\u529f\u80fd&#xff0c;\u5e95\u4e0b\u90fd\u7ad9\u7740\u5b83\u3002<\/p>\n<h3>3. \u987a\u5e8f\u662f\u8c01\u5b9a\u7684&#xff1a;\u4e09\u8def\u6bd4\u8f83\u51fd\u6570\u5c31\u662f\u8fd9\u53f0\u5f15\u64ce\u7684\u201c\u7269\u7406\u5b9a\u5f8b\u201d<\/h3>\n<p>\u56de\u5230\u5f00\u5934\u90a3\u4e2a\u8c1c&#xff1a;1 10 11 12 2\u3002\u73b0\u5728\u628a\u5b9a\u4e49\u987a\u5e8f\u7684\u90a3\u4e2a\u5bf9\u8c61\u8bf7\u51fa\u6765\u3002\u5b83\u5728 comparator.h \u91cc&#xff0c;\u63a5\u53e3\u5c0f\u5f97\u53ef\u601c&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ comparator.h<br \/>\nclass CompareInterface {<br \/>\n public:<br \/>\n  \/\/ Three-way comparison.  Returns value:<br \/>\n  \/\/   &lt; 0 iff &#034;a&#034; &lt; &#034;b&#034;,<br \/>\n  \/\/   &#061;&#061; 0 iff &#034;a&#034; &#061;&#061; &#034;b&#034;,<br \/>\n  \/\/   &gt; 0 iff &#034;a&#034; &gt; &#034;b&#034;<br \/>\n  virtual int Compare(const Slice&amp; a, const Slice&amp; b) const &#061; 0;<br \/>\n};<\/p>\n<p>\u4e00\u4e2a\u4e09\u8def\u6bd4\u8f83\u51fd\u6570&#xff0c;\u8fd4\u56de\u8d1f \/ \u96f6 \/ \u6b63\u3002\u5c31\u8fd9\u4e48\u4e00\u4e2a\u7eaf\u865a\u51fd\u6570&#xff0c;\u5b9a\u4e49\u4e86\u6574\u53f0\u5f15\u64ce\u91cc\u201c\u987a\u5e8f\u201d\u8fd9\u4e2a\u8bcd\u7684\u5168\u90e8\u542b\u4e49\u3002\u5b83\u4e0a\u9762\u90a3\u5c42\u00a0Comparator\u00a0\u7c7b\u7684\u6ce8\u91ca&#xff0c;\u628a\u8bdd\u8bf4\u5230\u4e86\u5934&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ comparator.h&#xff1a;A Comparator object provides a total order across<br \/>\n\/\/ slices that are used as keys in an sstable or a database.<\/p>\n<p>\u5168\u5e8f&#xff08;total order&#xff09;\u3002\u00a0\u4efb\u610f\u4e24\u4e2a key&#xff0c;\u8981\u4e48\u76f8\u7b49&#xff0c;\u8981\u4e48\u4e00\u4e2a\u4e25\u683c\u5728\u53e6\u4e00\u4e2a\u524d\u9762&#xff0c;\u6ca1\u6709\u201c\u65e0\u6cd5\u6bd4\u8f83\u201d\u8fd9\u79cd\u60c5\u51b5\u3002\u4f60\u81ea\u7814\u5f15\u64ce\u65f6\u5982\u679c\u6253\u7b97\u652f\u6301\u8303\u56f4\u626b\u63cf&#xff0c;\u8fd9\u56db\u4e2a\u5b57\u5c31\u662f\u4f60\u5fc5\u987b\u5148\u4ea4\u51fa\u7684\u4e1c\u897f&#xff1a;\u6570\u5b66\u610f\u4e49\u4e0a\u7684\u5168\u5e8f&#xff0c;\u4efb\u610f\u4e24\u4e2a key \u90fd\u80fd\u6bd4\u51fa\u5148\u540e&#xff0c;\u5426\u5219\u5e95\u5c42\u7684\u6709\u5e8f\u7ed3\u6784\u4f1a\u5728\u67d0\u4e24\u4e2a key \u4e0a\u76f4\u63a5\u5d29\u6389\u3002<\/p>\n<p>\u90a3\u9ed8\u8ba4\u90a3\u5957\u987a\u5e8f\u662f\u54ea\u6765\u7684&#xff1f;comparator.h \u5e95\u90e8&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ comparator.h&#xff1a;Return a builtin comparator that uses lexicographic<br \/>\n\/\/ ordering on unsigned bytes, so the empty string is ordered before<br \/>\n\/\/ everything else and a sufficiently long string of \\\\xFF orders<br \/>\n\/\/ after anything.<br \/>\nconst Comparator* BytewiseComparator();<\/p>\n<p>\u6309\u65e0\u7b26\u53f7\u5b57\u8282\u505a\u5b57\u5178\u5e8f\u3002\u00a0\u73b0\u5728\u5f00\u5934\u90a3\u4e2a\u73b0\u8c61\u4e00\u79d2\u5c31\u901a\u4e86&#xff1a;&#034;10&#034;\u00a0\u548c\u00a0&#034;2&#034;\u00a0\u662f\u4e24\u4e32\u5b57\u8282&#xff0c;\u9010\u5b57\u8282\u6bd4&#xff0c;&#039;1&#039;(0x31) \u649e\u00a0&#039;2&#039;(0x32)&#xff0c;\u524d\u8005\u5c0f&#xff0c;\u6240\u4ee5\u00a0&#034;12&#034; &lt; &#034;2&#034;\u3002\u5b83\u538b\u6839\u4e0d\u77e5\u9053\u4f60\u5fc3\u91cc\u90a3\u662f\u6574\u6570&#xff0c;\u5b83\u773c\u91cc\u53ea\u6709\u5b57\u8282\u3002<\/p>\n<p>\u8fd9\u5f15\u51fa\u81ea\u7814\u5f15\u64ce\u91cc\u6700\u7ecf\u5178\u7684\u4e00\u4e2a\u5751&#xff0c;\u6211\u4eec\u8ba9\u5b83\u5f53\u573a\u574f\u7ed9\u4f60\u770b\u3002\u5047\u8bbe\u4f60\u5acc\u5b57\u7b26\u4e32 key \u5360\u5730\u65b9&#xff0c;\u6539\u6210\u628a\u539f\u751f\u00a0int\u00a0\u76f4\u63a5\u62f7\u8fdb key&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>int k1 &#061; 1, k2 &#061; 256;<br \/>\ndb-&gt;Put(WriteOptions(),<br \/>\n        Slice(reinterpret_cast&lt;char*&gt;(&amp;k1), sizeof(int)), &#034;a&#034;);<br \/>\ndb-&gt;Put(WriteOptions(),<br \/>\n        Slice(reinterpret_cast&lt;char*&gt;(&amp;k2), sizeof(int)), &#034;b&#034;);<br \/>\n\/\/ x86 \u662f\u5c0f\u7aef&#xff1a;<br \/>\n\/\/   1   \u5728\u5185\u5b58\u91cc\u662f  01 00 00 00<br \/>\n\/\/   256 \u5728\u5185\u5b58\u91cc\u662f  00 01 00 00<br \/>\n\/\/ \u6309\u5b57\u8282\u6bd4&#xff1a;256 \u7684\u9996\u5b57\u8282 0x00 &lt; 1 \u7684\u9996\u5b57\u8282 0x01<br \/>\n\/\/ \u4e8e\u662f\u8303\u56f4\u626b\u63cf\u91cc&#xff0c;256 \u6392\u5728\u4e86 1 \u524d\u9762\u3002<\/p>\n<p>\u5728\u5c0f\u7aef\u673a\u5668\u4e0a&#xff0c;int\u00a0\u7684\u4f4e\u5b57\u8282\u5728\u524d&#xff0c;256\u00a0\u7684\u5b57\u8282\u5e8f\u5217\u00a000 01 00 00\u00a0\u9996\u5b57\u8282\u662f 0&#xff0c;\u6bd4\u00a01\u00a0\u7684\u00a001 00 00 00\u00a0\u8fd8\u5c0f&#xff0c;\u4e8e\u662f 256 \u88ab\u6392\u5230\u4e86 1 \u524d\u9762\u2014\u2014\u4f60\u7684\u6570\u503c\u987a\u5e8f\u88ab\u5b57\u8282\u5e8f\u5f7b\u5e95\u6253\u4e71\u3002\u4fee\u6cd5\u53ea\u6709\u4e00\u4e2a&#xff1a;key \u91cc\u7684\u6574\u6570\u5fc5\u987b\u6309\u5927\u7aef\u7f16\u7801\u518d\u5b58&#xff0c;\u8ba9\u9ad8\u4f4d\u5b57\u8282\u843d\u5728\u524d\u9762&#xff0c;\u5b57\u8282\u5b57\u5178\u5e8f\u624d\u548c\u6570\u503c\u987a\u5e8f\u5bf9\u9f50\u3002\u8fd9\u662f\u6bcf\u4e00\u4e2a\u7528\u6709\u5e8f KV \u5b58\u6574\u6570\u4e3b\u952e\u7684\u4eba\u90fd\u5fc5\u987b\u8fc7\u7684\u4e00\u9053\u574e&#xff0c;\u8fc7\u4e0d\u53bb&#xff0c;\u4f60\u7684\u8303\u56f4\u626b\u63cf\u5c31\u662f\u9519\u7684&#xff0c;\u800c\u4e14\u9519\u5f97\u6084\u65e0\u58f0\u606f\u2014\u2014\u6ca1\u6709\u62a5\u9519&#xff0c;\u53ea\u6709\u987a\u5e8f\u4e0d\u5bf9\u3002\u9762\u8bd5\u65f6\u5982\u679c\u6709\u4eba\u8ba9\u4f60\u7528\u6709\u5e8f KV \u5b58\u4e00\u5f20\u6309\u65f6\u95f4\u6392\u5e8f\u7684\u8868&#xff0c;\u7b2c\u4e00\u53e5\u5c31\u8be5\u95ee\u201c\u65f6\u95f4\u6233\u600e\u4e48\u7f16\u7801\u201d&#xff0c;\u7b54\u4e0d\u51fa\u5927\u7aef&#xff0c;\u8fd9\u9053\u9898\u57fa\u672c\u5c31\u5e9f\u4e86\u3002<\/p>\n<p>\u6bd4\u201c\u987a\u5e8f\u9519\u4e86\u201d\u66f4\u72e0\u7684&#xff0c;\u662f\u201c\u987a\u5e8f\u53d8\u4e86\u5374\u6ca1\u4eba\u544a\u8bc9\u4f60\u201d\u3002\u770b\u00a0Comparator\u00a0\u7684\u00a0Name()&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ comparator.h&#xff1a;The name of the comparator.  Used to check for<br \/>\n\/\/ comparator mismatches (i.e., a DB created with one comparator is<br \/>\n\/\/ accessed using a different comparator).<br \/>\n\/\/ The client of this package should switch to a new name whenever<br \/>\n\/\/ the comparator implementation changes in a way that will cause the<br \/>\n\/\/ relative ordering of any two keys to change.<br \/>\nconst char* Name() const override &#061; 0;<\/p>\n<p>\u6bd4\u8f83\u5668\u7684\u540d\u5b57\u4f1a\u88ab\u5199\u8fdb\u5e93\u91cc\u6301\u4e45\u5316\u3002\u4e0b\u6b21\u5f00\u5e93&#xff0c;\u5f15\u64ce\u62ff\u5f53\u524d\u6bd4\u8f83\u5668\u7684\u540d\u5b57\u548c\u5e93\u91cc\u5b58\u7684\u90a3\u4e2a\u6838\u5bf9&#xff0c;\u5bf9\u4e0d\u4e0a\u5c31\u62d2\u7edd\u6253\u5f00\u3002\u4e3a\u4ec0\u4e48\u8981\u8fd9\u4e48\u9632\u7740\u4f60&#xff1f;\u56e0\u4e3a\u987a\u5e8f\u4e0d\u662f\u67e5\u8be2\u65f6\u624d\u7528\u4e00\u4e0b\u7684\u8fd0\u884c\u671f\u53c2\u6570&#xff0c;\u5b83\u523b\u8fdb\u4e86\u78c1\u76d8\u4e0a\u6bcf\u4e00\u4e2a\u6709\u5e8f\u6570\u636e\u5757\u7684\u7269\u7406\u5e03\u5c40\u3002\u6574\u53f0\u5f15\u64ce\u7684\u78c1\u76d8\u7ed3\u6784\u3001\u7d22\u5f15\u5757\u3001\u4e8c\u5206\u67e5\u627e&#xff0c;\u5168\u90fd\u5efa\u7acb\u5728\u201c\u5e93\u91cc\u7684 key \u662f\u6309\u67d0\u4e2a\u56fa\u5b9a\u987a\u5e8f\u7801\u597d\u7684\u201d\u8fd9\u4e2a\u524d\u63d0\u4e0a\u3002\u4f60\u4eca\u5929\u7528\u5927\u7aef\u987a\u5e8f\u7801\u4e86\u4e00\u767e\u4e07\u6761\u6570\u636e&#xff0c;\u660e\u5929\u6362\u4e2a\u6bd4\u8f83\u5668\u6539\u6210\u5c0f\u7aef&#xff0c;\u90a3\u4e00\u767e\u4e07\u6761\u7684\u7269\u7406\u6392\u5217\u77ac\u95f4\u5168\u9519\u2014\u2014\u4e8c\u5206\u67e5\u627e\u4f1a\u6307\u5411\u9519\u8bef\u7684\u5757&#xff0c;\u626b\u63cf\u4f1a\u6f0f\u6389\u672c\u8be5\u5728\u533a\u95f4\u91cc\u7684 key\u3002\u6240\u4ee5\u5f15\u64ce\u7684\u6001\u5ea6\u662f&#xff1a;\u6362\u6bd4\u8f83\u5668\u7b49\u4e8e\u6362\u4e86\u4e00\u4e2a\u6570\u636e\u5e93&#xff0c;\u5b83\u5b81\u53ef\u62d2\u7edd\u5f00\u5e93\u4e5f\u4e0d\u8ba9\u4f60\u5728\u4e00\u4e2a\u987a\u5e8f\u4e0a\u5199\u3001\u53e6\u4e00\u4e2a\u987a\u5e8f\u4e0a\u8bfb\u3002<\/p>\n<p>\u8fd9\u5c31\u662f\u6211\u8bf4\u201c\u4e09\u8def\u6bd4\u8f83\u51fd\u6570\u662f\u8fd9\u53f0\u5f15\u64ce\u7684\u7269\u7406\u5b9a\u5f8b\u201d\u7684\u610f\u601d\u3002\u5b83\u662f\u4e00\u6761\u4e00\u65e6\u9009\u5b9a\u3001\u5199\u4e0b\u7b2c\u4e00\u4e2a key \u5c31\u51bb\u7ed3\u7684\u4e0d\u53d8\u91cf&#xff0c;\u8fd0\u884c\u671f\u52a8\u5b83\u4e0d\u5f97\u3002\u4f60\u81ea\u7814\u5f15\u64ce\u65f6\u5bf9\u5b83\u7684\u552f\u4e00\u6b63\u786e\u6001\u5ea6\u662f&#xff1a;\u5f00\u5de5\u7b2c\u4e00\u4ef6\u4e8b\u5c31\u5b9a\u6b7b\u6bd4\u8f83\u51fd\u6570&#xff0c;\u5e76\u4e14\u7ed9\u5b83\u4e00\u4e2a\u7248\u672c\u5316\u7684\u540d\u5b57&#xff0c;\u5f80\u540e\u4f46\u51e1\u6539\u52a8\u4e86\u4efb\u610f\u4e24\u4e2a key \u7684\u76f8\u5bf9\u987a\u5e8f&#xff0c;\u5c31\u6362\u540d\u5b57\u3001\u5c31\u5f53\u6210\u4e00\u4e2a\u65b0\u5e93\u6765\u8fc1\u79fb\u3002\u00a0\u987a\u5e8f\u5373\u8eab\u4efd\u3002<\/p>\n<p>\u6bd4\u8f83\u5668\u8fd8\u6709\u4e24\u4e2a\u4e0d\u8d77\u773c\u7684\u65b9\u6cd5&#xff0c;\u987a\u5e26\u70b9\u7834&#xff0c;\u5b83\u4eec\u66b4\u9732\u4e86\u987a\u5e8f\u6e17\u900f\u5f97\u6709\u591a\u6df1&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ comparator.h&#xff1a;Advanced functions: these are used to reduce the<br \/>\n\/\/ space requirements for internal data structures like index blocks.<br \/>\nvirtual void FindShortestSeparator(std::string* start,<br \/>\n                                   const Slice&amp; limit) const &#061; 0;<br \/>\nvirtual void FindShortSuccessor(std::string* key) const &#061; 0;<\/p>\n<p>\u5f15\u64ce\u4f1a\u62ff\u6bd4\u8f83\u5668\u53bb\u627e\u201c\u4e24\u4e2a key \u4e4b\u95f4\u4e00\u4e2a\u5c3d\u91cf\u77ed\u7684\u5206\u9694\u4e32\u201d&#xff0c;\u7528\u5b83\u5f53\u7d22\u5f15\u5757\u7684\u8fb9\u754c&#xff0c;\u7701\u7a7a\u95f4\u3002\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u6bd4\u8f83\u5668\u4e0d\u53ea\u5728\u4f60\u67e5\u8be2\u65f6\u88ab\u8c03\u7528&#xff0c;\u5b83\u8fd8\u5728\u540e\u53f0\u53c2\u4e0e\u5851\u9020\u7d22\u5f15\u7684\u7269\u7406\u5f62\u6001\u3002\u8fd9\u6761\u7ebf\u4f60\u73b0\u5728\u6709\u4e2a\u5370\u8c61\u5c31\u884c\u2014\u2014\u5b83\u8bf4\u660e\u7684\u662f\u540c\u4e00\u4ef6\u4e8b&#xff1a;\u987a\u5e8f\u8fd9\u4e2a\u4e1c\u897f&#xff0c;\u4ece\u4f60\u7684 key \u7f16\u7801&#xff0c;\u4e00\u8def\u6e17\u5230\u6700\u5e95\u5c42\u7684\u78c1\u76d8\u7ed3\u6784\u91cc&#xff0c;\u6ca1\u6709\u4e00\u5c42\u80fd\u7ed5\u5f00\u5b83\u3002<\/p>\n<p>\u987a\u5e8f\u8fd8\u6709\u4e00\u5c42\u4f60\u73b0\u5728\u672a\u5fc5\u7528\u5f97\u4e0a\u3001\u5374\u51b3\u5b9a\u4e86\u201c\u6709\u7248\u672c\u201d\u600e\u4e48\u843d\u5730\u7684\u4e1c\u897f\u2014\u2014\u65f6\u95f4\u6233\u3002\u56de\u5934\u770b\u00a0Compare\u00a0\u7684\u5b8c\u6574\u6ce8\u91ca&#xff0c;\u5b83\u591a\u8bf4\u4e86\u4e00\u53e5&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ comparator.h&#xff1a;Note that Compare(a, b) also compares timestamp if<br \/>\n\/\/ timestamp size is non-zero. For the same user key with different<br \/>\n\/\/ timestamps, larger (newer) timestamp comes first.<\/p>\n<p>\u540c\u4e00\u4e2a\u7528\u6237 key&#xff0c;\u5e26\u4e0d\u540c\u65f6\u95f4\u6233\u65f6&#xff0c;\u66f4\u65b0\u7684\u90a3\u4e2a\u6392\u5728\u524d\u9762\u3002\u8fd9\u53e5\u8bdd\u628a\u201c\u987a\u5e8f\u201d\u548c\u201c\u7248\u672c\u201d\u710a\u5728\u4e86\u4e00\u8d77&#xff1a;\u6bd4\u8f83\u5668\u4e0d\u53ea\u88c1\u5b9a key \u4e0e key \u4e4b\u95f4\u8c01\u5148\u8c01\u540e&#xff0c;\u8fd8\u88c1\u5b9a\u540c\u4e00\u4e2a key \u7684\u591a\u4e2a\u7248\u672c\u91cc\u8c01\u5148\u8c01\u540e\u2014\u2014\u800c\u201c\u65b0\u7248\u672c\u6392\u5728\u524d\u201d\u6b63\u662f\u8303\u56f4\u626b\u63cf\u9ed8\u8ba4\u8bfb\u5230\u6700\u65b0\u503c\u7684\u5e95\u5c42\u539f\u56e0\u3002\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48\u5185\u7f6e\u7684\u5e26\u65f6\u95f4\u6233\u6bd4\u8f83\u5668\u8981\u4e13\u95e8\u89c4\u5b9a\u201c\u5168\u96f6\u5b57\u8282\u662f\u6700\u5c0f&#xff08;\u6700\u65e7&#xff09;\u65f6\u95f4\u6233\u3001\u5168\u4e00\u5b57\u8282\u662f\u6700\u5927&#xff08;\u6700\u65b0&#xff09;\u201d&#xff1a;\u7248\u672c\u4e4b\u95f4\u7684\u5148\u540e&#xff0c;\u4e5f\u5f97\u662f\u4e00\u4e2a\u4f60\u80fd\u5728\u5b57\u8282\u5c42\u9762\u7b97\u5f97\u6e05\u7684\u5168\u5e8f\u3002\u4f60\u81ea\u7814\u5f15\u64ce\u8981\u652f\u6301\u591a\u7248\u672c\u8bfb&#xff0c;\u8fd9\u6761\u7ed5\u4e0d\u5f00\u2014\u2014\u7248\u672c\u53f7\u662f\u6392\u5e8f\u952e\u7684\u4e00\u90e8\u5206&#xff0c;\u4e0d\u662f\u6302\u5728 value \u4e0a\u7684\u4e00\u5757\u5143\u6570\u636e\u3002\u7b2c 10 \u8282\u6211\u4f1a\u5e26\u4f60\u770b\u8fd9\u4e2a\u7248\u672c\u53f7\u600e\u4e48\u53d8\u6210\u5feb\u7167\u3001\u600e\u4e48\u51b3\u5b9a\u4e00\u6761\u65e7\u6570\u636e\u80fd\u4e0d\u80fd\u88ab\u56de\u6536\u3002<\/p>\n<h3>4. \u6709\u5e8f Map \u548c\u65e0\u5e8f Hash&#xff0c;\u5206\u53c9\u7684\u662f\u6574\u53f0\u5f15\u64ce<\/h3>\n<p>\u73b0\u5728\u6b63\u9762\u56de\u7b54\u7b2c 1 \u8282\u7559\u4e0b\u7684\u201c\u5b83\u51ed\u4ec0\u4e48\u80fd\u7ed9\u4f60\u533a\u95f4\u201d\u3002\u628a\u6709\u5e8f\u7ed3\u6784\u548c\u54c8\u5e0c\u8868\u5e76\u6392\u653e&#xff0c;\u5582\u540c\u4e00\u4e2a\u64cd\u4f5c&#xff0c;\u770b\u5b83\u4eec\u5728\u54ea\u4e00\u6b65\u5206\u53c9\u3002<\/p>\n<p>\u70b9\u67e5\u8fd9\u4e00\u5173&#xff0c;\u4e24\u8005\u6253\u5e73&#xff0c;\u751a\u81f3\u54c8\u5e0c\u8fd8\u8d62\u4e00\u70b9\u3002\u54c8\u5e0c\u8868\u7406\u8bba\u4e0a\u662f\u5747\u644a\u00a0O(1)&#xff0c;\u6709\u5e8f\u7ed3\u6784\u662f\u00a0O(log n)\u00a0\u7684\u4e8c\u5206\u3002\u5dee\u8ddd\u5728\u8303\u56f4\u626b\u63cf&#xff1a;<\/p>\n<table>\n<tbody>\n<tr>\n<p>\u64cd\u4f5c<\/p>\n<p>\u65e0\u5e8f Hash<\/p>\n<p>\u6709\u5e8f\u7ed3\u6784<\/p>\n<\/tr>\n<tr>\n<td>\n<p>\u70b9\u67e5\u00a0user:1500<\/p>\n<\/td>\n<td>\n<p>\u7b97\u54c8\u5e0c\u5b9a\u6876&#xff0c;O(1)\u00a0\u5f88\u5feb<\/p>\n<\/td>\n<td>\n<p>\u4e8c\u5206\u5b9a\u4f4d&#xff0c;O(log n)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u626b\u00a0[user:1000, user:2000)<\/p>\n<\/td>\n<td>\n<p>\u76f8\u90bb key \u6563\u843d\u5404\u5904&#xff0c;\u53ea\u80fd\u5168\u8868\u626b\u4e00\u904d\u00a0O(n)<\/p>\n<\/td>\n<td>\n<p>\u5b9a\u4f4d\u8d77\u70b9\u00a0O(log n)&#xff0c;\u518d\u987a\u7740\u8d70\u00a0O(k)&#xff08;k\u00a0\u4e3a\u547d\u4e2d\u6761\u6570&#xff09;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u54c8\u5e0c\u8868\u505a\u8303\u56f4\u626b\u63cf\u8981\u9000\u5316\u6210\u5168\u8868\u626b\u63cf\u52a0\u8fc7\u6ee4&#xff0c;\u56e0\u4e3a\u5b83\u4e3b\u52a8\u628a key \u7684\u90bb\u63a5\u5173\u7cfb\u6253\u6563\u4e86\u2014\u2014\u8fd9\u6b63\u662f\u5b83\u00a0O(1)\u00a0\u70b9\u67e5\u7684\u4ee3\u4ef7\u6765\u6e90\u3002\u6709\u5e8f\u7ed3\u6784\u53cd\u8fc7\u6765&#xff0c;\u7528\u00a0O(log n)\u00a0\u7684\u70b9\u67e5&#xff0c;\u6362\u6765\u4e86\u201ckey \u5728\u7269\u7406\u4e0a\u5c31\u662f\u6328\u7740\u6392\u7684\u201d&#xff0c;\u4e8e\u662f\u8303\u56f4\u626b\u63cf\u80fd\u5148\u4e8c\u5206\u5b9a\u4f4d\u5230\u8d77\u70b9&#xff0c;\u518d\u987a\u7740\u5f80\u4e0b\u8d70\u3002\u627f\u63a5\u8fd9\u4e2a\u80fd\u529b\u7684&#xff0c;\u5c31\u662f\u5f00\u5934\u90a3\u4e2a\u00a0Iterator\u3002\u770b\u5b83\u7684\u6e38\u6807\u63a5\u53e3&#xff0c;\u5728 iterator_base.h \u91cc&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ iterator_base.h<br \/>\n\/\/ Position at the first key in the source that at or past target.<br \/>\nvirtual void Seek(const Slice&amp; target) &#061; 0;<br \/>\n\/\/ Moves to the next entry in the source. REQUIRES: Valid()<br \/>\nvirtual void Next() &#061; 0;<br \/>\nvirtual bool Valid() const &#061; 0;<br \/>\nvirtual Slice key() const &#061; 0;<\/p>\n<p>Seek(target)\u00a0\u7684\u8bed\u4e49\u662f\u201c\u505c\u5728\u7b2c\u4e00\u4e2a\u5927\u4e8e\u7b49\u4e8e target \u7684 key \u4e0a\u201d\u3002\u8fd9\u4e2a\u201c\u5927\u4e8e\u7b49\u4e8e\u201d&#xff0c;\u7528\u7684\u5c31\u662f\u7b2c 3 \u8282\u90a3\u4e2a\u6bd4\u8f83\u5668\u3002\u6240\u4ee5\u8303\u56f4\u626b\u63cf\u00a0[&#034;user:1000&#034;,&#034;user:2000&#034;)\u00a0\u843d\u5230\u63a5\u53e3\u4e0a&#xff0c;\u5c31\u662f\u00a0Seek(&#034;user:1000&#034;)\u00a0\u5b9a\u4f4d\u8d77\u70b9&#xff0c;\u7136\u540e\u00a0Next()\u00a0\u4e00\u8def\u8d70&#xff0c;\u6bcf\u6b65\u7528\u6bd4\u8f83\u5668\u5224\u65ad\u6709\u6ca1\u6709\u8d8a\u8fc7\u00a0&#034;user:2000&#034;\u00a0\u8fd9\u4e2a\u53f3\u754c\u3002\u6709\u5e8f\u6027\u5728\u8fd9\u91cc\u5151\u73b0\u6210\u4e86\u771f\u91d1\u767d\u94f6\u7684\u80fd\u529b&#xff1a;\u4e00\u6b21\u4e8c\u5206\u52a0\u4e00\u6bb5\u987a\u5e8f\u8bfb&#xff0c;\u800c\u4e0d\u662f\u626b\u5168\u5e93\u3002<\/p>\n<p>\u8fd9\u4e2a\u5206\u53c9\u4e0d\u6b62\u505c\u5728\u67e5\u8be2\u63a5\u53e3\u4e0a&#xff0c;\u5b83\u4e00\u8def\u5411\u4e0b\u51b3\u5b9a\u4e86\u6574\u53f0\u5f15\u64ce\u7684\u5f62\u6001&#xff0c;\u8fd9\u624d\u662f\u6211\u8981\u4f60\u8bb0\u4f4f\u7684\u91cd\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u78c1\u76d8 IO \u5f62\u6001\u3002\u00a0\u6709\u5e8f\u610f\u5473\u7740\u76f8\u90bb key \u5927\u6982\u7387\u843d\u5728\u540c\u4e00\u4e2a\u78c1\u76d8\u5757\u3001\u540c\u4e00\u6b21\u9884\u8bfb\u91cc\u3002\u8303\u56f4\u626b\u63cf\u53d8\u6210\u4e00\u6bb5\u63a5\u8fd1\u987a\u5e8f\u8bfb\u7684 IO&#xff0c;\u8fd9\u5bf9\u673a\u68b0\u76d8\u662f\u6570\u91cf\u7ea7\u7684\u5dee\u5f02&#xff0c;\u5bf9 SSD \u4e5f\u7701\u4e0b\u5927\u91cf\u968f\u673a\u8bfb\u3002\u54c8\u5e0c\u5e03\u5c40\u505a\u533a\u95f4\u53ea\u80fd\u6ee1\u76d8\u4e71\u8df3&#xff0c;\u968f\u673a IO \u6253\u6ee1\u3002\u4f60\u81ea\u7814\u5d4c\u5165\u5f0f\u5f15\u64ce\u3001\u53c8\u8dd1\u5728\u95ea\u5b58\u4e0a&#xff0c;\u8fd9\u4e00\u6761\u51e0\u4e4e\u5355\u72ec\u5c31\u80fd\u51b3\u5b9a\u4f60\u9009\u6709\u5e8f\u3002<\/p>\n<\/li>\n<li>\n<p>\u7f13\u5b58\u7b56\u7565\u3002\u00a0\u6709\u5e8f\u7ed3\u6784\u7684\u6570\u636e\u5757\u5929\u7136\u5e26\u5c40\u90e8\u6027&#xff0c;\u7f13\u5b58\u4e00\u4e2a\u5757&#xff0c;\u5757\u91cc\u4e00\u6279\u76f8\u90bb key \u5168\u8ddf\u7740\u70ed\u4e86&#xff0c;\u8303\u56f4\u626b\u63cf\u7684\u7f13\u5b58\u547d\u4e2d\u7387\u5f88\u9ad8\u3002\u54c8\u5e0c\u8868\u7f13\u5b58\u4e00\u4e2a\u6876&#xff0c;\u6876\u91cc\u7684 key \u5728\u903b\u8f91\u4e0a\u6beb\u65e0\u5173\u8054&#xff0c;\u7f13\u5b58\u4ef7\u503c\u4f4e\u5f97\u591a\u3002<\/p>\n<\/li>\n<li>\n<p>\u540e\u53f0\u6574\u7406\u3002\u00a0\u6709\u5e8f\u7ed3\u6784&#xff08;\u5178\u578b\u5c31\u662f LSM&#xff09;\u628a\u65b0\u5199\u5165\u6512\u5728\u5185\u5b58&#xff0c;\u6392\u597d\u5e8f\u5237\u6210\u4e00\u4e2a\u4e2a\u6709\u5e8f\u6587\u4ef6&#xff0c;\u518d\u9760\u540e\u53f0\u538b\u7f29\u628a\u591a\u4e2a\u6709\u5e8f\u6587\u4ef6\u5f52\u5e76\u6210\u66f4\u5927\u7684\u6709\u5e8f\u6587\u4ef6\u2014\u2014\u6574\u4e2a\u673a\u5236\u7684\u5730\u57fa\u5c31\u662f\u201c\u5f52\u5e76\u4e24\u4e2a\u6709\u5e8f\u5e8f\u5217\u5f88\u4fbf\u5b9c\u201d\u3002\u54c8\u5e0c\u5e03\u5c40\u6ca1\u6709\u8fd9\u4e2a\u4fbf\u5229\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u628a\u8fd9\u4e09\u6761\u518d\u5f80\u4e0b\u538b\u4e00\u5c42&#xff0c;\u4f60\u4f1a\u770b\u5230\u6709\u5e8f\u7ed3\u6784\u5728\u78c1\u76d8\u4e0a\u7684\u771f\u5b9e\u5f62\u6001&#xff0c;\u4e5f\u4f1a\u770b\u5230\u5b83\u4e3a\u70b9\u67e5\u4ed8\u7684\u90a3\u4efd\u4ee3\u4ef7\u5176\u5b9e\u6709\u6551\u2014\u2014\u8fd9\u4e00\u5c42\u6b63\u662f\u4f60\u8981\u8bbe\u8ba1\u7684\u78c1\u76d8 IO \u4e0e\u7f13\u5b58\u7b56\u7565\u3002<\/p>\n<p>\u6709\u5e8f\u6570\u636e\u5728\u76d8\u4e0a\u7684\u5f62\u6001&#xff0c;\u662f\u5207\u6210\u4e00\u4e2a\u4e2a\u5b9a\u957f\u6570\u636e\u5757&#xff08;\u5178\u578b 4KB \u5230 64KB \u4e00\u5757&#xff09;&#xff0c;\u5757\u5185 key \u6709\u5e8f&#xff0c;\u5757\u4e0e\u5757\u4e4b\u95f4\u4e5f\u6709\u5e8f&#xff0c;\u5757\u4e0a\u9762\u518d\u538b\u4e00\u5c42\u7a00\u758f\u7d22\u5f15&#xff0c;\u53ea\u8bb0\u201c\u6bcf\u4e2a\u5757\u7684\u7b2c\u4e00\u4e2a key\u201d\u3002\u4e00\u6b21\u70b9\u67e5\u662f\u5148\u5728\u7a00\u758f\u7d22\u5f15\u4e0a\u4e8c\u5206\u5b9a\u4f4d\u5230\u5757&#xff0c;\u518d\u628a\u6574\u5757\u8bfb\u8fdb\u5185\u5b58\u3001\u5728\u5757\u5185\u4e8c\u5206\u3002\u8fd9\u4e2a\u8bbe\u8ba1\u5bf9\u78c1\u76d8\u6781\u5176\u53cb\u597d&#xff1a;\u78c1\u76d8\u7684\u6700\u5c0f IO \u5355\u4f4d\u672c\u5c31\u662f\u5757&#xff0c;\u4f60\u8981\u7684\u90a3\u4e2a key \u548c\u5b83\u76f8\u90bb\u7684\u51e0\u5341\u4e0a\u767e\u4e2a key \u4e00\u6b21\u6027\u8fdb\u4e86\u5185\u5b58&#xff1b;\u8303\u56f4\u626b\u63cf\u63a5\u7740\u5f80\u4e0b\u8d70\u65f6&#xff0c;\u4e0b\u4e00\u4e2a key \u5927\u6982\u7387\u5c31\u5728\u8fd9\u5757\u91cc&#xff0c;\u8fde\u65b0\u7684 IO \u90fd\u7701\u4e86\u3002\u8fd9\u5c31\u662f\u7b2c 4 \u8282\u5f00\u5934\u90a3\u5f20\u8868\u91cc\u201c\u987a\u5e8f\u8bfb\u00a0O(k)\u201d\u7684\u7269\u7406\u6765\u6e90\u2014\u2014k \u4e2a\u547d\u4e2d\u91cc&#xff0c;\u7edd\u5927\u591a\u6570\u4e0d\u4ea7\u751f\u65b0\u7684\u78c1\u76d8 IO\u3002<\/p>\n<p>\u7f13\u5b58\u7b56\u7565\u4e5f\u987a\u7740\u5757\u8d70\u3002\u8bfb\u7f13\u5b58\u7f13\u5b58\u7684\u662f\u6570\u636e\u5757&#xff0c;\u4e0d\u662f\u5355\u4e2a key\u3002\u7f13\u5b58\u4e00\u4e2a\u5757&#xff0c;\u5757\u91cc\u4e00\u6279\u76f8\u90bb key \u5168\u8ddf\u7740\u70ed\u4e86&#xff0c;\u8fd9\u5bf9\u8303\u56f4\u626b\u63cf\u662f\u5de8\u5927\u7684\u7ea2\u5229\u2014\u2014\u4e00\u6b21\u533a\u95f4\u67e5\u8be2\u547d\u4e2d\u7684\u5f80\u5f80\u5c31\u662f\u540c\u51e0\u4e2a\u5757\u3002\u4f60\u81ea\u7814\u5f15\u64ce\u8bbe\u8ba1\u7f13\u5b58\u65f6&#xff0c;\u5757\u7c92\u5ea6\u51e0\u4e4e\u662f\u552f\u4e00\u5408\u7406\u7684\u9009\u62e9&#xff1a;\u592a\u7ec6&#xff08;\u7f13\u5b58\u5355 key&#xff09;\u5143\u6570\u636e\u5f00\u9500\u538b\u57ae\u4f60&#xff0c;\u592a\u7c97&#xff08;\u7f13\u5b58\u6574\u4e2a\u6587\u4ef6&#xff09;\u547d\u4e2d\u7387\u4e0a\u4e0d\u53bb&#xff0c;\u5757\u7c92\u5ea6\u6b63\u597d\u5361\u5728\u201c\u78c1\u76d8 IO \u5355\u4f4d\u201d\u548c\u201c\u8bbf\u95ee\u5c40\u90e8\u6027\u201d\u7684\u4ea4\u70b9\u4e0a\u3002<\/p>\n<p>\u90a3\u70b9\u67e5\u6162\u4e00\u4e2a\u5bf9\u6570\u56e0\u5b50\u8fd9\u7b14\u5f00\u9500\u600e\u4e48\u627e\u8865&#xff1f;\u9760\u5e03\u9686\u8fc7\u6ee4\u5668\u3002\u6709\u5e8f\u7ed3\u6784\u6700\u6015\u7684\u70b9\u67e5\u573a\u666f\u662f\u201c\u67e5\u4e00\u4e2a\u6839\u672c\u4e0d\u5b58\u5728\u7684 key\u201d\u2014\u2014\u5b83\u5f97\u4e00\u8def\u4e8c\u5206\u5230\u5e95\u624d\u80fd\u786e\u8ba4\u6ca1\u6709&#xff0c;\u767d\u8bfb\u4e00\u5806\u5757\u3002\u5e03\u9686\u8fc7\u6ee4\u5668\u7ed9\u6bcf\u4e2a\u6570\u636e\u5757\u914d\u4e00\u4e2a\u5f88\u5c0f\u7684\u4f4d\u56fe\u6458\u8981&#xff0c;\u70b9\u67e5\u524d\u5148\u95ee\u5b83\u201c\u8fd9\u4e2a key \u53ef\u80fd\u5728\u8fd9\u5757\u91cc\u5417\u201d&#xff0c;\u7b54\u201c\u4e0d\u53ef\u80fd\u201d\u5c31\u76f4\u63a5\u8df3\u8fc7\u6574\u5757\u7684\u78c1\u76d8\u8bfb\u3002\u5b83\u6709\u5047\u9633\u6027&#xff08;\u8bf4\u201c\u53ef\u80fd\u201d\u5176\u5b9e\u6ca1\u6709&#xff09;&#xff0c;\u4f46\u6ca1\u6709\u5047\u9634\u6027&#xff08;\u8bf4\u201c\u6ca1\u6709\u201d\u5c31\u4e00\u5b9a\u6ca1\u6709&#xff09;&#xff0c;\u4e8e\u662f\u5b83\u628a\u201c\u67e5\u4e0d\u5b58\u5728\u7684 key\u201d\u8fd9\u4e2a\u6700\u8d35\u573a\u666f\u7684\u78c1\u76d8 IO \u5e72\u5230\u63a5\u8fd1\u96f6\u3002\u8fd9\u5c31\u662f\u6709\u5e8f\u7ed3\u6784\u8ffd\u5e73\u54c8\u5e0c\u70b9\u67e5\u7684\u90a3\u5f20\u724c&#xff0c;\u4ee3\u4ef7\u662f\u6bcf\u4e2a\u5757\u591a\u5b58\u4e00\u4e2a\u6458\u8981\u3001\u591a\u5360\u4e00\u70b9\u5185\u5b58\u3002<\/p>\n<p>\u4ee3\u4ef7\u90a3\u4e00\u5934\u4e5f\u5f97\u7b97\u6e05&#xff0c;\u8fd9\u662f\u81ea\u7814\u65f6\u6700\u5bb9\u6613\u4f4e\u4f30\u7684\u2014\u2014\u5199\u653e\u5927\u3002\u6709\u5e8f\u7ed3\u6784\u7684\u540e\u53f0\u538b\u7f29\u8981\u53cd\u590d\u628a\u5c0f\u7684\u6709\u5e8f\u6587\u4ef6\u5f52\u5e76\u6210\u5927\u7684&#xff0c;\u540c\u4e00\u6761\u6570\u636e\u5728\u5b83\u751f\u547d\u5468\u671f\u91cc\u53ef\u80fd\u88ab\u642c\u52a8\u597d\u51e0\u6b21&#xff0c;\u5b9e\u9645\u5199\u76d8\u91cf\u662f\u903b\u8f91\u5199\u5165\u91cf\u7684\u82e5\u5e72\u500d&#xff08;\u505a\u5230\u4e2a\u4f4d\u6570\u500d\u5df2\u7ecf\u7b97\u8c03\u5f97\u4e0d\u9519&#xff09;\u3002\u8303\u56f4\u626b\u63cf\u90a3\u4efd\u987a\u5e8f\u8bfb\u7ea2\u5229&#xff0c;\u662f\u7528\u5199\u5165\u4fa7\u8fd9\u7b14\u989d\u5916 IO \u6362\u6765\u7684\u3002\u70b9\u67e5\u4e3a\u4e3b\u3001\u6781\u5c11\u626b\u63cf\u3001\u5199\u591a\u8bfb\u5c11\u7684\u8d1f\u8f7d&#xff0c;\u8fd9\u7b14\u6295\u5165\u53ef\u80fd\u5212\u4e0d\u6765&#xff0c;\u90a3\u65f6\u54c8\u5e0c\u5e03\u5c40\u624d\u662f\u66f4\u8bda\u5b9e\u7684\u9009\u62e9\u3002<\/p>\n<p>\u6240\u4ee5\u6709\u5e8f\u548c\u65e0\u5e8f\u7684\u9009\u62e9&#xff0c;\u4ece\u6765\u4e0d\u662f\u201c\u8981\u4e0d\u8981\u8303\u56f4\u626b\u63cf\u201d\u8fd9\u4e00\u4e2a\u67e5\u8be2\u529f\u80fd\u7684\u53d6\u820d&#xff0c;\u5b83\u662f\u78c1\u76d8\u5e03\u5c40\u3001IO \u5f62\u6001\u3001\u7f13\u5b58\u5c40\u90e8\u6027\u3001\u540e\u53f0\u6574\u7406\u8fd9\u4e00\u6574\u6761\u94fe\u8def\u7684\u5206\u53c9\u3002\u5d4c\u5165\u5f0f KV \u5f15\u64ce\u7edd\u5927\u591a\u6570\u9009\u6709\u5e8f&#xff0c;\u6839\u5b50\u5728\u78c1\u76d8\u548c\u7f13\u5b58&#xff1a;\u4e00\u65e6\u4f60\u8981\u9762\u5bf9\u5b83\u4eec&#xff0c;\u6709\u5e8f\u80fd\u628a\u968f\u673a\u8bbf\u95ee\u5c3d\u91cf\u63b0\u6210\u987a\u5e8f\u8bbf\u95ee\u2014\u2014\u800c\u8fd9\u662f\u78c1\u76d8\u65f6\u4ee3\u6700\u503c\u94b1\u7684\u4e00\u4ef6\u4e8b\u3002\u4ee3\u4ef7\u4e5f\u5f97\u8bf4\u6e05\u695a&#xff1a;\u6709\u5e8f\u7ed3\u6784\u7684\u5199\u5165\u8981\u7ef4\u62a4\u987a\u5e8f&#xff0c;\u70b9\u67e5\u6bd4\u54c8\u5e0c\u591a\u4e00\u4e2a\u5bf9\u6570\u56e0\u5b50&#xff0c;\u540e\u53f0\u538b\u7f29\u4f1a\u5403\u989d\u5916\u7684 IO \u548c CPU&#xff08;\u6240\u8c13\u5199\u653e\u5927&#xff09;\u3002\u7eaf KV \u7f13\u5b58\u3001\u53ea\u70b9\u67e5\u3001\u6c38\u4e0d\u626b\u63cf\u7684\u573a\u666f&#xff0c;\u54c8\u5e0c\u5e03\u5c40\u662f\u66f4\u8bda\u5b9e\u7684\u9009\u62e9\u3002\u6ca1\u6709\u514d\u8d39\u7684\u6709\u5e8f\u3002<\/p>\n<h3>5. \u201c\u6301\u4e45\u5316\u3001\u6709\u7248\u672c\u7684\u6709\u5e8f Map\u201d\u8fd9\u4e5d\u4e2a\u5b57&#xff0c;\u9010\u4e2a\u5151\u73b0<\/h3>\n<p>\u7b2c\u4e00\u90e8\u5206\u5230\u8fd9\u91cc\u53ef\u4ee5\u6536\u53e3\u4e86\u3002\u56de\u5230\u90a3\u53e5\u5b9a\u4e49&#xff0c;\u73b0\u5728\u6211\u4eec\u628a\u5b83\u4e5d\u4e2a\u5b57\u9010\u4e2a\u5151\u73b0&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h<br \/>\n\/\/ A DB is a persistent, versioned ordered map from keys to values.<br \/>\n\/\/ A DB is safe for concurrent access from multiple threads without<br \/>\n\/\/ any external synchronization.<br \/>\nclass DB {<\/p>\n<ul>\n<li>\n<p>Map from keys to values\u2014\u2014\u7b2c 1 \u8282\u3002\u5c31\u662f\u4e2a key \u5230 value \u7684\u6620\u5c04&#xff0c;Put\/Get\/Delete&#xff0c;\u4f60\u8111\u5b50\u91cc\u90a3\u4e2a map \u5fc3\u667a\u662f\u5bf9\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>Ordered\u2014\u2014\u7b2c 3\u30014 \u8282\u3002\u8fd9\u4e2a map \u7684\u952e\u7a7a\u95f4\u4e0a\u6709\u4e00\u4e2a\u7531\u6bd4\u8f83\u5668\u5b9a\u4e49\u7684\u5168\u5e8f&#xff0c;\u4e8e\u662f\u5b83\u80fd\u8303\u56f4\u626b\u63cf&#xff0c;\u4e8e\u662f\u5b83\u7684\u78c1\u76d8\u548c\u7f13\u5b58\u5168\u4e3a\u987a\u5e8f\u8bbf\u95ee\u670d\u52a1\u3002\u8fd9\u662f\u5b83\u548c\u00a0std::unordered_map\u00a0\u7684\u5206\u6c34\u5cad\u3002<\/p>\n<\/li>\n<li>\n<p>Persistent\u2014\u2014\u8de8\u8fdb\u7a0b\u6d3b\u7740&#xff0c;\u843d\u5728\u78c1\u76d8\u4e0a&#xff0c;\u8fdb\u7a0b\u91cd\u542f\u6570\u636e\u8fd8\u5728\u3002\u8fd9\u4e5f\u662f\u5b83\u5fc5\u987b\u5bf9\u4ed8\u78c1\u76d8 IO \u548c\u7f13\u5b58\u7684\u6839\u672c\u539f\u56e0&#xff1a;\u5185\u5b58\u91cc\u7684 map \u4e0d\u9700\u8981\u8003\u8651\u8fd9\u4e9b&#xff0c;\u4e00\u4e2a\u8981\u843d\u76d8\u7684 map \u5fc5\u987b\u8003\u8651\u3002<\/p>\n<\/li>\n<li>\n<p>Versioned\u2014\u2014\u8fd9\u4e2a\u8bcd\u7b2c 1\u30012 \u8282\u57cb\u4e86\u4e24\u6b21\u4f0f\u7b14\u3002\u8fd8\u8bb0\u5f97\u5417&#xff0c;\u6211\u8bf4\u8fc7\u201c\u66f4\u65b0\u5176\u5b9e\u6ca1\u8986\u76d6\u4efb\u4f55\u4e1c\u897f\u201d\u201c\u5220\u9664\u7559\u4e0b\u5893\u7891\u201d\u3002\u771f\u76f8\u662f&#xff1a;\u8fd9\u4e2a map \u771f\u6b63\u5b58\u7684\u662f\u201ckey &#043; \u7248\u672c\u53f7 \u2192 value\u201d\u3002\u6bcf\u4e00\u6b21\u00a0Put\u3001\u6bcf\u4e00\u6b21\u00a0Delete&#xff0c;\u90fd\u662f\u5f80\u8fd9\u4e2a key \u4e0a\u53e0\u4e00\u4e2a\u5e26\u66f4\u65b0\u7248\u672c\u53f7\u7684\u65b0\u8bb0\u5f55&#xff0c;\u65e7\u7248\u672c\u8fd8\u5728\u5e95\u4e0b\u538b\u7740\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6700\u540e\u90a3\u53e5\u201csafe for concurrent access &#8230; without any external synchronization\u201d\u4e5f\u522b\u653e\u8fc7&#xff1a;\u8fd9\u4e2a map \u81ea\u5e26\u5e76\u53d1\u5b89\u5168&#xff0c;\u591a\u7ebf\u7a0b\u76f4\u63a5\u8bfb\u5199\u4e0d\u7528\u4f60\u5728\u5916\u9762\u52a0\u9501\u3002\u4f60\u81ea\u7814\u5f15\u64ce\u65f6&#xff0c;\u8fd9\u662f\u4e00\u4e2a\u6602\u8d35\u7684\u627f\u8bfa\u2014\u2014\u5b83\u610f\u5473\u7740\u5185\u90e8\u6240\u6709\u7684\u987a\u5e8f\u7ed3\u6784\u3001\u7f13\u5b58\u3001\u540e\u53f0\u6574\u7406\u90fd\u5f97\u81ea\u5df1\u625b\u4f4f\u5e76\u53d1&#xff0c;\u8fd9\u7b14\u590d\u6742\u5ea6\u662f\u7701\u4e0d\u6389\u7684\u3002\u8fd9\u6761\u627f\u8bfa\u8fd8\u53cd\u8fc7\u6765\u6536\u7d27\u4e86\u524d\u9762\u6bcf\u4e00\u5c42&#xff1a;\u6bd4\u8f83\u5668\u5fc5\u987b\u7ebf\u7a0b\u5b89\u5168&#xff08;comparator.h \u660e\u8bf4\u5b83\u4f1a\u88ab\u591a\u4e2a\u8bfb\u7ebf\u7a0b\u540c\u65f6\u8c03\u7528&#xff09;&#xff0c;\u7f13\u5b58\u5f97\u7528\u5e76\u53d1\u5b89\u5168\u7684\u6dd8\u6c70\u7ed3\u6784&#xff0c;\u540e\u53f0\u538b\u7f29\u8981\u548c\u524d\u53f0\u8bfb\u5199\u62a2\u540c\u4e00\u6279\u6570\u636e\u8fd8\u4e0d\u8bb8\u4e92\u76f8\u8e29\u3002\u4f60\u80fd\u5728\u63a5\u53e3\u4e0a\u5199\u4e0b\u201c\u4e0d\u7528\u5916\u90e8\u52a0\u9501\u201d\u8fd9\u4e00\u53e5&#xff0c;\u80cc\u540e\u662f\u628a\u5e76\u53d1\u7684\u5168\u90e8\u590d\u6742\u5ea6\u54bd\u8fdb\u4e86\u5b9e\u73b0\u91cc\u3001\u4e00\u70b9\u6ca1\u6f0f\u7ed9\u8c03\u7528\u65b9\u3002<\/p>\n<p>\u201c\u6709\u7248\u672c\u201d\u8fd9\u4e2a\u8bcd&#xff0c;\u662f\u7b2c\u4e00\u90e8\u5206\u901a\u5f80\u540e\u9762\u4e24\u90e8\u5206\u7684\u6697\u95e8\u3002\u5b83\u4e00\u5934\u8fde\u7740\u201c\u9519\u8bef\u4e0e\u63a5\u53e3\u5206\u5c42\u201d\u2014\u2014\u56e0\u4e3a\u591a\u7248\u672c\u3001\u5e76\u53d1\u3001\u540e\u53f0\u538b\u7f29\u8fd9\u4e9b\u590d\u6742\u5ea6&#xff0c;\u5fc5\u987b\u88ab\u4e00\u5c42\u7a33\u5b9a\u7684\u63a5\u53e3\u5305\u4f4f&#xff0c;\u4e0d\u80fd\u6f0f\u7ed9\u4f60&#xff1b;\u53e6\u4e00\u5934\u8fde\u7740\u201c\u5bf9\u8c61\u751f\u547d\u5468\u671f\u201d\u2014\u2014\u56e0\u4e3a\u6709\u4e86\u7248\u672c&#xff0c;\u624d\u4f1a\u6709\u201c\u8fd9\u6761\u65e7\u6570\u636e\u8fd8\u5b58\u5728&#xff0c;\u4f46\u4f60\u5df2\u7ecf\u770b\u4e0d\u89c1\u5b83\u4e86\u201d\u8fd9\u79cd\u8be1\u5f02\u72b6\u6001&#xff0c;\u624d\u4f1a\u6709\u5feb\u7167&#xff0c;\u624d\u4f1a\u6709\u5173\u5e93\u65f6\u90a3\u4e2a\u80fd\u628a\u4f60\u62e6\u4f4f\u7684\u672a\u91ca\u653e\u5f15\u7528\u3002\u63a5\u4e0b\u6765\u4e24\u90e8\u5206&#xff0c;\u5c31\u662f\u62c6\u8fd9\u4e24\u6247\u95e8\u3002<\/p>\n<hr \/>\n<h3>6. \u4e00\u4e2a\u7eaf\u865a\u57fa\u7c7b&#xff0c;\u4e00\u4e2a\u5de8\u578b\u5b9e\u73b0&#xff0c;\u63a5\u53e3\u548c\u5b9e\u73b0\u5c31\u8fd9\u4e48\u5206\u4e86\u5bb6<\/h3>\n<p>\u7b2c\u4e00\u90e8\u5206\u4f60\u4e00\u76f4\u5728\u7528\u00a0DB\u00a0\u8fd9\u4e2a\u7c7b\u578b&#xff0c;Put\u3001Get\u3001NewIterator\u00a0\u90fd\u662f\u5b83\u7684\u65b9\u6cd5\u3002\u73b0\u5728\u628a\u5b83\u7684\u771f\u8eab\u7ffb\u51fa\u6765\u2014\u2014\u5b83\u662f\u4e2a\u7eaf\u865a\u57fa\u7c7b&#xff0c;\u4e00\u884c\u5b9e\u73b0\u90fd\u6ca1\u6709\u3002db.h \u7684\u7c7b\u6ce8\u91ca\u628a\u8fd9\u5c42\u5173\u7cfb\u4ea4\u4ee3\u5f97\u5f88\u5e72\u8106&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h<br \/>\n\/\/ A DB is an abstract base class with one primary implementation<br \/>\n\/\/ (DBImpl) and a number of wrapper implementations.<br \/>\nclass DB {<br \/>\n public:<br \/>\n  virtual Status Put(const WriteOptions&amp;, ColumnFamilyHandle*,<br \/>\n                     const Slice&amp; key, const Slice&amp; value) &#061; 0;<br \/>\n  virtual Status Get(const ReadOptions&amp;, ColumnFamilyHandle*,<br \/>\n                     const Slice&amp; key, PinnableSlice* value,<br \/>\n                     std::string* timestamp) &#061; 0;<br \/>\n  \/\/ &#8230; \u4e00\u6574\u5957 &#061; 0 \u7684\u7eaf\u865a\u51fd\u6570<br \/>\n};<\/p>\n<p>&#061; 0\u00a0\u7684\u7eaf\u865a\u51fd\u6570&#xff0c;\u4ece\u5934\u6392\u5230\u5c3e\u3002\u771f\u6b63\u5e72\u6d3b\u7684\u5b9e\u73b0\u5728\u53e6\u4e00\u4e2a\u76ee\u5f55\u3001\u53e6\u4e00\u4e2a\u7c7b\u91cc&#xff0c;db_impl.h&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db_impl.h<br \/>\n\/\/ Since it&#039;s a very large class, the definition of the functions is<br \/>\n\/\/ divided in several db_impl_*.cc files, besides db_impl.cc.<br \/>\nclass DBImpl : public DB {<br \/>\n public:<br \/>\n  \/\/ &#8212;- Implementations of the DB interface &#8212;-<br \/>\n  Status Put(const WriteOptions&amp; options, ColumnFamilyHandle* column_family,<br \/>\n             const Slice&amp; key, const Slice&amp; value) override;<br \/>\n  Status Delete(const WriteOptions&amp; options, ColumnFamilyHandle* column_family,<br \/>\n                const Slice&amp; key) override;<br \/>\n  \/\/ &#8230; \u628a DB \u7684\u6bcf\u4e2a\u7eaf\u865a\u51fd\u6570 override \u4e00\u904d<br \/>\n};<\/p>\n<p>\u6ce8\u91ca\u8bf4\u5f97\u5f88\u5b9e\u5728\u2014\u2014\u201c\u56e0\u4e3a\u8fd9\u4e2a\u7c7b\u5b9e\u5728\u592a\u5927&#xff0c;\u5b83\u7684\u51fd\u6570\u5b9a\u4e49\u88ab\u62c6\u5230\u597d\u51e0\u4e2a db_impl_*.cc \u6587\u4ef6\u91cc\u201d\u3002\u8fd9\u5c31\u662f\u63a5\u53e3\u548c\u5b9e\u73b0\u5206\u5bb6\u7684\u610f\u4e49&#xff1a;DB\u00a0\u662f\u4e00\u5f20\u8584\u8584\u7684\u5951\u7ea6&#xff0c;\u51e0\u767e\u884c\u7eaf\u865a\u58f0\u660e&#xff1b;DBImpl\u00a0\u662f\u90a3\u53f0\u771f\u6b63\u5904\u7406\u5185\u5b58\u8868\u3001\u9884\u5199\u65e5\u5fd7\u3001\u540e\u53f0\u538b\u7f29\u3001\u5e76\u53d1\u63a7\u5236\u7684\u5e9e\u7136\u5927\u7269&#xff0c;\u6563\u5728\u5341\u51e0\u4e2a\u6e90\u6587\u4ef6\u91cc\u3002\u4f60\u56de\u5934\u770b\u7b2c 1 \u8282\u7684\u00a0DB::Open&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h<br \/>\nstatic Status Open(const Options&amp; options, const std::string&amp; name,<br \/>\n                   std::unique_ptr&lt;DB&gt;* dbptr);<\/p>\n<p>\u5b83\u4ea4\u8fd8\u7ed9\u4f60\u7684\u662f\u00a0unique_ptr&lt;DB&gt;\u2014\u2014\u63a5\u53e3\u7c7b\u578b\u7684\u667a\u80fd\u6307\u9488\u3002\u4f60\u4ece\u5934\u5230\u5c3e\u6478\u5230\u7684\u90fd\u662f\u90a3\u5f20\u8584\u5951\u7ea6\u00a0DB&#xff0c;DBImpl\u00a0\u8fd9\u4e2a\u540d\u5b57\u4f60\u5728\u81ea\u5df1\u4ee3\u7801\u91cc\u6839\u672c\u4e0d\u9700\u8981\u51fa\u73b0\u3002\u8fd9\u5c31\u662f\u201c\u7a33\u5b9a\u516c\u5171 API\u201d\u548c\u201c\u5185\u90e8\u5b9e\u73b0\u201d\u7684\u7269\u7406\u8fb9\u754c&#xff1a;\u5e95\u4e0b\u90a3\u53f0\u5e9e\u7136\u5927\u7269\u968f\u7248\u672c\u600e\u4e48\u91cd\u6784\u3001\u62c6\u51e0\u4e2a\u6587\u4ef6\u3001\u6362\u4ec0\u4e48\u6570\u636e\u7ed3\u6784&#xff0c;\u53ea\u8981\u00a0DB\u00a0\u8fd9\u5f20\u7eaf\u865a\u5951\u7ea6\u4e0d\u53d8&#xff0c;\u4f60\u7684\u4ee3\u7801\u4e00\u884c\u90fd\u4e0d\u7528\u6539\u3002\u4f60\u81ea\u7814\u5f15\u64ce\u65f6\u5982\u679c\u53ea\u5b66\u4e00\u6761 API \u8bbe\u8ba1\u539f\u5219&#xff0c;\u5c31\u5b66\u8fd9\u6761\u2014\u2014\u5bf9\u5916\u4ea4\u51fa\u4e00\u4e2a\u7eaf\u865a\u63a5\u53e3\u548c\u4e00\u4e2a\u5de5\u5382\u51fd\u6570&#xff08;\u8fd9\u91cc\u662f\u00a0Open&#xff09;&#xff0c;\u628a\u5b9e\u73b0\u7c7b\u5f7b\u5e95\u710a\u6b7b\u5728\u4f60\u7684 .cc \u6587\u4ef6\u91cc&#xff0c;\u6c38\u8fdc\u4e0d\u8fdb\u516c\u5171\u5934\u3002<\/p>\n<p>\u8fd9\u5c42\u5206\u5bb6\u8fd8\u987a\u624b\u4e70\u5230\u4e00\u6837\u4f60\u73b0\u5728\u53ef\u80fd\u6ca1\u5728\u610f\u3001\u53d1\u5e03\u5e93\u65f6\u5374\u4f1a\u6551\u547d\u7684\u4e1c\u897f\u2014\u2014ABI \u7a33\u5b9a\u3002DB\u00a0\u662f\u7eaf\u865a\u57fa\u7c7b&#xff0c;\u4f60\u7684\u4ee3\u7801\u901a\u8fc7\u5b83\u7684\u865a\u8868\u8c03\u00a0Put\/Get&#xff0c;\u7f16\u8bd1\u671f\u4f60\u53ea\u4f9d\u8d56\u201c\u8fd9\u4e2a\u65b9\u6cd5\u6392\u5728\u865a\u8868\u7b2c\u51e0\u4e2a\u201d\u8fd9\u4e2a\u504f\u79fb&#xff0c;\u4e0d\u4f9d\u8d56\u00a0DBImpl\u00a0\u91cc\u6709\u54ea\u4e9b\u6210\u5458\u3001\u600e\u4e48\u6392\u5e03\u3002\u4e8e\u662f\u5e95\u5c42\u5b9e\u73b0\u52a0\u4e2a\u5b57\u6bb5\u3001\u6362\u4e2a\u6570\u636e\u7ed3\u6784\u3001\u91cd\u6392\u79c1\u6709\u6210\u5458&#xff0c;\u4f60\u7684\u4e8c\u8fdb\u5236\u4e00\u884c\u90fd\u4e0d\u7528\u91cd\u7f16&#xff0c;\u53ea\u8981\u865a\u8868\u7684\u5f62\u72b6\u4e0d\u53d8\u3002\u8fd9\u6b63\u662f\u4ee5\u00a0.so\u00a0\/\u00a0.dll\u00a0\u53d1\u5e03\u7684\u5e93\u68a6\u5bd0\u4ee5\u6c42\u7684\u6027\u8d28&#xff1a;\u63a5\u53e3\u4e0e\u5b9e\u73b0\u5728\u4e8c\u8fdb\u5236\u5c42\u9762\u89e3\u8026\u3002\u4ee3\u4ef7\u662f\u6bcf\u6b21\u8c03\u7528\u591a\u4e00\u8df3\u865a\u8868\u95f4\u63a5\u5bfb\u5740&#xff0c;\u4f46\u5bf9\u4e00\u4e2a\u52a8\u8f84\u8981\u8bfb\u76d8\u7684\u64cd\u4f5c&#xff0c;\u8fd9\u4e00\u8df3\u7684\u5f00\u9500\u5c0f\u5230\u53ef\u4ee5\u5ffd\u7565\u3002\u4f60\u81ea\u7814\u5f15\u64ce\u82e5\u8981\u7ed9\u4e0b\u6e38\u53d1\u4e8c\u8fdb\u5236&#xff0c;\u201c\u7eaf\u865a\u63a5\u53e3 &#043; \u5de5\u5382\u51fd\u6570\u201d\u51e0\u4e4e\u662f\u552f\u4e00\u625b\u5f97\u4f4f\u7248\u672c\u6f14\u8fdb\u7684\u5f62\u72b6\u2014\u2014\u628a\u5b9e\u73b0\u585e\u8fdb\u516c\u5171\u5934\u7684\u90a3\u4e00\u523b&#xff0c;\u4f60\u5c31\u628a\u81ea\u5df1\u710a\u6b7b\u5728\u4e86\u4e00\u4e2a\u518d\u4e5f\u6539\u4e0d\u52a8\u7684\u5185\u5b58\u5e03\u5c40\u4e0a\u3002<\/p>\n<p>\u5206\u5c42\u8fd8\u6709\u66f4\u7ec6\u7684\u4e00\u624b\u3002\u770b\u00a0Get\u00a0\u8fd9\u4e00\u65cf\u5728 db.h \u91cc\u7684\u6837\u5b50&#xff0c;\u5b83\u4e0d\u6b62\u4e00\u4e2a&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h&#xff1a;\u771f\u6b63\u8981\u88ab\u5b9e\u73b0\u7684&#xff0c;\u53ea\u6709\u8fd9\u4e00\u4e2a\u7eaf\u865a\u7248\u672c<br \/>\nvirtual Status Get(const ReadOptions&amp;, ColumnFamilyHandle*, const Slice&amp; key,<br \/>\n                   PinnableSlice* value, std::string* timestamp) &#061; 0;<\/p>\n<p>\/\/ \u5176\u4f59\u5168\u662f final \u7684\u4fbf\u5229\u91cd\u8f7d&#xff0c;\u6536\u655b\u5230\u4e0a\u9762\u90a3\u4e2a<br \/>\n\/\/ NOTE: virtual final &#061;&gt; disallow override (was previously allowed)<br \/>\nvirtual Status Get(const ReadOptions&amp; options, const Slice&amp; key,<br \/>\n                   std::string* value) final {<br \/>\n  return Get(options, DefaultColumnFamily(), key, value);<br \/>\n}<\/p>\n<p>\u4e00\u4e2a\u00a0Get\u00a0\u5bb6\u65cf&#xff0c;\u53ea\u6709\u90a3\u4e2a\u5e26\u00a0PinnableSlice*\u00a0\u548c\u00a0timestamp*\u00a0\u7684\u7248\u672c\u662f\u7eaf\u865a\u7684\u2014\u2014\u5b83\u662f\u552f\u4e00\u7684\u5b9e\u73b0\u70b9\u3002\u5176\u4f59\u4f60\u5929\u5929\u7528\u7684\u90a3\u4e9b\u201c\u7701\u4e8b\u7248\u201d&#xff08;\u7701\u6389\u5217\u65cf\u53c2\u6570\u3001value \u76f4\u63a5\u7ed9\u00a0std::string&#xff09;\u5168\u662f\u00a0final&#xff0c;\u8c01\u90fd\u4e0d\u8bb8\u518d override&#xff0c;\u5b83\u4eec\u53ea\u505a\u4e00\u4ef6\u4e8b&#xff1a;\u8865\u4e0a\u9ed8\u8ba4\u53c2\u6570&#xff0c;\u628a\u8c03\u7528\u8f6c\u53d1\u8fdb\u90a3\u4e2a\u552f\u4e00\u7684\u7eaf\u865a\u00a0Get\u3002\u6ce8\u91ca\u91cc\u90a3\u53e5\u00a0disallow override (was previously allowed)\u00a0\u662f\u6709\u6545\u4e8b\u7684\u2014\u2014\u65e9\u5e74\u8fd9\u4e9b\u91cd\u8f7d\u4e0d\u662f\u00a0final&#xff0c;\u4e8e\u662f\u6bcf\u4e2a\u60f3\u5b9a\u5236\u7684\u5b50\u7c7b\u90fd\u5f97\u628a\u4e03\u516b\u4e2a\u91cd\u8f7d\u5404\u5b9e\u73b0\u4e00\u904d&#xff0c;\u7a0d\u4e0d\u7559\u795e\u5c31\u6f0f\u6389\u4e00\u4e2a\u3001\u884c\u4e3a\u4e0d\u4e00\u81f4\u3002\u6539\u6210\u00a0final\u00a0\u4e4b\u540e&#xff0c;\u5b9e\u73b0\u8005\u7684\u4e49\u52a1\u88ab\u6536\u7a84\u5230\u4e00\u4e2a\u65b9\u6cd5&#xff0c;\u4fbf\u5229\u6027\u7559\u7ed9\u8c03\u7528\u65b9&#xff0c;\u4e00\u81f4\u6027\u7531\u7f16\u8bd1\u671f\u4fdd\u8bc1\u3002<\/p>\n<p>\u5230\u00a0DBImpl\u00a0\u91cc&#xff0c;\u8fd9\u4e2a\u552f\u4e00\u7684\u7eaf\u865a\u00a0Get\u00a0\u53c8\u8f6c\u53d1\u8fdb\u4e00\u4e2a\u66f4\u5185\u90e8\u7684\u5b9e\u73b0\u51fd\u6570&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db_impl.h&#xff1a;DBImpl \u91cc&#xff0c;\u516c\u5f00\u7684 Get \u4e4b\u4e0b\u8fd8\u6709\u4e00\u5c42\u5185\u90e8\u7684 GetImpl<br \/>\nStatus GetMergeOperands(const ReadOptions&amp; options,<br \/>\n                        ColumnFamilyHandle* column_family, const Slice&amp; key,<br \/>\n                        PinnableSlice* merge_operands, \/* &#8230; *\/) override {<br \/>\n  GetImplOptions get_impl_options;<br \/>\n  get_impl_options.column_family &#061; column_family;<br \/>\n  get_impl_options.merge_operands &#061; merge_operands;<br \/>\n  get_impl_options.get_value &#061; false;<br \/>\n  return GetImpl(options, key, get_impl_options);<br \/>\n}<\/p>\n<p>\u4e8e\u662f\u8bfb\u8def\u5f84\u662f\u4e09\u5c42\u5957\u5a03&#xff1a;\u6700\u5916\u5c42\u662f\u4e00\u5806\u00a0final\u00a0\u4fbf\u5229\u91cd\u8f7d&#xff08;\u516c\u5171 API \u7684\u4eba\u4f53\u5de5\u5b66&#xff09;&#xff0c;\u4e2d\u95f4\u662f\u552f\u4e00\u7684\u865a\u51fd\u6570\u00a0Get&#xff08;\u591a\u6001\u7684\u5b9e\u73b0\u70b9\u3001\u4e5f\u662f\u7a33\u5b9a\u7684 ABI \u8fb9\u754c&#xff09;&#xff0c;\u6700\u91cc\u5c42\u662f\u00a0GetImpl\u00a0\u5e26\u4e00\u4e2a\u00a0GetImplOptions\u00a0\u53c2\u6570\u5305&#xff08;\u5185\u90e8\u5b9e\u73b0&#xff0c;\u968f\u4fbf\u600e\u4e48\u6539&#xff09;\u3002\u00a0\u70b9\u67e5\u3001\u8bfb\u5408\u5e76\u7b97\u5b50\u3001\u591a\u952e\u6279\u91cf\u8bfb&#xff0c;\u6700\u540e\u90fd\u6c47\u5230\u00a0GetImpl\u00a0\u8fd9\u4e00\u4e2a\u6d1e\u91cc\u3002\u8fd9\u4e2a\u7ed3\u6784\u503c\u5f97\u4f60\u6284\u8fdb\u81ea\u7814\u5f15\u64ce&#xff1a;\u628a\u201c\u7ed9\u8c03\u7528\u65b9\u7684\u82b1\u6837\u201d\u548c\u201c\u7ed9\u5b9e\u73b0\u8005\u7684\u4e49\u52a1\u201d\u5206\u5f00&#xff0c;\u524d\u8005\u5c3d\u7ba1\u591a&#xff0c;\u540e\u8005\u6536\u655b\u5230\u4e00\u4e2a\u5185\u90e8\u51fd\u6570\u4e0a&#xff0c;\u4e2d\u95f4\u7528\u4e00\u4e2a\u7a33\u5b9a\u7684\u865a\u63a5\u53e3\u9694\u5f00\u3002<\/p>\n<h3>7. \u9519\u8bef\u662f\u503c\u4e0d\u662f\u5f02\u5e38&#xff1a;Status \u4e0e\u90a3\u4e2a\u4f1a abort \u7684\u6790\u6784\u51fd\u6570<\/h3>\n<p>\u7b2c 1\u30012 \u8282\u6211\u4e24\u6b21\u5356\u8fc7\u5173\u5b50&#xff0c;\u8bf4\u8fd9\u53f0\u5f15\u64ce\u4e0d\u7528\u5f02\u5e38\u3002\u73b0\u5728\u5151\u73b0\u3002\u5b83\u7684\u6574\u4e2a\u9519\u8bef\u901a\u9053\u5c31\u662f\u90a3\u4e2a\u5230\u5904\u51fa\u73b0\u7684\u8fd4\u56de\u503c\u00a0Status\u3002\u5148\u770b\u5b83\u627f\u8f7d\u4ec0\u4e48&#xff0c;status.h&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ status.h<br \/>\nenum Code : unsigned char {<br \/>\n  kOk &#061; 0,<br \/>\n  kNotFound &#061; 1,<br \/>\n  kCorruption &#061; 2,<br \/>\n  kNotSupported &#061; 3,<br \/>\n  kInvalidArgument &#061; 4,<br \/>\n  kIOError &#061; 5,<br \/>\n  \/\/ &#8230; \u4e00\u76f4\u5230<br \/>\n  kColumnFamilyDropped &#061; 15,<br \/>\n};<\/p>\n<p>\u4e00\u4e2a\u5b57\u8282\u7684\u9519\u8bef\u7801&#xff0c;\u5341\u516d\u79cd\u3002kNotFound\u00a0\u53ea\u662f\u5176\u4e2d\u666e\u666e\u901a\u901a\u7684\u4e00\u53f7\u2014\u2014\u67e5\u4e0d\u5230\u3001IO \u9519\u3001\u6570\u636e\u635f\u574f\u3001\u53c2\u6570\u975e\u6cd5\u3001\u5217\u65cf\u88ab\u5220&#xff0c;\u5168\u90fd\u662f\u540c\u4e00\u4e2a\u00a0Status\u00a0\u503c\u7684\u4e0d\u540c\u53d6\u503c&#xff0c;\u987a\u7740\u51fd\u6570\u8fd4\u56de\u503c\u4e00\u5c42\u5c42\u5f80\u4e0a\u4f20\u3002\u6ca1\u6709\u00a0throw&#xff0c;\u6ca1\u6709\u00a0catch&#xff0c;\u6ca1\u6709\u6808\u5c55\u5f00\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u4e00\u53f0\u8fd9\u4e48\u590d\u6742\u7684\u5f15\u64ce&#xff0c;\u5b81\u53ef\u7528\u8fd4\u56de\u503c\u4e5f\u4e0d\u7528\u5f02\u5e38&#xff1f;\u6bd4\u8f83\u5668\u90a3\u4e2a\u5934\u6587\u4ef6\u91cc\u6709\u4e00\u53e5\u6700\u76f4\u767d\u7684\u89e3\u91ca&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ comparator.h<br \/>\n\/\/ Exceptions MUST NOT propagate out of overridden functions into<br \/>\n\/\/ RocksDB, because RocksDB is not exception-safe. This could cause<br \/>\n\/\/ undefined behavior including data loss, unreported corruption,<br \/>\n\/\/ deadlocks, and more.<\/p>\n<p>\u201c\u8fd9\u53f0\u5f15\u64ce\u4e0d\u662f\u5f02\u5e38\u5b89\u5168\u7684\u3002\u201d\u00a0\u4e00\u4e2a\u6301\u6709\u5185\u90e8\u9501\u3001\u7ba1\u7740\u4e00\u5806\u591a\u7248\u672c\u6570\u636e\u3001\u540e\u53f0\u8fd8\u6709\u538b\u7f29\u7ebf\u7a0b\u5728\u8dd1\u7684\u7cfb\u7edf&#xff0c;\u5982\u679c\u8ba9\u5f02\u5e38\u5728\u4efb\u610f\u4e00\u5c42\u968f\u610f\u7a7f\u8fc7\u53bb&#xff0c;\u6808\u5c55\u5f00\u4f1a\u7ed5\u8fc7\u5b83\u7cbe\u5fc3\u5b89\u6392\u7684\u89e3\u9501\u3001\u56de\u6eda\u3001\u72b6\u6001\u590d\u4f4d&#xff0c;\u8f7b\u5219\u6b7b\u9501&#xff0c;\u91cd\u5219\u4e22\u6570\u636e\u3001\u635f\u574f\u8fd8\u4e0d\u4e0a\u62a5\u3002\u6240\u4ee5\u5b83\u7684\u9009\u62e9\u662f&#xff1a;\u5728\u6240\u6709\u6743\u548c\u8d44\u6e90\u8fb9\u754c\u4e0a\u4e0d\u4fe1\u4efb\u5f02\u5e38&#xff0c;\u628a\u9519\u8bef\u538b\u5e73\u6210\u4e00\u4e2a\u5fc5\u987b\u88ab\u9010\u5c42\u68c0\u67e5\u3001\u9010\u5c42\u4f20\u9012\u7684\u503c\u3002\u00a0\u4f60\u81ea\u7814\u5f15\u64ce\u3001\u5c24\u5176\u6d89\u53ca\u78c1\u76d8\u548c\u5e76\u53d1\u65f6&#xff0c;\u8fd9\u662f\u4e00\u4e2a\u503c\u5f97\u8ba4\u771f\u6382\u91cf\u7684\u7acb\u573a\u2014\u2014\u5f02\u5e38\u5728\u4e1a\u52a1\u4ee3\u7801\u91cc\u5f88\u9999&#xff0c;\u4f46\u5728\u4e00\u4e2a\u4e0d\u80fd\u5bb9\u5fcd\u201c\u534a\u4e2a\u64cd\u4f5c\u201d\u7684\u5b58\u50a8\u5f15\u64ce\u6838\u5fc3\u91cc&#xff0c;\u8fd4\u56de\u503c\u9519\u8bef\u7801\u7684\u53ef\u9884\u6d4b\u6027\u5f80\u5f80\u66f4\u503c\u94b1\u3002<\/p>\n<p>\u4f46\u8fd4\u56de\u503c\u6709\u4e2a\u81f4\u547d\u5f31\u70b9&#xff1a;\u6ca1\u4eba\u5f3a\u8feb\u4f60\u68c0\u67e5\u3002\u00a0throw\u00a0\u51fa\u6765\u7684\u5f02\u5e38\u4f60\u4e0d\u63a5\u5c31\u5d29&#xff0c;\u8fd4\u56de\u7684\u00a0Status\u00a0\u4f60\u4e0d\u770b\u5c31\u6084\u6084\u6e9c\u8fc7\u53bb\u4e86\u3002\u8fd9\u53f0\u5f15\u64ce\u600e\u4e48\u5835\u8fd9\u4e2a\u6d1e&#xff1f;\u6211\u4eec\u8ba9\u5b83\u5f53\u573a\u5d29\u7ed9\u4f60\u770b\u3002\u5199\u4e00\u6bb5\u201c\u5fd8\u4e86\u68c0\u67e5\u8fd4\u56de\u503c\u201d\u7684\u4ee3\u7801&#xff0c;\u7528\u6253\u5f00\u4e86\u72b6\u6001\u68c0\u67e5\u7684\u7f16\u8bd1\u914d\u7f6e\u8dd1&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ \u707e\u96be\u6f14\u793a&#xff1a;\u62ff\u5230 Status \u5374\u4e0d\u770b\u5b83<br \/>\ndb-&gt;Put(WriteOptions(), &#034;k&#034;, &#034;v&#034;);   \/\/ \u8fd4\u56de\u7684 Status \u76f4\u63a5\u88ab\u4e22\u5f03<br \/>\n\/\/ \u7a0b\u5e8f\u7ee7\u7eed\u5f80\u4e0b\u2026\u2026<\/p>\n<p>\u5728\u5f00\u4e86\u00a0ASSERT_STATUS_CHECKED\u00a0\u7684\u6784\u5efa\u91cc&#xff0c;\u8fd9\u6bb5\u8dd1\u5230\u90a3\u4e2a\u88ab\u4e22\u5f03\u7684\u00a0Status\u00a0\u6790\u6784\u65f6&#xff0c;\u76f4\u63a5 abort&#xff1a;<\/p>\n<p>text<\/p>\n<p>Failed to check Status 0x7ffe1a3c9080<br \/>\n  #4  Status::~Status()<br \/>\n  #5  main<br \/>\nAborted (core dumped)<\/p>\n<p>\u79d8\u5bc6\u5168\u5728\u00a0Status\u00a0\u7684\u6790\u6784\u51fd\u6570\u91cc&#xff0c;status.h&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ status.h<br \/>\n~Status() {<br \/>\n#ifdef ROCKSDB_ASSERT_STATUS_CHECKED<br \/>\n  if (!checked_) {<br \/>\n    fprintf(stderr, &#034;Failed to check Status %p\\\\n&#034;, this);<br \/>\n    port::PrintStack();<br \/>\n    std::abort();<br \/>\n  }<br \/>\n#endif<br \/>\n}<\/p>\n<p>\u6bcf\u4e2a\u00a0Status\u00a0\u5185\u90e8\u85cf\u4e86\u4e00\u4e2a\u00a0checked_\u00a0\u6807\u5fd7\u3002\u4f60\u8c03\u00a0ok()\u3001code()\u3001IsNotFound()\u00a0\u8fd9\u4e9b&#xff0c;\u90fd\u4f1a\u628a\u5b83\u6807\u8bb0\u4e3a\u201c\u5df2\u68c0\u67e5\u201d\u3002\u8981\u662f\u4e00\u4e2a\u00a0Status\u00a0\u5bf9\u8c61\u4e00\u8def\u6d3b\u5230\u6790\u6784\u90fd\u6ca1\u88ab\u4eba\u78b0\u8fc7\u4e00\u6b21&#xff0c;\u6790\u6784\u51fd\u6570\u5c31\u6253\u5370\u5730\u5740\u3001\u6253\u5370\u8c03\u7528\u6808\u3001std::abort()\u2014\u2014\u628a\u8fdb\u7a0b\u5f53\u573a\u5e72\u6389&#xff0c;\u903c\u4f60\u5728\u6d4b\u8bd5\u9636\u6bb5\u5c31\u628a\u8fd9\u4e2a\u6f0f\u68c0\u7684\u5730\u65b9\u63ea\u51fa\u6765\u3002\u8fd9\u5957\u68c0\u67e5\u53ea\u5728\u5e26\u00a0ASSERT_STATUS_CHECKED\u00a0\u7684\u8c03\u8bd5 \/ CI \u6784\u5efa\u91cc\u751f\u6548&#xff0c;\u53d1\u5e03\u7248\u662f\u96f6\u5f00\u9500\u7684&#xff08;\u90a3\u6bb5\u4ee3\u7801\u6839\u672c\u4e0d\u7f16\u8fdb\u53bb&#xff09;\u3002<\/p>\n<p>\u90a3\u8981\u662f\u6211\u786e\u5b9e\u60f3\u4e22\u5f03\u4e00\u4e2a\u9519\u8bef\u5462&#xff1f;\u4e5f\u6709\u6b63\u89c4\u51fa\u53e3&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ status.h<br \/>\n\/\/ In case of intentionally swallowing an error, user must explicitly<br \/>\n\/\/ call this function.<br \/>\ninline void PermitUncheckedError() const { MarkChecked(); }<\/p>\n<p>\u4f60\u5f97\u663e\u5f0f\u5199\u4e00\u53e5\u00a0s.PermitUncheckedError()&#xff0c;\u767d\u7eb8\u9ed1\u5b57\u58f0\u660e\u201c\u8fd9\u4e2a\u9519\u8bef\u6211\u662f\u6545\u610f\u4e0d\u5904\u7406\u7684\u201d\u3002\u8fd9\u53e5\u8bdd\u7684\u4ef7\u503c\u5168\u5728\u4ee3\u7801\u5ba1\u67e5\u2014\u2014\u5b83\u628a\u201c\u6211\u6f0f\u4e86\u201d\u548c\u201c\u6211\u6545\u610f\u7684\u201d\u4ece\u89c6\u89c9\u4e0a\u5f7b\u5e95\u5206\u5f00&#xff0c;\u5168\u5e93\u641c\u4e00\u4e0b\u5c31\u77e5\u9053\u54ea\u4e9b\u9519\u8bef\u662f\u88ab\u4eba\u6709\u610f\u54bd\u4e0b\u53bb\u7684\u3002\u8fd9\u662f\u628a\u4e00\u4e2a\u7eaf\u7ea6\u5b9a&#xff08;\u8bf7\u8bb0\u5f97\u68c0\u67e5\u8fd4\u56de\u503c&#xff09;\u5347\u7ea7\u6210\u4e86\u7f16\u8bd1\u671f\u53ef\u5f3a\u5236\u3001\u4ee3\u7801\u91cc\u53ef\u641c\u7d22\u7684\u7eaa\u5f8b\u3002\u00a0\u4f60\u81ea\u7814\u5f15\u64ce\u65f6\u5982\u679c\u4e5f\u8d70\u8fd4\u56de\u503c\u9519\u8bef\u901a\u9053&#xff0c;\u5f3a\u70c8\u5efa\u8bae\u6284\u8fd9\u4e00\u5957&#xff1a;\u5149\u6709\u00a0Status\u00a0\u4e0d\u591f&#xff0c;\u5f97\u6709\u4e00\u4e2a\u80fd\u5728\u6d4b\u8bd5\u91cc\u628a\u201c\u6f0f\u68c0\u201d\u53d8\u6210\u5d29\u6e83\u7684\u673a\u5236&#xff0c;\u5426\u5219\u8fd4\u56de\u503c\u9519\u8bef\u7801\u8fdf\u65e9\u4f1a\u88ab\u4eba\u8fd9\u91cc\u6f0f\u4e00\u4e2a\u90a3\u91cc\u6f0f\u4e00\u4e2a&#xff0c;\u9000\u5316\u6210\u6bd4\u5f02\u5e38\u8fd8\u5371\u9669\u7684\u4e1c\u897f\u2014\u2014\u56e0\u4e3a\u5f02\u5e38\u81f3\u5c11\u4e0d\u4f1a\u88ab\u65e0\u58f0\u541e\u6389\u3002<\/p>\n<h3>8. \u529f\u80fd\u600e\u4e48\u4e00\u5c42\u5c42\u53e0\u4e0a\u53bb&#xff0c;\u9760\u7684\u662f\u88c5\u9970<\/h3>\n<p>\u5230\u8fd9\u91cc\u4f60\u624b\u91cc\u6709\u4e86\u4e24\u5757&#xff1a;\u4e00\u5f20\u7eaf\u865a\u5951\u7ea6\u00a0DB&#xff0c;\u4e00\u4e2a\u5de8\u578b\u5b9e\u73b0\u00a0DBImpl\u3002\u73b0\u5728\u6765\u4e2a\u771f\u95ee\u9898&#xff1a;\u6211\u60f3\u7ed9\u8fd9\u53f0\u5f15\u64ce\u52a0\u4e2a\u529f\u80fd&#xff0c;\u6bd4\u5982\u7ed9\u6240\u6709 key \u81ea\u52a8\u5e26 TTL \u8fc7\u671f&#xff0c;\u6216\u8005\u5199\u4e4b\u524d\u5148\u52a0\u5bc6\u3002\u5f80\u54ea\u52a0&#xff1f;<\/p>\n<p>\u65b0\u624b\u7684\u7b2c\u4e00\u53cd\u5e94\u662f\u6539\u00a0DBImpl\u3002\u9519\u3002DBImpl\u00a0\u662f\u90a3\u53f0\u8c01\u90fd\u4e0d\u8be5\u78b0\u7684\u5e9e\u7136\u5927\u7269&#xff0c;\u4f60\u5f80\u91cc\u585e TTL \u903b\u8f91&#xff0c;\u7b49\u4e8e\u628a\u4e00\u4e2a\u6b63\u4ea4\u7684\u5173\u6ce8\u70b9\u710a\u6b7b\u8fdb\u6838\u5fc3\u5b9e\u73b0\u3002\u6b63\u786e\u7b54\u6848\u662f\u88c5\u9970&#xff0c;\u5b83\u7ed9\u4f60\u73b0\u6210\u7684\u57fa\u7c7b&#xff0c;stackable_db.h&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ stackable_db.h<br \/>\n\/\/ This class contains APIs to stack rocksdb wrappers.<br \/>\n\/\/ Eg. Stack TTL over base db.<br \/>\nclass StackableDB : public DB {<br \/>\n public:<br \/>\n  explicit StackableDB(DB* db) : db_(db) {}          \/\/ \u72ec\u5360\u5e95\u5c42 db<\/p>\n<p>  Status Put(const WriteOptions&amp; options, ColumnFamilyHandle* cf,<br \/>\n             const Slice&amp; key, const Slice&amp; val) override {<br \/>\n    return db_-&gt;Put(options, cf, key, val);          \/\/ \u539f\u6837\u8f6c\u53d1<br \/>\n  }<br \/>\n  Status DropColumnFamily(ColumnFamilyHandle* cf) override {<br \/>\n    return db_-&gt;DropColumnFamily(cf);                \/\/ \u539f\u6837\u8f6c\u53d1<br \/>\n  }<br \/>\n  virtual DB* GetBaseDB() { return db_; }            \/\/ \u9732\u51fa\u88ab\u5305\u7684\u90a3\u5c42<br \/>\n  DB* GetRootDB() override { return db_-&gt;GetRootDB(); }  \/\/ \u9012\u5f52\u5230\u6700\u5e95<br \/>\n private:<br \/>\n  DB* db_;<br \/>\n};<\/p>\n<p>StackableDB\u00a0\u81ea\u5df1\u5c31\u662f\u4e00\u4e2a\u00a0DB&#xff08;public DB&#xff09;&#xff0c;\u5b83\u6301\u6709\u53e6\u4e00\u4e2a\u00a0DB&#xff0c;\u628a\u6bcf\u4e00\u4e2a\u65b9\u6cd5\u539f\u5c01\u4e0d\u52a8\u8f6c\u53d1\u7ed9\u91cc\u9762\u90a3\u4e2a\u3002\u5b83\u81ea\u5df1\u4ec0\u4e48\u6d3b\u90fd\u4e0d\u5e72\u2014\u2014\u5b83\u7684\u4ef7\u503c\u6070\u6070\u5728\u4e8e\u201c\u4ec0\u4e48\u90fd\u4e0d\u5e72\u201d&#xff0c;\u56e0\u4e3a\u8fd9\u6837\u4f60\u5c31\u6709\u4e86\u4e00\u4e2a\u5e72\u51c0\u7684\u63d2\u5165\u70b9&#xff1a;\u7ee7\u627f\u00a0StackableDB&#xff0c;\u53ea\u91cd\u5199\u4f60\u5173\u5fc3\u7684\u90a3\u51e0\u4e2a\u65b9\u6cd5\u3002TTL \u5c31\u91cd\u5199\u00a0Put&#xff0c;\u585e\u4e00\u4e2a\u8fc7\u671f\u65f6\u95f4\u6233\u518d\u8f6c\u53d1&#xff1b;\u52a0\u5bc6\u5c31\u91cd\u5199\u00a0Put\/Get&#xff0c;\u8fdb\u51fa\u5404\u505a\u4e00\u6b21\u5bc6\u7801\u5b66\u53d8\u6362&#xff1b;\u7edf\u8ba1\u5c31\u6bcf\u4e2a\u65b9\u6cd5\u8f6c\u53d1\u524d\u540e\u8bb0\u4e00\u7b14\u8017\u65f6\u3002\u5176\u4f59\u51e0\u5341\u4e2a\u65b9\u6cd5&#xff0c;\u57fa\u7c7b\u66ff\u4f60\u539f\u6837\u900f\u4f20&#xff0c;\u4f60\u4e00\u884c\u90fd\u4e0d\u7528\u78b0\u3002\u8fd9\u5c31\u662f\u88c5\u9970\u5668&#xff1a;\u529f\u80fd\u50cf\u5957\u58f3\u4e00\u6837\u4e00\u5c42\u5c42\u53e0\u4e0a\u53bb&#xff0c;\u6bcf\u4e00\u5c42\u53ea\u8ba4\u5b83\u4e0b\u9762\u662f\u4e2a\u00a0DB&#xff0c;\u4e0d\u8ba4\u5177\u4f53\u662f\u8c01\u3002\u00a0TTL \u58f3\u53ef\u4ee5\u5957\u5728\u52a0\u5bc6\u58f3\u4e0a&#xff0c;\u52a0\u5bc6\u58f3\u5957\u5728\u00a0DBImpl\u00a0\u4e0a&#xff0c;GetRootDB()\u00a0\u4e00\u8def\u00a0db_-&gt;\u00a0\u9012\u5f52\u5230\u6700\u5e95\u90a3\u4e2a\u771f\u8eab\u3002<\/p>\n<p>\u987a\u4fbf\u628a\u5b83\u7684\u6240\u6709\u6743\u4e5f\u70b9\u7834&#xff0c;\u56e0\u4e3a\u8fd9\u662f\u81ea\u7814\u5f15\u64ce\u6700\u5bb9\u6613\u57cb\u96f7\u7684\u5730\u65b9\u3002StackableDB\u00a0\u7ed9\u4e86\u4e09\u4e2a\u6784\u9020\u51fd\u6570&#xff0c;\u5bf9\u5e94\u4e09\u79cd\u6240\u6709\u6743&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ stackable_db.h<br \/>\nexplicit StackableDB(DB* db) : db_(db) {}                    \/\/ \u88f8\u6307\u9488&#xff0c;\u72ec\u5360<br \/>\nexplicit StackableDB(std::shared_ptr&lt;DB&gt; db)                 \/\/ \u5171\u4eab<br \/>\n    : db_(db.get()), shared_db_ptr_(db) {}<br \/>\nexplicit StackableDB(std::unique_ptr&lt;DB&gt;&amp;&amp; db)               \/\/ \u79fb\u4ea4\u72ec\u5360<br \/>\n    : db_(db.get()), shared_db_ptr_(std::move(db)) {}<br \/>\n~StackableDB() override {<br \/>\n  if (shared_db_ptr_ &#061;&#061; nullptr) {<br \/>\n    delete db_;              \/\/ \u72ec\u5360\u6a21\u5f0f&#xff1a;\u6211\u6790\u6784&#xff0c;\u6211\u8d1f\u8d23\u5220\u5e95\u5c42<br \/>\n  } else {<br \/>\n    assert(shared_db_ptr_.get() &#061;&#061; db_);   \/\/ \u5171\u4eab\u6a21\u5f0f&#xff1a;\u4ea4\u7ed9 shared_ptr<br \/>\n  }<br \/>\n}<\/p>\n<p>\u5b83\u628a\u201c\u6211\u5230\u5e95\u62e5\u4e0d\u62e5\u6709\u88ab\u5305\u7684\u90a3\u4e2a\u00a0DB\u201d\u8fd9\u4ef6\u4e8b&#xff0c;\u5728\u6784\u9020\u51fd\u6570\u7b7e\u540d\u91cc\u5c31\u644a\u5f00\u8bf4\u6e05\u695a\u4e86\u2014\u2014\u4f20\u88f8\u6307\u9488\u6216\u00a0unique_ptr\u00a0\u5c31\u662f\u201c\u8fd9\u4e2a db \u5f52\u6211\u4e86&#xff0c;\u6211\u6790\u6784\u65f6\u5220\u5b83\u201d&#xff0c;\u4f20\u00a0shared_ptr\u00a0\u5c31\u662f\u201c\u5927\u5bb6\u5171\u4eab&#xff0c;\u8c01\u90fd\u522b\u4e71\u5220\u201d\u3002\u6790\u6784\u51fd\u6570\u636e\u6b64\u4e8c\u9009\u4e00\u3002\u6240\u6709\u6743\u5728\u7c7b\u578b\u7b7e\u540d\u91cc\u662f\u663e\u5f0f\u7684&#xff0c;\u4e0d\u9760\u6ce8\u91ca\u3001\u4e0d\u9760\u53e3\u5934\u7ea6\u5b9a\u3002\u00a0\u8fd9\u662f C&#043;&#043; \u63a5\u53e3\u8bbe\u8ba1\u7684\u4e00\u6761\u786c\u529f\u5e95&#xff1a;\u51e1\u662f\u6d89\u53ca\u201c\u8c01\u5220\u8fd9\u5757\u5185\u5b58\u201d\u7684\u5730\u65b9&#xff0c;\u8ba9\u7c7b\u578b\u81ea\u5df1\u628a\u7b54\u6848\u8bf4\u51fa\u6765\u3002<\/p>\n<p>\u6700\u540e\u6536\u4e00\u4e0b\u7b2c\u4e8c\u90e8\u5206&#xff0c;\u628a\u8fd9\u53f0\u5f15\u64ce\u7684 API \u9762\u5207\u6210\u4e09\u5c42&#xff0c;\u4f60\u81ea\u7814\u65f6\u4e5f\u8be5\u8fd9\u4e48\u5207&#xff1a;<\/p>\n<table>\n<tbody>\n<tr>\n<p>\u5c42<\/p>\n<p>\u662f\u4ec0\u4e48<\/p>\n<p>\u5bf9\u5916\u5951\u7ea6<\/p>\n<\/tr>\n<tr>\n<td>\n<p>\u7a33\u5b9a\u516c\u5171 API<\/p>\n<\/td>\n<td>\n<p>include\/\u00a0\u4e0b\u7684\u7eaf\u865a\u00a0DB\u00a0\/\u00a0Status\u00a0\/\u00a0Comparator\u00a0\/\u00a0Iterator<\/p>\n<\/td>\n<td>\n<p>\u7248\u672c\u95f4\u4e0d\u7834\u574f&#xff0c;\u5916\u90e8\u4ee3\u7801\u4f9d\u8d56\u5b83<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u5185\u90e8\u5b9e\u73b0<\/p>\n<\/td>\n<td>\n<p>DBImpl\u00a0\u53ca\u5176\u00a0GetImpl&#xff0c;\u6563\u5728\u5341\u51e0\u4e2a\u00a0.cc\u00a0\u91cc<\/p>\n<\/td>\n<td>\n<p>\u968f\u65f6\u53ef\u91cd\u6784&#xff0c;\u5916\u4eba\u770b\u4e0d\u89c1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u6d4b\u8bd5\u8f85\u52a9 API<\/p>\n<\/td>\n<td>\n<p>DBImpl\u00a0\u91cc 61 \u4e2a\u00a0TEST_\u00a0\u65b9\u6cd5<\/p>\n<\/td>\n<td>\n<p>\u53ea\u7ed9\u5355\u5143\u6d4b\u8bd5&#xff0c;\u9760\u00a0TEST_\u00a0\u524d\u7f00\u9694\u79bb<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u524d\u4e24\u5c42\u7b2c 6 \u8282\u8bb2\u900f\u4e86\u3002\u7b2c\u4e09\u5c42\u662f\u5f88\u591a\u4eba\u81ea\u7814\u65f6\u6f0f\u6389\u7684\u4e00\u5757\u2014\u2014\u6d4b\u8bd5\u9700\u8981\u6345\u8fdb\u5b9e\u73b0\u5185\u90e8\u53bb\u9a8c\u8bc1\u72b6\u6001&#xff0c;\u4f46\u8fd9\u4e9b\u6345\u8fdb\u53bb\u7684\u53e3\u5b50\u7edd\u4e0d\u80fd\u6df7\u8fdb\u516c\u5171 API\u3002\u8fd9\u53f0\u5f15\u64ce\u7684\u505a\u6cd5\u662f\u7ed9\u5b83\u4eec\u7edf\u4e00\u52a0\u00a0TEST_\u00a0\u524d\u7f00&#xff0c;db_impl.h \u91cc\u6570\u4e00\u4e0b\u6709\u516d\u5341\u591a\u4e2a&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db_impl.h&#xff1a;\u6e05\u4e00\u8272 TEST_ \u524d\u7f00&#xff0c;\u53ea\u670d\u52a1\u5355\u5143\u6d4b\u8bd5<br \/>\nSequenceNumber TEST_GetLastVisibleSequence() const;<br \/>\nStatus TEST_FlushMemTable(bool wait &#061; true, bool allow_write_stall &#061; false, &#8230;);<br \/>\nStatus TEST_WaitForCompact();<br \/>\nvoid TEST_LockMutex();<\/p>\n<p>TEST_GetLastVisibleSequence\u00a0\u76f4\u63a5\u638f\u51fa\u5f53\u524d\u6700\u65b0\u53ef\u89c1\u7684\u7248\u672c\u53f7&#xff0c;TEST_FlushMemTable\u00a0\u624b\u52a8\u903c\u4e00\u6b21\u5185\u5b58\u8868\u843d\u76d8&#xff0c;TEST_WaitForCompact\u00a0\u6b7b\u7b49\u540e\u53f0\u538b\u7f29\u5e72\u5b8c\u2014\u2014\u5168\u662f\u6d4b\u8bd5\u7528\u6765\u628a\u4e0d\u786e\u5b9a\u7684\u540e\u53f0\u65f6\u5e8f\u9489\u6210\u786e\u5b9a\u72b6\u6001\u7684\u94a9\u5b50\u3002\u524d\u7f00\u00a0TEST_\u00a0\u662f\u4e00\u53e5\u4e00\u773c\u53ef\u8fa8\u7684\u58f0\u660e&#xff1a;\u8fd9\u662f\u5b9e\u73b0\u7559\u7ed9\u81ea\u5df1\u4eba\u9a8c\u8bc1\u5185\u90e8\u72b6\u6001\u7684\u540e\u95e8&#xff0c;\u7edd\u4e0d\u5bf9\u5916\u5f00\u653e\u3002\u00a0\u4f60\u81ea\u7814\u5f15\u64ce\u8fdf\u65e9\u4e5f\u8981\u8fd9\u7c7b\u540e\u95e8&#xff0c;\u65e9\u70b9\u7ea6\u5b9a\u4e00\u4e2a\u524d\u7f00\u628a\u5b83\u4eec\u548c\u516c\u5171 API \u9694\u5f00&#xff0c;\u522b\u8ba9\u67d0\u4e2a\u6d4b\u8bd5\u8f85\u52a9\u51fd\u6570\u54ea\u5929\u4e0d\u5c0f\u5fc3\u88ab\u5916\u90e8\u7528\u6237\u4f9d\u8d56\u4e0a&#xff0c;\u90a3\u5c31\u518d\u4e5f\u5220\u4e0d\u6389\u4e86\u3002<\/p>\n<hr \/>\n<h3>9. Open\u3001\u53e5\u67c4\u3001\u5173\u5e93&#xff1a;\u8c01\u62e5\u6709\u8c01&#xff0c;\u8c01\u5fc5\u987b\u5148\u6b7b<\/h3>\n<p>\u7b2c\u4e09\u90e8\u5206\u53ea\u56de\u7b54\u4e00\u4e2a\u95ee\u9898&#xff1a;\u8fd9\u5957\u63a5\u53e3\u91cc\u7684\u5bf9\u8c61&#xff0c;\u4ec0\u4e48\u65f6\u5019\u751f&#xff0c;\u4ec0\u4e48\u65f6\u5019\u624d\u5141\u8bb8\u6b7b\u3002\u8fd9\u95ee\u9898\u5bf9\u81ea\u7814\u5f15\u64ce\u662f\u751f\u6b7b\u6538\u5173\u7684\u2014\u2014\u53e5\u67c4\u7684\u6240\u6709\u6743\u5207\u9519\u4e00\u5200&#xff0c;\u8981\u4e48\u6cc4\u6f0f&#xff0c;\u8981\u4e48\u4e8c\u6b21\u91ca\u653e&#xff0c;\u90fd\u662f\u6df1\u591c\u6392\u67e5\u7684\u5e38\u5ba2\u3002<\/p>\n<p>\u4ece\u5e93\u672c\u8eab\u5f00\u59cb\u3002Open\u00a0\u4ea4\u8fd8\u7684\u662f\u00a0unique_ptr&lt;DB&gt;&#xff0c;\u72ec\u5360\u6240\u6709\u6743&#xff0c;RAII \u515c\u5e95&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>std::unique_ptr&lt;DB&gt; db;<br \/>\nStatus s &#061; DB::Open(options, &#034;\/tmp\/kv&#034;, &amp;db);<br \/>\n\/\/ &#8230; \u7528 db &#8230;<br \/>\ndb.reset();   \/\/ \u6216\u8005\u79bb\u5f00\u4f5c\u7528\u57df\u81ea\u52a8\u6790\u6784<\/p>\n<p>db\u00a0\u4e00\u6790\u6784&#xff0c;\u5e93\u5c31\u5173\u4e86&#xff0c;\u5e72\u51c0\u3002\u4f46\u5e93\u4e0d\u662f\u5b64\u96f6\u96f6\u4e00\u4e2a\u5bf9\u8c61&#xff0c;\u5b83\u4e0b\u9762\u6302\u7740\u4e00\u4e32\u53e5\u67c4&#xff0c;\u8fd9\u4e9b\u53e5\u67c4\u7684\u6b7b\u6d3b\u5f97\u4f60\u81ea\u5df1\u7ba1\u3002\u770b\u5217\u65cf\u8fd9\u4e2a\u4f8b\u5b50\u7684\u5b8c\u6574\u751f\u6b7b\u6d41\u7a0b&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ \u5efa\u4e00\u4e2a\u5217\u65cf&#xff0c;\u62ff\u5230\u4e00\u4e2a\u88f8\u6307\u9488\u53e5\u67c4<br \/>\nColumnFamilyHandle* cf;<br \/>\nStatus s &#061; db-&gt;CreateColumnFamily(ColumnFamilyOptions(), &#034;new_cf&#034;, &amp;cf);<br \/>\n\/\/ &#8230; \u7528 cf \u505a\u8bfb\u5199 &#8230;<br \/>\n\/\/ \u5173\u5e93\u4e4b\u524d&#xff0c;\u5fc5\u987b\u4eb2\u624b\u628a\u53e5\u67c4\u9500\u6bc1<br \/>\ns &#061; db-&gt;DestroyColumnFamilyHandle(cf);<br \/>\ndb.reset();<\/p>\n<p>\u6ce8\u610f\u00a0CreateColumnFamily\u00a0\u7ed9\u4f60\u7684\u662f\u4e00\u4e2a\u88f8\u6307\u9488\u00a0ColumnFamilyHandle*&#xff0c;\u4e0d\u662f\u667a\u80fd\u6307\u9488\u3002\u5b83\u7ed9\u88f8\u6307\u9488\u6709\u9053\u7406&#xff1a;\u53e5\u67c4\u6d3b\u591a\u4e45&#xff0c;\u7531\u4f60\u7684\u4e1a\u52a1\u903b\u8f91\u8bf4\u4e86\u7b97&#xff0c;\u5b83\u66ff\u4f60\u51b3\u5b9a\u4e0d\u4e86\u3002\u4e8e\u662f\u6240\u6709\u6743\u660e\u786e\u843d\u5230\u4f60\u5934\u4e0a&#xff1a;\u4f60\u5efa\u7684\u53e5\u67c4&#xff0c;\u4f60\u8d1f\u8d23\u8c03\u00a0DestroyColumnFamilyHandle\u00a0\u9500\u6bc1&#xff0c;\u800c\u4e14\u5fc5\u987b\u5728\u5173\u5e93\u4e4b\u524d\u3002db.h \u90a3\u53e5\u8bdd\u662f\u786c\u8981\u6c42&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h&#xff1a;Before destroying the DB, you have to close all column<br \/>\n\/\/ families by calling DestroyColumnFamilyHandle() with all the handles.<\/p>\n<p>\u591a\u5217\u65cf\u6253\u5f00\u65f6&#xff0c;\u8fd9\u5957\u6240\u6709\u6743\u5c31\u662f\u4e00\u4e32&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>std::vector&lt;ColumnFamilyHandle*&gt; handles;<br \/>\ns &#061; DB::Open(DBOptions(), &#034;\/tmp\/kv&#034;, column_families, &amp;handles, &amp;db);<br \/>\n\/\/ &#8230; \u7528 handles[i] \u8bfb\u5199\u5404\u4e2a\u5217\u65cf &#8230;<br \/>\nfor (auto handle : handles) {<br \/>\n  s &#061; db-&gt;DestroyColumnFamilyHandle(handle);   \/\/ \u9010\u4e2a\u9500\u6bc1<br \/>\n}<br \/>\ndb.reset();   \/\/ \u53e5\u67c4\u5168\u6e05\u5b8c&#xff0c;\u624d\u5173\u5e93<\/p>\n<p>\u8fd9\u91cc\u6709\u4e2a\u53cd\u76f4\u89c9\u7684\u4f8b\u5916&#xff0c;\u5f97\u6572\u4e00\u4e0b&#xff1a;\u9ed8\u8ba4\u5217\u65cf\u7684\u53e5\u67c4\u4e0d\u8981\u4f60\u9500\u6bc1\u3002db.h \u91cc\u00a0DestroyColumnFamilyHandle\u00a0\u7684\u6ce8\u91ca\u4e13\u95e8\u70b9\u4e86\u540d\u2014\u2014except for DefaultColumnFamily()\u3002\u9ed8\u8ba4\u5217\u65cf\u7684\u53e5\u67c4\u7531\u5e93\u81ea\u5df1\u6301\u6709\u548c\u91ca\u653e&#xff0c;\u4f60\u53bb\u00a0Destroy\u00a0\u5b83\u53cd\u800c\u51fa\u9519\u3002\u8fd9\u7c7b\u201c\u770b\u7740\u4e00\u6837\u3001\u751f\u547d\u5468\u671f\u5f52\u5c5e\u5374\u4e0d\u540c\u201d\u7684\u5bf9\u8c61&#xff0c;\u662f\u81ea\u7814\u5f15\u64ce\u63a5\u53e3\u6700\u5bb9\u6613\u8ba9\u4eba\u8e29\u9519\u7684\u5730\u65b9&#xff1a;\u540c\u6837\u662f\u00a0ColumnFamilyHandle*&#xff0c;\u4f60\u5efa\u7684\u90a3\u4e2a\u5f52\u4f60\u9500\u6bc1&#xff0c;\u5e93\u9001\u4f60\u7684\u90a3\u4e2a\u5f52\u5e93\u9500\u6bc1\u3002<\/p>\n<p>\u8fed\u4ee3\u5668\u4e5f\u662f\u540c\u4e00\u5957\u89c4\u77e9&#xff0c;\u800c\u4e14\u5b83\u628a\u201c\u8c01\u5fc5\u987b\u5148\u6b7b\u201d\u8bf4\u5f97\u66f4\u72e0\u3002NewIterator\u00a0\u7684\u6ce8\u91ca&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h<br \/>\n\/\/ Caller should delete the iterator when it is no longer needed.<br \/>\n\/\/ The returned iterator should be deleted before this db is destroyed.<br \/>\nvirtual Iterator* NewIterator(const ReadOptions&amp; options,<br \/>\n                              ColumnFamilyHandle* column_family) &#061; 0;<\/p>\n<p>\u8fed\u4ee3\u5668\u5fc5\u987b\u5148\u4e8e\u5e93\u6b7b\u3002\u00a0\u60f3\u60f3\u4e5f\u5bf9&#xff1a;\u8fed\u4ee3\u5668\u662f\u9a91\u5728\u5e93\u7684\u5185\u90e8\u6570\u636e\u7ed3\u6784\u4e0a\u7684\u4e00\u4e2a\u6e38\u6807&#xff0c;\u5e93\u90fd\u6ca1\u4e86&#xff0c;\u5b83\u9a91\u7684\u90a3\u5339\u9a6c\u5c31\u6ca1\u4e86&#xff0c;\u518d\u52a8\u5b83\u5c31\u662f\u8bbf\u95ee\u5df2\u91ca\u653e\u5185\u5b58\u3002\u6240\u4ee5\u6790\u6784\u987a\u5e8f\u6709\u4e00\u6761\u94c1\u5f8b\u2014\u2014\u540e\u501f\u7684\u5148\u8fd8&#xff1a;\u8fed\u4ee3\u5668\u3001\u5217\u65cf\u53e5\u67c4\u8fd9\u4e9b\u4ece\u5e93\u501f\u51fa\u6765\u7684\u5bf9\u8c61&#xff0c;\u5168\u90fd\u5f97\u8d76\u5728\u5e93\u6790\u6784\u4e4b\u524d\u9500\u6bc1\u6389\u3002\u4f60\u81ea\u7814\u5f15\u64ce\u65f6&#xff0c;Open\u00a0\u8fd4\u56de\u00a0unique_ptr\u00a0\u5f88\u5bb9\u6613\u8ba9\u4eba\u4ee5\u4e3a\u201cRAII \u5168\u81ea\u52a8\u4e86\u201d&#xff0c;\u4f46 RAII \u53ea\u7ba1\u597d\u4e86\u5e93\u672c\u8eab&#xff1b;\u90a3\u4e9b\u5e93\u501f\u7ed9\u4f60\u7684\u88f8\u6307\u9488\u53e5\u67c4&#xff0c;\u5f97\u9760\u4f60\u81ea\u5df1\u4fdd\u8bc1\u5b83\u4eec\u6b7b\u5728\u5e93\u524d\u9762\u3002\u628a\u8fd9\u6761\u987a\u5e8f\u5199\u8fdb\u4f60\u7684\u63a5\u53e3\u6ce8\u91ca\u91cc&#xff0c;\u662f\u5bf9\u4e0b\u6e38\u6700\u8d77\u7801\u7684\u4ea4\u4ee3\u3002<\/p>\n<p>\u8fd9\u6761\u987a\u5e8f\u9519\u4e86\u4f1a\u600e\u6837&#xff0c;\u6211\u4eec\u8ba9\u5b83\u5d29\u4e00\u6b21&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>std::unique_ptr&lt;DB&gt; db;<br \/>\nDB::Open(options, &#034;\/tmp\/kv&#034;, &amp;db);<br \/>\nIterator* it &#061; db-&gt;NewIterator(ReadOptions());<br \/>\ndb.reset();          \/\/ \u5e93\u5148\u6790\u6784\u4e86&#xff01;<br \/>\nit-&gt;SeekToFirst();   \/\/ \u6e38\u6807\u8fd8\u9a91\u5728\u5df2\u7ecf\u6ca1\u4e86\u7684\u5185\u90e8\u7ed3\u6784\u4e0a<br \/>\n\/\/ use-after-free&#xff1a;\u8fd0\u6c14\u597d\u5f53\u573a\u6bb5\u9519\u8bef&#xff0c;\u8fd0\u6c14\u574f\u8bfb\u5230\u810f\u6570\u636e\u63a5\u7740\u8dd1<br \/>\ndelete it;<\/p>\n<p>db.reset()\u00a0\u628a\u5e93\u8fde\u540c\u5b83\u7684\u5185\u90e8\u7ed3\u6784\u4e00\u8d77\u6790\u6784\u4e86&#xff0c;it\u00a0\u624b\u91cc\u90a3\u6839\u6e38\u6807\u6307\u5411\u7684\u4e1c\u897f\u5df2\u7ecf\u4e0d\u5b58\u5728&#xff0c;SeekToFirst\u00a0\u4e00\u52a8\u5c31\u662f use-after-free\u3002\u6700\u8981\u547d\u7684\u662f\u5b83\u4e0d\u4e00\u5b9a\u5f53\u573a\u5d29\u2014\u2014\u5185\u5b58\u521a\u91ca\u653e\u3001\u8fd8\u6ca1\u88ab\u522b\u4eba\u590d\u7528\u65f6&#xff0c;\u5b83\u53ef\u80fd\u201c\u770b\u8d77\u6765\u6b63\u5e38\u201d\u5730\u8bfb\u51fa\u4e00\u6279\u5783\u573e&#xff0c;\u4f60\u4ee5\u4e3a\u67e5\u8be2\u6210\u529f\u4e86&#xff0c;\u5176\u5b9e\u62ff\u5230\u7684\u662f\u5df2\u91ca\u653e\u5185\u5b58\u91cc\u7684\u6b8b\u6e23\u3002\u8fd9\u7c7b bug \u5728\u81ea\u7814\u5f15\u64ce\u91cc\u6700\u96be\u67e5&#xff0c;\u56e0\u4e3a\u5b83\u662f\u6982\u7387\u6027\u7684\u3001\u548c\u5185\u5b58\u5206\u914d\u5668\u7684\u5373\u65f6\u884c\u4e3a\u8026\u5408&#xff0c;\u6362\u53f0\u673a\u5668\u3001\u6362\u4e2a\u8d1f\u8f7d\u5c31\u4e0d\u590d\u73b0\u3002\u9632\u5b83\u53ea\u6709\u4ece\u63a5\u53e3\u4e0a\u628a\u987a\u5e8f\u9489\u6b7b&#xff1a;\u6240\u6709\u501f\u51fa\u7684\u53e5\u67c4&#xff0c;\u8981\u4e48\u7528 RAII \u5305\u8d77\u6765\u3001\u968f\u4f5c\u7528\u57df\u81ea\u7136\u5148\u4e8e\u5e93\u6790\u6784&#xff0c;\u8981\u4e48\u5728\u5e93\u7684\u6790\u6784\u91cc\u4e3b\u52a8\u67e5\u4e00\u904d\u8fd8\u6709\u6ca1\u6709\u6d3b\u7740\u7684\u501f\u51fa\u5bf9\u8c61\u3001\u6709\u5c31\u5f53\u573a\u62a5\u9519&#xff0c;\u7edd\u4e0d\u8ba9\u5b83\u6084\u6084\u6e9c\u8fc7\u53bb\u3002<\/p>\n<h3>10. \u201c\u8fd8\u5b58\u5728\u201d\u548c\u201c\u8fd8\u770b\u5f97\u89c1\u201d&#xff0c;\u662f\u4e24\u6839\u72ec\u7acb\u7684\u8f74<\/h3>\n<p>\u8fd9\u662f\u7b2c\u4e09\u90e8\u5206\u7684\u6838\u5fc3&#xff0c;\u4e5f\u662f\u6574\u7bc7\u6700\u53cd\u76f4\u89c9\u7684\u4e00\u8282\u3002\u524d\u9762\u6240\u6709\u94fa\u57ab\u2014\u2014\u7b2c 2 \u8282\u7684\u5893\u7891\u3001\u7b2c 5 \u8282\u7684\u201c\u6709\u7248\u672c\u201d\u2014\u2014\u90fd\u662f\u4e3a\u4e86\u8fd9\u4e00\u8282\u80fd\u7ad9\u4f4f\u3002<\/p>\n<p>\u5148\u770b\u5217\u65cf\u7684\u201c\u5220\u9664\u201d\u3002\u4f60\u4ee5\u4e3a\u00a0DropColumnFamily\u00a0\u4f1a\u628a\u8fd9\u4e2a\u5217\u65cf\u7684\u6570\u636e\u62b9\u6389&#xff0c;\u770b\u5b83\u7684\u6ce8\u91ca&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h&#xff1a;This call only records a drop record in the manifest and<br \/>\n\/\/ prevents the column family from flushing and compacting.<br \/>\nvirtual Status DropColumnFamily(ColumnFamilyHandle* column_family);<\/p>\n<p>\u5b83\u53ea\u5e72\u4e24\u4ef6\u4e8b&#xff1a;\u5f80\u5143\u6570\u636e\u91cc\u8bb0\u4e00\u7b14\u201c\u8fd9\u4e2a\u5217\u65cf\u88ab\u5220\u4e86\u201d&#xff0c;\u7136\u540e\u7981\u6b62\u5b83\u7ee7\u7eed\u5237\u76d8\u548c\u538b\u7f29\u3002\u6570\u636e\u4e00\u4e2a\u5b57\u8282\u90fd\u6ca1\u52a8\u3002\u90a3\u8fd9\u4e2a\u5217\u65cf\u4ec0\u4e48\u65f6\u5019\u624d\u771f\u6b63\u6d88\u5931&#xff1f;\u7b54\u6848\u5728\u00a0DestroyColumnFamilyHandle\u00a0\u7684\u6ce8\u91ca\u91cc&#xff0c;\u8fd9\u53e5\u8bdd\u662f\u6574\u7bc7\u7684\u9898\u773c&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h&#xff1a;A column family is only removed once it is dropped<br \/>\n\/\/ (DropColumnFamily) and all handles have been destroyed<br \/>\n\/\/ (DestroyColumnFamilyHandle).<\/p>\n<p>\u4e00\u4e2a\u5217\u65cf\u771f\u6b63\u88ab\u79fb\u9664&#xff0c;\u8981\u540c\u65f6\u6ee1\u8db3\u4e24\u4e2a\u6761\u4ef6&#xff1a;\u88ab drop \u4e86&#xff0c;\u800c\u4e14\u6240\u6709\u53e5\u67c4\u90fd\u9500\u6bc1\u4e86\u3002\u628a\u8fd9\u4e24\u4e2a\u6761\u4ef6\u62c6\u5f00&#xff0c;\u4f60\u5c31\u649e\u89c1\u4e86\u6574\u53f0\u5b58\u50a8\u5f15\u64ce\u6700\u6838\u5fc3\u7684\u4e00\u7ec4\u6982\u5ff5\u2014\u2014\u201c\u8fd8\u5b58\u5728\u201d\u548c\u201c\u8fd8\u770b\u5f97\u89c1\u201d\u662f\u4e24\u6839\u72ec\u7acb\u7684\u8f74&#xff1a;<\/p>\n<ul>\n<li>\n<p>DropColumnFamily\u00a0\u4e4b\u540e&#xff0c;\u8fd9\u4e2a\u5217\u65cf\u4e0d\u53ef\u89c1\u4e86&#xff1a;\u65b0\u7684\u8bfb\u5199\u8ba4\u4e3a\u5b83\u6ca1\u4e86&#xff0c;\u5b83\u4e0d\u518d\u5237\u76d8\u4e0d\u518d\u538b\u7f29\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f46\u53ea\u8981\u8fd8\u6709\u4e00\u4e2a\u53e5\u67c4\u6ca1\u9500\u6bc1&#xff0c;\u5b83\u5c31\u8fd8\u5b58\u5728&#xff1a;\u6570\u636e\u8fd8\u8eba\u5728\u76d8\u4e0a&#xff0c;\u90a3\u4e2a\u53e5\u67c4\u8fd8\u80fd\u8bbf\u95ee\u5230\u5b83\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u53ef\u89c1\u6027\u548c\u5b58\u5728\u6027&#xff0c;\u88ab\u8fd9\u4e24\u4e2a\u52a8\u4f5c\u5207\u6210\u4e86\u4e24\u4ef6\u4e8b\u3002\u8fd9\u4e0d\u662f\u5217\u65cf\u72ec\u6709\u7684\u602a\u7656&#xff0c;\u5b83\u662f\u201c\u6709\u7248\u672c\u201d\u8fd9\u4e2a\u8bcd\u7684\u5fc5\u7136\u7ed3\u679c\u3002\u540c\u4e00\u6839\u8f74&#xff0c;\u5728\u5feb\u7167\u4e0a\u8868\u73b0\u5f97\u66f4\u7eaf\u7cb9\u3002\u5148\u8ba4\u8bc6\u7248\u672c\u53f7&#xff0c;snapshot.h&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ snapshot.h<br \/>\n\/\/ Abstract handle to particular state of a DB.<br \/>\nclass Snapshot {<br \/>\n public:<br \/>\n  virtual SequenceNumber GetSequenceNumber() const &#061; 0;<br \/>\n};<\/p>\n<p>\u4e00\u4e2a\u5feb\u7167&#xff0c;\u672c\u8d28\u5c31\u662f\u4e00\u4e2a\u5e8f\u5217\u53f7\u2014\u2014\u7b2c 5 \u8282\u8bf4\u7684\u90a3\u4e2a\u201c\u6709\u7248\u672c\u201d\u7684\u7248\u672c\u53f7\u3002\u5f15\u64ce\u5185\u90e8\u6bcf\u4e00\u6b21\u5199\u64cd\u4f5c\u90fd\u9886\u4e00\u4e2a\u5355\u8c03\u9012\u589e\u7684\u5e8f\u5217\u53f7&#xff0c;\u4e00\u4e2a\u5feb\u7167\u9489\u4f4f\u67d0\u4e2a\u5e8f\u5217\u53f7&#xff0c;\u610f\u601d\u662f\u201c\u6211\u8981\u770b\u8fd9\u53f0\u5e93\u5728\u8fd9\u4e2a\u5e8f\u5217\u53f7\u90a3\u4e00\u523b\u7684\u6837\u5b50\u201d\u3002db.h \u91cc\u00a0GetSnapshot\u00a0\u7684\u7ea6\u5b9a&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h&#xff1a;Return a handle to the current DB state.  Iterators created<br \/>\n\/\/ with this handle will all observe a stable snapshot of the current<br \/>\n\/\/ DB state.  The caller must call ReleaseSnapshot(result) when the<br \/>\n\/\/ snapshot is no longer needed.<br \/>\nvirtual const Snapshot* GetSnapshot() &#061; 0;<\/p>\n<p>\u73b0\u5728\u201c\u5b58\u5728\u4e0e\u53ef\u89c1\u201d\u8fd9\u6761\u7ebf\u5f7b\u5e95\u663e\u5f62\u4e86\u3002\u753b\u4e00\u6761\u65f6\u95f4\u8f74&#xff1a;<\/p>\n<p>text<\/p>\n<p>\u5e8f\u5217\u53f7: 100         105          110<br \/>\n        \u2502Put k&#061;v1   \u2502Delete k     \u2502(\u6b64\u523b)<br \/>\n        \u25bc           \u25bc             \u25bc<br \/>\n\u6301\u6709\u4e00\u4e2a seq&#061;100 \u7684\u5feb\u7167\u7684\u8bfb\u8005&#xff1a;<br \/>\n    \u2192 \u7167\u6837\u8bfb\u5230 k&#061;v1&#xff08;\u5bf9\u4ed6&#xff0c;v1 \u8fd8\u3010\u53ef\u89c1\u3011&#xff09;<br \/>\n\u4e0d\u6301\u5feb\u7167\u3001\u8bfb\u6700\u65b0\u7684\u8bfb\u8005&#xff1a;<br \/>\n    \u2192 \u8bfb k \u5f97\u5230 NotFound&#xff08;\u5bf9\u4ed6&#xff0c;k \u5df2\u3010\u4e0d\u53ef\u89c1\u3011&#xff09;<br \/>\n\u800c v1 \u8fd9\u6761\u6570\u636e&#xff1a;<br \/>\n    \u2192 \u4e00\u76f4\u3010\u5b58\u5728\u3011\u5728\u76d8\u4e0a&#xff0c;\u56e0\u4e3a\u90a3\u4e2a\u5feb\u7167\u8fd8\u9489\u7740\u5b83<\/p>\n<p>Delete k\u00a0\u4e4b\u540e&#xff0c;\u5bf9\u8bfb\u6700\u65b0\u72b6\u6001\u7684\u4eba&#xff0c;k\u00a0\u5df2\u7ecf\u4e0d\u53ef\u89c1\u4e86\u3002\u4f46\u90a3\u4e2a\u6301\u6709 seq&#061;100 \u5feb\u7167\u7684\u8bfb\u8005&#xff0c;\u7167\u6837\u80fd\u8bfb\u5230\u00a0v1\u2014\u2014\u56e0\u4e3a\u5bf9\u4ed6\u6765\u8bf4&#xff0c;\u5220\u9664\u53d1\u751f\u5728\u201c\u672a\u6765\u201d&#xff0c;\u8fd8\u6ca1\u8f6e\u5230\u3002\u4e8e\u662f\u00a0v1\u00a0\u8fd9\u6761\u88ab\u5220\u7684\u6570\u636e\u5fc5\u987b\u7ee7\u7eed\u5b58\u5728&#xff0c;\u7269\u7406\u4e0a\u4e0d\u80fd\u88ab\u538b\u7f29\u56de\u6536\u6389&#xff0c;\u76f4\u5230\u90a3\u4e2a\u5feb\u7167\u88ab\u91ca\u653e\u3002\u5feb\u7167 pin \u4f4f\u7684\u662f\u53ef\u89c1\u6027\u548c\u53ef\u56de\u6536\u6027&#xff0c;\u4e0d\u662f\u5b58\u5728\u6027\u672c\u8eab\u2014\u2014\u53cd\u8fc7\u6765\u8bf4&#xff0c;\u4e00\u4e2a\u6ca1\u91ca\u653e\u7684\u5feb\u7167&#xff0c;\u4f1a\u628a\u4e00\u5927\u7968\u201c\u903b\u8f91\u4e0a\u65e9\u8be5\u6d88\u5931\u201d\u7684\u65e7\u7248\u672c\u6570\u636e\u9489\u5728\u78c1\u76d8\u4e0a&#xff0c;\u8c01\u90fd\u5220\u4e0d\u6389\u3002\u8fd9\u5c31\u662f\u81ea\u7814 MVCC \u5f15\u64ce\u7ed5\u4e0d\u5f00\u7684\u53d6\u820d&#xff1a;\u8bfb\u7684\u4e00\u81f4\u6027&#xff0c;\u662f\u7528\u63a8\u8fdf\u56de\u6536\u65e7\u7248\u672c\u7684\u7a7a\u95f4\u6362\u6765\u7684\u3002<\/p>\n<p>\u8fd9\u4e2a\u4ee3\u4ef7\u5728\u540e\u53f0\u8fd8\u6709\u66f4\u786c\u7684\u4e00\u9762\u3002\u5f15\u64ce\u7684\u540e\u53f0\u538b\u7f29\u8981\u56de\u6536\u65e7\u7248\u672c\u2014\u2014\u4e00\u4e2a key \u88ab\u8986\u76d6\u6216\u5220\u9664\u540e&#xff0c;\u5b83\u7684\u65e7\u7248\u672c\u8fdf\u65e9\u5f97\u7269\u7406\u6e05\u6389&#xff0c;\u5426\u5219\u78c1\u76d8\u53ea\u6da8\u4e0d\u843d\u3002\u53ef\u538b\u7f29\u4e0d\u80fd\u968f\u4fbf\u6e05&#xff1a;\u53ea\u8981\u8fd8\u6709\u4e00\u4e2a\u5feb\u7167\u9489\u7740\u67d0\u4e2a\u65e7\u5e8f\u5217\u53f7&#xff0c;\u6bd4\u5b83\u65b0\u7684\u5220\u9664\u5c31\u4e0d\u80fd\u771f\u6b63\u751f\u6548&#xff0c;\u88ab\u5220\u7684\u6570\u636e\u4e5f\u4e0d\u80fd\u771f\u6b63\u56de\u6536\u3002\u4e8e\u662f\u6700\u8001\u7684\u90a3\u4e2a\u672a\u91ca\u653e\u5feb\u7167\u7684\u5e8f\u5217\u53f7&#xff0c;\u5c31\u662f\u6574\u53f0\u5f15\u64ce\u7684\u56de\u6536\u6c34\u4f4d\u7ebf\u2014\u2014\u538b\u7f29\u53ea\u80fd\u5b89\u5168\u6e05\u7406\u8fd9\u6761\u6c34\u4f4d\u7ebf\u4ee5\u4e0b\u3001\u4e14\u786e\u5b9e\u6ca1\u6709\u5feb\u7167\u518d\u5173\u5fc3\u7684\u7248\u672c\u3002\u4e00\u4e2a\u5fd8\u4e86\u91ca\u653e\u3001\u8dd1\u4e86\u4e00\u6574\u5929\u7684\u5feb\u7167&#xff0c;\u4f1a\u628a\u6c34\u4f4d\u7ebf\u6b7b\u6b7b\u710a\u5728\u4e00\u5929\u524d&#xff0c;\u8fd9\u4e00\u5929\u91cc\u6240\u6709\u88ab\u5220\u3001\u88ab\u8986\u76d6\u7684\u6570\u636e\u5168\u90fd\u6e05\u4e0d\u6389&#xff0c;\u78c1\u76d8\u5360\u7528\u8089\u773c\u53ef\u89c1\u5730\u5f80\u4e0a\u6da8\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u957f\u547d\u5feb\u7167\u5728\u5b58\u50a8\u5f15\u64ce\u91cc\u662f\u5934\u53f7\u8fd0\u7ef4\u4e8b\u6545\u6e90&#xff0c;\u4e5f\u662f\u4e3a\u4ec0\u4e48\u5173\u5e93\u65f6\u90a3\u9053\u201c\u6709\u672a\u91ca\u653e\u5feb\u7167\u5c31\u00a0Abort\u201d\u7684\u95e8\u7981\u5fc5\u987b\u5b58\u5728\u2014\u2014\u5b83\u62e6\u4e0b\u7684\u4e0d\u53ea\u662f\u4e00\u6b21\u5173\u5e93&#xff0c;\u662f\u5728\u63d0\u9192\u4f60&#xff1a;\u6709\u4e00\u4e2a\u6b63\u6084\u6084\u6491\u7206\u78c1\u76d8\u7684\u5f15\u7528\u8fd8\u6ca1\u8fd8\u3002\u4f60\u81ea\u7814 MVCC \u5f15\u64ce\u65f6&#xff0c;\u628a\u201c\u6700\u8001\u5feb\u7167\u5e8f\u5217\u53f7\u201d\u505a\u6210\u4e00\u4e2a\u80fd\u76d1\u63a7\u3001\u80fd\u544a\u8b66\u7684\u6307\u6807&#xff0c;\u6bd4\u5927\u591a\u6570\u82b1\u54e8\u4f18\u5316\u90fd\u503c\u3002<\/p>\n<p>\u8fd9\u4e2a\u4ee3\u4ef7\u4f1a\u5728\u5173\u5e93\u65f6\u5f53\u9762\u627e\u4e0a\u4f60\u3002\u6211\u4eec\u8ba9\u5b83\u5d29\u4e00\u6b21&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>const Snapshot* snap &#061; db-&gt;GetSnapshot();<br \/>\n\/\/ &#8230; \u7528 snap \u8bfb\u4e86\u4e00\u4f1a\u513f&#xff0c;\u7136\u540e\u5fd8\u4e86\u8fd8 &#8230;<\/p>\n<p>Status s &#061; db-&gt;Close();<br \/>\n\/\/ s.IsAborted() &#061;&#061; true \u2014\u2014 \u5173\u4e0d\u6389&#xff01;<\/p>\n<p>Close\u00a0\u76f4\u63a5\u8fd4\u56de\u00a0Aborted&#xff0c;\u5e93\u5173\u4e0d\u6389\u3002db.h \u91cc\u00a0Close\u00a0\u7684\u6ce8\u91ca\u628a\u539f\u56e0\u548c\u89e3\u6cd5\u90fd\u7ed9\u4e86&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ db.h&#xff1a;If the return status is Aborted(), closing fails because<br \/>\n\/\/ there is unreleased snapshot in the system. In this case, users<br \/>\n\/\/ can release the unreleased snapshots and try again and expect it<br \/>\n\/\/ to succeed.<\/p>\n<p>\u4e00\u4e2a\u6ca1\u91ca\u653e\u7684\u5feb\u7167&#xff0c;\u4f1a\u628a\u5173\u5e93\u6574\u4e2a\u62e6\u4e0b\u6765\u2014\u2014\u56e0\u4e3a\u5e93\u4e00\u65e6\u5173\u4e86&#xff0c;\u90a3\u4e2a\u5feb\u7167\u9489\u7740\u7684\u65e7\u7248\u672c\u5185\u5b58\u548c\u6587\u4ef6\u5c31\u90fd\u6ca1\u4e86&#xff0c;\u5f15\u64ce\u5b81\u53ef\u62d2\u7edd\u5173\u5e93\u4e5f\u4e0d\u5236\u9020\u8fd9\u79cd\u60ac\u7a7a\u3002\u89e3\u6cd5\u662f\u5148\u8fd8\u5feb\u7167&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>db-&gt;ReleaseSnapshot(snap);   \/\/ \u5148\u628a\u53ef\u89c1\u6027\u5f15\u7528\u8fd8\u56de\u53bb<br \/>\ns &#061; db-&gt;Close();             \/\/ \u73b0\u5728\u80fd\u5173\u4e86<\/p>\n<p>\u90a3\u80fd\u4e0d\u80fd\u5e72\u8106\u00a0delete snap&#xff1f;\u4e0d\u80fd&#xff0c;\u7f16\u8bd1\u5668\u4e0d\u8ba9\u3002\u770b snapshot.h&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ snapshot.h<br \/>\nclass Snapshot {<br \/>\n protected:<br \/>\n  virtual ~Snapshot();   \/\/ \u6790\u6784\u51fd\u6570\u662f protected&#xff01;<br \/>\n};<\/p>\n<p>\u6790\u6784\u51fd\u6570\u662f\u00a0protected\u00a0\u7684&#xff0c;\u4f60\u5728\u5916\u9762\u00a0delete snap\u00a0\u76f4\u63a5\u7f16\u8bd1\u4e0d\u8fc7\u3002\u8fd9\u662f\u4e00\u9053\u7f16\u8bd1\u671f\u7684\u5f3a\u5236\u2014\u2014\u5feb\u7167\u7684\u91ca\u653e\u53ea\u80fd\u8d70\u00a0ReleaseSnapshot\u00a0\u8fd9\u4e00\u4e2a\u53e3\u5b50&#xff0c;\u56e0\u4e3a\u91ca\u653e\u5feb\u7167\u4e0d\u53ea\u662f\u5220\u4e2a\u5bf9\u8c61&#xff0c;\u8fd8\u8981\u901a\u77e5\u5f15\u64ce\u201c\u8fd9\u4e2a\u5e8f\u5217\u53f7\u6211\u4e0d\u9489\u4e86&#xff0c;\u4f60\u53ef\u4ee5\u56de\u6536\u5bf9\u5e94\u7684\u65e7\u7248\u672c\u4e86\u201d\u3002delete\u00a0\u5e72\u4e0d\u4e86\u540e\u534a\u4ef6\u4e8b&#xff0c;\u6240\u4ee5\u5e72\u8106\u4ece\u7c7b\u578b\u5c42\u9762\u7981\u6389\u3002\u60f3\u8981 RAII \u7684\u7701\u5fc3&#xff0c;\u5b83\u7ed9\u4e86\u4e2a\u5305\u88c5&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ snapshot.h<br \/>\n\/\/ Simple RAII wrapper class for Snapshot.<br \/>\nclass ManagedSnapshot {<br \/>\n public:<br \/>\n  explicit ManagedSnapshot(DB* db);   \/\/ \u6784\u9020\u5373 GetSnapshot<br \/>\n  ~ManagedSnapshot();                 \/\/ \u6790\u6784\u5373 ReleaseSnapshot<br \/>\n};<\/p>\n<p>\u6784\u9020\u65f6\u62ff\u5feb\u7167&#xff0c;\u6790\u6784\u65f6\u81ea\u52a8\u00a0ReleaseSnapshot\u2014\u2014\u628a\u201c\u5fc5\u987b\u6210\u5bf9\u8c03\u7528\u3001\u5426\u5219\u5173\u4e0d\u6389\u5e93\u201d\u7684\u624b\u52a8\u534f\u8bae&#xff0c;\u5305\u6210\u4e00\u4e2a\u79bb\u5f00\u4f5c\u7528\u57df\u81ea\u52a8\u5f52\u8fd8\u7684\u5bf9\u8c61\u3002\u4f60\u81ea\u7814\u5f15\u64ce\u91cc\u51e1\u662f\u8fd9\u79cd\u201c\u501f\u4e86\u5fc5\u987b\u8fd8\u3001\u8fd8\u9519\u4e86\u6216\u5fd8\u8fd8\u4f1a\u62d6\u4f4f\u7cfb\u7edf\u201d\u7684\u8d44\u6e90&#xff0c;\u90fd\u8be5\u987a\u624b\u914d\u4e00\u4e2a\u8fd9\u6837\u7684 RAII \u5305\u88c5&#xff0c;\u522b\u628a\u6210\u5bf9\u8c03\u7528\u7684\u7eaa\u5f8b\u7559\u7ed9\u8c03\u7528\u65b9\u7684\u8bb0\u6027\u3002<\/p>\n<h3>11. Slice\u3001pin \u4e0e Cache Handle&#xff1a;\u501f\u51fa\u53bb\u7684\u5185\u5b58\u4ec0\u4e48\u65f6\u5019\u5931\u6548<\/h3>\n<p>\u751f\u547d\u5468\u671f\u8fd8\u6709\u6700\u7ec6\u7684\u4e00\u5c42&#xff0c;\u7ec6\u5230\u5355\u4e2a\u00a0Slice\u00a0\u6307\u5411\u7684\u90a3\u51e0\u5341\u4e2a\u5b57\u8282\u3002\u8fd9\u4e00\u5c42\u76f4\u63a5\u8fde\u7740\u4f60\u8981\u7684\u78c1\u76d8 IO \u4e0e\u7f13\u5b58\u7b56\u7565&#xff0c;\u662f\u63a5\u53e3\u548c\u6027\u80fd\u7684\u4ea4\u754c\u9762\u3002<\/p>\n<p>\u5148\u5d29\u4e00\u4e2a\u6700\u5e38\u89c1\u7684\u3002\u4f60\u60f3\u5728\u904d\u5386\u65f6\u628a\u67d0\u4e2a key \u5b58\u4e0b\u6765\u5f85\u4f1a\u513f\u7528&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>Slice saved_key &#061; it-&gt;key();   \/\/ \u5b58\u4e0b\u5f53\u524d key<br \/>\nit-&gt;Next();                    \/\/ \u6e38\u6807\u5f80\u524d\u8d70\u4e00\u6b65<br \/>\nuse(saved_key);                \/\/ \u60ac\u7a7a&#xff01;saved_key \u6307\u5411\u7684\u5185\u5b58\u5df2\u88ab\u590d\u7528<\/p>\n<p>saved_key\u00a0\u5728\u00a0Next()\u00a0\u4e4b\u540e\u5c31\u662f\u4e00\u4e2a\u60ac\u7a7a\u5f15\u7528\u3002\u4e3a\u4ec0\u4e48&#xff1f;iterator_base.h \u7684\u00a0key()\u00a0\u6ce8\u91ca&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>\/\/ iterator_base.h&#xff1a;The underlying storage for the returned slice is<br \/>\n\/\/ valid only until the next modification of the iterator (i.e. the<br \/>\n\/\/ next SeekToFirst\/SeekToLast\/Seek\/SeekForPrev\/Next\/Prev operation).<br \/>\nvirtual Slice key() const &#061; 0;<\/p>\n<p>key()\u00a0\u548c\u00a0value()\u00a0\u8fd4\u56de\u7684\u00a0Slice\u00a0\u53ea\u662f\u6307\u5411\u5f15\u64ce\u5185\u90e8\u7f13\u51b2\u533a\u7684\u4e00\u4e2a\u89c6\u56fe&#xff0c;\u4e0d\u62e5\u6709\u5185\u5b58\u3002\u6e38\u6807\u4e00\u52a8&#xff0c;\u90a3\u5757\u7f13\u51b2\u533a\u5c31\u88ab\u4e0b\u4e00\u4e2a key \u590d\u7528\u4e86&#xff0c;\u4f60\u4e4b\u524d\u5b58\u7684\u00a0Slice\u00a0\u7acb\u523b\u5931\u6548\u3002\u8fd9\u662f\u96f6\u62f7\u8d1d\u8fed\u4ee3\u7684\u4ee3\u4ef7\u2014\u2014\u5b83\u4e0d\u7ed9\u4f60\u62f7\u8d1d&#xff0c;\u6362\u6765\u7684\u662f\u4f60\u5fc5\u987b\u5728\u6e38\u6807\u79fb\u52a8\u524d\u628a\u8981\u7559\u7684\u6570\u636e\u81ea\u5df1\u62f7\u8d70&#xff08;it-&gt;key().ToString()\u00a0\u5b58\u6210\u00a0std::string&#xff09;\u3002\u8fd9\u4e2a\u5751\u5728\u81ea\u7814\u5f15\u64ce\u91cc\u51e0\u4e4e\u4eba\u4eba\u8e29\u4e00\u904d&#xff0c;\u56e0\u4e3a\u00a0Slice\u00a0\u957f\u5f97\u592a\u50cf\u00a0string_view&#xff0c;\u4f60\u4f1a\u4e0b\u610f\u8bc6\u4ee5\u4e3a\u5b83\u4e00\u76f4\u6709\u6548\u3002\u5343\u4e07\u8bb0\u4f4f&#xff1a;\u4ece\u6e38\u6807\u501f\u51fa\u6765\u7684\u00a0Slice&#xff0c;\u5bff\u547d\u53ea\u5230\u4e0b\u4e00\u6b21\u79fb\u52a8\u6e38\u6807\u3002<\/p>\n<p>\u540c\u6837\u7684\u201c\u501f\u51fa\u5185\u5b58\u201d\u903b\u8f91&#xff0c;\u5728\u70b9\u67e5\u8fd9\u4fa7\u5c31\u662f\u7b2c 1 \u8282\u89c1\u8fc7\u7684\u00a0PinnableSlice\u3002\u56de\u770b\u90a3\u6bb5\u4ee3\u7801&#xff0c;\u73b0\u5728\u4f60\u80fd\u8bfb\u61c2\u5b83\u6bcf\u4e00\u884c\u4e86&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>PinnableSlice pinnable_val;<br \/>\ndb-&gt;Get(ReadOptions(), db-&gt;DefaultColumnFamily(), &#034;key2&#034;, &amp;pinnable_val);<br \/>\n\/\/ pinnable_val \u76f4\u63a5\u6307\u5411\u7f13\u5b58\u91cc\u90a3\u4efd value&#xff0c;\u4e00\u6b21\u62f7\u8d1d\u90fd\u6ca1\u6709<br \/>\nassert(pinnable_val &#061;&#061; &#034;value&#034;);<\/p>\n<p>pinnable_val.Reset();<br \/>\n\/\/ The Slice pointed by pinnable_val is not valid after this point<\/p>\n<p>PinnableSlice\u00a0\u662f\u4e3a\u4e86\u7701\u6389\u00a0Get\u00a0\u90a3\u6b21\u503c\u62f7\u8d1d\u3002\u666e\u901a\u7684\u00a0Get(&#8230;, std::string* value)\u00a0\u4f1a\u628a\u503c\u4ece\u7f13\u5b58\u62f7\u8fdb\u4f60\u7684 string&#xff1b;PinnableSlice\u00a0\u4e0d\u62f7&#xff0c;\u5b83\u76f4\u63a5pin \u4f4f\u7f13\u5b58\u91cc\u90a3\u4efd\u503c\u2014\u2014\u5728\u4f60\u00a0Reset\u00a0\u4e4b\u524d&#xff0c;\u90a3\u4efd\u503c\u6240\u5728\u7684\u7f13\u5b58\u5757\u4e0d\u8bb8\u88ab\u6dd8\u6c70&#xff0c;\u4f60\u624b\u91cc\u7684\u00a0Slice\u00a0\u5c31\u4e00\u76f4\u6307\u7740\u5b83\u6709\u6548\u3002\u7528\u5b8c\u5fc5\u987b\u00a0Reset&#xff0c;\u628a pin \u89e3\u5f00\u3002<\/p>\n<p>\u8fd9\u91cc\u5c31\u5192\u51fa\u4e86\u4f60\u8981\u7684\u201c\u7f13\u5b58\u7b56\u7565\u201d\u548c\u63a5\u53e3\u751f\u547d\u5468\u671f\u7684\u4ea4\u754c\u70b9\u3002pin \u4f4f\u4e00\u4efd\u7f13\u5b58\u503c&#xff0c;\u5e95\u4e0b\u5bf9\u5e94\u7684\u662f pin \u4f4f\u4e00\u4e2a\u00a0Cache Handle\u2014\u2014\u7f13\u5b58\u91cc\u90a3\u4e2a\u6570\u636e\u5757\u7684\u5f15\u7528\u3002\u8fd9\u4e2a\u5f15\u7528\u7684\u4ee3\u4ef7\u662f\u8fd9\u6837\u7684&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e00\u4e2a\u5757\u88ab pin \u4f4f&#xff0c;\u5b83\u5c31\u4e0d\u80fd\u88ab\u7f13\u5b58\u6dd8\u6c70&#xff0c;\u54ea\u6015\u7f13\u5b58\u5df2\u7ecf\u6ee1\u4e86\u3001\u8fd9\u4e2a\u5757\u662f\u6700\u8be5\u88ab\u8e22\u51fa\u53bb\u7684\u51b7\u5757&#xff0c;\u53ea\u8981\u8fd8\u6709\u4e00\u4e2a pin \u6ca1\u89e3\u5f00&#xff0c;\u5b83\u5c31\u5f97\u5728\u7f13\u5b58\u91cc\u5360\u7740\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e8e\u662f\u201c\u501f\u51fa\u4e00\u4efd\u96f6\u62f7\u8d1d\u7684\u503c\u201d\u8fd9\u4e2a\u4fbf\u5229&#xff0c;\u4ee3\u4ef7\u662f\u5ef6\u957f\u4e86\u4e00\u4e2a\u7f13\u5b58\u5757\u7684\u5bff\u547d\u3001\u5360\u4f4f\u4e86\u4e00\u683c\u7f13\u5b58\u3002\u4f60\u8981\u662f\u62ff\u4e00\u5806\u00a0PinnableSlice\u00a0\u8fdf\u8fdf\u4e0d\u00a0Reset&#xff0c;\u7b49\u4e8e\u628a\u4e00\u6279\u7f13\u5b58\u5757\u9489\u6b7b&#xff0c;\u7f13\u5b58\u7684\u6709\u6548\u5bb9\u91cf\u88ab\u4f60\u6084\u6084\u5403\u6389&#xff0c;\u547d\u4e2d\u7387\u5f80\u4e0b\u6389\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u770b\u5230\u8fd9\u6761\u7ebf\u4e86\u5417\u2014\u2014\u5b83\u548c\u7b2c 10 \u8282\u7684\u5feb\u7167\u662f\u540c\u4e00\u4e2a\u9053\u7406&#xff0c;\u6362\u4e86\u4e2a\u5c3a\u5ea6&#xff1a;\u5feb\u7167 pin \u4f4f\u7684\u662f\u6574\u4e2a\u5e93\u67d0\u4e2a\u7248\u672c\u7684\u53ef\u56de\u6536\u6027&#xff0c;Cache Handle pin \u4f4f\u7684\u662f\u4e00\u4e2a\u7f13\u5b58\u5757\u7684\u53ef\u6dd8\u6c70\u6027\u3002\u00a0\u90fd\u662f\u201c\u4f60\u501f\u4e86\u4e00\u4e2a\u5f15\u7528&#xff0c;\u5c31\u5ef6\u957f\u4e86\u67d0\u4e2a\u4e1c\u897f\u8be5\u6b7b\u800c\u672a\u6b7b\u7684\u65f6\u95f4\u201d\u3002\u5b58\u50a8\u5f15\u64ce\u7684\u751f\u547d\u5468\u671f\u7ba1\u7406&#xff0c;\u4ece\u5e93\u3001\u5230\u5feb\u7167\u3001\u5230\u5217\u65cf\u53e5\u67c4\u3001\u5230\u4e00\u4e2a\u00a0PinnableSlice&#xff0c;\u4ece\u5934\u5230\u5c3e\u662f\u540c\u4e00\u5957\u54f2\u5b66\u5728\u4e0d\u540c\u7c92\u5ea6\u4e0a\u7684\u91cd\u590d&#xff1a;\u6bcf\u4e00\u4e2a\u53e5\u67c4&#xff0c;\u7ba1\u7684\u90fd\u662f\u53ef\u89c1\u6027 \/ \u53ef\u56de\u6536\u6027&#xff0c;\u4e0d\u662f\u5b58\u5728\u6027&#xff1b;\u4f60\u591a\u6525\u4e00\u4e2a\u5f15\u7528&#xff0c;\u5c31\u591a\u9489\u4f4f\u4e00\u5206\u672c\u8be5\u88ab\u56de\u6536\u7684\u8d44\u6e90\u3002<\/p>\n<p>\u628a\u8fd9\u6761\u7ebf\u5728\u7f13\u5b58\u8fd9\u5934\u518d\u9489\u5b9e\u4e00\u70b9&#xff0c;\u56e0\u4e3a\u5b83\u76f4\u63a5\u5c31\u662f\u4f60\u8981\u8bbe\u8ba1\u7684\u7f13\u5b58\u7b56\u7565\u3002\u8bfb\u7f13\u5b58\u901a\u5e38\u662f\u4e2a LRU&#xff1a;\u5bb9\u91cf\u6ee1\u4e86&#xff0c;\u5c31\u628a\u6700\u4e45\u6ca1\u78b0\u7684\u5757\u8e22\u51fa\u53bb\u3002\u4f46\u201c\u8e22\u51fa\u53bb\u201d\u6709\u4e2a\u524d\u63d0\u2014\u2014\u8fd9\u4e2a\u5757\u6ca1\u88ab\u4efb\u4f55\u4eba pin \u4f4f\u3002\u4e00\u4e2a\u5757\u53ea\u8981\u8fd8\u6709\u4e00\u4e2a Cache Handle \u6ca1\u91ca\u653e&#xff0c;\u5b83\u7684\u5f15\u7528\u8ba1\u6570\u5c31\u4e0d\u4e3a\u96f6&#xff0c;LRU \u518d\u60f3\u6dd8\u6c70\u5b83\u4e5f\u53ea\u80fd\u8df3\u8fc7\u3002\u4e8e\u662f\u7f13\u5b58\u7684\u771f\u5b9e\u53ef\u7528\u5bb9\u91cf&#xff0c;\u662f\u201c\u603b\u5bb9\u91cf\u51cf\u53bb\u5f53\u524d\u88ab pin \u4f4f\u7684\u90a3\u90e8\u5206\u201d\u3002\u6b63\u5e38\u60c5\u51b5\u4e0b pin \u662f\u77ac\u65f6\u7684\u2014\u2014Get\u00a0\u62ff\u5230\u503c\u3001\u62f7\u8d70\u6216\u7528\u5b8c\u3001Reset&#xff0c;\u51e0\u5fae\u79d2\u7684\u4e8b&#xff0c;\u5bf9\u7f13\u5b58\u6beb\u65e0\u538b\u529b\u3002\u53ef\u53ea\u8981\u4f60\u628a\u4e00\u6279\u00a0PinnableSlice\u00a0\u6525\u5728\u624b\u91cc\u8fdf\u8fdf\u4e0d\u00a0Reset&#xff08;\u6bd4\u5982\u628a\u4e00\u5806\u67e5\u8be2\u7ed3\u679c\u5bf9\u8c61\u7f13\u5b58\u8d77\u6765&#xff0c;\u6bcf\u4e2a\u91cc\u9762\u8eba\u7740\u4e00\u4e2a\u6ca1\u91ca\u653e\u7684\u00a0PinnableSlice&#xff09;&#xff0c;\u4f60\u5c31\u7b49\u4e8e\u5728\u7f13\u5b58\u91cc\u51ff\u4e86\u4e00\u6279\u6c38\u4e0d\u878d\u5316\u7684\u51b0\u5757&#xff0c;\u53ef\u7528\u5bb9\u91cf\u88ab\u6084\u6084\u5403\u6389&#xff0c;\u547d\u4e2d\u7387\u5f80\u4e0b\u6389\u2014\u2014\u800c\u4e14\u8fd9\u79cd\u4e0b\u8dcc\u5728\u76d1\u63a7\u4e0a\u6781\u96be\u5b9a\u4f4d&#xff1a;\u7f13\u5b58\u660e\u660e\u6ca1\u6ee1&#xff0c;\u547d\u4e2d\u7387\u5374\u5728\u5d29\u3002\u4f60\u81ea\u7814\u5f15\u64ce\u8bbe\u8ba1\u7f13\u5b58\u65f6&#xff0c;\u201c\u88ab pin \u4f4f\u7684\u5757\u4e0d\u8ba1\u5165\u53ef\u6dd8\u6c70\u5bb9\u91cf\u201d\u8fd9\u6761\u5fc5\u987b\u4e00\u5f00\u59cb\u5c31\u60f3\u6e05\u695a&#xff0c;\u5e76\u4e14\u7ed9\u201c\u957f\u671f\u88ab pin \u7684\u5757\u6570\u201d\u914d\u4e00\u4e2a\u6307\u6807&#xff0c;\u5426\u5219\u96f6\u62f7\u8d1d\u90a3\u70b9\u4fbf\u5229&#xff0c;\u8fdf\u65e9\u53d8\u6210\u4e00\u6b21\u8bf4\u4e0d\u6e05\u6839\u56e0\u7684\u6027\u80fd\u4e8b\u6545\u3002<\/p>\n<p>\u6700\u540e\u8865\u4e00\u4e2a\u904d\u5386\u91cc\u5fc5\u8e29\u7684\u6536\u5c3e\u5751&#xff0c;\u628a\u751f\u547d\u5468\u671f\u548c\u9519\u8bef\u5904\u7406\u8fd9\u4e24\u6761\u7ebf\u5728\u8fd9\u91cc\u7cfb\u4e0a\u3002\u904d\u5386\u7ed3\u675f\u522b\u53ea\u770b\u00a0Valid()&#xff1a;<\/p>\n<p>C&#043;&#043;<\/p>\n<p>for (it-&gt;SeekToFirst(); it-&gt;Valid(); it-&gt;Next()) {<br \/>\n  \/\/ \u5904\u7406 it-&gt;key(), it-&gt;value()<br \/>\n}<br \/>\nif (!it-&gt;status().ok()) {<br \/>\n  \/\/ Valid() \u53d8 false \u6709\u4e24\u79cd\u53ef\u80fd&#xff1a;\u8d70\u5230\u5934\u4e86&#xff0c;\u6216\u8005\u4e2d\u9014 IO \u51fa\u9519\u4e86&#xff01;<br \/>\n  \/\/ \u53ea\u6709\u67e5 status() \u624d\u5206\u5f97\u6e05\u662f\u6b63\u5e38\u7ed3\u675f\u8fd8\u662f\u51fa\u9519\u4e2d\u65ad<br \/>\n}<\/p>\n<p>Valid()\u00a0\u8fd4\u56de false \u6709\u4e24\u79cd\u542b\u4e49&#xff1a;\u6b63\u5e38\u8d70\u5230\u4e86\u533a\u95f4\u5c3d\u5934&#xff0c;\u6216\u8005\u4e2d\u9014\u8bfb\u76d8\u51fa\u4e86\u9519\u3002iterator_base.h \u8bf4\u5f97\u5f88\u76f4\u767d\u2014\u2014Always returns false if !status().ok()\u3002\u8981\u662f\u4f60\u53ea\u7528\u00a0Valid()\u00a0\u5f53\u5faa\u73af\u6761\u4ef6\u3001\u4e0d\u5728\u5faa\u73af\u5916\u67e5\u4e00\u6b21\u00a0status()&#xff0c;\u4e00\u6b21\u8bfb\u76d8\u9519\u8bef\u5c31\u4f1a\u88ab\u4f60\u5f53\u6210\u201c\u6b63\u5e38\u904d\u5386\u5b8c\u4e86\u201d&#xff0c;\u6084\u6084\u6f0f\u6389\u534a\u4e2a\u533a\u95f4\u7684\u6570\u636e\u8fd8\u6d51\u7136\u4e0d\u89c9\u3002\u8fd9\u6b63\u597d\u547c\u5e94\u7b2c 7 \u8282&#xff1a;\u9519\u8bef\u662f\u4e00\u4e2a\u5fc5\u987b\u4e3b\u52a8\u53bb\u67e5\u7684\u8fd4\u56de\u503c&#xff0c;\u8fde\u8fed\u4ee3\u5668\u8fd9\u79cd\u5730\u65b9\u90fd\u4e0d\u4f8b\u5916\u3002<\/p>\n<h3>12. \u4e09\u9053\u5224\u65ad\u9898&#xff0c;\u628a\u8fd9\u5957\u6a21\u578b\u642c\u5230\u4f60\u81ea\u5df1\u7684\u5f15\u64ce\u4e0a<\/h3>\n<p>\u56de\u5230\u5f00\u5934\u90a3\u4e5d\u884c\u4ee3\u7801\u3002\u90a3\u65f6\u4f60\u770b\u5230\u00a01 10 11 12 2\u00a0\u4f1a\u6123\u4e00\u4e0b&#xff0c;\u73b0\u5728\u4f60\u8be5\u80fd\u4e00\u53e3\u6c14\u8bf4\u6e05&#xff1a;\u5b83\u6309\u65e0\u7b26\u53f7\u5b57\u8282\u505a\u5b57\u5178\u5e8f&#xff08;\u7b2c 3 \u8282&#xff09;&#xff0c;\u5b57\u7b26\u4e32\u00a0&#034;12&#034;\u00a0\u7684\u9996\u5b57\u8282\u6bd4\u00a0&#034;2&#034;\u00a0\u5c0f&#xff1b;\u8981\u8ba9\u5b83\u6309\u6570\u503c\u6392&#xff0c;key \u91cc\u7684\u6574\u6570\u5f97\u5927\u7aef\u7f16\u7801\u3002\u540c\u4e00\u6bb5\u4ee3\u7801&#xff0c;\u4f60\u624b\u91cc\u7684\u4fe1\u606f\u5df2\u7ecf\u5b8c\u5168\u4e0d\u540c\u4e86\u3002<\/p>\n<p>\u4e0d\u505a\u603b\u7ed3&#xff0c;\u7ed9\u4f60\u4e09\u9053\u5224\u65ad\u9898&#xff0c;\u6bcf\u9053\u90fd\u5bf9\u7740\u4f60\u81ea\u7814\u5f15\u64ce\u65f6\u771f\u4f1a\u4e0b\u7684\u4e00\u4e2a\u51b3\u5b9a&#xff0c;\u968f\u5224\u968f\u7b54&#xff1a;<\/p>\n<p>\u7b2c\u4e00\u9898&#xff1a;\u4f60\u7684 key \u7f16\u7801&#xff0c;\u5728\u5b57\u8282\u5b57\u5178\u5e8f\u4e0b\u987a\u5e8f\u8fd8\u5bf9\u5417&#xff1f;\u00a0\u4f46\u51e1\u4f60\u7684\u5f15\u64ce\u8981\u652f\u6301\u8303\u56f4\u626b\u63cf&#xff0c;\u8fd9\u5c31\u662f\u7b2c\u4e00\u9053\u574e\u3002\u6574\u6570\u4e3b\u952e&#xff1f;\u5fc5\u987b\u5927\u7aef\u3002\u591a\u5b57\u6bb5\u590d\u5408 key&#xff1f;\u6bcf\u4e2a\u5b57\u6bb5\u7684\u8fb9\u754c\u548c\u987a\u5e8f\u90fd\u5f97\u5728\u5b57\u8282\u5c42\u9762\u5bf9\u9f50\u3002\u5b9a\u957f\u8fd8\u662f\u53d8\u957f&#xff0c;\u76f4\u63a5\u51b3\u5b9a\u524d\u7f00\u626b\u63cf\u6210\u4e0d\u6210\u7acb\u3002\u7b54\u4e0d\u5229\u7d22\u8fd9\u4e00\u9898&#xff0c;\u4f60\u7684\u6709\u5e8f\u6027\u662f\u5047\u7684\u2014\u2014\u4e0d\u62a5\u9519&#xff0c;\u53ea\u662f\u626b\u63cf\u7ed3\u679c\u6084\u6084\u4e0d\u5bf9\u3002<\/p>\n<p>\u7b2c\u4e8c\u9898&#xff1a;\u4f60\u8fd9\u5957\u63a5\u53e3\u91cc&#xff0c;\u54ea\u4e9b\u5bf9\u8c61 pin \u7684\u662f\u201c\u53ef\u89c1\u6027\u201d&#xff0c;\u54ea\u4e9b\u662f\u201c\u5b58\u5728\u6027\u201d&#xff1f;\u00a0\u5feb\u7167\u3001\u5217\u65cf\u53e5\u67c4\u3001PinnableSlice\u3001\u8fed\u4ee3\u5668&#xff0c;\u5168\u662f\u5f15\u7528\u578b\u5bf9\u8c61&#xff0c;\u5b83\u4eec\u9489\u4f4f\u7684\u90fd\u662f\u201c\u53ef\u56de\u6536\u6027\u201d\u8fd9\u6839\u8f74&#xff0c;\u4e0d\u662f\u201c\u5b58\u5728\u6027\u201d\u3002\u60f3\u6e05\u695a\u6bcf\u4e00\u4e2a\u7684\u91ca\u653e\u4f1a\u653e\u5f00\u4ec0\u4e48\u3001\u5fd8\u4e86\u91ca\u653e\u4f1a\u9489\u4f4f\u4ec0\u4e48\u2014\u2014\u5173\u4e0d\u6389\u7684\u5e93\u3001\u6dd8\u6c70\u4e0d\u6389\u7684\u7f13\u5b58\u5757\u3001\u56de\u6536\u4e0d\u4e86\u7684\u65e7\u7248\u672c&#xff0c;\u6839\u5b50\u90fd\u5728\u8fd9\u91cc\u3002\u7ed9\u6bcf\u4e2a\u8fd9\u6837\u7684\u5f15\u7528\u914d\u4e00\u4e2a RAII \u5305\u88c5&#xff0c;\u628a\u6210\u5bf9\u8c03\u7528\u7684\u7eaa\u5f8b\u4ece\u8c03\u7528\u65b9\u7684\u8bb0\u6027\u91cc\u62ff\u8d70\u3002<\/p>\n<p>\u7b2c\u4e09\u9898&#xff1a;\u4f60\u7684\u9519\u8bef\u901a\u9053&#xff0c;\u662f\u503c\u8fd8\u662f\u5f02\u5e38&#xff1f;\u00a0\u5982\u679c\u4f60\u7684\u5f15\u64ce\u6838\u5fc3\u4e5f\u78b0\u78c1\u76d8\u3001\u4e5f\u5e26\u5e76\u53d1\u3001\u4e5f\u5bb9\u4e0d\u4e0b\u201c\u534a\u4e2a\u64cd\u4f5c\u201d&#xff0c;\u8ba4\u771f\u8003\u8651\u8d70\u8fd4\u56de\u503c\u00a0Status\u3002\u4f46\u5149\u6709\u8fd4\u56de\u503c\u4e0d\u591f\u2014\u2014\u914d\u4e00\u5957\u80fd\u5728\u6d4b\u8bd5\u6784\u5efa\u91cc\u628a\u201c\u6f0f\u68c0\u8fd4\u56de\u503c\u201d\u53d8\u6210\u5f53\u573a\u5d29\u6e83\u7684\u673a\u5236&#xff0c;\u5426\u5219\u5b83\u8fdf\u65e9\u9000\u5316\u6210\u6bd4\u5f02\u5e38\u66f4\u5371\u9669\u7684\u4e1c\u897f&#xff1a;\u88ab\u65e0\u58f0\u541e\u6389\u7684\u9519\u8bef\u3002<\/p>\n<p>\u4e09\u9053\u9898\u80cc\u540e\u662f\u540c\u4e00\u53e5\u5224\u65ad&#xff0c;\u4e5f\u662f\u8fd9\u7bc7\u552f\u4e00\u60f3\u710a\u8fdb\u4f60\u8111\u5b50\u7684\u90a3\u4e00\u53e5&#xff1a;\u6709\u5e8f KV \u5b58\u50a8\u7684\u6bcf\u4e00\u4e2a\u63a5\u53e3\u51b3\u5b9a&#xff0c;\u6700\u7ec8\u90fd\u6536\u655b\u5230\u4e00\u4e2a\u95ee\u9898\u2014\u2014\u987a\u5e8f\u7531\u8c01\u5b9a\u4e49\u3001\u72b6\u6001\u5bf9\u8c01\u53ef\u89c1\u3001\u8d44\u6e90\u5f52\u8c01\u56de\u6536\u3002\u00a0\u987a\u5e8f\u5373\u8eab\u4efd&#xff0c;\u53ef\u89c1\u5373\u7248\u672c&#xff0c;\u5f15\u7528\u5373\u8d26\u5355\u3002\u4f60\u628a\u81ea\u7814\u5f15\u64ce\u7684\u63a5\u53e3\u6309\u8fd9\u4e09\u6761\u634b\u4e00\u904d&#xff0c;\u78c1\u76d8 IO\u3001\u7f13\u5b58\u7b56\u7565\u3001\u6027\u80fd\u4f18\u5316\u90a3\u4e9b\u4e0b\u6e38\u7684\u6d3b&#xff0c;\u624d\u6709\u4e00\u4e2a\u7acb\u5f97\u4f4f\u7684\u5730\u57fa\u3002<\/p>\n<p>\u8fd9\u5957\u6a21\u578b\u6709\u5b83\u7684\u4fdd\u8d28\u671f\u3002\u5b83\u6210\u7acb&#xff0c;\u5efa\u7acb\u5728\u4e09\u4ef6\u4e8b\u4e0a&#xff1a;key \u7a7a\u95f4\u5b58\u5728\u4e00\u4e2a\u4f60\u5b9a\u5f97\u6b7b\u7684\u5168\u5e8f\u3001\u5199\u5165\u662f\u591a\u7248\u672c\u53e0\u52a0\u800c\u975e\u539f\u5730\u8986\u76d6\u3001\u8d44\u6e90\u9760\u5f15\u7528\u8ba1\u6570\u800c\u975e\u5783\u573e\u56de\u6536\u6765\u6536\u3002\u54ea\u5929\u4f60\u7684\u5f15\u64ce\u6539\u7528\u4e86\u522b\u7684\u5b58\u50a8\u8303\u5f0f\u2014\u2014\u6bd4\u5982\u6362\u6210\u7eaf\u5185\u5b58\u3001\u6216\u8005\u4e0a\u4e86\u5e26 GC \u7684\u8fd0\u884c\u65f6\u2014\u2014\u8fd9\u4e09\u6761\u91cc\u4f46\u51e1\u584c\u4e00\u6761&#xff0c;\u4e0a\u9762\u6574\u5957\u5173\u4e8e\u201c\u5b58\u5728\u4e0e\u53ef\u89c1\u201d\u201c\u987a\u5e8f\u5373\u8eab\u4efd\u201d\u7684\u63a8\u8bba\u5c31\u5f97\u91cd\u753b\u3002\u5230\u90a3\u65f6&#xff0c;\u522b\u5fd8\u4e86\u56de\u6765\u628a\u8fd9\u4e09\u6761\u524d\u63d0\u91cd\u65b0\u5bf9\u4e00\u904d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u4f60\u4e60\u60ef\u4e86\u00a0std::unordered_map\u00a0\u6216 Redis \u8fd9\u79cd\u628a\u6570\u636e\u6563\u5217\u843d\u6876\u7684\u601d\u7ef4&#xff0c;\u521d\u6b21\u63a5\u89e6\u5de5\u4e1a\u7ea7\u5d4c\u5165\u5f0f KV \u5f15\u64ce&#xff08;\u5982 RocksDB \/ LevelDB&#xff09;\u65f6&#xff0c;\u5927\u6982\u7387\u4f1a\u88ab\u5b83\u7684\u201c\u8d8a\u6743\u201d\u884c\u4e3a\u6253\u4e2a\u63aa\u624b\u4e0d\u53ca&#xff1a;\u4f60\u660e\u660e\u4ece\u672a\u6307\u5b9a\u8fc7\u4efb\u4f55\u6392\u5e8f\u89c4\u5219&#xff0c;\u5b83\u5374\u56fa\u6267\u5730\u91cd\u6392\u4e86\u4f60\u7684\u6bcf\u4e00\u4e2a\u5b57\u8282\u3002\u5199\u8fdb 1 \u5230 12 \u7684\u6574\u6570\u5b57\u7b26\u4e32&#xff0c;\u8bfb\u51fa\u6765\u5374\u53d8\u6210\u4e86\u5b57\u5178\u5e8f&#xff1b;\u5982\u679c\u4f60\u76f4\u63a5\u628a\u00a0uint64_t\u00a0\u7684\u5185\u5b58<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,3419],"topic":[],"class_list":["post-99779","post","type-post","status-publish","format-standard","hentry","category-server","tag-c","tag-c23"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4e3a\u4ec0\u4e48\u8bf4\u201c\u6709\u5e8f\u201d\u662f\u5b58\u50a8\u5f15\u64ce\u7684\u5e95\u5c42\u7269\u7406\u5b9a\u5f8b\uff1f\u6df1\u5ea6\u62c6\u89e3 LevelDB\/RocksDB \u7684 C++ \u63a5\u53e3\u6a21\u578b\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/99779.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4e3a\u4ec0\u4e48\u8bf4\u201c\u6709\u5e8f\u201d\u662f\u5b58\u50a8\u5f15\u64ce\u7684\u5e95\u5c42\u7269\u7406\u5b9a\u5f8b\uff1f\u6df1\u5ea6\u62c6\u89e3 LevelDB\/RocksDB \u7684 C++ \u63a5\u53e3\u6a21\u578b\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5982\u679c\u4f60\u4e60\u60ef\u4e86\u00a0std::unordered_map\u00a0\u6216 Redis \u8fd9\u79cd\u628a\u6570\u636e\u6563\u5217\u843d\u6876\u7684\u601d\u7ef4&#xff0c;\u521d\u6b21\u63a5\u89e6\u5de5\u4e1a\u7ea7\u5d4c\u5165\u5f0f KV \u5f15\u64ce&#xff08;\u5982 RocksDB \/ LevelDB&#xff09;\u65f6&#xff0c;\u5927\u6982\u7387\u4f1a\u88ab\u5b83\u7684\u201c\u8d8a\u6743\u201d\u884c\u4e3a\u6253\u4e2a\u63aa\u624b\u4e0d\u53ca&#xff1a;\u4f60\u660e\u660e\u4ece\u672a\u6307\u5b9a\u8fc7\u4efb\u4f55\u6392\u5e8f\u89c4\u5219&#xff0c;\u5b83\u5374\u56fa\u6267\u5730\u91cd\u6392\u4e86\u4f60\u7684\u6bcf\u4e00\u4e2a\u5b57\u8282\u3002\u5199\u8fdb 1 \u5230 12 \u7684\u6574\u6570\u5b57\u7b26\u4e32&#xff0c;\u8bfb\u51fa\u6765\u5374\u53d8\u6210\u4e86\u5b57\u5178\u5e8f&#xff1b;\u5982\u679c\u4f60\u76f4\u63a5\u628a\u00a0uint64_t\u00a0\u7684\u5185\u5b58\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/99779.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-03T02:24:48+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/99779.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/99779.html\",\"name\":\"\u4e3a\u4ec0\u4e48\u8bf4\u201c\u6709\u5e8f\u201d\u662f\u5b58\u50a8\u5f15\u64ce\u7684\u5e95\u5c42\u7269\u7406\u5b9a\u5f8b\uff1f\u6df1\u5ea6\u62c6\u89e3 LevelDB\/RocksDB \u7684 C++ \u63a5\u53e3\u6a21\u578b\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-03T02:24:48+00:00\",\"dateModified\":\"2026-09-03T02:24:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/99779.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/99779.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/99779.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4e3a\u4ec0\u4e48\u8bf4\u201c\u6709\u5e8f\u201d\u662f\u5b58\u50a8\u5f15\u64ce\u7684\u5e95\u5c42\u7269\u7406\u5b9a\u5f8b\uff1f\u6df1\u5ea6\u62c6\u89e3 LevelDB\/RocksDB \u7684 C++ \u63a5\u53e3\u6a21\u578b\uff01\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4e3a\u4ec0\u4e48\u8bf4\u201c\u6709\u5e8f\u201d\u662f\u5b58\u50a8\u5f15\u64ce\u7684\u5e95\u5c42\u7269\u7406\u5b9a\u5f8b\uff1f\u6df1\u5ea6\u62c6\u89e3 LevelDB\/RocksDB \u7684 C++ \u63a5\u53e3\u6a21\u578b\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/99779.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4e3a\u4ec0\u4e48\u8bf4\u201c\u6709\u5e8f\u201d\u662f\u5b58\u50a8\u5f15\u64ce\u7684\u5e95\u5c42\u7269\u7406\u5b9a\u5f8b\uff1f\u6df1\u5ea6\u62c6\u89e3 LevelDB\/RocksDB \u7684 C++ \u63a5\u53e3\u6a21\u578b\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5982\u679c\u4f60\u4e60\u60ef\u4e86\u00a0std::unordered_map\u00a0\u6216 Redis \u8fd9\u79cd\u628a\u6570\u636e\u6563\u5217\u843d\u6876\u7684\u601d\u7ef4&#xff0c;\u521d\u6b21\u63a5\u89e6\u5de5\u4e1a\u7ea7\u5d4c\u5165\u5f0f KV \u5f15\u64ce&#xff08;\u5982 RocksDB \/ LevelDB&#xff09;\u65f6&#xff0c;\u5927\u6982\u7387\u4f1a\u88ab\u5b83\u7684\u201c\u8d8a\u6743\u201d\u884c\u4e3a\u6253\u4e2a\u63aa\u624b\u4e0d\u53ca&#xff1a;\u4f60\u660e\u660e\u4ece\u672a\u6307\u5b9a\u8fc7\u4efb\u4f55\u6392\u5e8f\u89c4\u5219&#xff0c;\u5b83\u5374\u56fa\u6267\u5730\u91cd\u6392\u4e86\u4f60\u7684\u6bcf\u4e00\u4e2a\u5b57\u8282\u3002\u5199\u8fdb 1 \u5230 12 \u7684\u6574\u6570\u5b57\u7b26\u4e32&#xff0c;\u8bfb\u51fa\u6765\u5374\u53d8\u6210\u4e86\u5b57\u5178\u5e8f&#xff1b;\u5982\u679c\u4f60\u76f4\u63a5\u628a\u00a0uint64_t\u00a0\u7684\u5185\u5b58","og_url":"https:\/\/www.wsisp.com\/helps\/99779.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-03T02:24:48+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"19 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/99779.html","url":"https:\/\/www.wsisp.com\/helps\/99779.html","name":"\u4e3a\u4ec0\u4e48\u8bf4\u201c\u6709\u5e8f\u201d\u662f\u5b58\u50a8\u5f15\u64ce\u7684\u5e95\u5c42\u7269\u7406\u5b9a\u5f8b\uff1f\u6df1\u5ea6\u62c6\u89e3 LevelDB\/RocksDB \u7684 C++ \u63a5\u53e3\u6a21\u578b\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-03T02:24:48+00:00","dateModified":"2026-09-03T02:24:48+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/99779.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/99779.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/99779.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4e3a\u4ec0\u4e48\u8bf4\u201c\u6709\u5e8f\u201d\u662f\u5b58\u50a8\u5f15\u64ce\u7684\u5e95\u5c42\u7269\u7406\u5b9a\u5f8b\uff1f\u6df1\u5ea6\u62c6\u89e3 LevelDB\/RocksDB \u7684 C++ \u63a5\u53e3\u6a21\u578b\uff01"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/99779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=99779"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/99779\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=99779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=99779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=99779"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=99779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}