Zookeeper for assigning shard indices

I have seen several posts on the internet on how to use Zookeeper to assign dash numbers to servers as they go online (assuming you are plastering data across a cluster) - but for the rest of my life I can't find any Java code example how to do this this is. Anyone already working? Thank.

+3


source to share


1 answer


There are many details about what data in a cluster is stored in a cluster, such as replication and disaster recovery. I assume you mean you have N nodes and each node has to handle 1 / N th requests and clients can detect which servers are busy.

First create a persistent node /service

. Each server creates an ephemeral child /service

when it starts up, something like /service/hostname:port

. Clients keep watch on /service

and are notified when children are added and removed (clients must update their watch after each notification). This way, the client knows which servers are serving requests and can distribute requests as needed (round robin, random). When the server goes down, the ephemeral node will disappear and clients can stop sending its requests.



If you are looking for the zookeeper library, curator is probably the best one. Clients will use Path-Cache , and the server just creates an ephemeral node.

+2


source







All Articles