[erlang-questions] Custom supervisor

Paul Guyot <>
Sat Jan 17 09:49:21 CET 2009


Hello,

We have worker processes that are identified by a key and on each  
node, a manager that provides the pid of the worker process from the  
key, spawning a new worker if required. The key is independent from  
the node. The workers may crash and if they do, they should be  
restarted, being told they are restarted as a parameter of the init  
callback function, and when queried, the manager will return the new  
pid. The workers may also be stopped and started on another node (i.e.  
migrated). The workers are simple gen_servers.

To perform this, we wrote the manager as a gen_server that traps exits  
and spawn processes and that stores the key/pid mapping in a mnesia  
table. However, I am wondering if the workers are visible in the OTP  
supervision tree since they are children of a worker and not of a  
supervisor. If we declare to the manager's supervisor that the manager  
is a supervisor (and not a worker), this has consequences I do not  
fully understand. I figured out that the manager will receive a  
which_children message during a release update, but that's all I know.

We did update the worker's code, but we only needed {load_module,  
worker} and not {update, worker, {advanced, extra}}, i.e. we did not  
need to call code_change yet. Still, I guess that Module:code_change  
is only called when the module is in the supervision tree.

Is there a more OTP-way to perform this, i.e. to track the death/ 
restarts of the children of a supervisor?
What are the consequences of having worker or supervisor in the  
supervisor's child specifications?

Paul




More information about the erlang-questions mailing list