II: Zookeeper Terminology concept

Source: Internet
Author: User

The basic concept of zookeeper
This paper introduces several core concepts of zookeeper, which are used throughout the book to further explain zookeeper, so it is necessary to understand these concepts in advance.

Cluster role
One: Cluster role
Usually in a distributed system, each machine that makes up a cluster has its own role, and the most typical cluster mode is the Master/slave mode (master Standby mode). In this mode, we refer to the machine that can handle all the writes, called the Master machine, and all the machines that get the latest data by means of asynchronous replication and provide the read service are called Salve machines.
And in zookeeper, these concepts are overturned. It does not follow the traditional master/slave concept, but introduces the three roles of Leader,follower and Observer. All machines in the Zookeeper cluster Select a machine called "Leader" through a Leader election process, and the Leader server provides read and write services to clients. In addition to leader, other machines, including follower and Observer.follower and Observer, are able to provide read services, the only difference being that the observer machine does not participate in the leader election process and does not participate in the "Half write success" strategy of the write operation. Therefore, observer can improve the read performance of the cluster without compromising write performance.

--->leader
(1) Leader server is the core of the whole zookeeper cluster working mechanism
--->follower
(1) Follower server is a follower of the Zookeeper cluster state
--->observer
(1) Observer server acts as an observer
---> Two design modes
(1) Leader,follower design mode
(2) observer observer design pattern


Two: Session
---> Session refers to the connection between the client and the zookeeper server. Zookeeper in the session, the client and the server to establish a long TCP connection to maintain a session, the client starts with the server to establish a TCP connection, through this connection, the client through heartbeat detection and the server to maintain a valid session, You can also send a request to the ZK cluster server and get a response.
--->zookeeper external service port default is 2181
---> Through the TCP link, the client can maintain a valid session with the server through heartbeat detection, and can send a request to the ZK cluster and accept a response, while also being able to accept the Watch event notification from the server through the link.
--->session sessiontimeout to set the time-out for a client session. A previously created session is still valid when a client link is broken due to server stress, network failure, or a client's active disconnection, as long as any of the servers in the cluster can be re-linked within the time specified by Sessiontimeout.

Three: Data node
There are two types of nodes in the--->zookeeper cluster
---> A node: A machine in a cluster is called a node, called a machine node.
---> Another node: Data unit Znode in the data model, divided into persistent nodes and temporary nodes.
Persistent node
Temporary node
--->zookeeper data model is a tree, the node of the tree is Znode,znode can save information. (Data content and a series of attribute information)
Data Model for--->zookeeper
---> Persistent node: Once this znode is created, the Znode will remain on zookeeper unless the znode is actively removed.
---> Temporary node: It's lifecycle and client session bindings, and once the client session fails, all temporary nodes created by the client are deleted.
--->zookeeper also allows the user to add a special attribute to each node, sequential. Once the node is marked on this property, when the node is created, zookeeper automatically adds an integer number to its node name, which is a self-increment number maintained by the parent node.




IV: Version
---> version is used to send a record of node data, or the node's child node list, or the number of changes to the permission information
---> Version type and description, for which a data structure called stat is maintained for Znode,zookeeper
Version (the revision number of the current data node data content)
Cversion (the version number of the node in the current data section)
Aversion (current data node ACL change version number)
---> Use version to implement distributed lock service
---> Lock is divided into pessimistic lock and optimistic lock
Pessimistic lock: Also known as pessimistic concurrent lock, is a very strict locking policy in the database, has a strong exclusive nature, can avoid different transactions on the same data caused by concurrent update data inconsistency, before the last transaction is not completed, the next transaction can not access the same resources, suitable for data update competition is very fierce scene

Optimistic lock: Compared to pessimistic lock, optimistic lock use the scene more, pessimistic lock when the transaction access to the same data must have mutual interference, so the simple rough use of exclusive access, and optimistic locks that different transactions access to the same resources is very few mutual interference, so during transaction processing does not need concurrency control, Of course
Optimistic lock is also a lock, it will still have concurrency control. In the case of a database, we typically add a version field to each table, read the data before the transaction modifies the data, and of course the version number is read in the same way, then add the read version number to the condition of the UPDATE statement, for example, the version number that is read is 1, The statement that we modify the data can be written like this, update the Set field of a table = a where id= and version=1. So if the update fails, it means that there are other transactions already modified in the concurrency situation, then the system needs to throw an error to the client. Allow the client to process itself and the client can choose to retry.

V: Watcher
---> Event listeners.
--->zookeeper cluster allows the user to register watcher (event listener) on the specified node, the zookeeper server sends notifications of this change to interested clients when the data node changes. The client receives this change notification and can go back to zookeeper to get the details of the data.



VI: ACL permission control
--->acl is shorthand for access control lists, zookeeper uses ACL policy to control permissions
--->acl has the following five types of permissions
Create: Permissions for creating child nodes
READ: Get Permissions for node data and child node lists
WRITE: Permissions to update node data
Delete: Delete permissions for child nodes
ADMIN: Set permissions for node ACLs

II: Zookeeper Terminology concept

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.