对Zookeeper的一致性保证感到困惑(顺序一致性与最终一致性)

n3ipq98p  于 2022-12-09  发布在  Apache
关注(0)|答案(1)|浏览(134)

As I understand, Zookeeper enforces "sequential consistency" which states any execution is the same as if all read/write ops were executed in some global ordering. Basically, a client may see stale data but it's guaranteed to see values in the order of the writes which are linearized.
I have two confusions

1. How is the ordering guarantee from sequential consistency preserved when a node goes down? For example, what happens in a following scenario?

  1. Write x=1
  2. Write x=2
  3. Node A has the most recent value x=2, Node B is still on old value x=1
  4. A client reads x=2 from Node A
  5. Node A goes down.
  6. A client is now connected to Node B.
  7. A client now reads x=1 from Node B.
    Doesn't this break the ordering guarantee provided by the sequential consistency?

2. Am I correct in saying that all eventual consistency model provides an ordering guarantee as long as a client is always reading from the same node?

Is the lack of ordering guarantee in eventual consistency due to the fact that a client can read from any node and is not tied to a specific node when reading a value?
(Wouldn't systems that implement sequential consistency suffer from the same issue though in a scenario where a node goes down and a client is forced to read from a client with a stale data? Kinda goes back to my question #1)
Any clarification would be greatly appreciated. Thank you.

c6ubokkw

c6ubokkw1#

What you are seeing is sequential consistency. That's it, no restrictions on the nodes going down/up or connecting to the same node. The question is, how we make sure the client handles the situation without reaching a wrong conclusion. Here is how:

  1. Each event has a version number (e,1) (e'',2) (e''',3)
  2. The client notes down the version number (high water mark) after processing each node.
  3. If the system (Zookeeper) ever goes back in time, delivering an event older than client's high water mark. Client waits, ignoring these event.
    Only with sequential consistency, the client can ignore redeliveries and avoid processing duplicate events. So the client avoids going back and forth in time.

相关问题