Skip to content

Commit

Permalink
More mirrored supervisor logging
Browse files Browse the repository at this point in the history
(cherry picked from commit 9a0f4b1)
  • Loading branch information
michaelklishin authored and mergify-bot committed Aug 5, 2021
1 parent 3d4f9c1 commit a9b1c86
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions deps/rabbit_common/src/mirrored_supervisor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,14 @@ handle_call({init, Overall}, _From,
initial_childspecs = ChildSpecs}) ->
process_flag(trap_exit, true),
ok = pg:join(Group, Overall),
rabbit_log:debug("Mirrored supervisor: initializing, joined group ~p", [Group]),
rabbit_log:debug("Mirrored supervisor: initializing, overall supervisor ~p joined group ~p", [Overall, Group]),
Rest = pg:get_members(Group) -- [Overall],
Nodes = [node(M) || M <- Rest],
rabbit_log:debug("Mirrored supervisor: known group ~p members: ~p on nodes ~p", [Group, Rest, Nodes]),
case Rest of
[] -> TxFun(fun() -> delete_all(Group) end);
[] ->
rabbit_log:debug("Mirrored supervisor: no known peer members in group ~p, will delete all child records for it", [Group]),
TxFun(fun() -> delete_all(Group) end);
_ -> ok
end,
[begin
Expand Down Expand Up @@ -414,7 +416,8 @@ maybe_start(Group, TxFun, Overall, Delegate, ChildSpec) ->
end.

check_start(Group, Overall, Delegate, ChildSpec) ->
rabbit_log:debug("Mirrored supervisor: check_start for group ~p, id: ~p", [Group, id(ChildSpec)]),
rabbit_log:debug("Mirrored supervisor: check_start for group ~p, id: ~p, overall: ~p",
[Group, id(ChildSpec), Overall]),
ReadResult = mnesia:wread({?TABLE, {Group, id(ChildSpec)}}),
rabbit_log:debug("Mirrored supervisor: check_start table ~s read for key ~p returned ~p",
[?TABLE, {Group, id(ChildSpec)}, ReadResult]),
Expand All @@ -424,12 +427,19 @@ check_start(Group, Overall, Delegate, ChildSpec) ->
[S] -> #mirrored_sup_childspec{key = {Group, Id},
mirroring_pid = Pid} = S,
case Overall of
Pid -> child(Delegate, Id);
_ -> case supervisor(Pid) of
dead -> _ = write(Group, Overall, ChildSpec),
start;
Delegate0 -> child(Delegate0, Id)
end
Pid ->
rabbit_log:debug("Mirrored supervisor: overall matched mirrored pid ~p", [Pid]),
child(Delegate, Id);
_ ->
rabbit_log:debug("Mirrored supervisor: overall ~p did not match mirrored pid ~p", [Overall, Pid]),
rabbit_log:debug("Mirrored supervisor: supervisor(~p) returned ~p", [Pid, supervisor(Pid)]),
case supervisor(Pid) of
dead ->
_ = write(Group, Overall, ChildSpec),
start;
Delegate0 ->
child(Delegate0, Id)
end
end
end.

Expand Down Expand Up @@ -460,6 +470,8 @@ stop(Group, TxFun, Delegate, Id) ->
end.

check_stop(Group, Delegate, Id) ->
rabbit_log:debug("Mirrored supervisor: checking if child ~p in group ~p should be stopped: ~p",
[Id, Group, child(Delegate, Id)]),
case child(Delegate, Id) of
undefined -> delete(Group, Id),
deleted;
Expand Down

0 comments on commit a9b1c86

Please sign in to comment.