[erlang-questions] preserving state through a gen_server restart
Siraaj Khandkar
siraaj.khandkar@REDACTED
Sat Oct 20 06:04:31 CEST 2012
On Oct 19, 2012, at 11:03 AM, Ivan Uemlianin wrote:
> 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?
Seems like ETS is the natural choice for this sort of thing.
--
Siraaj Khandkar
.o.
..o
ooo
More information about the erlang-questions
mailing list