Zookeeper Distributed Process Collaboration technology detailed

Source: Internet
Author: User
Tags zookeeper

English version name: zookeeper:distributed Process Coordination

Introduction to the 1th Chapter

When you decide to use zookeeper to design your app, it's a good idea to separate application data and collaborative data.
For example, the user of the webmail service is interested in the content in their mailbox, but does not care about which server handles the request for a particular mailbox. In this example, the mailbox content is the application data, and the mapping between the mailbox and a mailbox server is the collaborative data (or meta-data). The latter is managed by the entire zookeeper service.

1.1 Zookeeper's mission
  • Apache Hbase
    HBase is a data storage warehouse that is typically used with Hadoop. In HBase, zookeeper is used to elect a master node within a cluster to keep track of available servers and to save the cluster's metadata.
  • About the origin of the zookeeper name
    ZooKeeper was developed at Yahoo! We had been working on ZooKeeper for a while and pitching it to other groups, so we needed a name. At the time the group had been working with the Hadoop team and had started a variety of projects with the names of animal S, Apache Pig being the most well known. As we were talking about different possible names, one of the group members mentioned that we should avoid another animal Name because our manager thought it is starting to the sound as we lived in a zoo. That was when it clicked:distributed systems was a zoo. They was chaotic and hard to manage, and ZooKeeper was meant to keep them under control.
    The Cat on the book cover is also appropriate, because a early article from Yahoo! 's about ZooKeeper described dis tributed process management as similar to herding cats. ZooKeeper sounds much better than catherder, though.
  • The entire zookeeper server cluster manages key data for application collaboration. Zookeeper is not suitable for mass data storage.
2nd Chapter Understanding ZooKeeper2.1 Zookeeper Foundation
  • Instead of exposing the primitives directly, zookeeper exposes a file-system-like API consisting of a small number of invocation methods to allow the application to implement its own primitives. We usually use recipes (recipes) to represent the implementations of these primitives. Recipes include the zookeeper operation and maintenance of a small data node, known as Znode, which is managed in a hierarchical tree-like structure similar to the file system.
  • Api
    • Create/path data
      Create a Znode node named/path, and include the data DATA,-E parameter flags to create the Znode as a temporary node.
    • Delete/path
      Delete the znode named/path.
    • Exists/path
      Check for the presence of a node named/path.
    • Setdata/path data
      Set the data for the znode named/path.
    • Getdata/path
      Returns the data information for a node named/path.
    • Getchildren/path
      Returns a list of all child nodes of all/path nodes, note: child nodes that do not contain child nodes.
    • Note: Zookeeper does not allow local write or read data from Znode nodes. When a Znode node is set up for data or read, the contents of the Znode node are completely replaced or read in all.
    • Stat/path [True]
      The stat command can get the properties of a Znode node/path, and allows us to set the monitoring point on the Znode node that already exists. Add a watch point by setting the parameter true after the path. For example, you can monitor the node delete event nodedeleted event.
    • Ls/path [True]
      You can view the sub-nodes under/path, and set the true parameter to set the monitoring point corresponding to the Znode's child node changes.
  • Different types of Znode
    • Persistent (persistent) nodes and temporary (ephemeral) nodes
      Persistent Znode can only be deleted by calling delete. Temporary znode In contrast, when the client that created the node crashes or shuts down the connection to zookeeper, the entire node is deleted. Create a temporary node with the-e parameter.
    • Ordered nodes, creating an ordered node with the-s parameter
  • Monitoring and notification
    The client registers with zookeeper the Znode to receive notifications and receives notifications by setting a watch on the znode. A monitor point is a word-triggered operation, meaning that a monitoring point triggers a notification. In order to receive multiple notifications, the client must set up a new monitoring point after each notification.
  • Version
    Each znode has a version number that is self-increasing with each data change. Two API actions can be performed conditionally: SetData and delete. This two call takes the version number as an incoming parameter, and the call succeeds only if the version number of the incoming parameter matches the version number on the server.
2.2 Zookeeper Architecture

The zookeeper server runs in two modes: Standalone mode (standalone) and quorum mode (quorum).

2.3 Getting started with zookeeper
    • Windows considerations
      • Use the following command to run the Times the following error, workaround, without the start parameter, but can not stop, can only be stopped by CTRL + C, carefully review the Windows Script and Linux script, found that Windows script is too weak, want to learn more or go to Linux.
        D:\soft\zookeeper-3.4.8\bin>zkServer.cmd start
D:\soft\zookeeper-3.5.1-alpha\bin>zkServer.cmd start系统找不到指定的路径。Error:set.
    • If you report the above error (appearing in Zookeeper-3.5.1-alpha), there are spaces in your java_home path, just modify the Bin/zkenv.cmd file and %JAVA_HOME% add double quotes outside, as shown below:
ifnotexist "%JAVA_HOME%\bin\java.exe" (  echoset.  @REM goto :eof)set JAVA="%JAVA_HOME%\bin\java"
    • The state and life cycle of a session
    • Transaction identifier Zkid
    • This section is developed on Windows, and you need to modify the Zkserver.cmd file to
      java "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %*
      Switch
      java "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% %*
      That is, remove "%ZOOCFG%" , manually specify the path to the configuration file *.cfg when the command is executed.
    • Implement a primitive: implement locks through zookeeper
2.4 Implementation of a master-slave pattern example

Some of the features of the master-slave sample are implemented through the ZKCLI tool.
The master-slave model consists of three characters:

    • Master Node
      The primary node is responsible for monitoring the new slave nodes and tasks, assigning tasks to the available slave nodes.
    • From the node
      The slave node registers itself with the system to ensure that the primary node sees that they can perform the task, and then begins to monitor the new task.
    • Client
      The client creates a new task and waits for the system to respond.
The 3rd chapter starts using Zookeeper's API

Note: Order and Connectionlossexception exceptions
Zookeeper will strictly maintain the order of execution, and provide a strong orderly guarantee, however, in the multi-threaded still need to face the order problem carefully. In multiple threads, when the callback function includes code for retry logic, some common scenarios can cause errors to occur. When an connectionlossexception exception is encountered and a request is reissued, the newly created request may be sorted after the request in the other thread, and the request in the other thread should actually be after the original request.

The 4th chapter deals with state changes

Zookeeper Distributed Process Collaboration technology detailed

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.