preface

Now the topic is distributed system. After the interviewer has talked to you about dubbo, you have already confirmed that you have some knowledge of distributed service framework /RPC framework. Then he might want to start talking to you about other distribution-related issues.

Distributed locks are a very common thing, if you’re doing Java system development, distributed systems, you might have a few scenarios. The most common distributed lock implementation is based on ZooKeeper.

In fact, to be honest, this question is usually asked to see if you know zooKeeper, because ZooKeeper is a very common basic system in distributed systems. What are the usage scenarios of ZooKeeper? See if you know some basic usage scenarios. But in fact, Zookeeper dug deep nature can ask very deep.

Analysis of interview questions

Generally speaking, the usage scenarios of ZooKeeper are as follows. I will just mention a few simple ones.

  • Distributed coordination
  • A distributed lock
  • Metadata/configuration information management
  • HA High availability

Distributed coordination

This is actually A classic use of ZooKeeper. In simple terms, it is like that you send A request to MQ, and then system B consumes the message and processes it. How does system A know the result of system B? Zookeeper can be used to coordinate distributed systems. After system A sends the request, it can register A listener for the value of A node on ZooKeeper. Once system B finishes processing, it can modify the value of the ZooKeeper node, and system A can receive notification immediately and solve the problem perfectly.

A distributed lock

Here’s an example. When two consecutive modification operations are performed on a single piece of data, both machines receive the request at the same time, but only one machine can execute the other machine first. Zookeeper distributed lock can be used at this time. After a machine receives a request, it first obtains a distributed lock on ZooKeeper, that is, it can create a ZNode and then perform operations. Then another machine tried to create the ZNode, only to find that it couldn’t because someone else had created it and had to wait until the first machine had finished executing it.

Metadata/configuration information management

Zookeeper can be used to manage the configuration information of many systems, such as Kafka, Storm and many other distributed systems use ZooKeeper to manage metadata and configuration information, including dubbo registry.

HA High availability

For example, many big data systems such as Hadoop, HDFS, and YARN choose to develop HA mechanisms based on ZooKeeper. That is, an important process usually has two main and standby processes. When the main process dies, zooKeeper detects that the main process is switched to the standby process immediately.

The last

Welcome to pay attention to my public number [programmer chasing wind], the article will be updated in it, sorting out the data will be placed in it.