[erlang-questions] Can OTP worker resume from same state after being restarted by supervisor?

Essien Essien essiene@REDACTED
Sun Sep 19 02:00:22 CEST 2010


Hi Tushar,

On Sun, Sep 19, 2010 at 12:37 AM, Tushar Deshpande
<tushar.erlang@REDACTED> wrote:
> Hi,
>
> I've a question about OTP's restart strategy.
>
> I wrote a simple OTP application with just a root supervisor
> and a single worker.  The worker has an internal state defined
> by a single integer (count).  The 'count' is initialized to zero.
> Each call to the worker process increments this count by one.
> I called the worker process 5 times using gen_server:call.
> This updated current value of counter to be 5.
>
> Then, I opened the appmon and killed the worker process.
> OTP supervisor promptly restarted it.  I thought that the
> process would be resume with the same state that it had at
> the time of crash.  But, I observed that for the restarted process,
> the 'counter' was reset to zero.
>
> I would like the process to resume from the same state after
> it's restarted by supervisor.

You will have to maintain your own persistent state. Write to a file,
update a DETS table, use mnesia... But you do have to do this
yourself. Supervision tree is not about managing state, only about
keeping the tree up and running.

>
> Is it possible to do this in OTP?
>
>
> Best Regards,
>
> Tushar Deshpande
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>


More information about the erlang-questions mailing list