2013年9月10日星期二

Android [Share] Zookeeper in learning and

primer

cloud computing more and more popular today, a single machine processing capacity can not meet our needs, had to use a lot of services cluster. Cluster Services to provide services in the process, there are many configuration needs to update, the need for coordination between services work how this information pushed to each node? And to ensure the consistency and reliability of the information?

As we all know, the distributed coordination of services is difficult to achieve accurate, they are easy to make mistakes on the race conditions and deadlocks. How to save energy in this regard? Zookeeper is a good choice. Zookeeper is the motivation behind the lifting of distributed applications in the realization of the pain on the coordination of services. This paper introduces the basic theory based on the Zookeeper with Zookeeper implements a configuration management center, using Zookeeper configuration information will be distributed to each service node, and ensure information accuracy and consistency.

Zookeeper what?


references to the official statement: "Zookeeper is a high-performance, distributed, open-source distributed application coordination services it provides simple primitive functions, distributed applications can be based on it implements more advanced services, such as synchronization, configuration management, cluster management, name space and it is designed to be easy to program, use the file system directory tree as a data model on the server running the java, java and C provide a client API ".

Zookeeper overall structure

Zookeeper service itself composed of a cluster (2n +1 a service allows n-lapse). Zookeeper service has two roles, one is the leader, responsible for writing services and data synchronization, and the rest is follower, providing reading services, leader in the follower after the failure to re-elect a new leader.

Zookeeper logic diagram below,


1. clients can connect to each server, each server exactly the same data.
2. every follower and leader is connected both to accept leader data update operation.
3.Server transaction log records and snapshots to persistent storage.
4. most of the server is available, you can use the overall service.

Zookeeper data model

Zookeeper expressed as a hierarchical file system directory tree structure (different from the file system is that the node can have its own data, and the file system directory node only child nodes).

data model structure is as follows,


circular node may contain child nodes, the node can not have child nodes polygon. A node corresponds to an application, the data stored in the node configuration information is application needs.


Zookeeper Features


sequential consistency: In accordance with the order of the client sends a request to update the data.
Atomicity: update either succeed or fail, does not appear partial update.
unity: No matter which client connection server, will see the same view.
Reliability: Once the data update is successful, will remain until a new update.
Timeliness: The client will be in a defined period of time to get the latest data.

Zookeeper use scenes

1. data publish and subscribe (my business use this feature, there will be described in detail later)

node application configuration to focus on application startup initiative to obtain and register a node watcher, will notify each configuration updates to the application.

2. name space services

distributed naming service, create a node, the node's path is globally unique, and can be used as a global name.

3. Distributed notification / coordination

monitor different systems are the same node, as soon as the update, another system can be notified.

4. Distributed Lock

Zookeeper ensure strong data consistency, any time you can be confident data for each node in the cluster are the same. A user creates a node in a lock, the user detects the other node, if present, on behalf of another user has locked, if not, you can create a node represents has a lock.

5. cluster management

machines are each joined to create a cluster node, write their own state. Monitoring the parent node of the users will be informed and make the appropriate treatment. Leave delete nodes, monitoring of the parent node users will also be notified.

Zookeeper in our business logic on the use of
our company, Aurora Push, Push business platform with a large number of logical servers, grouped by type of business. Logical services run depends on configuration, and configuration line adjustment requires a centralized configuration item management center. Zookeeper publish and subscribe features, and send an update notification mechanism well positioned to meet our needs. Zookeeper disaster recovery feature also eliminates the need for a lot of our related management.

Here I share with you the major and Zookeeper in our internal service application.

a. Our logical server contains two types of configurations.

one for Acl (access control list), the user's news consumption, in accordance with the conditions of the list to the next logical server. Another algorithm is only a single logical unswitching called Agl (access algorithm list), but some of which will determine the conditions change frequently. This configuration is collected two configuration management center (i.e. Zookeeper).

logic diagram below,


good strategy users to edit the configuration information (xml format), through the client loaded into Zookeeper. Zookeeper immediately notify its next logical server (BLx), logical server to download the latest configuration policies and apply the new policy. The new strategy may change within a certain period of id user's data flow, or over the original logical server, or to a new logical server.

b. data model design

same type of logic to create a service node in Zookeeper, share the same configuration information.
this node for the policy configuration items, divided into Acl and Agl two categories, as shown below: (as an agent logical services, for example)


Acl1, Acl2, Acl3, Agl1, Agl2 there were policy configuration information. Changes will notify logical server node listens Proxy, Proxy logical server to download the latest policy and apply the policy. New nodes join and leave logic will notify the Proxy server.

c. business processes as shown


1. logical service listens own type node (such as the former figure of the Proxy node)
2. Edit the new strategy, loading strategy to Zookeeper (policy saved in Proxy / Acls / Acl [1 .. n], or Proxy/Agls/Agl1 [1 .. n] )
3.Zookeeper notify each logical node
4. each logical node to download the new strategy to the local, and apply the new policy

attach the original address http://blog.jpush.cn/index.php/push_zookeeper_study_usage/

------ Solution ------------------------------------ --------

Thank under study share
------ Solution ----------------------------- ---------------
although unknown Danjue Li
------ reference ----------------- ----------------------

kind, Thanks for the support
------ reference ------ Related Articles ---------------------------------
Zookeeper much
----- - reference ---------------------------------------
intends to examine the next piece of content
------ reference --------------------------------------- < br> learn, thanks for sharing

------ reference ------------------------------------ ---
not how to read. . .
------ reference --------------------------------------- < br> save provincial traffic power is a basic
------ reference ------------------------------- --------
first saved,
------ reference - --------------------------------------
looking for this information
------ reference ---------------------------------------
mark about

没有评论:

发表评论