You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@curator.apache.org by Patrick Peralta <pp...@gmail.com> on 2019/02/27 19:55:16 UTC
LeaderLatch random selection
Hello!
I have a question about the JavaDoc for LeaderLatch:
https://curator.apache.org/apidocs/org/apache/curator/framework/recipes/leader/LeaderLatch.html
It states "If a group of N thread/processes contend for leadership one
will randomly be assigned leader until it releases leadership at which
time another one from the group will randomly be chosen". However,
when reading the source it appears to me that leadership is actually
assigned in the order in which the participants contend for the lock
since it uses ephemeral sequential nodes and sorts them accordingly.
Am I misunderstanding the code or the meaning of the word "randomly"
in the JavaDoc?
Thanks!
Re: LeaderLatch random selection
Posted by Patrick Peralta <pp...@gmail.com>.
> The order that processes contend is essentially random. Whichever client
connects first gets the next ephemeral node. It's not deterministic.
Yes that makes sense, thank you for the explanation. That JavaDoc is
different from LeaderSelector:
https://curator.apache.org/apidocs/org/apache/curator/framework/recipes/leader/LeaderSelector.html
That doc states "Note that this class uses an underlying InterProcessMutex
and as a result leader election is "fair" - each user will become leader in
the order originally requested (from ZK's point of view)."
This sounds similar to how LeaderLatch works, but the use of the term
"random" confused me into thinking that LeaderSelector was truly random as
opposed to LeaderSelector which grants leadership based on order of
contention.
Thanks!
Patrick
On Wed, Feb 27, 2019 at 3:04 PM Jordan Zimmerman <jo...@jordanzimmerman.com>
wrote:
> > the order in which the participants contend for the lock
>
> The order that processes contend is essentially random. Whichever client
> connects first gets the next ephemeral node. It's not deterministic.
>
> -JZ
>
> > On Feb 27, 2019, at 2:55 PM, Patrick Peralta <pp...@gmail.com> wrote:
> >
> > Hello!
> >
> > I have a question about the JavaDoc for LeaderLatch:
> >
> >
> https://curator.apache.org/apidocs/org/apache/curator/framework/recipes/leader/LeaderLatch.html
> >
> > It states "If a group of N thread/processes contend for leadership one
> > will randomly be assigned leader until it releases leadership at which
> > time another one from the group will randomly be chosen". However,
> > when reading the source it appears to me that leadership is actually
> > assigned in the order in which the participants contend for the lock
> > since it uses ephemeral sequential nodes and sorts them accordingly.
> > Am I misunderstanding the code or the meaning of the word "randomly"
> > in the JavaDoc?
> >
> > Thanks!
>
>
Re: LeaderLatch random selection
Posted by Jordan Zimmerman <jo...@jordanzimmerman.com>.
> the order in which the participants contend for the lock
The order that processes contend is essentially random. Whichever client connects first gets the next ephemeral node. It's not deterministic.
-JZ
> On Feb 27, 2019, at 2:55 PM, Patrick Peralta <pp...@gmail.com> wrote:
>
> Hello!
>
> I have a question about the JavaDoc for LeaderLatch:
>
> https://curator.apache.org/apidocs/org/apache/curator/framework/recipes/leader/LeaderLatch.html
>
> It states "If a group of N thread/processes contend for leadership one
> will randomly be assigned leader until it releases leadership at which
> time another one from the group will randomly be chosen". However,
> when reading the source it appears to me that leadership is actually
> assigned in the order in which the participants contend for the lock
> since it uses ephemeral sequential nodes and sorts them accordingly.
> Am I misunderstanding the code or the meaning of the word "randomly"
> in the JavaDoc?
>
> Thanks!