主管重启战略和儿童规范

时间:2012-11-18 21:22:50

标签: erlang rabbitmq supervisor

我正在阅读rabbitmq的supervisor2.erl,rabbit_channel_sup_sup.erl, rabbit_channel_sup.erl源代码。

childspec的起始参数为"temporary"时,表示在退出任何原因后子节点不会重新启动。是不是?

当start参数为"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}.

1 个答案:

答案 0 :(得分:1)

永远不会重新启动临时子项,这是真的。但是重启策略仍然在确定主管行为中起作用 - 一对一策略将杀死所有孩子(因为它们是临时的而不会重启),而one_for_one不会杀死任何其他孩子。基本上这些重启策略告诉主管如何处理其他进程(其他进程没有死),所以存在差异。