diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2011-07-18 14:49:28 +0100 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2011-07-18 14:49:28 +0100 |
| commit | 9b8e28e5a2f2650830d9c703e5d649ec69cb4128 (patch) | |
| tree | 576fe1016c3d56ee87f473cdaf807adb6e81525c /src | |
| parent | 3a2f261753bfd7f061d1ccde3184def04a5184b3 (diff) | |
| download | rabbitmq-server-git-9b8e28e5a2f2650830d9c703e5d649ec69cb4128.tar.gz | |
Defer all of the startup work to the second stage startup, so that we can't get a DOWN message while we're still half started and then fall over.
Diffstat (limited to 'src')
| -rw-r--r-- | src/mirrored_supervisor.erl | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/mirrored_supervisor.erl b/src/mirrored_supervisor.erl index 2787001bdc..09d38630ec 100644 --- a/src/mirrored_supervisor.erl +++ b/src/mirrored_supervisor.erl @@ -237,7 +237,7 @@ start_link({global, _SupName}, _Group, _Mod, _Args) -> start_link0(Prefix, Group, Mod, Args) -> case apply(?SUPERVISOR, start_link, Prefix ++ [?MODULE, {overall, Group, Mod, Args}]) of - {ok, Pid} -> call(Pid, {finish_startup, Pid}), + {ok, Pid} -> call(Pid, {init, Pid}), {ok, Pid}; Other -> Other end. @@ -283,23 +283,26 @@ init({delegate, Restart}) -> {ok, {Restart, []}}; init({mirroring, Group, ChildSpecs}) -> + {ok, #state{group = Group, initial_childspecs = ChildSpecs}}. + +handle_call({init, Overall}, _From, + State = #state{overall = undefined, + delegate = undefined, + group = Group, + initial_childspecs = ChildSpecs}) -> process_flag(trap_exit, true), ?PG2:create(Group), ok = ?PG2:join(Group, self()), - {ok, lists:foldl( - fun(Pid, State0) -> - gen_server2:cast(Pid, {ensure_monitoring, self()}), - add_peer_monitor(Pid, State0) - end, #state{group = Group, initial_childspecs = ChildSpecs}, - ?PG2:get_members(Group) -- [self()])}. - -handle_call({finish_startup, Overall}, _From, - State = #state{overall = undefined, - initial_childspecs = ChildSpecs}) -> + State1 = lists:foldl( + fun(Pid, State0) -> + gen_server2:cast(Pid, {ensure_monitoring, self()}), + add_peer_monitor(Pid, State0) + end, State, ?PG2:get_members(Group) -- [self()]), + Delegate = child(Overall, delegate), erlang:monitor(process, Delegate), [maybe_start(Delegate, S) || S <- ChildSpecs], - {reply, ok, State#state{overall = Overall, delegate = Delegate}}; + {reply, ok, State1#state{overall = Overall, delegate = Delegate}}; handle_call({start_child, ChildSpec}, _From, State = #state{delegate = Delegate}) -> |
