master 和 slave 不能通信会怎样?

What would happen if master and slave can't communicate?

我正在学习zookeeper中的主从模型。我有一个问题:

如果一主一从无法通信会怎样?像 master 不能从 slave 得到 ACK? slave 会自动重启吗?

这取决于法定人数如何划分。您可能知道 zookeeper 作为 zookeeper 服务器的法定人数运行。如果两台服务器无法相互通信,则意味着存在网络分区问题(一组服务器无法访问网络不同部分的其他服务器)。由于我们在仲裁中使用奇数个服务器,因此将有两个分区,一个是大多数服务器,一个是少数服务器。

如果leader在多数分区,

法定人数将继续运作,因为领导者拥有多数法定人数。在少数分区中,服务器将关闭并进入领导者选举阶段。以下文本引自 Apache Zookeeper user mail list 中的邮件线程。

After the partition, all the servers in the minority region will get shutdown and moves to leader election phase. All the client sessions connected to these servers will be disconnected and will receive "KeeperState.Disconnected" event to their watchers, if any registered.

But ZooKeeper supports read-only server mode. In this mode, client can connect to the read-only server even when the server might be partitioned from the quorum.

如果leader在少数分区,

同样,两个分区都将进行领导选举,少数分区将无法选举领导者。因此,将关机。多数分区将选出新的领导者并继续运行。

在你的问题中,你所说的 master cannot connect to slave 是网络分区的一个例子。要么master(leader)在少数分区,要么slave在少数分区。

希望你明白了:-)