Introduction to Zookeeper

    Zookeeper is a typical distributed data consistency solution, based on which distributed applications can implement such as: data publish/subscribe (as a dubbo registry), load balancing (as a duubo registry), naming services, distributed coordination /Notification (as dubbo's message push), cluster management, master election, distributed locks and distributed queues and other functions.

 

The consistency guaranteed by Zookeeper is as follows:

              Sequential consistency : transaction requests initiated by the same client will be executed strictly in the order in which they were initiated

      Atomicity : Either all machines in the entire cluster successfully apply a transaction, or none of them are applied

      Single view : the server-side data seen by the client is consistent

      Reliability : server-side state changes that perform transactional diligence are permanently preserved

      Real-time : ensure that within a period of time, the client can finally read the latest data status from the server

 

Zookeeper 's design goals

            Goal 1: Simple Data Model

              This is a tree structure that exists in memory and consists of a series of Znode data nodes. Full data storage

      Goal 2: Can build a cluster

              The client will choose to create a TCP connection with any machine in the cluster, and after disconnection, it will automatically connect to other machines in the cluster.


 

             Goal 3: Sequential Access

               Each request is assigned a globally unique incremental number.

       Goal 4: High Performance

               The full amount of data is stored in memory, which is suitable for read operation scenarios.

 

 

Basic Concepts of Zookeeper

 

            Cluster role

             Leader: All machines in the cluster select a machine called "Leader" through a Leader election process.

                       Provide read and write services to clients.                                             

             Follower: can provide reading services

             Observer : can provide read services

      The difference between a follower and an observer is that the observer machine does not participate in the leader election process, nor does it participate in the "more than half of the write success" strategy for write operations. The observer is mainly used to improve the read performance of the cluster.

 

 

     Session:

             A client connection refers to a long TCP connection between the client and the server.

             When the first connection is established, the life cycle of the client session also begins.

             If you accidentally disconnect, as long as you can reconnect to any server in the cluster within the time specified by sessionTimeout, the previously created session will still be valid.

 

 

     Data node (Znode):

              The data model is a tree (Znode Tree), and a path divided by a slash (/) is a Znode.

              Each Znode will save its own data content, as well as a series of attribute information

              Divided into:

                    Persistent node: will always be saved on zookeeper unless manually deleted

                    Temporary node: bound to the client session, the session is invalid, and all temporary nodes are removed

      zookeeper allows users to add a special attribute, SEQUENTIAL, to each node. Once a node is marked with this attribute, when the node is created, zookeeper will automatically append an integer number to its node name, which is an auto-incrementing number maintained by the parent node.

 

 

     Version:

              对于每个ZNode,zookeeper都会为其维护一个叫做Stat的数据结构,Stat中记录了这个ZNode的三个数据版本,分别是version(当前ZNode的版本)、cversion(当前ZNode子节点的版本)和aversion(当前ZNode的ACL版本)

 

 

     Watcher

              事件监听器。

              zookeeper允许用户在指定节点上注册一些Watcher,并且在一些特定事件触发的时候,zookeeper服务端会将事件通知到感兴趣的客户端上。

         

     ACL:

             zookeeper采用ACL策略来进行权限控制。

             5中权限:

                    CREATE:创建子节点的权限

                    READ:获取节点数据和子节点列表的权限

                    WRITE:更新节点数据的权限

                    DELETE:删除子节点的权限

                    ADMIN:设置节点ACL的权限






参考书籍:《zookeeper分布式一致性原理与实践》


Guess you like

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