what is the difference between LeaderLatch and LeaderSelector in the apache curator framework?
http://curator.incubator.apache.org/curator-recipes/leader-election.html
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.
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).
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With