Hi,

Yeah, third server is always elected due to the timing, mostly all the servers 
will be started at the same time.


I'm trying to explain few basics of leader election algo (there are few 
additions/updation made to improve it better, but I didn't include that details 
here). 
Please feel free to add/modify if I miss anything.

Election Algo:
--------------
Each server will participate in the election by giving their transaction 
id(zxid number), epoch number and the sid(myid number).

Say we have three servers A,B,C. Assume this is fresh environment and all the 
servers started at the same time, here everyone has equal chance to become 
LEADER.
Vote of A(zxid=0, epoch=1, myid=1), Vote of B(zxid=0, epoch=1, myid=2), Vote of 
C(zxid=0, epoch=1, myid=3)
Since zxid and epoch is same for all the servers, it will consider the myid 
value, whoever has the higher myid value will become LEADER, others will give 
their vote to him.


What happens when you restart the servers?
-----------------------------------------

Sometimes, follower may be behind the Leader so the transaction id of the peers 
will differ.
On receiving the vote notifications, each server will do voting based on their 
respective values and peer's values.

Say, I'm server A. I got a vote notification from my peer(B), now I will do 
comparison between the notified peer's epochid, zxid and myid with myself. 
If any of the following matches I will support him to become LEADER, otw I will 
propose myself as LEADER. Voting will happen till majority reaches.

-> his epoch is higher than me
-> his epoch is the same as my epoch, but his zxid is higher than me
-> his epoch is the same as my epoch, also zxid is the same as my zxid, but his 
myid is higher than me


Best Regards,
Rakesh

-----Original Message-----
From: Flavio Junqueira [mailto:[email protected]] 
Sent: 28 October 2014 15:09
To: [email protected]; zookeeper-user
Subject: Re: Strange behaviour in Leader election

Exactly, when you start the third server, you have a majority, which causes the 
leader election to complete.The election algorithm doesn't really force it to 
be the third server, it is just a matter of timing.
-Flavio  

     On Tuesday, October 28, 2014 3:06 AM, "[email protected]" <[email protected]> 
wrote:
   
 

 When you start the five servers one by one, and the server 3 is the 3rd server 
that you start , then you will have the server 3 as the leader always, this is 
what the zookeeper election algorithm does.



[email protected]
 
From: Ibrahim
Date: 2014-10-28 04:04
To: zookeeper-user
Subject: Strange behaviour in Leader election Strange behaviour in Leader 
election
 
I have 5 ZooKeeper servers. When I start running the Zookeeper, there is always 
one particular machine elected as leader and the other is follower.
For example, assume we have machine 1,2,3,4, and 5. When I start the Zookeeper, 
it always elects machine number 3 as leader. Note that before I start Zookeeper 
I delete all DataDir and log  files (information history). 
 
I expect each new run I see different machine elect as leader. But this does 
not happen.
Question:
What criteria does election algorithm use to elect a machine to become a 
leader? 
 
Thank you
 
Ibrahim
 
 
 
 
--
View this message in context: 
http://zookeeper-user.578899.n2.nabble.com/Strange-behaviour-in-Leader-election-tp7580475.html
Sent from the zookeeper-user mailing list archive at Nabble.com.


 
   

Reply via email to