14

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

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

user2474033
  • 155
  • 1
  • 5

2 Answers2

33

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.

Randgalt
  • 2,907
  • 1
  • 17
  • 31
  • In the docs, it is mentioned that I should consider using LeaderSelector to run the Reapers as they don't need to run in every client. Why is that? – Arun Apr 02 '15 at 14:36
  • 2
    Only one server needs to reap. It's overkill to have multiple clients reaping. It could also hurt performance. – Randgalt Apr 15 '15 at 16:14
  • I would like leader election to be done each time isLeader is called to give some randomness to the process that handles a critical path. I don't see an easy way to do this? – stewart99 Oct 17 '18 at 01:06
  • As I understand there will be one leader and multiple followers. But if the use case demands that only one host (leader) executes the code and others just sit idle doing nothing or block, does this framework help ? In other words, if leader is restarted, the others should not get leader privilege. Only the host which is leader initially should retain the authority. is there more detail documentation around the behavior ? – Albatross Dec 17 '21 at 17:43
11

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.

sourcedelica
  • 23,940
  • 7
  • 66
  • 74