gen_server中的数据是否在其主管重新启动后保留? [英] Will data in gen_server be kept after restarted by its supervisor?
问题描述
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屋!