airbnb / nerve

A service registration daemon that performs health checks; companion to airbnb/synapse
MIT License
942 stars 151 forks source link

Zk leader election (sequence) #28

Closed Dareen closed 10 years ago

Dareen commented 10 years ago

added the ability to use ZK leader election capability

igor47 commented 10 years ago

can you give a little more context here? if a number of nodes register with the same service, you want to pick the one with the lowest sequential id to write to? how/where do you use these sequential nodes?

Dareen commented 10 years ago

yes but there's an issue that i found in deleting the node, because @key doesn't contain the sequence and the node doesn't know which sequence did it get, i'll work on that and update the code.

as for usage, yes it's for leader election, to use the node with the lowest sequence as the master node, suitable for services that must have a leader/master such as DB's, the consumer that will have synapse installed, will read the lowest sequence node from haproxy and consider it the master node

Dareen commented 10 years ago

@igor47 the pull request is ready now

igor47 commented 10 years ago

i am not sure how this code would be used right now; i would like to see a matching PR for nerve that takes advantage of this feature before merging.

i am concerned that if the sequential id is being appended to the node name (@key) you might not get what you expect from a straightforward aphanumeric sort.

additionally, i've heard concerns about the general node naming strategy for nerve. i might be open to the idea of making all node names sequential ids, and including more information (like hostname) in the node information instead. this would solve the problem we fix here.

Dareen commented 10 years ago

I'm currently working on consuming this feature and will be opening a PR for the usage of it.

as for using the sequence as an id, a key must be provided before the sequence can be appended to it, that is not a problem however and it's still a valid approach because each time a new sequential node is created with the same key, a new sequence will be appended and thus can fix the issue.

Dareen commented 10 years ago

I opened a PR for synapse to consume this feature, and use haproxy to set the slave nodes as backup servers https://github.com/airbnb/synapse/pull/29

lwf commented 10 years ago

+1 for this. Would be a very useful feature when dealing with master/slave db pairs and similar setups.

Dareen commented 10 years ago

@igor47 what's the status of merging this PR?