【问题标题】:supervisor restart stratgy and childspec主管重启策略和 childspec
【发布时间】:2012-11-06 20:09:52
【问题描述】:

我在看rabbitmq的supervisor2.erl,rabbit_channel_sup_sup.erl, rabbit_channel_sup.erl源码。

childspec的启动参数为"temporary"时,表示无论任何原因退出后子进程都不会重新启动。对吗?

当启动参数为"temporary"时,每个重启参数one-for-one, one-for-all,one-for-rest,simple-one-for-one没有区别。因为代码运行结果是一样的。对吗?

以下代码来自supervisor2.erl文件

do_restart({permanent = RestartType, Delay}, Reason, Child, State) ->
    do_restart_delay({RestartType, Delay}, Reason, Child, State);
do_restart(permanent, Reason, Child, State) ->
    report_error(child_terminated, Reason, Child, State#state.name),
    restart(Child, State);
do_restart(Type, normal, Child, State) ->
    del_child_and_maybe_shutdown(Type, Child, State);
do_restart({RestartType, Delay}, {shutdown, restart} = Reason, Child, State)
  when RestartType =:= transient orelse RestartType =:= intrinsic ->
    do_restart_delay({RestartType, Delay}, Reason, Child, State);
do_restart(Type, {shutdown, _}, Child, State) ->
    del_child_and_maybe_shutdown(Type, Child, State);
do_restart(Type, shutdown, Child = #child{child_type = supervisor}, State) ->
    del_child_and_maybe_shutdown(Type, Child, State);
do_restart({RestartType, Delay}, Reason, Child, State)
  when RestartType =:= transient orelse RestartType =:= intrinsic ->
    do_restart_delay({RestartType, Delay}, Reason, Child, State);
do_restart(Type, Reason, Child, State) when Type =:= transient orelse
                                            Type =:= intrinsic ->
    report_error(child_terminated, Reason, Child, State#state.name),
    restart(Child, State);
do_restart(temporary, Reason, Child, State) ->  %%<<----attention here, just report_error,not calling restart child function
    report_error(child_terminated, Reason, Child, State#state.name),
    NState = state_del_child(Child, State),
    {ok, NState}.

【问题讨论】:

    标签: erlang rabbitmq erlang-supervisor


    【解决方案1】:

    一个临时的孩子永远不会重新启动,这是真的。但是重启策略仍然在决定主管行为方面发挥作用——all-for-one 策略将杀死所有孩子(不会重新启动,因为它们是临时的),而 one_for_one 不会杀死任何其他孩子。基本上,这些重启策略告诉主管如何处理其他进程(其他是没有死的进程),所以有区别。

    【讨论】:

    • 我在上面复制了更多代码并在上面添加了一条注释。因为没有调用“重启函数”,一对一、一休的策略没有机会生效。对吗?
    • 我认为这段代码只处理死掉的进程。我假设必须有其他代码来决定如何处理其他子进程。但我在这里肯定是错的......
    猜你喜欢
    • 2012-04-03
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多