服务器会失败导致客户端丢失更新吗?

will server fail cause client lost their update?

首先让我描述一个情况:
客户端刚刚更新一个值(操作成功),然后它连接的服务器失败,客户端故障转移到另一个服务器,但此时更新还没有同步到新服务器,然后客户端调用getData获取它刚刚设置的值.它可能会看到它刚刚设置的值丢失了。

想知道zookeeper是怎么处理这种情况的

阅读一些资源后,我找到了答案。
在本文here中,它说:

Responses include the zxid that the response is relative to.Even heartbeat messages during intervals of no activity include the last zxid seen by the server that the client is connected to. If the client connects to a new server, that new server ensures that its view of the ZooKeeper data is at least as recent as the view of the client by checking the last zxid of the client against its last zxid. If the client has a more recent view than the server, the server does not reestablish the session with the client until the server has caught up.

所以每次更新都会分配一个zxid​​表示zookeeper的当前状态。当client发出更新操作时,响应中会有分配给这次更新操作的zxid,这个zxid​​会在下一个读请求中携带。当服务器收到读取请求时,它会将 zxid 与它当前的 zxid 进行比较,如果请求中的 zxid 大于它当前的 zxid,它就知道客户端看到了更新的系统图像,因此它必须与领导赶上客户。