[erlang-questions] preserving state through a gen_server restart

Ivan Uemlianin ivan@REDACTED
Fri Oct 19 17:03:41 CEST 2012


Dear All

I have an erlang/OTP application consisting mostly of gen_servers.  One 
repeated pattern is having a gateway/aggregate gen_server process that 
provides access (and other management) to individual gen_server 
processes, e.g.:

               my_sup
                  |
               my_lambs
              /        \      \
         my_lamb     my_lamb    my_lamb    ...

my_lambs' state variable holds a dictionary {LambName: LambPid} and 
among other functions it allows me to call lambs by name instead of my Pid.

If my_lambs terminates normally --- e.g., if the whole application is 
closing down --- its terminate/s function can call my:lamb:stop for each 
of the processes in its care.

However, if my_lambs terminates abnormally, and is restarted by my_sup, 
I think I'd like to preserve its state variable --- at least the Pids of 
the my_lamb processes --- so that it can be passed on to the new version 
of my_lambs.

I'd like to avoid losing all of the my_lamb processes, if the my_lambs 
process crashes.

Can state be passed to the supervisor, to be used when it restarts its 
child?

Could I park the state variable in some kind of holding process, so that 
the new my_lambs can retrieve it?

Or is there another way of doing this?

With thanks and best wishes

Ivan



-- 
============================================================
Ivan A. Uemlianin PhD
Llaisdy
Speech Technology Research and Development

                     ivan@REDACTED
                      www.llaisdy.com
                          llaisdy.wordpress.com
               github.com/llaisdy
                      www.linkedin.com/in/ivanuemlianin

               "hilaritas excessum habere nequit"
                  (Spinoza, Ethica, IV, XLII)
============================================================



More information about the erlang-questions mailing list