[Zookeeper] Common interview questions

Zookeeper common interview questions

1. What is Zk

Zookeeper is a distributed, open source distributed application coordination service (hereinafter referred to as Zk). Zk is an important component of hadoop and hbase.

Zk is a software that provides consistent services for distributed applications. The functions provided mainly include:

  • Configuration maintenance
  • Domain name service
  • Distributed synchronization
  • Group service

2. What functions does Zk have?

  • Cluster management: monitoring the survival status of nodes and running requests

  • Primary node election: After the primary node hangs up, a new round of elections can be conducted from the standby nodes. This election process is called the primary node election.

  • Distributed locks: Zookeeper provides two types of locks: 独占锁, 共享锁.

    • Exclusive lock, that is, only one thread can use resources at a time,
    • Shared locks, read locks are shared, and read and write are mutually exclusive. That is, multiple threads can read the same resource at the same time. If a write lock is used, only one thread can use it at the same time.
    • Zookeeper can control distributed locks
  • Naming Service: distributed systems, by using a naming service, the client application able to obtain resources or services specified name 地址, 提供者and other information

3. What are the deployment modes of Zk?

Zk has three deployment modes:

  1. Single machine deployment: run on a cluster;
  2. Cluster deployment: multiple clusters running;
  3. Pseudo cluster deployment: a cluster starts multiple zookeeper instances and runs;

4. How does Zk ensure the synchronization of the state of the master and slave nodes?

The core of Zk: Atomic broadcasting , which ensures synchronization between various servers. The protocol that implements this mechanism is called the zab protocol.

The zab protocol has two modes:

  1. Recovery mode (choose main)
  2. Broadcast mode (synchronous)

When 服务启动/ 主节点宕机after, zab enters the recovery mode; the master node is elected, and after most servers have completed the synchronization with the master node, the recovery mode ends.

State synchronization ensures that the master node and the slave node have the same system state.

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

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

6. In the cluster, there are 3 servers and one of the nodes is down. Can Zk still be used at this time?

Singular servers can continue to be used as long as no more than half of the servers are down.

7. Tell me about Zk's notification mechanism

The client will create a watcher event for a znode.

When the znode changes, these clients will be notified by zookeeper, and then can make business changes according to the znode changes.

Guess you like

Origin blog.csdn.net/weixin_40849588/article/details/107695077