zookeeper cluster structures and ZAB agreement

  zookeeper Cluster Setup is very simple to prepare three zookeeper installed server, add the following configuration in its configuration carved table zoo.cfg

The maximum number of heartbeats to complete initialization can tolerate simultaneous connections (the number of tickTime) initLimit 10 between the follower and the cluster leader. If the amount of environmental data zk large clusters, data synchronization time becomes long, such a case can be suitably adjusted major changes in parameters 
up to tolerate request syncLimit 2 between the cluster leader and follower of the response time of the number of heartbeats 
server.1 = node1: 2881: 3881
server.2 = node2: 2881: 3881
server.3 = node3: 2881: 3881
which 1,2,3 is the service id, by creating a file named myid in each directory for each dataDir server gives a server id, myid file contains only one line of text machine id, id must be unique, value between 1-255,
two first port number is the port number follower connected leader of the second election leader port number, node1, node2, node3 corresponding to three servers ip

  Once configured, respectively zookeeper start on three machines, a minimal version of the cluster will be set up is complete, you can see information related to leader and follower of the log, all nodes in the cluster can provide the service, the client connection, connection string may be specified or a plurality of addresses of all nodes connected to the cluster, when one node fails, the client will automatically switch to another node.

  All related to the cluster on data consistency problems inevitable, data consistency protocol ZAB protocol (atom message broadcasting agreement) is specifically designed for the zookeeper. To ensure that all read data consistency, the client can at any node, write operation can only be forwarded to the lead node to perform. zookeeper cluster write procedure is as follows

  leader server crash or network and causes more than half of the follower loses connection, zk cluster goes into repair mode crashes, the cluster is not available at this time, it is a zookeeper cluster CP service. ZAB is agreed that if a thing proposal (proposal) process successfully on a machine, then all the machines should be treated successfully, to ensure that those things presented at the leader server eventually all servers are submitted to ensure discard only lead server was presented proposal.

  In order to meet the requirements of ZAB, when the zookeeper leader election must ensure that the elected leader servers have things proposal cluster highest ZXID of all machines.

  ZXID (transaction number) is a 64-bit number, the lower 32 bits of a monotonically increasing counter, each generating a leader Proposal things, will add an operation counter, the upper 32 bits is the number leader epoch period each time a new leader election, leader will be removed from this server zxid largest proposal of things, and extracts from the epoch zxid out corresponding value, on the basis of an increase, after this number as a new era, and the lower 32 bits from zero again count. Can solve the problem of discarding things that proposal based on this rule, when a server contains something proposal within the period not yet submitted a leader rejoins the cluster, the cluster has been found to exist leader, the follower's identity added to the cluster, the server at this time leader Compare proposal will be based on the transaction proposal submitted last and follower own server and found follower has a leader within the period of the transaction proposal, leader will be asked to conduct a follower back operation, to fall back to a cluster has indeed been submitted by more than half machine the latest business proposal

  zookeeper leader when the leader elected by the election to ensure compliance with two requirements: to have the highest zxid and more than half of the nodes agree on elected leader, has built-in algorithms: LeaderElection FastLeaderElection AuthFastLeaderElection

  The concept elections: server id, transaction id, logic clock (sponsored poll rounds Technology), the state electoral looking (election), following, observing (observing, not only synchronized elections), leading.

  Specific steps voting algorithm:

  1, each server polls to elect their own bit lead, election information contained in the above four information
  2, the other server receives an invitation to vote, more initiator zxid is larger than themselves, the big vote, the same words Compare the server id, the vote than their
  3, the initiator of the vote received feedback to see if the number of votes greater than half of the cluster, called the win is greater than the lead, otherwise the next round of voting initiated

  Elected leader after complete synchronization with the new leader of the follower, when half of the follower synchronization is complete, it can provide the service. The synchronization process is as follows:

  After the leader server for each follower have a ready queue, and those that are not synchronized with each follower things sent to each follower in the form of proposal message and a comiit followed in every proposal, follower receive a message in their local application, and leader after leader synchronize the follower will really join the list of available, more than half after the service can be provided.

  

Guess you like

Origin www.cnblogs.com/hhhshct/p/11567044.html