GenServer and Global Registration

Quick question about a global process and restarts…

I have a genserver which is registered using {global, term} and I’ve been doing some testing using a 3 node cluster.

I can (from the terminal) kill the pid using whereis(); and I see the process get restarted; usually on the same node it was running on.

If I kill the VM on the node the process is running on (using control-C), the other two nodes (the supervisors), the process does not get restarted. genserver:whereis returns nil at this point.

The process is a worker managed by a supervisor; (there are a few other workers) and the restart strategy is one_to_one.

So I’m trying to figure out how/where to tell something that I want the remaining nodes to restart the process. Perhaps I need to monitor the pid and messages myself? Do I need to design a leader/election thing or is there an idiomatic / supervisor way of doing this?

Link to the GenServer code:

3 Likes

You specify how/when/if an Application should replicate to another node based on the information at it’s setup. The official documentation (erlang) is at: http://erlang.org/doc/design_principles/distributed_applications.html

Basically you need to say what nodes it is allowed to run at and with what priorities at startup, and there are a ton more options too. :slight_smile:

For a specific GenServer, if you only want one instance of it running (when the application is running in multiple places), then something like gen_leader is what you want. :slight_smile:

2 Likes

Zookeeper and other fancy consensus tools are useful if you need to be absolutely sure only one instance runs, even in the case of netsplits. If you can live with a weaker guarantee, then it’s very simple to setup the GenServer for automatic fallover:

1 Like