{"id":165728,"date":"2019-12-21T12:00:21","date_gmt":"2019-12-21T04:00:21","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=165728"},"modified":"2019-12-02T13:54:51","modified_gmt":"2019-12-02T05:54:51","slug":"basic-principle-zookeeper","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/basic-principle-zookeeper.html","title":{"rendered":"\u6765\u7cfb\u7edf\u5b66\u4e60\u4e00\u4e0bZooKeeper\u57fa\u672c\u7684\u539f\u7406"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nZooKeeper\u662f\u4e00\u4e2a\u5f00\u653e\u6e90\u7801\u7684\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u534f\u8c03\u670d\u52a1\uff0c\u5b83\u5305\u542b\u4e00\u4e2a\u7b80\u5355\u7684\u539f\u8bed\u96c6\uff0c\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u57fa\u4e8e\u5b83\u5b9e\u73b0\u540c\u6b65\u670d\u52a1\uff0c\u914d\u7f6e\u7ef4\u62a4\u548c\u547d\u540d\u670d\u52a1\u7b49\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u00a0ZooKeeper\u7b80\u4ecb<\/strong><\/strong><\/div>\n

ZooKeeper\u662f\u4e00\u4e2a\u5f00\u653e\u6e90\u7801\u7684\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u534f\u8c03\u670d\u52a1\uff0c\u5b83\u5305\u542b\u4e00\u4e2a\u7b80\u5355\u7684\u539f\u8bed\u96c6\uff0c\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u57fa\u4e8e\u5b83\u5b9e\u73b0\u540c\u6b65\u670d\u52a1\uff0c\u914d\u7f6e\u7ef4\u62a4\u548c\u547d\u540d\u670d\u52a1\u7b49\u3002<\/p>\n

\"\"<\/p>\n

ZooKeeper\u8bbe\u8ba1\u76ee\u7684<\/strong><\/strong><\/div>\n
    \n
  1. \u6700\u7ec8\u4e00\u81f4\u6027\uff1aclient\u4e0d\u8bba\u8fde\u63a5\u5230\u54ea\u4e2aServer\uff0c\u5c55\u793a\u7ed9\u5b83\u90fd\u662f\u540c\u4e00\u4e2a\u89c6\u56fe\uff0c\u8fd9\u662fzookeeper\u6700\u91cd\u8981\u7684\u6027\u80fd\u3002<\/li>\n
  2. \u53ef\u9760\u6027\uff1a\u5177\u6709\u7b80\u5355\u3001\u5065\u58ee\u3001\u826f\u597d\u7684\u6027\u80fd\uff0c\u5982\u679c\u6d88\u606fm\u88ab\u5230\u4e00\u53f0\u670d\u52a1\u5668\u63a5\u53d7\uff0c\u90a3\u4e48\u5b83\u5c06\u88ab\u6240\u6709\u7684\u670d\u52a1\u5668\u63a5\u53d7\u3002<\/li>\n
  3. \u5b9e\u65f6\u6027\uff1aZookeeper\u4fdd\u8bc1\u5ba2\u6237\u7aef\u5c06\u5728\u4e00\u4e2a\u65f6\u95f4\u95f4\u9694\u8303\u56f4\u5185\u83b7\u5f97\u670d\u52a1\u5668\u7684\u66f4\u65b0\u4fe1\u606f\uff0c\u6216\u8005\u670d\u52a1\u5668\u5931\u6548\u7684\u4fe1\u606f\u3002\u4f46\u7531\u4e8e\u7f51\u7edc\u5ef6\u65f6\u7b49\u539f\u56e0\uff0cZookeeper\u4e0d\u80fd\u4fdd\u8bc1\u4e24\u4e2a\u5ba2\u6237\u7aef\u80fd\u540c\u65f6\u5f97\u5230\u521a\u66f4\u65b0\u7684\u6570\u636e\uff0c\u5982\u679c\u9700\u8981\u6700\u65b0\u6570\u636e\uff0c\u5e94\u8be5\u5728\u8bfb\u6570\u636e\u4e4b\u524d\u8c03\u7528sync()\u63a5\u53e3\u3002<\/li>\n
  4. \u7b49\u5f85\u65e0\u5173(wait-free)\uff1a\u6162\u7684\u6216\u8005\u5931\u6548\u7684client\u4e0d\u5f97\u5e72\u9884\u5feb\u901f\u7684client\u7684\u8bf7\u6c42\uff0c\u4f7f\u5f97\u6bcf\u4e2aclient\u90fd\u80fd\u6709\u6548\u7684\u7b49\u5f85\u3002<\/li>\n
  5. \u539f\u5b50\u6027\uff1a\u66f4\u65b0\u53ea\u80fd\u6210\u529f\u6216\u8005\u5931\u8d25\uff0c\u6ca1\u6709\u4e2d\u95f4\u72b6\u6001\u3002<\/li>\n
  6. \u987a\u5e8f\u6027\uff1a\u5305\u62ec\u5168\u5c40\u6709\u5e8f\u548c\u504f\u5e8f\u4e24\u79cd\uff1a\u5168\u5c40\u6709\u5e8f\u662f\u6307\u5982\u679c\u5728\u4e00\u53f0\u670d\u52a1\u5668\u4e0a\u6d88\u606fa\u5728\u6d88\u606fb\u524d\u53d1\u5e03\uff0c\u5219\u5728\u6240\u6709Server\u4e0a\u6d88\u606fa\u90fd\u5c06\u5728\u6d88\u606fb\u524d\u88ab\u53d1\u5e03;\u504f\u5e8f\u662f\u6307\u5982\u679c\u4e00\u4e2a\u6d88\u606fb\u5728\u6d88\u606fa\u540e\u88ab\u540c\u4e00\u4e2a\u53d1\u9001\u8005\u53d1\u5e03\uff0ca\u5fc5\u5c06\u6392\u5728b\u524d\u9762\u3002<\/li>\n<\/ol>\n
    ZooKeeper\u6570\u636e\u6a21\u578b<\/strong><\/strong><\/div>\n

    Zookeeper\u4f1a\u7ef4\u62a4\u4e00\u4e2a\u5177\u6709\u5c42\u6b21\u5173\u7cfb\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u975e\u5e38\u7c7b\u4f3c\u4e8e\u4e00\u4e2a\u6807\u51c6\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u5982\u56fe\u6240\u793a\uff1a<\/p>\n

    \"\"<\/p>\n

    Zookeeper\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u6709\u5982\u4e0b\u8fd9\u4e9b\u7279\u70b9\uff1a<\/strong><\/p>\n

    1)\u6bcf\u4e2a\u5b50\u76ee\u5f55\u9879\u5982NameService\u90fd\u88ab\u79f0\u4f5c\u4e3aznode\uff0c\u8fd9\u4e2aznode\u662f\u88ab\u5b83\u6240\u5728\u7684\u8def\u5f84\u552f\u4e00\u6807\u8bc6\uff0c\u5982Server1\u8fd9\u4e2aznode\u7684\u6807\u8bc6\u4e3a\/NameService\/Server1\u3002<\/p>\n

    2)znode\u53ef\u4ee5\u6709\u5b50\u8282\u70b9\u76ee\u5f55\uff0c\u5e76\u4e14\u6bcf\u4e2aznode\u53ef\u4ee5\u5b58\u50a8\u6570\u636e\uff0c\u6ce8\u610fEPHEMERAL(\u4e34\u65f6\u7684)\u7c7b\u578b\u7684\u76ee\u5f55\u8282\u70b9\u4e0d\u80fd\u6709\u5b50\u8282\u70b9\u76ee\u5f55\u3002<\/p>\n

    3)znode\u662f\u6709\u7248\u672c\u7684(version)\uff0c\u6bcf\u4e2aznode\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u53ef\u4ee5\u6709\u591a\u4e2a\u7248\u672c\uff0c\u4e5f\u5c31\u662f\u4e00\u4e2a\u8bbf\u95ee\u8def\u5f84\u4e2d\u53ef\u4ee5\u5b58\u50a8\u591a\u4efd\u6570\u636e\uff0cversion\u53f7\u81ea\u52a8\u589e\u52a0\u3002<\/p>\n

    4)znode\u7684\u7c7b\u578b\uff1a<\/p>\n

      \n
    • Persistent \u8282\u70b9\uff0c\u4e00\u65e6\u88ab\u521b\u5efa\uff0c\u4fbf\u4e0d\u4f1a\u610f\u5916\u4e22\u5931\uff0c\u5373\u4f7f\u670d\u52a1\u5668\u5168\u90e8\u91cd\u542f\u4e5f\u4f9d\u7136\u5b58\u5728\u3002\u6bcf\u4e2a Persist \u8282\u70b9\u5373\u53ef\u5305\u542b\u6570\u636e\uff0c\u4e5f\u53ef\u5305\u542b\u5b50\u8282\u70b9\u3002<\/li>\n
    • Ephemeral \u8282\u70b9\uff0c\u5728\u521b\u5efa\u5b83\u7684\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u95f4\u7684 Session \u7ed3\u675f\u65f6\u81ea\u52a8\u88ab\u5220\u9664\u3002\u670d\u52a1\u5668\u91cd\u542f\u4f1a\u5bfc\u81f4 Session \u7ed3\u675f\uff0c\u56e0\u6b64 Ephemeral \u7c7b\u578b\u7684 znode \u6b64\u65f6\u4e5f\u4f1a\u81ea\u52a8\u5220\u9664\u3002<\/li>\n
    • Non-sequence \u8282\u70b9\uff0c\u591a\u4e2a\u5ba2\u6237\u7aef\u540c\u65f6\u521b\u5efa\u540c\u4e00 Non-sequence \u8282\u70b9\u65f6\uff0c\u53ea\u6709\u4e00\u4e2a\u53ef\u521b\u5efa\u6210\u529f\uff0c\u5176\u5b83\u5300\u5931\u8d25\u3002\u5e76\u4e14\u521b\u5efa\u51fa\u7684\u8282\u70b9\u540d\u79f0\u4e0e\u521b\u5efa\u65f6\u6307\u5b9a\u7684\u8282\u70b9\u540d\u5b8c\u5168\u4e00\u6837\u3002<\/li>\n
    • Sequence \u8282\u70b9\uff0c\u521b\u5efa\u51fa\u7684\u8282\u70b9\u540d\u5728\u6307\u5b9a\u7684\u540d\u79f0\u4e4b\u540e\u5e26\u670910\u4f4d10\u8fdb\u5236\u6570\u7684\u5e8f\u53f7\u3002\u591a\u4e2a\u5ba2\u6237\u7aef\u521b\u5efa\u540c\u4e00\u540d\u79f0\u7684\u8282\u70b9\u65f6\uff0c\u90fd\u80fd\u521b\u5efa\u6210\u529f\uff0c\u53ea\u662f\u5e8f\u53f7\u4e0d\u540c\u3002<\/li>\n<\/ul>\n

      5)znode\u53ef\u4ee5\u88ab\u76d1\u63a7\uff0c\u5305\u62ec\u8fd9\u4e2a\u76ee\u5f55\u8282\u70b9\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u7684\u4fee\u6539\uff0c\u5b50\u8282\u70b9\u76ee\u5f55\u7684\u53d8\u5316\u7b49\uff0c\u4e00\u65e6\u53d8\u5316\u53ef\u4ee5\u901a\u77e5\u8bbe\u7f6e\u76d1\u63a7\u7684\u5ba2\u6237\u7aef\uff0c\u8fd9\u4e2a\u662fZookeeper\u7684\u6838\u5fc3\u7279\u6027\uff0cZookeeper\u7684\u5f88\u591a\u529f\u80fd\u90fd\u662f\u57fa\u4e8e\u8fd9\u4e2a\u7279\u6027\u5b9e\u73b0\u7684\u3002<\/p>\n

      6)ZXID\uff1a\u6bcf\u6b21\u5bf9Zookeeper\u7684\u72b6\u6001\u7684\u6539\u53d8\u90fd\u4f1a\u4ea7\u751f\u4e00\u4e2azxid(ZooKeeper Transaction Id)\uff0czxid\u662f\u5168\u5c40\u6709\u5e8f\u7684\uff0c\u5982\u679czxid1\u5c0f\u4e8ezxid2\uff0c\u5219zxid1\u5728zxid2\u4e4b\u524d\u53d1\u751f\u3002<\/p>\n

      ZooKeeper Session<\/strong><\/strong><\/div>\n

      Client\u548cZookeeper\u96c6\u7fa4\u5efa\u7acb\u8fde\u63a5\uff0c\u6574\u4e2asession\u72b6\u6001\u53d8\u5316\u5982\u56fe\u6240\u793a\uff1a<\/p>\n

      \"\"<\/p>\n

      \u5982\u679cClient\u56e0\u4e3aTimeout\u548cZookeeper Server\u5931\u53bb\u8fde\u63a5\uff0cclient\u5904\u5728CONNECTING\u72b6\u6001\uff0c\u4f1a\u81ea\u52a8\u5c1d\u8bd5\u518d\u53bb\u8fde\u63a5Server\uff0c\u5982\u679c\u5728session\u6709\u6548\u671f\u5185\u518d\u6b21\u6210\u529f\u8fde\u63a5\u5230\u67d0\u4e2aServer\uff0c\u5219\u56de\u5230CONNECTED\u72b6\u6001\u3002<\/p>\n

      \u6ce8\u610f\uff1a\u5982\u679c\u56e0\u4e3a\u7f51\u7edc\u72b6\u6001\u4e0d\u597d\uff0cclient\u548cServer\u5931\u53bb\u8054\u7cfb\uff0cclient\u4f1a\u505c\u7559\u5728\u5f53\u524d\u72b6\u6001\uff0c\u4f1a\u5c1d\u8bd5\u4e3b\u52a8\u518d\u6b21\u8fde\u63a5Zookeeper Server\u3002client\u4e0d\u80fd\u5ba3\u79f0\u81ea\u5df1\u7684session expired\uff0csession expired\u662f\u7531Zookeeper Server\u6765\u51b3\u5b9a\u7684\uff0cclient\u53ef\u4ee5\u9009\u62e9\u81ea\u5df1\u4e3b\u52a8\u5173\u95edsession\u3002<\/p>\n

      ZooKeeper Watch<\/strong><\/strong><\/div>\n

      Zookeeper watch\u662f\u4e00\u79cd\u76d1\u542c\u901a\u77e5\u673a\u5236\u3002Zookeeper\u6240\u6709\u7684\u8bfb\u64cd\u4f5cgetData(), getChildren()\u548c exists()\u90fd\u53ef\u4ee5\u8bbe\u7f6e\u76d1\u89c6(watch)\uff0c\u76d1\u89c6\u4e8b\u4ef6\u53ef\u4ee5\u7406\u89e3\u4e3a\u4e00\u6b21\u6027\u7684\u89e6\u53d1\u5668<\/p>\n

      \u5b98\u65b9\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n

      a watch event is one-time trigger, sent to the client that set the watch, whichoccurs when the data for which the watch was set changes\u3002<\/p>\n

      Watch\u7684\u4e09\u4e2a\u5173\u952e\u70b9\uff1a<\/p>\n

      (\u4e00\u6b21\u6027\u89e6\u53d1)One-time trigger<\/strong><\/strong><\/div>\n

      \u5f53\u8bbe\u7f6e\u76d1\u89c6\u7684\u6570\u636e\u53d1\u751f\u6539\u53d8\u65f6\uff0c\u8be5\u76d1\u89c6\u4e8b\u4ef6\u4f1a\u88ab\u53d1\u9001\u5230\u5ba2\u6237\u7aef\uff0c\u4f8b\u5982\uff0c\u5982\u679c\u5ba2\u6237\u7aef\u8c03\u7528\u4e86getData(\"\/znode1\", true) \u5e76\u4e14\u7a0d\u540e \/znode1 \u8282\u70b9\u4e0a\u7684\u6570\u636e\u53d1\u751f\u4e86\u6539\u53d8\u6216\u8005\u88ab\u5220\u9664\u4e86\uff0c\u5ba2\u6237\u7aef\u5c06\u4f1a\u83b7\u53d6\u5230 \/znode1 \u53d1\u751f\u53d8\u5316\u7684\u76d1\u89c6\u4e8b\u4ef6\uff0c\u800c\u5982\u679c \/znode1 \u518d\u4e00\u6b21\u53d1\u751f\u4e86\u53d8\u5316\uff0c\u9664\u975e\u5ba2\u6237\u7aef\u518d\u6b21\u5bf9\/znode1 \u8bbe\u7f6e\u76d1\u89c6\uff0c\u5426\u5219\u5ba2\u6237\u7aef\u4e0d\u4f1a\u6536\u5230\u4e8b\u4ef6\u901a\u77e5\u3002<\/p>\n

      (\u53d1\u9001\u81f3\u5ba2\u6237\u7aef)Sent to the client<\/strong><\/strong><\/div>\n

      Zookeeper\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u7aef\u662f\u901a\u8fc7 socket \u8fdb\u884c\u901a\u4fe1\u7684\uff0c\u7531\u4e8e\u7f51\u7edc\u5b58\u5728\u6545\u969c\uff0c\u6240\u4ee5\u76d1\u89c6\u4e8b\u4ef6\u5f88\u6709\u53ef\u80fd\u4e0d\u4f1a\u6210\u529f\u5730\u5230\u8fbe\u5ba2\u6237\u7aef\uff0c\u76d1\u89c6\u4e8b\u4ef6\u662f\u5f02\u6b65\u53d1\u9001\u81f3\u76d1\u89c6\u8005\u7684\uff0cZookeeper \u672c\u8eab\u63d0\u4f9b\u4e86\u987a\u5e8f\u4fdd\u8bc1(ordering guarantee)\uff1a\u5373\u5ba2\u6237\u7aef\u53ea\u6709\u9996\u5148\u770b\u5230\u4e86\u76d1\u89c6\u4e8b\u4ef6\u540e\uff0c\u624d\u4f1a\u611f\u77e5\u5230\u5b83\u6240\u8bbe\u7f6e\u76d1\u89c6\u7684znode\u53d1\u751f\u4e86\u53d8\u5316(a client will never see a change for which it has set a watch until it first sees the watch event)\u3002<\/p>\n

      \u7f51\u7edc\u5ef6\u8fdf\u6216\u8005\u5176\u4ed6\u56e0\u7d20\u53ef\u80fd\u5bfc\u81f4\u4e0d\u540c\u7684\u5ba2\u6237\u7aef\u5728\u4e0d\u540c\u7684\u65f6\u523b\u611f\u77e5\u67d0\u4e00\u76d1\u89c6\u4e8b\u4ef6\uff0c\u4f46\u662f\u4e0d\u540c\u7684\u5ba2\u6237\u7aef\u6240\u770b\u5230\u7684\u4e00\u5207\u5177\u6709\u4e00\u81f4\u7684\u987a\u5e8f\u3002<\/p>\n

      (\u88ab\u8bbe\u7f6e watch \u7684\u6570\u636e)The data for which the watch was set<\/strong><\/strong><\/div>\n

      \u8fd9\u610f\u5473\u7740znode\u8282\u70b9\u672c\u8eab\u5177\u6709\u4e0d\u540c\u7684\u6539\u53d8\u65b9\u5f0f\u3002\u4f60\u4e5f\u53ef\u4ee5\u60f3\u8c61 Zookeeper \u7ef4\u62a4\u4e86\u4e24\u6761\u76d1\u89c6\u94fe\u8868\uff1a\u6570\u636e\u76d1\u89c6\u548c\u5b50\u8282\u70b9\u76d1\u89c6(data watches and child watches) getData() \u548cexists()\u8bbe\u7f6e\u6570\u636e\u76d1\u89c6\uff0cgetChildren()\u8bbe\u7f6e\u5b50\u8282\u70b9\u76d1\u89c6\u3002\u6216\u8005\u4f60\u4e5f\u53ef\u4ee5\u60f3\u8c61 Zookeeper \u8bbe\u7f6e\u7684\u4e0d\u540c\u76d1\u89c6\u8fd4\u56de\u4e0d\u540c\u7684\u6570\u636e\uff0cgetData() \u548c exists() \u8fd4\u56deznode\u8282\u70b9\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u800cgetChildren() \u8fd4\u56de\u5b50\u8282\u70b9\u5217\u8868\u3002<\/p>\n

      \u56e0\u6b64\uff0csetData() \u4f1a\u89e6\u53d1\u8bbe\u7f6e\u5728\u67d0\u4e00\u8282\u70b9\u4e0a\u6240\u8bbe\u7f6e\u7684\u6570\u636e\u76d1\u89c6(\u5047\u5b9a\u6570\u636e\u8bbe\u7f6e\u6210\u529f)\uff0c\u800c\u4e00\u6b21\u6210\u529f\u7684create() \u64cd\u4f5c\u5219\u4f1a\u51fa\u53d1\u5f53\u524d\u8282\u70b9\u4e0a\u6240\u8bbe\u7f6e\u7684\u6570\u636e\u76d1\u89c6\u4ee5\u53ca\u7236\u8282\u70b9\u7684\u5b50\u8282\u70b9\u76d1\u89c6\u3002\u4e00\u6b21\u6210\u529f\u7684 delete\u64cd\u4f5c\u5c06\u4f1a\u89e6\u53d1\u5f53\u524d\u8282\u70b9\u7684\u6570\u636e\u76d1\u89c6\u548c\u5b50\u8282\u70b9\u76d1\u89c6\u4e8b\u4ef6\uff0c\u540c\u65f6\u4e5f\u4f1a\u89e6\u53d1\u8be5\u8282\u70b9\u7236\u8282\u70b9\u7684child watch\u3002<\/p>\n

      Zookeeper \u4e2d\u7684\u76d1\u89c6\u662f\u8f7b\u91cf\u7ea7\u7684\uff0c\u56e0\u6b64\u5bb9\u6613\u8bbe\u7f6e\u3001\u7ef4\u62a4\u548c\u5206\u53d1\u3002\u5f53\u5ba2\u6237\u7aef\u4e0e Zookeeper \u670d\u52a1\u5668\u5931\u53bb\u8054\u7cfb\u65f6\uff0c\u5ba2\u6237\u7aef\u5e76\u4e0d\u4f1a\u6536\u5230\u76d1\u89c6\u4e8b\u4ef6\u7684\u901a\u77e5\uff0c\u53ea\u6709\u5f53\u5ba2\u6237\u7aef\u91cd\u65b0\u8fde\u63a5\u540e\uff0c\u82e5\u5728\u5fc5\u8981\u7684\u60c5\u51b5\u4e0b\uff0c\u4ee5\u524d\u6ce8\u518c\u7684\u76d1\u89c6\u4f1a\u91cd\u65b0\u88ab\u6ce8\u518c\u5e76\u89e6\u53d1\uff0c\u5bf9\u4e8e\u5f00\u53d1\u4eba\u5458\u6765\u8bf4\u8fd9\u901a\u5e38\u662f\u900f\u660e\u7684\u3002<\/p>\n

      \u53ea\u6709\u4e00\u79cd\u60c5\u51b5\u4f1a\u5bfc\u81f4\u76d1\u89c6\u4e8b\u4ef6\u7684\u4e22\u5931\uff0c\u5373\uff1a\u901a\u8fc7exists()\u8bbe\u7f6e\u4e86\u67d0\u4e2aznode\u8282\u70b9\u7684\u76d1\u89c6\uff0c\u4f46\u662f\u5982\u679c\u67d0\u4e2a\u5ba2\u6237\u7aef\u5728\u6b64znode\u8282\u70b9\u88ab\u521b\u5efa\u548c\u5220\u9664\u7684\u65f6\u95f4\u95f4\u9694\u5185\u4e0ezookeeper\u670d\u52a1\u5668\u5931\u53bb\u4e86\u8054\u7cfb\uff0c\u8be5\u5ba2\u6237\u7aef\u5373\u4f7f\u7a0d\u540e\u91cd\u65b0\u8fde\u63a5 zookeeper\u670d\u52a1\u5668\u540e\u4e5f\u5f97\u4e0d\u5230\u4e8b\u4ef6\u901a\u77e5\u3002<\/p>\n

      Consistency Guarantees<\/strong><\/strong><\/div>\n

      Zookeeper\u662f\u4e00\u4e2a\u9ad8\u6548\u7684\u3001\u53ef\u6269\u5c55\u7684\u670d\u52a1\uff0cread\u548cwrite\u64cd\u4f5c\u90fd\u88ab\u8bbe\u8ba1\u4e3a\u5feb\u901f\u7684\uff0cread\u6bd4write\u64cd\u4f5c\u66f4\u5feb\u3002<\/p>\n

        \n
      • \u987a\u5e8f\u4e00\u81f4\u6027(Sequential Consistency)\uff1a\u4ece\u4e00\u4e2a\u5ba2\u6237\u7aef\u6765\u7684\u66f4\u65b0\u8bf7\u6c42\u4f1a\u88ab\u987a\u5e8f\u6267\u884c\u3002<\/li>\n
      • \u539f\u5b50\u6027(Atomicity)\uff1a\u66f4\u65b0\u8981\u4e48\u6210\u529f\u8981\u4e48\u5931\u8d25\uff0c\u6ca1\u6709\u90e8\u5206\u6210\u529f\u7684\u60c5\u51b5\u3002<\/li>\n
      • \u552f\u4e00\u7684\u7cfb\u7edf\u955c\u50cf(Single System Image)\uff1a\u65e0\u8bba\u5ba2\u6237\u7aef\u8fde\u63a5\u5230\u54ea\u4e2aServer\uff0c\u770b\u5230\u7cfb\u7edf\u955c\u50cf\u662f\u4e00\u81f4\u7684\u3002<\/li>\n
      • \u53ef\u9760\u6027(Reliability)\uff1a\u66f4\u65b0\u4e00\u65e6\u6709\u6548\uff0c\u6301\u7eed\u6709\u6548\uff0c\u76f4\u5230\u88ab\u8986\u76d6\u3002<\/li>\n
      • \u65f6\u95f4\u7ebf(Timeliness)\uff1a\u4fdd\u8bc1\u5728\u4e00\u5b9a\u7684\u65f6\u95f4\u5185\u5404\u4e2a\u5ba2\u6237\u7aef\u770b\u5230\u7684\u7cfb\u7edf\u4fe1\u606f\u662f\u4e00\u81f4\u7684\u3002<\/li>\n<\/ul>\n
        ZooKeeper\u7684\u5de5\u4f5c\u539f\u7406<\/strong><\/strong><\/div>\n

        \u5728zookeeper\u7684\u96c6\u7fa4\u4e2d\uff0c\u5404\u4e2a\u8282\u70b9\u5171\u6709\u4e0b\u97623\u79cd\u89d2\u8272\u548c4\u79cd\u72b6\u6001\uff1a<\/p>\n

          \n
        • \u89d2\u8272\uff1aleader,follower,observer<\/li>\n
        • \u72b6\u6001\uff1aleading,following,observing,looking<\/li>\n<\/ul>\n

          Zookeeper\u7684\u6838\u5fc3\u662f\u539f\u5b50\u5e7f\u64ad\uff0c\u8fd9\u4e2a\u673a\u5236\u4fdd\u8bc1\u4e86\u5404\u4e2aServer\u4e4b\u95f4\u7684\u540c\u6b65\u3002\u5b9e\u73b0\u8fd9\u4e2a\u673a\u5236\u7684\u534f\u8bae\u53eb\u505aZab\u534f\u8bae(ZooKeeper Atomic Broadcast protocol)\u3002Zab\u534f\u8bae\u6709\u4e24\u79cd\u6a21\u5f0f\uff0c\u5b83\u4eec\u5206\u522b\u662f\u6062\u590d\u6a21\u5f0f(Recovery\u9009\u4e3b)\u548c\u5e7f\u64ad\u6a21\u5f0f(Broadcast\u540c\u6b65)\u3002<\/p>\n

          \u5f53\u670d\u52a1\u542f\u52a8\u6216\u8005\u5728\u9886\u5bfc\u8005\u5d29\u6e83\u540e\uff0cZab\u5c31\u8fdb\u5165\u4e86\u6062\u590d\u6a21\u5f0f\uff0c\u5f53\u9886\u5bfc\u8005\u88ab\u9009\u4e3e\u51fa\u6765\uff0c\u4e14\u5927\u591a\u6570Server\u5b8c\u6210\u4e86\u548cleader\u7684\u72b6\u6001\u540c\u6b65\u4ee5\u540e\uff0c\u6062\u590d\u6a21\u5f0f\u5c31\u7ed3\u675f\u4e86\u3002\u72b6\u6001\u540c\u6b65\u4fdd\u8bc1\u4e86leader\u548cServer\u5177\u6709\u76f8\u540c\u7684\u7cfb\u7edf\u72b6\u6001\u3002<\/p>\n

          \u4e3a\u4e86\u4fdd\u8bc1\u4e8b\u52a1\u7684\u987a\u5e8f\u4e00\u81f4\u6027\uff0czookeeper\u91c7\u7528\u4e86\u9012\u589e\u7684\u4e8b\u52a1id\u53f7(zxid)\u6765\u6807\u8bc6\u4e8b\u52a1\u3002\u6240\u6709\u7684\u63d0\u8bae(proposal)\u90fd\u5728\u88ab\u63d0\u51fa\u7684\u65f6\u5019\u52a0\u4e0a\u4e86zxid\u3002<\/p>\n

          \u5b9e\u73b0\u4e2dzxid\u662f\u4e00\u4e2a64\u4f4d\u7684\u6570\u5b57\uff0c\u5b83\u9ad832\u4f4d\u662fepoch\u7528\u6765\u6807\u8bc6leader\u5173\u7cfb\u662f\u5426\u6539\u53d8\uff0c\u6bcf\u6b21\u4e00\u4e2aleader\u88ab\u9009\u51fa\u6765\uff0c\u5b83\u90fd\u4f1a\u6709\u4e00\u4e2a\u65b0\u7684epoch\uff0c\u6807\u8bc6\u5f53\u524d\u5c5e\u4e8e\u90a3\u4e2aleader\u7684\u7edf\u6cbb\u65f6\u671f\u3002\u4f4e32\u4f4d\u7528\u4e8e\u9012\u589e\u8ba1\u6570\u3002<\/p>\n

          \u6bcf\u4e2aServer\u5728\u5de5\u4f5c\u8fc7\u7a0b\u4e2d\u67094\u79cd\u72b6\u6001\uff1a<\/p>\n

            \n
          • LOOKING\uff1a\u5f53\u524dServer\u4e0d\u77e5\u9053leader\u662f\u8c01\uff0c\u6b63\u5728\u641c\u5bfb\u3002<\/li>\n
          • LEADING\uff1a\u5f53\u524dServer\u5373\u4e3a\u9009\u4e3e\u51fa\u6765\u7684leader\u3002<\/li>\n
          • FOLLOWING\uff1aleader\u5df2\u7ecf\u9009\u4e3e\u51fa\u6765\uff0c\u5f53\u524dServer\u4e0e\u4e4b\u540c\u6b65\u3002<\/li>\n
          • OBSERVING\uff1aobserver\u7684\u884c\u4e3a\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u4e0efollower\u5b8c\u5168\u4e00\u81f4\uff0c\u4f46\u662f\u4ed6\u4eec\u4e0d\u53c2\u52a0\u9009\u4e3e\u548c\u6295\u7968\uff0c\u800c\u4ec5\u4ec5\u63a5\u53d7(observing)\u9009\u4e3e\u548c\u6295\u7968\u7684\u7ed3\u679c\u3002<\/li>\n<\/ul>\n
            Leader Election<\/strong><\/strong><\/div>\n

            \u5f53leader\u5d29\u6e83\u6216\u8005leader\u5931\u53bb\u5927\u591a\u6570\u7684follower\uff0c\u8fd9\u65f6\u5019zk\u8fdb\u5165\u6062\u590d\u6a21\u5f0f\uff0c\u6062\u590d\u6a21\u5f0f\u9700\u8981\u91cd\u65b0\u9009\u4e3e\u51fa\u4e00\u4e2a\u65b0\u7684leader\uff0c\u8ba9\u6240\u6709\u7684Server\u90fd\u6062\u590d\u5230\u4e00\u4e2a\u6b63\u786e\u7684\u72b6\u6001\u3002Zk\u7684\u9009\u4e3e\u7b97\u6cd5\u6709\u4e24\u79cd\uff1a\u4e00\u79cd\u662f\u57fa\u4e8ebasic paxos\u5b9e\u73b0\u7684\uff0c\u53e6\u5916\u4e00\u79cd\u662f\u57fa\u4e8efast paxos\u7b97\u6cd5\u5b9e\u73b0\u7684\u3002\u7cfb\u7edf\u9ed8\u8ba4\u7684\u9009\u4e3e\u7b97\u6cd5\u4e3afast paxos\u3002\u5148\u4ecb\u7ecdbasic paxos\u6d41\u7a0b\uff1a<\/p>\n

              \n
            1. \u9009\u4e3e\u7ebf\u7a0b\u7531\u5f53\u524dServer\u53d1\u8d77\u9009\u4e3e\u7684\u7ebf\u7a0b\u62c5\u4efb\uff0c\u5176\u4e3b\u8981\u529f\u80fd\u662f\u5bf9\u6295\u7968\u7ed3\u679c\u8fdb\u884c\u7edf\u8ba1\uff0c\u5e76\u9009\u51fa\u63a8\u8350\u7684Server;<\/li>\n
            2. \u9009\u4e3e\u7ebf\u7a0b\u9996\u5148\u5411\u6240\u6709Server\u53d1\u8d77\u4e00\u6b21\u8be2\u95ee(\u5305\u62ec\u81ea\u5df1);<\/li>\n
            3. \u9009\u4e3e\u7ebf\u7a0b\u6536\u5230\u56de\u590d\u540e\uff0c\u9a8c\u8bc1\u662f\u5426\u662f\u81ea\u5df1\u53d1\u8d77\u7684\u8be2\u95ee(\u9a8c\u8bc1zxid\u662f\u5426\u4e00\u81f4)\uff0c\u7136\u540e\u83b7\u53d6\u5bf9\u65b9\u7684id(myid)\uff0c\u5e76\u5b58\u50a8\u5230\u5f53\u524d\u8be2\u95ee\u5bf9\u8c61\u5217\u8868\u4e2d\uff0c\u6700\u540e\u83b7\u53d6\u5bf9\u65b9\u63d0\u8bae\u7684leader\u76f8\u5173\u4fe1\u606f(id,zxid)\uff0c\u5e76\u5c06\u8fd9\u4e9b\u4fe1\u606f\u5b58\u50a8\u5230\u5f53\u6b21\u9009\u4e3e\u7684\u6295\u7968\u8bb0\u5f55\u8868\u4e2d;<\/li>\n
            4. \u6536\u5230\u6240\u6709Server\u56de\u590d\u4ee5\u540e\uff0c\u5c31\u8ba1\u7b97\u51fazxid\u6700\u5927\u7684\u90a3\u4e2aServer\uff0c\u5e76\u5c06\u8fd9\u4e2aServer\u76f8\u5173\u4fe1\u606f\u8bbe\u7f6e\u6210\u4e0b\u4e00\u6b21\u8981\u6295\u7968\u7684Server;<\/li>\n
            5. \u7ebf\u7a0b\u5c06\u5f53\u524dzxid\u6700\u5927\u7684Server\u8bbe\u7f6e\u4e3a\u5f53\u524dServer\u8981\u63a8\u8350\u7684Leader\uff0c\u5982\u679c\u6b64\u65f6\u83b7\u80dc\u7684Server\u83b7\u5f97n\/2 + 1\u7684Server\u7968\u6570\uff0c\u8bbe\u7f6e\u5f53\u524d\u63a8\u8350\u7684leader\u4e3a\u83b7\u80dc\u7684Server\uff0c\u5c06\u6839\u636e\u83b7\u80dc\u7684Server\u76f8\u5173\u4fe1\u606f\u8bbe\u7f6e\u81ea\u5df1\u7684\u72b6\u6001\uff0c\u5426\u5219\uff0c\u7ee7\u7eed\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u76f4\u5230leader\u88ab\u9009\u4e3e\u51fa\u6765\u3002<\/li>\n<\/ol>\n

              \u901a\u8fc7\u6d41\u7a0b\u5206\u6790\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\uff1a\u8981\u4f7fLeader\u83b7\u5f97\u591a\u6570Server\u7684\u652f\u6301\uff0c\u5219Server\u603b\u6570\u5fc5\u987b\u662f\u5947\u65702n+1\uff0c\u4e14\u5b58\u6d3b\u7684Server\u7684\u6570\u76ee\u4e0d\u5f97\u5c11\u4e8en+1.<\/p>\n

              \u6bcf\u4e2aServer\u542f\u52a8\u540e\u90fd\u4f1a\u91cd\u590d\u4ee5\u4e0a\u6d41\u7a0b\u3002\u5728\u6062\u590d\u6a21\u5f0f\u4e0b\uff0c\u5982\u679c\u662f\u521a\u4ece\u5d29\u6e83\u72b6\u6001\u6062\u590d\u7684\u6216\u8005\u521a\u542f\u52a8\u7684server\u8fd8\u4f1a\u4ece\u78c1\u76d8\u5feb\u7167\u4e2d\u6062\u590d\u6570\u636e\u548c\u4f1a\u8bdd\u4fe1\u606f\uff0czk\u4f1a\u8bb0\u5f55\u4e8b\u52a1\u65e5\u5fd7\u5e76\u5b9a\u671f\u8fdb\u884c\u5feb\u7167\uff0c\u65b9\u4fbf\u5728\u6062\u590d\u65f6\u8fdb\u884c\u72b6\u6001\u6062\u590d\u3002<\/p>\n

              fast paxos\u6d41\u7a0b\u662f\u5728\u9009\u4e3e\u8fc7\u7a0b\u4e2d\uff0c\u67d0Server\u9996\u5148\u5411\u6240\u6709Server\u63d0\u8bae\u81ea\u5df1\u8981\u6210\u4e3aleader\uff0c\u5f53\u5176\u5b83Server\u6536\u5230\u63d0\u8bae\u4ee5\u540e\uff0c\u89e3\u51b3epoch\u548czxid\u7684\u51b2\u7a81\uff0c\u5e76\u63a5\u53d7\u5bf9\u65b9\u7684\u63d0\u8bae\uff0c\u7136\u540e\u5411\u5bf9\u65b9\u53d1\u9001\u63a5\u53d7\u63d0\u8bae\u5b8c\u6210\u7684\u6d88\u606f\uff0c\u91cd\u590d\u8fd9\u4e2a\u6d41\u7a0b\uff0c\u6700\u540e\u4e00\u5b9a\u80fd\u9009\u4e3e\u51faLeader\u3002<\/p>\n

              Leader\u5de5\u4f5c\u6d41\u7a0b<\/strong><\/strong><\/div>\n

              Leader\u4e3b\u8981\u6709\u4e09\u4e2a\u529f\u80fd\uff1a<\/p>\n

                \n
              1. \u6062\u590d\u6570\u636e;<\/li>\n
              2. \u7ef4\u6301\u4e0efollower\u7684\u5fc3\u8df3\uff0c\u63a5\u6536follower\u8bf7\u6c42\u5e76\u5224\u65adfollower\u7684\u8bf7\u6c42\u6d88\u606f\u7c7b\u578b;<\/li>\n
              3. follower\u7684\u6d88\u606f\u7c7b\u578b\u4e3b\u8981\u6709PING\u6d88\u606f\u3001REQUEST\u6d88\u606f\u3001ACK\u6d88\u606f\u3001REVALIDATE\u6d88\u606f\uff0c\u6839\u636e\u4e0d\u540c\u7684\u6d88\u606f\u7c7b\u578b\uff0c\u8fdb\u884c\u4e0d\u540c\u7684\u5904\u7406\u3002<\/li>\n<\/ol>\n

                \u8bf4\u660e\uff1a<\/p>\n

                PING\u6d88\u606f\u662f\u6307follower\u7684\u5fc3\u8df3\u4fe1\u606f;REQUEST\u6d88\u606f\u662ffollower\u53d1\u9001\u7684\u63d0\u8bae\u4fe1\u606f\uff0c\u5305\u62ec\u5199\u8bf7\u6c42\u53ca\u540c\u6b65\u8bf7\u6c42;<\/p>\n

                ACK\u6d88\u606f\u662ffollower\u7684\u5bf9\u63d0\u8bae\u7684\u56de\u590d\uff0c\u8d85\u8fc7\u534a\u6570\u7684follower\u901a\u8fc7\uff0c\u5219commit\u8be5\u63d0\u8bae;<\/p>\n

                REVALIDATE\u6d88\u606f\u662f\u7528\u6765\u5ef6\u957fSESSION\u6709\u6548\u65f6\u95f4\u3002<\/p>\n

                Follower\u5de5\u4f5c\u6d41\u7a0b<\/strong><\/strong><\/div>\n

                Follower\u4e3b\u8981\u6709\u56db\u4e2a\u529f\u80fd\uff1a<\/p>\n

                  \n
                1. \u5411Leader\u53d1\u9001\u8bf7\u6c42(PING\u6d88\u606f\u3001REQUEST\u6d88\u606f\u3001ACK\u6d88\u606f\u3001REVALIDATE\u6d88\u606f);<\/li>\n
                2. \u63a5\u6536Leader\u6d88\u606f\u5e76\u8fdb\u884c\u5904\u7406;<\/li>\n
                3. \u63a5\u6536Client\u7684\u8bf7\u6c42\uff0c\u5982\u679c\u4e3a\u5199\u8bf7\u6c42\uff0c\u53d1\u9001\u7ed9Leader\u8fdb\u884c\u6295\u7968;<\/li>\n
                4. \u8fd4\u56deClient\u7ed3\u679c\u3002<\/li>\n<\/ol>\n

                  Follower\u7684\u6d88\u606f\u5faa\u73af\u5904\u7406\u5982\u4e0b\u51e0\u79cd\u6765\u81eaLeader\u7684\u6d88\u606f\uff1a<\/p>\n

                    \n
                  1. PING\u6d88\u606f\uff1a\u5fc3\u8df3\u6d88\u606f<\/li>\n
                  2. PROPOSAL\u6d88\u606f\uff1aLeader\u53d1\u8d77\u7684\u63d0\u6848\uff0c\u8981\u6c42Follower\u6295\u7968<\/li>\n
                  3. COMMIT\u6d88\u606f\uff1a\u670d\u52a1\u5668\u7aef\u6700\u65b0\u4e00\u6b21\u63d0\u6848\u7684\u4fe1\u606f<\/li>\n
                  4. UPTODATE\u6d88\u606f\uff1a\u8868\u660e\u540c\u6b65\u5b8c\u6210<\/li>\n
                  5. REVALIDATE\u6d88\u606f\uff1a\u6839\u636eLeader\u7684REVALIDATE\u7ed3\u679c\uff0c\u5173\u95ed\u5f85revalidate\u7684session\u8fd8\u662f\u5141\u8bb8\u5176\u63a5\u53d7\u6d88\u606f<\/li>\n
                  6. SYNC\u6d88\u606f\uff1a\u8fd4\u56deSYNC\u7ed3\u679c\u5230\u5ba2\u6237\u7aef\uff0c\u8fd9\u4e2a\u6d88\u606f\u6700\u521d\u7531\u5ba2\u6237\u7aef\u53d1\u8d77\uff0c\u7528\u6765\u5f3a\u5236\u5f97\u5230\u6700\u65b0\u7684\u66f4\u65b0\u3002<\/li>\n<\/ol>\n
                    Zab: Broadcasting State Updates<\/strong><\/strong><\/div>\n

                    Zookeeper Server\u63a5\u6536\u5230\u4e00\u6b21request\uff0c\u5982\u679c\u662ffollower\uff0c\u4f1a\u8f6c\u53d1\u7ed9leader\uff0cLeader\u6267\u884c\u8bf7\u6c42\u5e76\u901a\u8fc7Transaction\u7684\u5f62\u5f0f\u5e7f\u64ad\u8fd9\u6b21\u6267\u884c\u3002Zookeeper\u96c6\u7fa4\u5982\u4f55\u51b3\u5b9a\u4e00\u4e2aTransaction\u662f\u5426\u88abcommit\u6267\u884c?\u901a\u8fc7\u201c\u4e24\u6bb5\u63d0\u4ea4\u534f\u8bae\u201d(a two-phase commit)\uff1a<\/p>\n

                      \n
                    • Leader\u7ed9\u6240\u6709\u7684follower\u53d1\u9001\u4e00\u4e2aPROPOSAL\u6d88\u606f\u3002<\/li>\n
                    • \u4e00\u4e2afollower\u63a5\u6536\u5230\u8fd9\u6b21PROPOSAL\u6d88\u606f\uff0c\u5199\u5230\u78c1\u76d8\uff0c\u53d1\u9001\u7ed9leader\u4e00\u4e2aACK\u6d88\u606f\uff0c\u544a\u77e5\u5df2\u7ecf\u6536\u5230\u3002<\/li>\n
                    • \u5f53Leader\u6536\u5230\u6cd5\u5b9a\u4eba\u6570(quorum)\u7684follower\u7684ACK\u65f6\u5019\uff0c\u53d1\u9001commit\u6d88\u606f\u6267\u884c\u3002<\/li>\n<\/ul>\n

                      Zab\u534f\u8bae\u4fdd\u8bc1\uff1a<\/p>\n

                        \n
                      • \u5982\u679cleader\u4ee5T1\u548cT2\u7684\u987a\u5e8f\u5e7f\u64ad\uff0c\u90a3\u4e48\u6240\u6709\u7684Server\u5fc5\u987b\u5148\u6267\u884cT1\uff0c\u518d\u6267\u884cT2\u3002<\/li>\n
                      • \u5982\u679c\u4efb\u610f\u4e00\u4e2aServer\u4ee5T1\u3001T2\u7684\u987a\u5e8fcommit\u6267\u884c\uff0c\u5176\u4ed6\u6240\u6709\u7684Server\u4e5f\u5fc5\u987b\u4ee5T1\u3001T2\u7684\u987a\u5e8f\u6267\u884c\u3002<\/li>\n<\/ul>\n

                        \u201c\u4e24\u6bb5\u63d0\u4ea4\u534f\u8bae\u201d\u6700\u5927\u7684\u95ee\u9898\u662f\u5982\u679cLeader\u53d1\u9001\u4e86PROPOSAL\u6d88\u606f\u540ecrash\u6216\u6682\u65f6\u5931\u53bb\u8fde\u63a5\uff0c\u4f1a\u5bfc\u81f4\u6574\u4e2a\u96c6\u7fa4\u5904\u5728\u4e00\u79cd\u4e0d\u786e\u5b9a\u7684\u72b6\u6001(follower\u4e0d\u77e5\u9053\u8be5\u653e\u5f03\u8fd9\u6b21\u63d0\u4ea4\u8fd8\u662f\u6267\u884c\u63d0\u4ea4)\u3002Zookeeper\u8fd9\u65f6\u4f1a\u9009\u51fa\u65b0\u7684leader\uff0c\u8bf7\u6c42\u5904\u7406\u4e5f\u4f1a\u79fb\u5230\u65b0\u7684leader\u4e0a\uff0c\u4e0d\u540c\u7684leader\u7531\u4e0d\u540c\u7684epoch\u6807\u8bc6\u3002\u5207\u6362Leader\u65f6\uff0c\u9700\u8981\u89e3\u51b3\u4e0b\u9762\u4e24\u4e2a\u95ee\u9898\uff1a<\/p>\n

                        1. Never forget delivered messages<\/strong><\/strong><\/span><\/div>\n

                        Leader\u5728COMMIT\u6295\u9012\u5230\u4efb\u4f55\u4e00\u53f0follower\u4e4b\u524dcrash\uff0c\u53ea\u6709\u5b83\u81ea\u5df1commit\u4e86\u3002\u65b0Leader\u5fc5\u987b\u4fdd\u8bc1\u8fd9\u4e2a\u4e8b\u52a1\u4e5f\u5fc5\u987bcommit\u3002<\/p>\n

                        2. Let go of messages that are skipped<\/strong><\/strong><\/span><\/div>\n

                        Leader\u4ea7\u751f\u67d0\u4e2aproposal\uff0c\u4f46\u662f\u5728crash\u4e4b\u524d\uff0c\u6ca1\u6709follower\u770b\u5230\u8fd9\u4e2aproposal\u3002\u8be5server\u6062\u590d\u65f6\uff0c\u5fc5\u987b\u4e22\u5f03\u8fd9\u4e2aproposal\u3002<\/p>\n

                        Zookeeper\u4f1a\u5c3d\u91cf\u4fdd\u8bc1\u4e0d\u4f1a\u540c\u65f6\u67092\u4e2a\u6d3b\u52a8\u7684Leader\uff0c\u56e0\u4e3a2\u4e2a\u4e0d\u540c\u7684Leader\u4f1a\u5bfc\u81f4\u96c6\u7fa4\u5904\u5728\u4e00\u79cd\u4e0d\u4e00\u81f4\u7684\u72b6\u6001\uff0c\u6240\u4ee5Zab\u534f\u8bae\u540c\u65f6\u4fdd\u8bc1\uff1a<\/p>\n

                          \n
                        • \u5728\u65b0\u7684leader\u5e7f\u64adTransaction\u4e4b\u524d\uff0c\u5148\u524dLeader commit\u7684Transaction\u90fd\u4f1a\u5148\u6267\u884c\u3002<\/li>\n
                        • \u5728\u4efb\u610f\u65f6\u523b\uff0c\u90fd\u4e0d\u4f1a\u67092\u4e2aServer\u540c\u65f6\u6709\u6cd5\u5b9a\u4eba\u6570(quorum)\u7684\u652f\u6301\u8005\u3002<\/li>\n<\/ul>\n

                          \u8fd9\u91cc\u7684quorum\u662f\u4e00\u534a\u4ee5\u4e0a\u7684Server\u6570\u76ee\uff0c\u786e\u5207\u7684\u8bf4\u662f\u6709\u6295\u7968\u6743\u529b\u7684Server(\u4e0d\u5305\u62ecObserver)\u3002<\/p>\n

                          \u603b\u7ed3<\/strong><\/strong><\/div>\n

                          \u7b80\u5355\u4ecb\u7ecd\u4e86Zookeeper\u7684\u57fa\u672c\u539f\u7406\uff0c\u6570\u636e\u6a21\u578b\uff0cSession\uff0cWatch\u673a\u5236\uff0c\u4e00\u81f4\u6027\u4fdd\u8bc1\uff0cLeader Election\uff0cLeader\u548cFollower\u7684\u5de5\u4f5c\u6d41\u7a0b\u548cZab\u534f\u8bae\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

                          ZooKeeper\u662f\u4e00\u4e2a\u5f00\u653e\u6e90\u7801\u7684\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u534f\u8c03\u670d\u52a1\uff0c\u5b83\u5305\u542b\u4e00\u4e2a\u7b80\u5355\u7684\u539f\u8bed\u96c6\uff0c\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u57fa\u4e8e\u5b83\u5b9e\u73b0 […]<\/p>\n","protected":false},"author":1898,"featured_media":165733,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[474],"class_list":["post-165728","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-zookeeper"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/165728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=165728"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/165728\/revisions"}],"predecessor-version":[{"id":165736,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/165728\/revisions\/165736"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/165733"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=165728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=165728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=165728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}