Reputation: 51
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?
Upvotes: 5
Views: 1295
Reputation: 1535
When connecting to a node, the client submits the latest zxid it's seen. If this is newer than the last zxid the node has seen, it will refuse to connect.
So the scenario where client writes but then disconnects and reconnects to an outdated follower can't happen (reconnect is refused by the node).
Upvotes: 0
Reputation: 11377
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:
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.
Upvotes: 5