ZooKeeper and CAP Theory and Consistency Principle

<iframe id="iframeu2567428_0" style="word-wrap: break-word; margin: 0px; padding: 0px; border-width: 0px; border-style: initial; vertical-align: bottom;" src="http://pos.baidu.com/ucvm?rdid=2567428&dc=2&exps=110005&di=u2567428&dri=0&dis=0&dai=6&ps=704x1261&dcb=BAIDU_SSP_define&dtm=HTML_POST&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1480923179190&ti=ZooKeeper%E5%92%8CCAP%E7%90%86%E8%AE%BA%E5%8F%8A%E4%B8%80%E8%87%B4%E6%80%A7%E5%8E%9F%E5%88%99%20-%20zookeeper%20-%20%E8%BF%90%E7%BB%B4%E7%BD%91%20-%20iyunv.com&ari=2&dbv=2&drs=1&pcs=1372x637&pss=1372x976&cfv=22&cpl=6&chi=1&cce=true&cec=UTF-8&tlm=1480923179&rw=637&ltu=http%3A%2F%2Fwww.iyunv.com%2Fthread-109830-1-1.html&ltr=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3D1ZCHmGgDDIsmdyzxCqXdQA5d2nJcJFTooifKTqICU7mJrXpM8cwMivBHQpEjTOUooUsBX2ct37d_nIChtXK_dq%26wd%3D%26eqid%3Dd752508c0000ee330000000458451731&ecd=1&psr=1600x900&par=1600x860&pis=-1x-1&ccd=24&cja=true&cmi=8&col=zh-CN&cdo=-1&tcn=1480923179&qn=8ea89d3aec3ac762&tt=1480923179150.254.296.298" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" align="center,center" width="300" height="250"></iframe>com%2Flink%3Furl%3D1ZCHmGgDDIsmdyzxCqXdQA5d2nJcJFTooifKTqICU7mJrXpM8cwMivBHQpEjTOUooUsBX2ct37d_nIChtXK_dq%26wd%3D%26eqid%3Dd752508c0000ee330000000458451731&ecd=1&psr=1600x900&par=1600x860&pis=-1x-1&ccd=24&cja=true&cmi=8&col=zh-CN&cdo=-1&tcn=1480923179&qn=8ea89d3aec3ac762&tt=1480923179150.254.296.298" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" align="center,center" width="300" height="250"></iframe>com%2Flink%3Furl%3D1ZCHmGgDDIsmdyzxCqXdQA5d2nJcJFTooifKTqICU7mJrXpM8cwMivBHQpEjTOUooUsBX2ct37d_nIChtXK_dq%26wd%3D%26eqid%3Dd752508c0000ee330000000458451731&ecd=1&psr=1600x900&par=1600x860&pis=-1x-1&ccd=24&cja=true&cmi=8&col=zh-CN&cdo=-1&tcn=1480923179&qn=8ea89d3aec3ac762&tt=1480923179150.254.296.298" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" align="center,center" width="300" height="250"></iframe>amp;cdo=-1&tcn=1480923179&qn=8ea89d3aec3ac762&tt=1480923179150.254.296.298" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" align="center,center" width="300" height="250"></iframe>amp;cdo=-1&tcn=1480923179&qn=8ea89d3aec3ac762&tt=1480923179150.254.296.298" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" align="center,center" width="300" height="250"></iframe>

1. Overview of CAP Theory The
  CAP theory exists in the distributed field, and this theory has been proven: any distributed system can only satisfy two points at the same time, and cannot take into account the three.
   C: Consistency, consistency, consistent data update, all data changes are synchronized.
   A: Availability, availability, the system has good response performance.
   P: Partition tolerance, partition fault tolerance.
Therefore, it is stupid to waste energy thinking about how to design a perfect system that can satisfy the three, and appropriate trade-offs should be made according to the application scenario.
  (1) Consistency
  Consistency means that when reading data inside the system from outside the system, it is the same under certain constraints, that is, data changes should be synchronized within the system at each node. According to the degree of consistency, the consistency level can be divided into the following types:
    ①Strong consistency. At any time, any user can read the last successfully updated data.
  ② monotonic consistency (monotonic consistency). At any time, once any user reads the value of a certain data after a certain update, he will never read a value older than this value. That is, the available data sequence must be monotonically increasing.
  ③ Session consistency (session consistency). In a session, once any user reads the value of a certain data after a certain update, he will not read a value older than this value in this session. Session consistency is monotonic consistency On the basis, the constraints are further relaxed, and only the monotonicity within a single session of a single user is guaranteed, and there is no guarantee between different users or different sessions of the same user. Example case: php's session concept.
  ④ Eventual consistency. The user can only read the value after a certain update, but the system guarantees that the data will eventually reach a completely consistent state, but the required time cannot be guaranteed.
  ⑥ weak consistency (weak consistency). The user cannot read the latest updated value within a certain time.
2. Consistency service provided by ZooKeeper
  As mentioned in many articles and blogs, zookeeper is a service that provides strong consistency, and has made a certain compromise between partition fault tolerance and availability, which is consistent with the CAP theory. But in fact zookeeper provides only monotonic consistency.
Reasons :
  1. Suppose there are 2n+1 servers. In the synchronization process, the leader synchronizes data with the followers. When the number of followers completed by synchronization is greater than n+1, the synchronization process ends, and the system accepts the client's connection request. If the client is connected to a follower that is not synchronously completed, the obtained data is not the latest data, but monotonicity can be guaranteed.
  2. After the follower receives the write request, it forwards it to the leader for processing; the leader completes the two-phase commit mechanism. Initiate a proposal to all servers. When the proposal is approved by more than half (n+1) servers, the entire cluster will be synchronized. After more than half (n+1) servers are synchronized, the write request is completed. If the client is connected to a follower that is not synchronously completed, then the obtained data is not the latest data, but monotonicity can be guaranteed.
  Use the CAP principle of distributed systems to analyze Zookeeper :
(1) C : Zookeeper ensures eventual consistency, and can sync to each node in more than ten seconds.
(2) A: Zookeeper ensures availability, data is always available, and there is no lock. And the data owned by more than half of the nodes is up-to-date and real-time. If you want to ensure that the data must be up-to-date, you need to manually call Sync()
(2 ) P : There are 2 points to be analyzed.
      Too many nodes will cause a very large delay in writing data, because multiple nodes need to be synchronized.
     If there are more nodes  , leader election is very time-consuming, which will magnify network problems. The observer node alleviates this problem.

 

 

http://www.iyunv.com/thread-109830-1-1.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326534935&siteId=291194637