根据Elixir Registry documentation,如果注册进程崩溃,其密钥将自动从注册表中删除。 当注册表进程本身崩溃并由主管重新启动时,它是否使用已注册进程的密钥恢复或重新重新启动?
答案 0 :(得分:3)
注册表进程将“重新启动”。 (在其主管中配置)
实际上,注册表注册的所有进程都link加入了注册表进程check this line。这意味着当注册表崩溃时,所有注册的进程也将退出,除非它们指定其他行为。
答案 1 :(得分:1)
注册表进程重新启动。事实证明,使用交互式Elixir很容易进行测试。
# Create a Registry process and registers an Agent process.
{:ok, _} = Registry.start_link(keys: :unique, name: Registry.ViaTest)
name = {:via, Registry, {Registry.ViaTest, "agent"}}
{:ok, _} = Agent.start_link(fn -> 0 end, name: name)
iex(4)> Registry.lookup(Registry.ViaTest, "agent")
[{#PID<0.90.0>, nil}]
# Kill Registry process
iex(7)> Process.exit(Process.whereis(Registry.ViaTest), :kill)
** (EXIT from #PID<0.84.0>) evaluator process exited with reason: killed
Interactive Elixir (1.5.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>
15:20:42.180 [error] GenServer Registry.ViaTest.PIDPartition0 terminating
** (stop) killed
Last message: {:EXIT, #PID<0.86.0>, :killed}
State: #Reference<0.2950178278.1828847617.245854>
nil
# Confirm the Registry process died
iex(2)> Process.whereis(Registry.ViaTest)
nil
# Restart the Registry process with the same name
iex(3)> {:ok, _} = Registry.start_link(keys: :unique, name: Registry.ViaTest)
{:ok, #PID<0.100.0>}
# Look up previously registered Agent process
iex(4)> Registry.lookup(Registry.ViaTest, "agent")
[]