• 面试无忧之Zookeeper总结心得


                    <p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 128pt;background-color: rgb(255, 255, 255);"><span style="font-family: 等线;font-size: 1.333rem;"></span></p><h2 style="margin-top: 1.25rem;margin-bottom: 0.625rem;break-after: avoid;text-align: justify;line-height: 41.52px;font-size: 1.5rem;font-variant-numeric: normal;font-variant-east-asian: normal;white-space: normal;widows: 1;"><strong><span style="font-family: 宋体;font-size: 1.333rem;"><span style="font-family:宋体;">为什么需要分布式系统</span></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;"><o:p></o:p></span></strong></h2><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 42pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: -21pt;"><span style="font-family: Wingdings;font-size: 1.167rem;">l&nbsp;</span><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">单机系统已经无法满足业务需要</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 42pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: -21pt;"><span style="font-family: Wingdings;font-size: 1.167rem;">l&nbsp;</span><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">高性能硬件价格昂贵</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><h2 style="margin-top: 1.25rem;margin-bottom: 0.625rem;break-after: avoid;text-align: justify;line-height: 41.52px;font-size: 1.5rem;font-variant-numeric: normal;font-variant-east-asian: normal;white-space: normal;widows: 1;"><strong><span style="font-family: 宋体;font-size: 1.333rem;"><span style="font-family:宋体;">分布式系统带来哪些问题</span></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;"><o:p></o:p></span></strong></h2><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 42pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: -21pt;"><span style="font-family: Wingdings;font-size: 1.167rem;">l&nbsp;</span><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">集群中节点数据一致性问题</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 42pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: -21pt;"><span style="font-family: Wingdings;font-size: 1.167rem;">l&nbsp;</span><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">集群产生分区</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 42pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: -21pt;"><span style="font-family: Wingdings;font-size: 1.167rem;">l&nbsp;</span><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">负载问题</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 42pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: -21pt;"><span style="font-family: Wingdings;font-size: 1.167rem;">l&nbsp;</span><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">幂等性问题</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 42pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: -21pt;"><span style="font-family: Wingdings;font-size: 1.167rem;">l&nbsp;</span><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">可用性问题</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 42pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: -21pt;"><span style="font-family: Wingdings;font-size: 1.167rem;">l&nbsp;</span><span style="font-family: Calibri;font-size: 1.167rem;">Session</span><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">问题</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><h2 style="margin-top: 1.25rem;margin-bottom: 0.625rem;break-after: avoid;text-align: justify;line-height: 41.52px;font-size: 1.5rem;font-variant-numeric: normal;font-variant-east-asian: normal;white-space: normal;widows: 1;"><strong><span style="font-family: 宋体;font-size: 1.333rem;"><span style="font-family:宋体;">分布式</span>PAC<span style="font-family:宋体;">设计原则</span></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;"><o:p></o:p></span></strong></h2><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">一个经典的分布式系统理论。</span>CAP<span style="font-family:宋体;">理论告诉我们:一个分布式系统不可能同时满足一致性(</span><span style="font-family:Calibri;">C</span><span style="font-family:宋体;">:</span><span style="font-family:Calibri;">Consistency</span><span style="font-family:宋体;">)、可用性(</span><span style="font-family:Calibri;">A</span><span style="font-family:宋体;">:</span><span style="font-family:Calibri;">Availability</span><span style="font-family:宋体;">)和分区容错性(</span><span style="font-family:Calibri;">P</span><span style="font-family:宋体;">:</span><span style="font-family:Calibri;">Partition tolerance</span><span style="font-family:宋体;">)这三个基本需求,最多只能同时满足其中两项。</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;">1<span style="font-family:宋体;">、一致性</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">在分布式环境下,一致性是指数据在多个副本之间能否保持一致的特性。在一致性的需求下,当一个系统在数据一致的状态下执行更新操作后,应该保证系统的数据仍然处于一</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">致</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">的状态。</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">对于一个将数据副本分布在不同分布式节点上的系统来说,如果对第一个节点的数据进</span><span class="">&nbsp;</span><span style="font-family:宋体;">行了更新操作并且更新成功后,却没有使得第二个节点上的数据得到相应的更新,于是在对第二个节点的数据进行读取操作时,获取的依然是老数据(或称为脏数</span><span class="">&nbsp;</span><span style="font-family:宋体;">据),这就是典型的分布式数据不一致的情况。在分布式系统中,如果能够做到针对一个数据项的更新操作执行成功后,所有的用户都可以读取到其最新的值,那么</span><span class="">&nbsp;</span><span style="font-family:宋体;">这样的系统就被认为具有强一致性</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;">2<span style="font-family:宋体;">、可用性</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">可用性是指系统提供的服务必须一直处于可用的状态,对于用户的每一个操作请求总是能够在有限的时间内返回结果。这里的重点是</span>"<span style="font-family:宋体;">有限时间内</span><span style="font-family:Calibri;">"</span><span style="font-family:宋体;">和</span><span style="font-family:Calibri;">"</span><span style="font-family:宋体;">返回结果</span><span style="font-family:Calibri;">"</span><span style="font-family:宋体;">。</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;">"<span style="font-family:宋体;">有限时间内</span><span style="font-family:Calibri;">"</span><span style="font-family:宋体;">是指,对于用户的一个操作请求,系统必须能够在指定的时间内返回对 应的处理结果,如果超过了这个时间范围,那么系统就被认为是不可用的。另外,</span><span style="font-family:Calibri;">"</span><span style="font-family:宋体;">有限的时间内</span><span style="font-family:Calibri;">"</span><span style="font-family:宋体;">是指系统设计之初就设计好的运行指标,通常不同系统之间有很 大的不同,无论如何,对于用户请求,系统必须存在一个合理的响应时间,否则用户便会对系统感到失望。</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;">"<span style="font-family:宋体;">返回结果</span><span style="font-family:Calibri;">"</span><span style="font-family:宋体;">是可用性的另一个非常重要的指标,它要求系统在完成对用户请求的处理后,返回一个正常的响应结果。正常的响应结果通常能够明确地反映出队请求的处理结果,即成功或失败,而不是一个让用户感到困惑的返回结果。</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;">3<span style="font-family:宋体;">、分区容错性</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">分区容错性约束了一个分布式系统具有如下特性:分布式系统在遇到任何网络分区故障的时候,仍然需要能够保证对外提供满足一致性和可用性的服务,除非是整个网络环境都发生了故障。</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">网络分区是指在分布式系统中,不同的节点分布在不同的子网络(机房或异地网络)</span><span class="">&nbsp;</span><span style="font-family:宋体;">中,由于一些特殊的原因导致这些子网络出现网络不连通的状况,但各个子网络的内部网络是正常的,从而导致整个系统的网络环境被切分成了若干个孤立的区域。</span><span class="">&nbsp;</span><span style="font-family:宋体;">需要注意的是,组成一个分布式系统的每个节点的加入与退出都可以看作是一个特殊的网络分区。</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">既然一个分布式系统无法同时满足一致性、可用性、分区容错性三个特点,所以我们就需要抛弃一样:</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><h2 style="margin-top: 1.25rem;margin-bottom: 0.625rem;break-after: avoid;text-align: justify;line-height: 41.52px;font-size: 1.5rem;font-variant-numeric: normal;font-variant-east-asian: normal;white-space: normal;widows: 1;"><strong><span style="font-family: 宋体;font-size: 1.333rem;">Paxos<span style="font-family:宋体;">如何解决分布式一致问题</span></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;"><o:p></o:p></span></strong></h2><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">&nbsp;</span><span style="font-family: 宋体;font-size: 1.167rem;">&nbsp;Paxos<span style="font-family:宋体;">的基本思路:</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">假设有一个社团,其中有团员、议员(决议小组成员)两个角色</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">团员可以向议员申请提案来修改社团制度</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">议员坐在一起,拿出自己收到的提案,对每个提案进行投票表决,超过半数通过即可生效</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">为了秩序,规定每个提案都有编号</span>ID<span style="font-family:宋体;">,按顺序自增</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">每个议员都有一个社团制度笔记本,上面记着所有社团制度,和最近处理的提案编号,初始为</span>0</span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">投票通过的规则:</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">新提案</span>ID<span class="">&nbsp;</span><span style="font-family:宋体;">是否大于 议员本中的</span><span style="font-family:Calibri;">ID</span><span style="font-family:宋体;">,是议员举手赞同</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">如果举手人数大于议员人数的半数,即让新提案生效</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">例如:</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">刚开始,每个议员本子上的</span>ID<span style="font-family:宋体;">都为</span><span style="font-family:Calibri;">0</span><span style="font-family:宋体;">,现在有一个议员拿出一个提案:团费降为</span><span style="font-family:Calibri;">100</span><span style="font-family:宋体;">元,这个提案的</span><span style="font-family:Calibri;">ID</span><span style="font-family:宋体;">自增为</span><span style="font-family:Calibri;">1</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">每个议员都和自己</span>ID<span style="font-family:宋体;">对比,一看<span class="">&nbsp;</span></span><span style="font-family:Calibri;">1&gt;0</span><span style="font-family:宋体;">,举手赞同,同时修改自己本中的</span><span style="font-family:Calibri;">ID</span><span style="font-family:宋体;">为</span><span style="font-family:Calibri;">1</span></span><span style="font-family: Calibri;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">发出提案的议员一看超过半数同意,就宣布:</span>1<span style="font-family:宋体;">号提案生效</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">然后所有议员都修改自己笔记本中的团费为</span>100<span style="font-family:宋体;">元</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">以后任何一个团员咨询任何一个议员:</span>"<span style="font-family:宋体;">团费是多少?</span><span style="font-family:Calibri;">"</span><span style="font-family:宋体;">,议员可以直接打开笔记本查看,并回答:团费为</span><span style="font-family:Calibri;">100</span><span style="font-family:宋体;">元</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">可能会有极端的情况,就是多个议员一起发出了提案,就是并发的情况</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">例如</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">刚开始,每个议员本子上的编号都为</span>0<span style="font-family:宋体;">,现在有两个议员(</span><span style="font-family:Calibri;">A</span><span style="font-family:宋体;">和</span><span style="font-family:Calibri;">B</span><span style="font-family:宋体;">)同时发出了提案,那么根据自增规则,这两个提案的编号都为</span><span style="font-family:Calibri;">1</span><span style="font-family:宋体;">,但只会有一个被先处理</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">假设</span>A<span style="font-family:宋体;">的提案在</span><span style="font-family:Calibri;">B</span><span style="font-family:宋体;">的上面,议员们先处理</span><span style="font-family:Calibri;">A</span><span style="font-family:宋体;">提案并通过了,这时,议员们的本子上的</span><span style="font-family:Calibri;">ID</span><span style="font-family:宋体;">已经变为了</span><span style="font-family:Calibri;">1</span><span style="font-family:宋体;">,接下来处理</span><span style="font-family:Calibri;">B</span><span style="font-family:宋体;">的提案,由于它的</span><span style="font-family:Calibri;">ID</span><span style="font-family:宋体;">是</span><span style="font-family:Calibri;">1</span><span style="font-family:宋体;">,不大于议员本子上的</span><span style="font-family:Calibri;">ID</span><span style="font-family:宋体;">,</span><span style="font-family:Calibri;">B</span><span style="font-family:宋体;">提案就被拒绝了,</span><span style="font-family:Calibri;">B</span><span style="font-family:宋体;">议员需要重新发起提案</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: Calibri;font-size: 1.167rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">上面就是</span>Paxos<span style="font-family:宋体;">的基本思路,对照</span><span style="font-family:Calibri;">ZooKeeper</span><span style="font-family:宋体;">,对应关系就是:</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">团员</span><span class="">&nbsp;</span>-client</span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">议员</span><span class="">&nbsp;</span>-server</span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">议员的笔记本</span><span class="">&nbsp;</span>-server<span style="font-family:宋体;">中的数据</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">提案</span><span class="">&nbsp;</span>-<span style="font-family:宋体;">变更数据的请求</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">提案编号</span><span class="">&nbsp;</span>-zxid<span style="font-family:宋体;">(</span><span style="font-family:Calibri;">ZooKeeper Transaction Id</span><span style="font-family:宋体;">)</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;"><span style="font-family:宋体;">提案生效</span><span class="">&nbsp;</span>-<span style="font-family:宋体;">执行变更数据的操作</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;">ZooKeeper<span style="font-family:宋体;">中还有一个</span><span style="font-family:Calibri;">leader</span><span style="font-family:宋体;">的概念,就是把发起提案的权利收紧了,以前是每个议员都可以发起提案,现在有了</span><span style="font-family:Calibri;">leader</span><span style="font-family:宋体;">,大家就不要七嘴八舌了,先把提案都交给</span><span style="font-family:Calibri;">leader</span><span style="font-family:宋体;">,由</span><span style="font-family:Calibri;">leader</span><span style="font-family:宋体;">一个个发起提案</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;text-indent: 28pt;"><span style="font-family: 宋体;font-size: 1.167rem;">Paxos<span style="font-family:宋体;">算法就是通过投票、全局编号机制,使同一时刻只有一个写操作被批准,同时并发的写操作要去争取选票,只有获得过半数选票的写操作才会被批准,所以永远只会有一个写操作得到批准,其他的写操作竞争失败只好再发起一轮投票</span></span><span style="font-family: 宋体;font-size: 1.167rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><h2 style="margin-top: 1.25rem;margin-bottom: 0.625rem;break-after: avoid;text-align: justify;line-height: 41.52px;font-size: 1.5rem;font-variant-numeric: normal;font-variant-east-asian: normal;white-space: normal;widows: 1;"><strong><span style="font-family: 宋体;font-size: 1.333rem;"></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;">zookeeper<span style="font-family:宋体;">特性介绍</span></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;"><o:p></o:p></span></strong></h2><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">一致性保证</span>:</span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">更新请求顺序进行,来自同一个</span>client<span style="font-family:宋体;">的更新请求按其发送顺序依次执行</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">数据更新原子性,一次数据更新要么成功,要么失败</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">全局唯一数据视图,</span>client<span style="font-family:宋体;">无论连接到哪个</span><span style="font-family:Calibri;">server</span><span style="font-family:宋体;">,数据视图都是一致的</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">实时性,在一定事件范围内,</span>client<span style="font-family:宋体;">能读到最新数据</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><h2 style="margin-top: 1.25rem;margin-bottom: 0.625rem;break-after: avoid;text-align: justify;line-height: 41.52px;font-size: 1.5rem;font-variant-numeric: normal;font-variant-east-asian: normal;white-space: normal;widows: 1;"><strong><span style="font-family: 宋体;font-size: 1.333rem;"></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;">zookeeper<span style="font-family:宋体;">选举流程</span></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;"><o:p></o:p></span></strong></h2><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">1.<span style="font-family:宋体;">选举线程由当前</span><span style="font-family:Calibri;">Server</span><span style="font-family:宋体;">发起选举的线程担任,其主要功能是对投票结果进行统计,并选出推荐的</span><span style="font-family:Calibri;">Server</span><span style="font-family:宋体;">;</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">2.<span style="font-family:宋体;">选举线程首先向所有</span><span style="font-family:Calibri;">Server</span><span style="font-family:宋体;">发起一次询问</span><span style="font-family:Calibri;">(</span><span style="font-family:宋体;">包括自己</span><span style="font-family:Calibri;">)</span><span style="font-family:宋体;">;</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">3.<span style="font-family:宋体;">选举线程收到回复后,验证是否是自己发起的询问</span><span style="font-family:Calibri;">(</span><span style="font-family:宋体;">验证</span><span style="font-family:Calibri;">zxid</span><span style="font-family:宋体;">是否一致</span><span style="font-family:Calibri;">)</span><span style="font-family:宋体;">,然后获取对方的</span><span style="font-family:Calibri;">id(myid)</span><span style="font-family:宋体;">,并存储到当前询问对象列表中,最后获取对方提议的</span><span style="font-family:Calibri;">leader</span><span style="font-family:宋体;">相关信息</span><span style="font-family:Calibri;">(id,zxid)</span><span style="font-family:宋体;">,并将这些信息存储到当次选举的投票记录表中;</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">4.<span style="font-family:宋体;">收到所有</span><span style="font-family:Calibri;">Server</span><span style="font-family:宋体;">回复以后,就计算出</span><span style="font-family:Calibri;">zxid</span><span style="font-family:宋体;">最大的那个</span><span style="font-family:Calibri;">Server</span><span style="font-family:宋体;">,并将这个</span><span style="font-family:Calibri;">Server</span><span style="font-family:宋体;">相关信息设置成下一次要投票的</span><span style="font-family:Calibri;">Server</span><span style="font-family:宋体;">;</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">5.<span style="font-family:宋体;">线程将当前</span><span style="font-family:Calibri;">zxid</span><span style="font-family:宋体;">最大的</span><span style="font-family:Calibri;">Server</span><span style="font-family:宋体;">设置为当前</span><span style="font-family:Calibri;">Server</span><span style="font-family:宋体;">要推荐的</span><span style="font-family:Calibri;">Leader</span><span style="font-family:宋体;">,如果此时获胜的</span><span style="font-family:Calibri;">Server</span><span style="font-family:宋体;">获得</span><span style="font-family:Calibri;">n/2 + 1</span><span style="font-family:宋体;">的</span><span style="font-family:Calibri;">Server</span><span style="font-family:宋体;">票数,设置当前推荐的</span><span style="font-family:Calibri;">leader</span><span style="font-family:宋体;">为获胜的</span><span style="font-family:Calibri;">Server</span><span style="font-family:宋体;">,将根据获胜的</span><span style="font-family:Calibri;">Server</span><span style="font-family:宋体;">相关信息设置自己的状态,否则,继续这个过程,直到</span><span style="font-family:Calibri;">leader</span><span style="font-family:宋体;">被选举出来</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><h2 style="margin-top: 1.25rem;margin-bottom: 0.625rem;break-after: avoid;text-align: justify;line-height: 41.52px;font-size: 1.5rem;font-variant-numeric: normal;font-variant-east-asian: normal;white-space: normal;widows: 1;"><strong><span style="font-family: 宋体;font-size: 1.333rem;"></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;">zookeeper<span style="font-family:宋体;">读写流程</span></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;"><o:p></o:p></span></strong></h2><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">写流程</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">客户端连接到集群中某一个节点</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">客户端发送写请求</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">服务端连接节点,把该写请求转发给</span>leader</span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">leader<span style="font-family:宋体;">处理写请求,一半以上的从节点也写成功,返回给客户端成功。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">读流程</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">客户端连接到集群中某一节点</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">读请求,直接返回。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><h2 style="margin-top: 1.25rem;margin-bottom: 0.625rem;break-after: avoid;text-align: justify;line-height: 41.52px;font-size: 1.5rem;font-variant-numeric: normal;font-variant-east-asian: normal;white-space: normal;widows: 1;"><strong><span style="font-family: 宋体;font-size: 1.333rem;">zookeeper<span style="font-family:宋体;">存储策略</span></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;"><o:p></o:p></span></strong></h2><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family:宋体;">持久化存储是基于内存快照</span>(snapshot)<span style="font-family:宋体;">和事务日志(</span><span style="font-family:Calibri;">txlog</span><span style="font-family:宋体;">)来存储。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">snapshot<span style="font-family:宋体;">和</span><span style="font-family:Calibri;">txlog</span><span style="font-family:宋体;">的存储目录定义在</span><span style="font-family:Calibri;">zoo.cfg</span><span style="font-family:宋体;">中,</span><span style="font-family:Calibri;">txlog</span><span style="font-family:宋体;">存储磁盘和</span><span style="font-family:Calibri;">snapshot</span><span style="font-family:宋体;">存储磁盘分开,避免</span><span style="font-family:Calibri;">io</span><span style="font-family:宋体;">争夺。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">txlog<span style="font-family:宋体;">的刷盘阈值是</span><span style="font-family:Calibri;">1000</span><span style="font-family:宋体;">。</span><span style="font-family:Calibri;">txlog</span><span style="font-family:宋体;">是生成</span><span style="font-family:Calibri;">snapshot</span><span style="font-family:宋体;">之后生成。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">snapshot<span style="font-family:宋体;">的保存数量和清理时间间隔配置在</span><span style="font-family:Calibri;">zoo.cfg</span><span style="font-family:宋体;">中。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">zookeeper<span class="">&nbsp;</span><span style="font-family:宋体;">使用</span><span style="font-family:Calibri;">concurrenthashmap</span><span style="font-family:宋体;">进行存储。锁的粒度是</span><span style="font-family:Calibri;">segment</span><span style="font-family:宋体;">,减少锁竞争,</span><span style="font-family:Calibri;">segment</span><span style="font-family:宋体;">里对应一个</span><span style="font-family:Calibri;">hashtable<span class="">&nbsp;</span></span><span style="font-family:宋体;">的若干桶</span><span style="font-family:Calibri;">.</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">所以时间复杂度都是</span><span class="">&nbsp;</span>O(1)</span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><h2 style="margin-top: 1.25rem;margin-bottom: 0.625rem;break-after: avoid;text-align: justify;line-height: 41.52px;font-size: 1.5rem;font-variant-numeric: normal;font-variant-east-asian: normal;white-space: normal;widows: 1;"><strong><span style="font-family: 宋体;font-size: 1.333rem;"></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;">zookeeper<span style="font-family:宋体;">应用场景</span></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;"><o:p></o:p></span></strong></h2><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">数据发布与订阅</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">发布与订阅即所谓的配置管理,顾名思义就是将数据发布到</span>zk<span style="font-family:宋体;">节点上,供订阅者动态获取数据,实现配置信息的集中式管理和动态更新。例如全局的配置信息,地址列表等就非常适合使用。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">1.<span class="">&nbsp;</span><span style="font-family:宋体;">索引信息和集群中机器节点状态存放在</span><span style="font-family:Calibri;">zk</span><span style="font-family:宋体;">的一些指定节点,供各个客户端订阅使用。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">2.<span class="">&nbsp;</span><span style="font-family:宋体;">系统日志(经过处理后的)存储,这些日志通常</span><span style="font-family:Calibri;">2-3</span><span style="font-family:宋体;">天后被清除。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">3.<span class="">&nbsp;</span><span style="font-family:宋体;">应用中用到的一些配置信息集中管理,在应用启动的时候主动来获取一次,并且在节点上注册一个</span><span style="font-family:Calibri;">Watcher</span><span style="font-family:宋体;">,以后每次配置有更新,实时通知到应用,获取最新配置信息。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">4.<span class="">&nbsp;</span><span style="font-family:宋体;">业务逻辑中需要用到的一些全局变量,比如一些消息中间件的消息队列通常有个</span><span style="font-family:Calibri;">offset</span><span style="font-family:宋体;">,这个</span><span style="font-family:Calibri;">offset</span><span style="font-family:宋体;">存放在</span><span style="font-family:Calibri;">zk</span><span style="font-family:宋体;">上,这样集群中每个发送者都能知道当前的发送进度。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">5.<span class="">&nbsp;</span><span style="font-family:宋体;">系统中有些信息需要动态获取,并且还会存在人工手动去修改这个信息。以前通常是暴露出接口,例如</span><span style="font-family:Calibri;">JMX</span><span style="font-family:宋体;">接口,有了</span><span style="font-family:Calibri;">zk</span><span style="font-family:宋体;">后,只要将这些信息存放到</span><span style="font-family:Calibri;">zk</span><span style="font-family:宋体;">节点上即可。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">分布通知</span>/<span style="font-family:宋体;">协调</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">ZooKeeper<span class="">&nbsp;</span><span style="font-family:宋体;">中特有</span><span style="font-family:Calibri;">watcher</span><span style="font-family:宋体;">注册与异步通知机制,能够很好的实现分布式环境下不同系统之间的通知与协调,实现对数据变更的实时处理。使用方法通常是不同系统都对<span class="">&nbsp;</span></span><span style="font-family:Calibri;">ZK</span><span style="font-family:宋体;">上同一个</span><span style="font-family:Calibri;">znode</span><span style="font-family:宋体;">进行注册,监听</span><span style="font-family:Calibri;">znode</span><span style="font-family:宋体;">的变化(包括</span><span style="font-family:Calibri;">znode</span><span style="font-family:宋体;">本身内容及子节点的),其中一个系统</span><span style="font-family:Calibri;">update</span><span style="font-family:宋体;">了</span><span style="font-family:Calibri;">znode</span><span style="font-family:宋体;">,那么另一个系统能 够收到通知,并作出相应处理。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">1.<span class="">&nbsp;</span><span style="font-family:宋体;">另一种心跳检测机制:检测系统和被检测系统之间并不直接关联起来,而是通过</span><span style="font-family:Calibri;">zk</span><span style="font-family:宋体;">上某个节点关联,大大减少系统耦合。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">2.<span class="">&nbsp;</span><span style="font-family:宋体;">另一种系统调度模式:某系统有控制台和推送系统两部分组成,控制台的职责是控制推送系统进行相应的推送工作。管理人员在控制台作的一些操作,实际上是修改 了</span><span style="font-family:Calibri;">ZK</span><span style="font-family:宋体;">上某些节点的状态,而</span><span style="font-family:Calibri;">zk</span><span style="font-family:宋体;">就把这些变化通知给他们注册</span><span style="font-family:Calibri;">Watcher</span><span style="font-family:宋体;">的客户端,即推送系统,于是,作出相应的推送任务。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">3.<span class="">&nbsp;</span><span style="font-family:宋体;">另一种工作汇报模式:一些类似于任务分发系统,子任务启动后,到</span><span style="font-family:Calibri;">zk</span><span style="font-family:宋体;">来注册一个临时节点,并且定时将自己的进度进行汇报(将进度写回这个临时节点),这样任务管理者就能够实时知道任务进度。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">总之,使用</span>zookeeper<span style="font-family:宋体;">来进行分布式通知和协调能够大大降低系统之间的耦合。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">分布式锁</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">分布式锁,这个主要得益于</span>ZooKeeper<span style="font-family:宋体;">为我们保证了数据的强一致性,即用户只要完全相信每时每刻,</span><span style="font-family:Calibri;">zk</span><span style="font-family:宋体;">集群中任意节点(一个</span><span style="font-family:Calibri;">zk server</span><span style="font-family:宋体;">)上的相同</span><span style="font-family:Calibri;">znode</span><span style="font-family:宋体;">的数据是一定是相同的。锁服务可以分为两类,一个是保持独占,另一个是控制时序。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">保持独占,就是所有试图来获取这个锁的客户端,最终只有一个可以成功获得这把锁。通常的做法是把</span>zk<span style="font-family:宋体;">上的一个</span><span style="font-family:Calibri;">znode</span><span style="font-family:宋体;">看作是一把锁,通过</span><span style="font-family:Calibri;">create znode</span><span style="font-family:宋体;">的方式来实现。所有客户端都去创建<span class="">&nbsp;</span></span><span style="font-family:Calibri;">/distribute_lock<span class="">&nbsp;</span></span><span style="font-family:宋体;">节点,最终成功创建的那个客户端也即拥有了这把锁。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">控制时序,就是所有视图来获取这个锁的客户端,最终都是会被安排执行,只是有个全局时序了。做法和上面基本类似,只是这里</span><span class="">&nbsp;</span>/distribute_lock<span class="">&nbsp;</span><span style="font-family:宋体;">已经预先存在,客户端在它下面创建临时有序节点(这个可以通过节点的属性控制:</span><span style="font-family:Calibri;">CreateMode.EPHEMERAL_SEQUENTIAL</span><span style="font-family:宋体;">来指定)。</span><span style="font-family:Calibri;">Zk</span><span style="font-family:宋体;">的父节点(</span><span style="font-family:Calibri;">/distribute_lock</span><span style="font-family:宋体;">)维持一份</span><span style="font-family:Calibri;">sequence,</span><span style="font-family:宋体;">保证子节点创建的时序性,从而也形成了每个客户端的全局时序。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">集群管理</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">1.<span class="">&nbsp;</span><span style="font-family:宋体;">集群机器监控:这通常用于那种对集群中机器状态,机器在线率有较高要求的场景,能够快速对集群中机器变化作出响应。这样的场景中,往往有一个监控系统,实时检测集群机器是否存活。过去的做法通常是:监控系统通过某种手段(比如</span><span style="font-family:Calibri;">ping</span><span style="font-family:宋体;">)定时检测每个机器,或者每个机器自己定时向监控系统汇报“我还活着”。 这种做法可行,但是存在两个比较明显的问题:</span><span style="font-family:Calibri;">1.<span class="">&nbsp;</span></span><span style="font-family:宋体;">集群中机器有变动的时候,牵连修改的东西比较多。</span><span style="font-family:Calibri;">2.<span class="">&nbsp;</span></span><span style="font-family:宋体;">有一定的延时。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">利用</span>ZooKeeper<span style="font-family:宋体;">有两个特性,就可以实时另一种集群机器存活性监控系统:</span><span style="font-family:Calibri;">a.<span class="">&nbsp;</span></span><span style="font-family:宋体;">客户端在节点<span class="">&nbsp;</span></span><span style="font-family:Calibri;">x<span class="">&nbsp;</span></span><span style="font-family:宋体;">上注册一个</span><span style="font-family:Calibri;">Watcher</span><span style="font-family:宋体;">,那么如果<span class="">&nbsp;</span></span><span style="font-family:Calibri;">x<span class="">&nbsp;</span></span><span style="font-family:宋体;">的子节点变化了,会通知该客户端。</span><span style="font-family:Calibri;">b.<span class="">&nbsp;</span></span><span style="font-family:宋体;">创建</span><span style="font-family:Calibri;">EPHEMERAL</span><span style="font-family:宋体;">类型的节点,一旦客户端和服务器的会话结束或过期,那么该节点就会消失。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;">2. Master<span style="font-family:宋体;">选举则是</span><span style="font-family:Calibri;">zookeeper</span><span style="font-family:宋体;">中最为经典的使用场景了。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">在分布式环境中,相同的业务应用分布在不同的机器上,有些业务逻辑(例如一些耗时的计算,网络</span>I/O<span style="font-family:宋体;">处理),往往只需要让整个集群中的某一台机器进行执行, 其余机器可以共享这个结果,这样可以大大减少重复劳动,提高性能,于是这个</span><span style="font-family:Calibri;">master</span><span style="font-family:宋体;">选举便是这种场景下的碰到的主要问题。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">利用</span>ZooKeeper<span style="font-family:宋体;">的强一致性,能够保证在分布式高并发情况下节点创建的全局唯一性,即:同时有多个客户端请求创建<span class="">&nbsp;</span></span><span style="font-family:Calibri;">/currentMaster<span class="">&nbsp;</span></span><span style="font-family:宋体;">节点,最终一定只有一个客户端请求能够创建成功。</span></span><span style="font-family: 宋体;font-size: 0.875rem;"><o:p></o:p></span></p><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;white-space: normal;widows: 1;"><span style="font-family: Calibri;font-size: 0.875rem;"><o:p>&nbsp;</o:p></span></p><h2 style="margin-top: 1.25rem;margin-bottom: 0.625rem;break-after: avoid;text-align: justify;line-height: 41.52px;font-size: 1.5rem;font-variant-numeric: normal;font-variant-east-asian: normal;white-space: normal;widows: 1;"><strong><span style="font-family: 宋体;font-size: 1.333rem;">zookeeper<span style="font-family:宋体;">虚拟机安装</span></span></strong><strong><span style="font-family: 宋体;font-size: 1.333rem;"><o:p></o:p></span></strong></h2><p class="" style="margin-top: 8px;margin-bottom: 8px;margin-left: 36pt;font-family: Helvetica, &quot;Hiragino Sans GB&quot;, 微软雅黑, &quot;Microsoft YaHei UI&quot;, SimSun, SimHei, arial, sans-serif;font-size: 16px;font-variant-numeric: normal;font-variant-east-asian: normal;line-height: 27.2px;text-indent: 0pt;white-space: normal;widows: 1;"><span style="font-family: 宋体;font-size: 0.875rem;"><span style="font-family:宋体;">略</span></span></p><p style="text-align: center;"><img class="" data-copyright="0" data-ratio="0.47810650887573963" data-s="300,640" data-src="https://img2018.cnblogs.com/blog/1112483/201811/1112483-20181112172218519-1844295641.webp"
    

    " data-type="jpeg" data-w="845" style=" 677px !important; height: auto !important; visibility: visible !important;" _width="677px" src="https://img2018.cnblogs.com/blog/1112483/201811/1112483-20181112172218519-1844295641.webp" crossorigin="anonymous" data-fail="0">





    原文地址:https://mp.weixin.qq.com/s?__biz=MzU0NTk2MjQyOA==&mid=2247483654&idx=1&sn=6909d8ec8b96cf6297e5fa1afcd86129&chksm=fb65a1d5cc1228c3b0898a05773e4396457e30a5567c4f0cb8bc6e652383bfd6bfce4537e21d&mpshare=1&scene=23&srcid=1112wZgWIS4QYtpGfvjHSJN5#rd

  • 相关阅读:
    吉林大学2020年数学分析考研试题参考解答
    华中科技大学2020年数学分析考研试题参考解答
    华南理工大学2020年数学分析考研试题参考解答
    华南理工大学2020年高等代数考研试题参考解答
    华东师范大学2020年数学分析考研试题参考解答
    华东师范大学2020年高等代数考研试题参考解答
    华东师范大学2020年高等代数考研试题部分参考解答
    湖南大学2020年数学分析考研试题参考解答
    哈尔滨工业大学2020年数学分析考研试题参考解答
    哈尔滨工业大学2020年高等代数考研试题参考解答
  • 原文地址:https://www.cnblogs.com/jpfss/p/9947721.html
Copyright © 2020-2023  润新知