Good programmer Java tutorial ZooKeeper interview questions combing summary

  The ZooKeeper interview questions of the good programmer Java tutorial are sorted out and summarized . With the improvement of the epidemic, major companies began to recruit talents in the form of remote interviews, and the Java industry is still the most in demand, but the recruitment requirements have been greatly improved. . Some students worry that they cannot pass the business interview. In fact, as long as you pass the skills and perform well, high salary is not a problem. The next good programmer Java employment guidance editor will share the interview questions related to ZooKeeper .

ZooKeeper.png

What is  ZooKeeper ?

  ZooKeeper is an open source distributed coordination service. It is the administrator of the cluster, monitoring the status of each node in the cluster and performing the next reasonable operation based on the feedback submitted by the nodes. In the end, the user will be provided with an easy-to-use interface and a system with high performance and stable functions.

  Distributed applications can implement functions such as data publishing / subscription, load balancing, naming services, distributed coordination / notification, cluster management, master election, distributed locks, and distributed queues based on Zookeeper . Zookeeper guarantees distributed consistency features: sequential consistency, atomicity, single view, reliability, real-time ( final consistency ) .

Difference between  ZooKeeper load balancing and nginx load balancing

  ZooKeeper

  1) There is no single point problem, the zab mechanism ensures that a single point of failure can re-elect a leader;

  2) Only responsible for service registration and discovery, not responsible for forwarding, reducing one data exchange ( consumer and server directly communicate );

  3) You need to implement the corresponding load balancing algorithm yourself.

  nginx

  1)) There is a single point problem, a single point of load is high, and the amount of data is large . It is necessary to achieve high availability through the KeepAlived + LVS backup machine ;

  2) Each load acts as an intermediary forwarding role, increasing the network load ( consumer and server indirect communication );

  3) Comes with load balancing algorithm.

  Zookeeper Watcher mechanism - data change notification

  Zookeeper allows a client to a server-side Znode a registered Watcher listen when some specified event server triggers the Watcher , the server sends an event notification to a specified client to achieve distributed notification, then the client according Watcher Notification status and event type make business changes.

  Working Mechanism:

  Client register watcher

  The server handles the watcher

  Client callback watcher

How does  ZooKeeper guarantee the order consistency of transactions ?

  ZooKeeper uses a globally increasing transaction Id to identify, all proposals ( proposals ) are added with zxid when it is proposed , zxid is actually a 64 -bit number, the upper 32 bits are epoch ( period ; era ; world ; New era ) is used to identify the leader cycle. If a new leader is generated, the epoch will increase automatically, and the lower 32 bits are used to increment the count. When a new proposal is generated , it will issue a transaction execution request to other servers according to the two-stage process of the database . If more than half of the machines can execute and can succeed, then it will start execution.

  Is Zookeeper 's watch monitoring notification for nodes permanent ?

  No. Official statement: A Watch event is a one-time trigger. When the data of the Watch is changed, the server sends the change to the client of the Watch to notify them.

  Why is it not permanent? For example, if the server changes frequently and the listening clients are in many cases, all clients will be notified of each change, which will cause great pressure on the network and the server.

  Generally, the client executes getData ("/ node A", true) . If node A is changed or deleted, the client will get its watch event, but after node A has changed, and the client has not set Watch events are no longer sent to the client.

  In practical applications, in many cases, our client does not need to know every change of the server, I only need the latest data.

How to deal with  ZK node downtime ?

  Zookeeper itself is also a cluster, it is recommended to configure no less than 3 servers. Zookeeper must also ensure that when one node goes down, other nodes will continue to provide services.

  If a Follower is down, there are 2 servers to provide access, because there are multiple copies of the data on Zookeeper , the data will not be lost ;

  If a leader goes down, Zookeeper will elect a new leader .

The mechanism of  ZK cluster is that as long as more than half of the nodes are normal, the cluster can provide services normally. Only when ZK nodes are hung too much, only half or less than half of the nodes can work, the cluster will fail.

  and so:

  3 nodes cluster can hang 1 node (leader can get 2 votes > 1.5);

A cluster of  2 nodes cannot hang up any 1 node (the leader can get 1 vote <= 1) .

 


Guess you like

Origin blog.51cto.com/14793189/2488760
Recommended