之所以要记录这个是因为看到很多博客都说Zookeeper满足了CPA中的CP。 但是Zookeeper的Follower和Observer是可以处理非事务请求的,那么问题来了,如果一个读请求到了未同步的Follower和Observer上,那读到的数据不就是旧数据吗?那不就不一致了吗?
Zookeeper的官方文档回答了我这个问题
Sometimes developers mistakenly assume one other guarantee that ZooKeeper does not in fact make. This is: * Simultaneously Consistent Cross-Client Views* : ZooKeeper does not guarantee that at every instance in time, two different clients will have identical views of ZooKeeper data. Due to factors like network delays, one client may perform an update before another client gets notified of the change. Consider the scenario of two clients, A and B. If client A sets the value of a znode /a from 0 to 1, then tells client B to read /a, client B may read the old value of 0, depending on which server it is connected to. If it is important that Client A and Client B read the same value, Client B should should call the sync() method from the ZooKeeper API method before it performs its read. So, ZooKeeper by itself doesn't guarantee that changes occur synchronously across all servers, but ZooKeeper primitives can be used to construct higher level functions that provide useful client synchronization. (For more information, see the ZooKeeper Recipes. [tbd:..]).
问题确实是存在的,所以要取最新数据可以通过调用sync方法