gen_server中的数据是否在其主管重新启动后保留? [英] Will data in gen_server be kept after restarted by its supervisor?

查看:94
本文介绍了gen_server中的数据是否在其主管重新启动后保留?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主管启动许多gen_server。每个gen_server都有大量的数据加载需要很多时间。我想知道错误发生时,将存储在gen_server状态中的数据及其进程dict是否保持下一次启动,所以我不需要再次启动它们。

解决方案

Erlang行为的当前状态不会保存在任何地方。您将不得不自己照顾。



您可以在外部保存状态(在另一个进程中,在ETS表中,数据库等)或您确保您的 init / 1 函数是足够聪明和动态的,以便能够在启动时重新创建状态(恢复现有文件,基于原始输入参数重新创建一些缓存) 。)



基本上,您必须定义哪些数据应该能够在崩溃中生存,以及如何坚持或重新创建它。


I have a supervisor which starts many gen_server. Each gen_server has a lot of data load which takes a lot of time. I want to know when error happens, will the data stored in gen_server's state and its process dict be kept for next start so I don't need to init them again?

解决方案

The current state of an Erlang behavior is not saved anywhere. You would have to take care of that yourself.

Either you save the state regurlarly somewhere externally (in another process, in an ETS table, a database etc.) or you make sure that your init/1 function is sufficiently smart and dynamic to be able to recreate the state upon starting (recover existing files, recreate some cache based on the original input arguments etc.)

Basically, you have to define what data should survive a crash and how to persist or recreate it.

这篇关于gen_server中的数据是否在其主管重新启动后保留?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