Java Review notes distributed article: Zookeeper

Source: Internet
Author: User

Foreword: Finally to the distributed chapter, in front of some of Java's core Knowledge Review, but also a Java programmer to master the most basic knowledge points, the next distributed knowledge is the Internet industry Java programmer must have the skills;

Concept: Zookeeper is a distributed , open source distributed application Coordination Service that is an open source implementation of Google's chubby and an important component of Hadoop and HBase. It is a software that provides consistent services for distributed applications, including: Configuration maintenance, domain name services, distributed synchronization, group services, etc.

Keywords: distributed, consistent service

Speaking in a more popular way, the birth of zookeeper is to solve the problem of distributed consistency.

What is distributed consistency?

Distributed: A distributed system consists of a group of computer nodes that communicate through the network and coordinate their work in order to accomplish common tasks. The emergence of distributed systems is to use inexpensive, ordinary machines to complete a single computer can not complete the calculation, storage tasks. The goal is to use more machines to process more data .

Consistency: Refers to each node of a data update, the entire cluster is aware of the update, and is consistent;

PS: Popular a little before a server to support a system of the mode upgrade to multiple servers (multiple containers) to support a system, so that the system's concurrency, disaster tolerance and other aspects of the ability will be greatly improved (traditional ngix and clusters can also do), One of the biggest differences between distributed and clustered clusters is that distributed nodes are different businesses (such as account systems, order systems, logistics systems, and commodity systems that are deployed on different servers), and the benefit is that resources can be allocated reasonably according to the characteristics of different modules (such as the large number of account accesses, the need to deploy 3-5 machines, and logistics system access is small, only need to deploy 1-2 servers can be, consistency is that although the account system deploys 3 servers, for the client is transparent (order system calls the service of the account system, do not know which server to call the system, the result can be idempotent every time), So how do you make sure you get this idempotent result every time? Which is zookeeper's problem to solve.

Basic architecture Diagram

Role:

Group Head (leader): Leader as the master node of the entire zookeeper cluster, responsible for responding to all requests for zookeeper state changes;

Follower (follower): In addition to responding to read requests on the server (read-only requests such as Exists,getdata,getchildren), follower also handles leader proposals and commits locally when leader submits the proposal

Observer (Observer): Observer and follower are similar, with only a few small differences: first observer do not participate in the election and do not respond to the proposal; followed by observer does not need to persist the transaction to disk, once the observer is restarted, The entire namespace needs to be resynchronized from the leader.

The entire zookeeper cluster only has these 3 roles, you can see leader only one, all requests for data changes need to have leader to dispatch (leader will send atomic broadcasts to all nodes, receive the message that more than half of the nodes agree), and then actually commit the transaction. So leader this node is very important, how to establish this learder?

The answer is the election, zookeeper the election to establish leader (there are 2 scenarios for triggering an election, one is when the server is initialized, and one is that the server cannot be connected to the leader while it is running)

You need to know a few nouns before you explain the election process.

Electionepoch: Every leader election, Electionepoch will be self-increasing to mark leader election rounds.

Peerepoch: After each leader election, a new Peerepoch is elected to mark the turn that the transaction request belongs to

ZXID: The unique token for the transaction request, which is assigned by the leader server. Composed of 2 parts, the high 32 bits are the above Peerepoch, the low 32 bits are the count of requests, starting from 0. So by Zxid we can know which round the request was, and it was the first of the rounds.

Lastprocessedzxid: Zxid of the last commit transaction request

Election process (first deployment): Assume that there are currently 3 servers (SERVER0,SERVER1,SERVER3) deployed ZK, start in turn, the first time each server will vote to vote for themselves, the voting information contains its own node ID and transaction ID ZXID, First Server0 cast (0,0), Server1 cast (1,0) Server2 cast (2,0)

Each node will receive voting information from other servers after it has cast its own ticket, Server0 received Server1 's vote (1,0), because

============================================== to Be Continued =======================================


  

Java Review notes distributed article: Zookeeper

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.