The latest collection of JAVA interview questions (12)

Zookeeper

139. What is zookeeper?

zookeeper is a distributed, open source distributed application coordination service, an open source implementation of google chubby, and an important component of hadoop and hbase. It is a software that provides consistent services for distributed applications. The functions provided include: configuration maintenance, domain name services, distributed synchronization, group services, etc.

140. What are the functions of zookeeper?

  • Cluster management: monitor the survival status of nodes, operation requests, etc.

  • Primary node election: After the primary node is hung up, a new round of primary election can be started from the standby node. The primary node election refers to the election process, and zookeeper can assist in completing this process.

  • Distributed locks: Zookeeper provides two types of locks: exclusive locks and shared locks. Exclusive lock means that only one thread can use resources at a time. Shared lock means read lock sharing and read-write mutual exclusion. That is, multiple threads can read the same resource at the same time. If a write lock is to be used, only one thread can use it. Zookeeper can control distributed locks.

  • Naming service: In a distributed system, by using a naming service, client applications can obtain information such as the address and provider of a resource or service according to a specified name.

141. How many deployment modes does zookeeper have?

There are three deployment modes for zookeeper:

Single machine deployment: run on a cluster;

Cluster deployment: multiple clusters running;

Pseudo cluster deployment: A cluster starts multiple zookeeper instances to run.

142. How does zookeeper ensure the synchronization of the master and slave nodes?

The core of zookeeper is atomic broadcasting. This mechanism ensures synchronization between various servers. The protocol that implements this mechanism is called the zab protocol. The zab protocol has two modes, recovery mode (primary selection) and broadcast mode (synchronization). When the service is started or after the leader crashes, zab enters the recovery mode. When the leader is elected and most of the servers are synchronized with the leader's state, the recovery mode ends. State synchronization ensures that the leader and server have the same system state.

143. Why is there a master node in the cluster?

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

144. There are 3 servers in the cluster, and one of the nodes is down. Can zookeeper still be used at this time?

It can continue to be used, and the singular server can continue to be used as long as no more than half of the servers are down.

145. Tell me about the notification mechanism of zookeeper?

The client will create a watcher event for a znode. When the znode changes, these clients will be notified by zookeeper, and then the client can make business changes based on the znode changes.

Guess you like

Origin blog.csdn.net/weixin_42120561/article/details/115272291