1

I am writing a leader election algorithm using zookeeper. I was able to write the leader election part. But I need all the nodes, in a path, to receive events of node addition/removal, to that particular path.

For an example, let's say I have several nodes in /election. When some other node is added to the same path, or removed from path, I need to receive this event to all the existing nodes in that path. I am able to watch a single node. But how to watch all the nodes in a path.

Furthermore, I need to receive leader changed event to all the nodes too. Is there a way to achieve this?

SameeraR
  • 415
  • 1
  • 6
  • 19
  • 1
    I strongly suggest that you do not write the code yourself but use Apache Curator (note: I'm the main author), Kazoo, etc. i.e. use one of the well known clients. Writing correct ZooKeeper recipes is much too hard. – Randgalt Jan 19 '17 at 18:07
  • @Randgalt can you please provide an answer at https://stackoverflow.com/questions/39125064/how-to-use-kazoo-client-for-leader-election? – Aditya Jun 01 '18 at 23:13

1 Answers1

1

Using the Apache Curator API (as comment recommends - and I would agree having implemented - thanks Netflix guys!) ...

http://curator.apache.org/curator-recipes/node-cache.html

That API allows for watching a "ZNode" to get value updates as well as delete/change events by registering a listener.

Darrell Teague
  • 4,132
  • 1
  • 26
  • 38