31

QQA: Zookeeper 如何保证单一视图

 4 years ago
source link: https://www.tuicool.com/articles/6ZRb6zZ
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Zookeeper 集群由多个节点构成,写入数据时只要多数节点确认就算成功,那些没有确认的节点此时存放的就是老数据。Zookeeper 的“单一视图(single system image)”保证说的是客户端如果读到了新数据,则再也不会读到老数据。如果重新连接连上了老的节点,怎么能保证不会读到老的数据?

真相 很直接很残酷:老的节点会拒绝新客户端的连接。

zxid

Zookeeper 会为每个消息打上递增的 zxid (zookeeper transactioin id),客户端会维护一个 lastZxid ,存放最后一次读取数据对应的 zxid ,当客户端连接时,节点会判断 lastZxid 是不是比自己的 zxid 更大,如果是,说明节点的数据比客户端老,拒绝连接。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK