[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"site-config":3,"primary-menu":6,"cat-zookeeper":85,"catposts-zookeeper":99,"post-detail-post-zk-watcher-831fbae2":208},{"config":4,"socialLinks":5},null,[],{"metadata":7,"spec":10,"menuItems":20},{"name":8,"creationTimestamp":9},"primary","2026-09-12T06:13:55.024154Z",{"displayName":11,"menuItems":12},"主菜单",[13,14,15,16,17,18,19],"88c3f10b-321c-4092-86a8-70db00251b74","menu-item-izrtmxer","c4c814d1-0c2c-456b-8c96-4864965fee94","menu-item-column","menu-item-tools","menu-item-zsxq","menu-item-ocrxlczu",[21,30,40,49,58,67,76],{"displayName":22,"metadata":23,"spec":25,"status":28,"children":29},"首页",{"name":13,"creationTimestamp":24},"2026-09-12T06:13:54.422830Z",{"displayName":22,"href":26,"priority":27,"menuName":8},"\u002F",0,{"displayName":22,"href":26},[],{"displayName":31,"metadata":32,"spec":34,"status":38,"children":39},"Java面试八股",{"name":14,"creationTimestamp":33},"2026-09-13T09:42:02.854891Z",{"displayName":31,"href":35,"target":36,"priority":37,"menuName":8},"\u002Fjava-interview","_self",1,{"displayName":31,"href":35},[],{"displayName":41,"metadata":42,"spec":44,"status":47,"children":48},"文章",{"name":15,"creationTimestamp":43},"2026-09-12T06:13:54.457307Z",{"displayName":41,"href":45,"priority":46,"menuName":8},"\u002Farchives",2,{"displayName":41,"href":45},[],{"displayName":50,"metadata":51,"spec":53,"status":56,"children":57},"项目实战",{"name":16,"creationTimestamp":52},"2026-09-14T00:35:08.138170Z",{"displayName":50,"href":54,"target":36,"priority":55,"menuName":8},"\u002Fcolumn",3,{"displayName":50,"href":54},[],{"displayName":59,"metadata":60,"spec":62,"status":65,"children":66},"在线工具",{"name":17,"creationTimestamp":61},"2026-09-14T00:35:08.171474Z",{"displayName":59,"href":63,"target":36,"priority":64,"menuName":8},"\u002Ftools",4,{"displayName":59,"href":63},[],{"displayName":68,"metadata":69,"spec":71,"status":74,"children":75},"知识星球",{"name":18,"creationTimestamp":70},"2026-09-14T00:35:08.199145Z",{"displayName":68,"href":72,"target":36,"priority":73,"menuName":8},"\u002Fzsxq",5,{"displayName":68,"href":72},[],{"displayName":77,"metadata":78,"spec":80,"status":83,"children":84},"特价云服务器",{"name":19,"creationTimestamp":79},"2026-09-25T15:30:59.201614Z",{"displayName":77,"href":81,"target":36,"priority":82,"menuName":8},"\u002Fserver",6,{"displayName":77,"href":81},[],{"metadata":86,"spec":91,"status":97,"postCount":73},{"name":87,"creationTimestamp":88,"labels":89},"zookeeper","2026-09-13T09:13:25.785846Z",{"haloweb.section":90},"interview",{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},"Zookeeper 面试题","","Zookeeper 面试题：数据节点、Watcher 机制、ZAB 协议与分布式锁选举实现。",11,false,{"permalink":98,"postCount":73,"visiblePostCount":73},"\u002Fcategories\u002Fzookeeper",[100,124,145,166,187],{"metadata":101,"spec":104,"status":113,"categories":118},{"name":102,"creationTimestamp":103},"post-zk-vs-nacos-9f45de84","2026-09-13T10:01:08.519766Z",{"title":105,"slug":106,"cover":93,"excerpt":107,"publishTime":109,"categories":110,"tags":111,"priority":27,"pinned":96,"deleted":96,"visible":112,"allowComment":108},"ZooKeeper 和 Nacos 的区别？","zk-vs-nacos",{"raw":93,"autoGenerate":108},true,"2026-09-13T10:01:08.716026Z",[87],[],"PUBLIC",{"permalink":114,"excerpt":115,"lastModifyTime":116,"phase":117},"\u002Farchives\u002Fzk-vs-nacos","一、对比 维度 ZooKeeper Nacos 一致性 CP（ZAB） 支持 CP\u002FAP 配置中心 需自行封装 原生支持，实时推送 服务发现 临时节点 临时\u002F持久实例 控制台 无官方 有 Web 控制台 语言 Java Java 二、选择 需要强一致、分布式协调（锁、选主）→ ZooKeeper。 ","2026-09-16T09:15:13.739294Z","PUBLISHED",[119],{"metadata":120,"spec":122,"status":123,"postCount":73},{"name":87,"creationTimestamp":88,"labels":121},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},{"permalink":98,"postCount":73,"visiblePostCount":73},{"metadata":125,"spec":128,"status":135,"categories":139},{"name":126,"creationTimestamp":127},"post-zk-watcher-831fbae2","2026-09-13T10:01:08.166056Z",{"title":129,"slug":130,"cover":93,"excerpt":131,"publishTime":132,"categories":133,"tags":134,"priority":27,"pinned":96,"deleted":96,"visible":112,"allowComment":108},"ZooKeeper 的 Watcher 机制？","zk-watcher",{"raw":93,"autoGenerate":108},"2026-09-13T10:01:08.357926Z",[87],[],{"permalink":136,"excerpt":137,"lastModifyTime":138,"phase":117},"\u002Farchives\u002Fzk-watcher","一、定义 客户端可以在 ZNode 上注册 Watcher，当节点状态变化时，服务端通知客户端，触发回调。 二、特性 一次性：Watcher 触发后失效，需重新注册。 轻量：只发送事件类型和路径，不发送数据。 异步：通知是异步发送的。 三、事件类型 NodeCreated：节点创建。 NodeDel","2026-09-16T09:15:14.749985Z",[140],{"metadata":141,"spec":143,"status":144,"postCount":73},{"name":87,"creationTimestamp":88,"labels":142},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},{"permalink":98,"postCount":73,"visiblePostCount":73},{"metadata":146,"spec":149,"status":156,"categories":160},{"name":147,"creationTimestamp":148},"post-zk-distributed-lock-fd097039","2026-09-13T10:01:07.954983Z",{"title":150,"slug":151,"cover":93,"excerpt":152,"publishTime":153,"categories":154,"tags":155,"priority":27,"pinned":96,"deleted":96,"visible":112,"allowComment":108},"ZooKeeper 实现分布式锁？","zk-distributed-lock",{"raw":93,"autoGenerate":108},"2026-09-13T10:01:08.004287Z",[87],[],{"permalink":157,"excerpt":158,"lastModifyTime":159,"phase":117},"\u002Farchives\u002Fzk-distributed-lock","一、原理 利用临时顺序节点 + Watcher。 二、加锁流程 在 \u002Flock 节点下创建临时顺序节点 \u002Flock\u002Fseq-000000001。 获取 \u002Flock 下所有子节点，判断自己是否最小。 是最小 → 获取锁成功。 不是最小 → 监听前一个节点的删除事件，阻塞等待。 三、释放锁 主动删除自己","2026-09-16T09:14:42.588286Z",[161],{"metadata":162,"spec":164,"status":165,"postCount":73},{"name":87,"creationTimestamp":88,"labels":163},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},{"permalink":98,"postCount":73,"visiblePostCount":73},{"metadata":167,"spec":170,"status":177,"categories":181},{"name":168,"creationTimestamp":169},"post-zk-consistency-c28d9cc9","2026-09-13T10:01:07.760506Z",{"title":171,"slug":172,"cover":93,"excerpt":173,"publishTime":174,"categories":175,"tags":176,"priority":27,"pinned":96,"deleted":96,"visible":112,"allowComment":108},"ZooKeeper 如何保证一致性？","zk-consistency",{"raw":93,"autoGenerate":108},"2026-09-13T10:01:07.825110Z",[87],[],{"permalink":178,"excerpt":179,"lastModifyTime":180,"phase":117},"\u002Farchives\u002Fzk-consistency","一、ZAB 协议 ZooKeeper Atomic Broadcast，类似 Paxos。 二、角色 Leader：处理写请求，发起投票。 Follower：处理读请求，参与投票。 Observer：只读，不参与投票，扩展读能力。 三、写流程 客户端写请求发给任意节点，非 Leader 转发给 Le","2026-09-16T09:15:13.291445Z",[182],{"metadata":183,"spec":185,"status":186,"postCount":73},{"name":87,"creationTimestamp":88,"labels":184},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},{"permalink":98,"postCount":73,"visiblePostCount":73},{"metadata":188,"spec":191,"status":198,"categories":202},{"name":189,"creationTimestamp":190},"post-zk-data-model-a6c49102","2026-09-13T10:01:07.565180Z",{"title":192,"slug":193,"cover":93,"excerpt":194,"publishTime":195,"categories":196,"tags":197,"priority":27,"pinned":96,"deleted":96,"visible":112,"allowComment":108},"ZooKeeper 的数据模型？","zk-data-model",{"raw":93,"autoGenerate":108},"2026-09-13T10:01:07.617887Z",[87],[],{"permalink":199,"excerpt":200,"lastModifyTime":201,"phase":117},"\u002Farchives\u002Fzk-data-model","一、ZNode ZooKeeper 数据以树形结构存储，每个节点叫 ZNode，路径用 \u002F 分隔，如 \u002Fa\u002Fb\u002Fc。 二、节点类型 持久节点：创建后一直存在，直到删除。 临时节点：创建者会话断开自动删除。 持久顺序节点：持久 + 单调递增序号。 临时顺序节点：临时 + 单调递增序号，常用于分布式锁。","2026-09-16T09:15:14.325893Z",[203],{"metadata":204,"spec":206,"status":207,"postCount":73},{"name":87,"creationTimestamp":88,"labels":205},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},{"permalink":98,"postCount":73,"visiblePostCount":73},{"metadata":209,"spec":210,"status":214,"categories":215,"content":221},{"name":126,"creationTimestamp":127},{"title":129,"slug":130,"cover":93,"excerpt":211,"publishTime":132,"categories":212,"tags":213,"priority":27,"pinned":96,"deleted":96,"visible":112,"allowComment":108},{"raw":93,"autoGenerate":108},[87],[],{"permalink":136,"excerpt":137,"lastModifyTime":138,"phase":117},[216],{"metadata":217,"spec":219,"status":220,"postCount":73},{"name":87,"creationTimestamp":88,"labels":218},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},{"permalink":98,"postCount":73,"visiblePostCount":73},{"content":222,"raw":222},"\u003Ch2>一、定义\u003C\u002Fh2>\n\u003Cp>客户端可以在 ZNode 上注册 Watcher，当节点状态变化时，服务端通知客户端，触发回调。\u003C\u002Fp>\n\u003Ch2>二、特性\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>\u003Cstrong>一次性\u003C\u002Fstrong>：Watcher 触发后失效，需重新注册。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>轻量\u003C\u002Fstrong>：只发送事件类型和路径，不发送数据。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>异步\u003C\u002Fstrong>：通知是异步发送的。\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2>三、事件类型\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>NodeCreated：节点创建。\u003C\u002Fli>\n\u003Cli>NodeDeleted：节点删除。\u003C\u002Fli>\n\u003Cli>NodeDataChanged：节点数据变化。\u003C\u002Fli>\n\u003Cli>NodeChildrenChanged：子节点变化。\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2>四、应用\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>配置中心：监听配置节点，数据变化自动更新。\u003C\u002Fli>\n\u003Cli>服务发现：监听服务节点列表变化。\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2>五、Curator 客户端\u003C\u002Fh2>\n\u003Cp>Apache Curator 封装了 Watcher 的一次性问题，提供 NodeCache、PathChildrenCache 等持续监听。\u003C\u002Fp>"]