The interview questions of ZooKeeper made me not escape the soul torture of the interviewer, I was too difficult

Foreword:

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

The interview questions of ZooKeeper made me not escape the soul torture of the interviewer, I was too difficult

 

ZooKeeper interview soul torture

There are benefits at the end of the article

1. What does ZooKeeper provide?

  • 1. File system
  • 2. Notification mechanism

 

2. Zookeeper file system

 

Zookeeper provides a multi-level node namespace (nodes are called znodes). The difference with the file system is that these nodes can all set the associated data, but in the file system, only file nodes can store data, but directory nodes cannot. In order to ensure high throughput and low latency, Zookeeper maintains this tree-like directory structure in memory. This feature makes Zookeeper unable to store large amounts of data. The upper limit of data storage for each node is 1M

 

3. The ZAB agreement?

The ZAB protocol is an atomic broadcast protocol that supports crash recovery specially designed for the distributed coordination service Zookeeper.

The ZAB protocol includes two basic modes: crash recovery and message broadcasting .

When the entire zookeeper cluster has just started or the Leader server is down, restarted, or network failure causes no more than half of the servers to maintain normal communication with the Leader server, all processes (servers) enter the crash recovery mode. First, a new Leader server is elected, and then the cluster The Follower server starts to synchronize data with the new Leader server. After more than half of the machines in the cluster complete data synchronization with the Leader server, exit the recovery mode and enter the message broadcast mode. The Leader server starts to receive client transaction requests to generate transaction proposals for transactions. Request processing.

 

4. Four types of data nodes Znode

1. PERSISTENT -Unless the persistent node is manually deleted, the node always exists on Zookeeper

2. EPHEMERAL -Temporary node The life cycle of the temporary node is bound to the client session. Once the client session fails (the client is disconnected from zookeeper, the session may not be invalid), then all temporary nodes created by the client will be removed .

3. PERSISTENT_SEQUENTIAL -The basic characteristics of a persistent sequence node are the same as those of a persistent node, except that the sequence attribute is added. A self-increasing integer number maintained by the parent node will be appended to the node name.

4. EPHEMERAL_SEQUENTIAL -The basic characteristics of a temporary sequence node are the same as that of a temporary node, with the addition of a sequence attribute. A self-increasing integer number maintained by the parent node will be appended to the node name.

 

5. Client registration Watcher implementation

1. Call the three APIs of getData()/getChildren()/exist() and pass in the Watcher object

2. Mark the request and encapsulate Watcher to WatchRegistration

3. Encapsulate it into a Packet object and send the request to the server

4. After receiving the server response, register Watcher to ZKWatcherManager for management

5. Request to return and complete registration

 

6. Client callback Watcher

The SendThread thread of the client receives the event notification, and the EventThread thread calls back the Watcher.

The Watcher mechanism of the client is also one-time. Once triggered, the Watcher becomes invalid.

 

7.Chroot features

After version 3.2.0, the Chroot feature was added, which allows each client to set a namespace for itself. If a client sets up Chroot, then any operation of the client on the server will be restricted to its own namespace. By setting Chroot, a client can be applied to a subtree of the Zookeeper server. In the scenario where multiple applications share a Zookeeper into the group, it is very helpful to achieve mutual isolation between different applications.

 

8. Server working status under ookeeper

 

The server has four states: LOOKING, FOLLOWING, LEADING, OBSERVING.

1. LOOKING : Look for Leader status. When the server is in this state, it will think that there is no Leader in the current cluster, so it needs to enter the Leader election state.

2. FOLLOWING : Follower status. Indicates that the current server role is Follower.

3. LEADING : Leader status. Indicates that the current server role is Leader.

4. OBSERVING : Observer status. Indicates that the current server role is Observer.

 

9. How does zookeeper ensure the sequence consistency of transactions?

