A fan who has been working for 7 years and ran into a problem with Zookeeper.
Because I have been exposed to the technology of Zookeeper, I don't know how to answer.
I say that a programmer who has worked for 7 years and has no exposure to mainstream technology is not normal.
So after I asked him about his salary, I understood!
Well, about the "implementation principle of the Watch mechanism in Zookeeper", look at the answers of ordinary people and experts.
Ordinary people:
Ok. . . . . . . . . . . . . . .
Expert:
OK, I'm going to answer this question in two ways.
Zookeeper is a distributed coordination component that provides sequential access control capabilities for multiple application components in a distributed architecture.
Its data storage adopts a tree structure similar to the file system, and manages the data stored on Zookeeper in the form of nodes.
Zookeeper provides a Watch mechanism that allows clients to perceive changes in data stored on Zookeeper Server. Such a mechanism allows Zookeeper to implement many scenarios, such as configuration centers, registration centers, and so on.
The Watch mechanism is implemented by the Push method, that is to say, the client and the Zookeeper Server will establish a long connection. Once the specified node to be monitored changes, the changed event will be pushed to the client through this long connection.
The specific process of Watch is divided into several parts:
- First, the client adds watch to a specific path by specifying commands such as
exists
,get
Then after the server receives the request, it uses HashMap to save the client session and the corresponding concerned node path, and the client also uses HashMap
Stores the corresponding relationship between the specified node and the event callback function.
- When the node specified by the server changes, it will find the session corresponding to the node, and send the changed event and node information to the client.
- After the client receives the request, it calls the corresponding callback method in ZkWatcherManager to complete the notification of the event change.
The above is my understanding of the problem!
Summarize
As for this interview question, I think the value of the inspection is also great. In fact, for the data change notification on the server side,
There are nothing more than two solutions, pull and push, and the technical point involved in this question is the implementation of push.
In business development, similar scenarios may also be involved, such as message notification, scan code login, etc.
If you understand these ideas, you will become more relaxed when dealing with these kinds of problems.
This issue of ordinary people VS master interview series ends here.
If you need a master interview document (with a 100,000-word interview document inside Ali) or have any technical interview questions you don't understand and want to consult, you can send a private message or leave a message in the comment area.
Copyright notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated. Please indicate the source forMic带你学架构
!
If this article is helpful to you, please help to follow and like, your persistence is the driving force for my continuous creation. Welcome to follow the WeChat public account of the same name to get more technical dry goods!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。