ZooKeeper Basic Mechanism Principle

Znode:

1. Znode is both a path (directory) and information (file)

2, Znode has two categories: One is divided into temporary nodes (session life cycle) and permanent nodes; two are divided into normal nodes and sequential nodes

Watch:

1. Monitoring and notification mechanism, which can monitor itself (addition, deletion, modification) or its child node (addition, deletion) events on the node

2, register through exist, getData, and getChildren on the code Monitoring, notification can be triggered by create, delete, setData

Consistency mechanism:

1, Single System Image, data It will be synchronized to all nodes, and the client can connect to any node to get data. Data synchronization to each node will definitely take some time, which is final consistency. Therefore, for transactions similar to transfers, you should not directly check, but register and listen for notification to ensure data consistency.

2, Sequential Consistency, write the same record at the same time, Leader-Follower mechanism, write requests will be routed to Leader, each write request will add a digital label to indicate the transaction sequence, write requests are executed in order (asynchronous distributed system achieves synchronization effect)

Application:

The most commonly used positioning of Zookeeper is distributed coordination service. Coordination is a relatively broad concept. According to Official documents can actually have many application scenarios

Name Service

Configuration Management

Cluster Management Group Membership-Detect member status, that is, cluster node status

Cluster Management Election-Cluster Election

Distributed lock

*Distributed Queue-Producer Consumer Queue

*Barriers (Fence Wall)-A barrier is a primitive that enables a group of processes to synchronize the beginning and the end of a computation.

*Two-phased Commit two-phase submission, Usually used for distributed transactions

*BookKeeper-distributed log stream storage

The implementation of these applications The principle is to use the above znode and watch mechanism, such as cluster election, each node corresponds to a temporary sequence node, the smallest sequence is the main; the principle of distributed lock is exactly the same, and the node with the smallest sequence acquires the lock.

Leave a Comment

Your email address will not be published.