Zookeeper - 如果我只传入 zk 集群(合奏)中的一些节点的连接字符串会发生什么?

Zookeeper - what will happen if I pass in a connection string only some of the nodes from the zk cluster (ensemble)?

我有一个由 N 个节点组成的 zookeeper 集群(它们相互了解)。如果我在 zk 客户端连接字符串中只传递 M < N 个节点地址怎么办?集群的行为是什么?

在更具体的情况下,如果我从集群中仅传递 1 个 zk 的主机地址会怎样?那么 zk 客户端是否可以连接到集群中的其他主机?如果这台主机宕机了怎么办?客户端能否连接到整体中的其他动物园管理员节点?

另一个问题是,是否可以限制客户端仅使用集合中的特定节点?

What if I pass only M < N of the nodes' addresses in zk client connection string? What will be the cluster's behavior?

ZooKeeper 客户端将仅连接到连接字符串中指定的 M 个节点。 ZooKeeper ensemble 的 back-end 交互(leader 选举和处理写入事务提议)将继续由集群中的所有 N 个节点处理。 N 个节点中的任何一个仍然可以成为集成领导者。如果一个 ZooKeeper 服务器接收到写事务请求,并且该服务器不是当前领导者,那么它会将请求转发给当前领导者。

In a more specific case, what if I pass host address of only 1 zk from the cluster? Is it possible then for the zk client to connect to other hosts from the cluster? What if this one host is down? Will be client able to connect to other zookeeper nodes in an ensemble?

不,客户端只能连接到连接字符串中指定的单个地址。该地址实际上成为应用程序的单点故障,因为如果服务器出现故障,客户端将没有任何其他建立连接的选项。

The other question is, is it possible to limit client to use only specific nodes from the ensemble?

是的,您可以通过仅列出客户端连接字符串中的节点来限制客户端考虑建立连接的节点。但是,请记住,集群中的 N 个节点中的任何一个仍然可以成为领导者,然后所有客户端写请求都将转发给该领导者。从这个意义上讲,客户端正在间接使用其他节点,但客户端并未与这些节点建立直接套接字连接。

Apache 文档中的 ZooKeeper Overview 页面进一步讨论了 ZooKeeper 集群中的客户端和服务器行为。例如,在 Implementation 部分有相关引用:

As part of the agreement protocol all write requests from clients are forwarded to a single server, called the leader. The rest of the ZooKeeper servers, called followers, receive message proposals from the leader and agree upon message delivery. The messaging layer takes care of replacing leaders on failures and syncing followers with leaders.