Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LeaderLatch vs LeaderSelector

what is the difference between LeaderLatch and LeaderSelector in the apache curator framework?

http://curator.incubator.apache.org/curator-recipes/leader-election.html

like image 427
user2474033 Avatar asked Aug 01 '13 15:08

user2474033


People also ask

What is Curatorframework?

The Curator Framework is a high-level API that greatly simplifies using ZooKeeper. It adds many features that build on ZooKeeper and handles the complexity of managing connections to the ZooKeeper cluster and retrying operations.

What is curator client?

Background. CuratorZookeeperClient is a wrapper around ZooKeeper's Java client that makes client access to ZooKeeper much simpler and less error prone. It provides the following features: Continuous connection management - ZooKeeper has many caveats regarding connection management (see the ZooKeeper FAQ for details).

How do you use ZooKeeper leader elections?

Leader Election. A simple way of doing leader election with ZooKeeper is to use the SEQUENCE|EPHEMERAL flags when creating znodes that represent "proposals" of clients. The idea is to have a znode, say "/election", such that each znode creates a child znode "/election/guid-n_" with both flags SEQUENCE|EPHEMERAL.


2 Answers

They are different abstractions for the same behavior. LeaderSelector was written first (NOTE: I'm the main author of Curator). It uses a callback mechanism. Some Curator users wanted something that looked more like the JDK CountDownLatch, so I wrote LeaderLatch based on those requests. They both accomplish the same thing: leader election. Use whichever suits your needs.

like image 147
Randgalt Avatar answered Oct 19 '22 01:10

Randgalt


LeaderLatch is simpler to use but LeaderSelector gives you more control. It depends on how much control you need.

Check out this presentation that I did and the gists that it links to for more details.

like image 26
sourcedelica Avatar answered Oct 19 '22 01:10

sourcedelica