3
votes

In here someone said:

"even if you read from a different follower every time, you'll never see version 3 of the data after seeing version 4."

So if I have 3 nodes zookeeper quorum as below:

zk0 -- leader
zk1
zk2

Assume there is a value in quorum "3" and I have a client connects to zk1, then my client sends a write request (update "3" to "4") and zk0 (leader) writes the value then subsequently received the confirmation from zk1. My client can see the new ("4"), because it connects to zk1.

Now my question is, if I switch my client from zk1 to zk2 (leader hasn't received write confirmation from zk2, so zk2 is behind the quorum) I will see the value as "3" rather than "4". Does it break the sequential consistency?

1

1 Answers

5
votes

ZooKeeper uses a special atomic messaging protocol called ZooKeeper Atomic Broadcast (ZAB), which ensures that the local replicas in the ensemble (groups of Zookeeper servers) never diverge.

ZAB protocol is atomic, so the protocol guarantees that updates either succeed or fail.

In Zookeeper every write goes through the leader and leader generates a transaction id (called zxid) and assigns it to this write request.

A zxid is a long (64-bit) integer split into two parts:

  • epoch
  • counter

The zxid represents the order in which the writes are applied on all replicas. The epoch represents the changes in leadership over time. Epochs refer to the period during which a given server exercised leadership. During an epoch, a leader broadcasts proposals and identifies each one according to the counter.

A write is considered successful if the leader receives the ack from the majority.

The zxid is used to keep servers synchronized and avoid the conflict you described.

enter image description here