Zookeeper uses a globally increasing transaction Id to identify, all proposals (proposals) are added with zxid when they are proposed, zxid is actually a 64-bit number, the high 32-bit is epoch (period; epoch; 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 count up. When a new proposal is generated, it will first issue a transaction execution request to other servers according to the two-phase process of the database. If more than half of the machines can execute and succeed, then it will start execution.

 

10. Why is there a Master in a distributed cluster?

 

In a distributed environment, some business logic only needs to be executed by one machine in the cluster, and other machines can share this result, which can greatly reduce repetitive calculations and improve performance, so leader election is required.

11. How to deal with zk node downtime?

Zookeeper itself is also a cluster, and it is recommended to configure no less than 3 servers. Zookeeper itself must also ensure that when one node goes down, other nodes will continue to provide services. If one follower goes down, there are still 2 servers to provide access, because the data on Zookeeper has multiple copies, and the data will not be lost; if one leader goes down, Zookeeper will elect a new leader. The mechanism of the ZK cluster is that as long as more than half of the nodes are normal, the cluster can provide services normally. Only when the ZK node hangs too much and only half or less than half of the nodes can work, the cluster fails. and so

A cluster of 3 nodes can suspend 1 node (the leader can get 2 votes>1.5)

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

 

12. The difference between zookeeper load balancing and nginx load balancing

The load balance of zk can be adjusted, nginx can only adjust the weight, and other things that need to be controlled need to be written by yourself

Plug-in; but the throughput of nginx is much larger than zk, it should be said which way to choose according to business.

 

13. What are the deployment modes of Zookeeper?

Deployment mode: stand-alone mode, pseudo cluster mode, cluster mode.

 

14. Is Zookeeper's watch monitoring notification to the node permanent? Why is it not permanent?

It's not. Official statement: A Watch event is a one-time trigger. When the data set with Watch changes, the server will send the change to the client set with Watch to notify them. Why is it not permanent? For example, if the server changes frequently and the monitored client is in many cases, all clients must be notified of each change, which will put a lot of 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 the node A has changed again, the client has not set it 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.

 

15. What is chubby, and how do you compare to zookeeper?

Chubby is Google, which fully implements the paxos algorithm and is not open source. zookeeper is chubby

Open source implementation of, using zab protocol, a variant of paxos algorithm.

 

16.Typical application scenarios of Zookeeper

 

Zookeeper is a typical publish/subscribe model of distributed data management and coordination framework. Developers can use it to publish and subscribe distributed data. Through the cross-use of the rich data nodes in Zookeeper and the Watcher event notification mechanism, it is very convenient to build a series of core functions that will be involved in distributed applications in the middle of the year, such as:

1. Data publish/subscribe

2. Load balancing

3. Naming service

4. Distributed coordination/notification

5. Cluster management

6. Master election

7. Distributed lock

8. Distributed queue

to sum up:

These interview questions are a collection of thousands of interview question documents I have collected and shared a small part of it for everyone. To get the offer you want, you must first be prepared to go to the interview, and secondly, you must have excellent knowledge. This PDF interview material contains interviews with major Java core knowledge, all with detailed answers to share with those in need

collection method

Contains knowledge:

  • MyBatis interview questions (27 questions)
  • ZooKeeper interview questions (28 questions)
  • Dubbo interview questions (30 questions)
  • Elasticsearch interview questions (24 questions)
  • Memcached interview questions (23 questions)
  • Redis interview questions (40 questions)
  • MySQL interview questions (50 questions)
  • Java concurrent programming (1), Java concurrent programming (2) (123 questions in total)
  • Java Interview Questions (1), Java Interview Questions (2) (228 questions in total)
  • Spring interview questions (1), Spring interview questions (2) (116 questions in total)
  • Microservice interview questions (50 questions)
  • Linux interview questions (45 questions)
  • Spring Boot interview questions (22 questions)
  • Spring Cloud interview questions (8 questions)
  • RabbitMQ interview questions (12 questions)
  • Kafka interview questions (18 questions)

 

The interview questions of ZooKeeper made me not escape the soul torture of the interviewer, I was too difficult

 

The interview questions of ZooKeeper made me not escape the soul torture of the interviewer, I was too difficult

Guess you like

Origin blog.csdn.net/qq_46388795/article/details/108732142