Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit group coordinator if member pid gone #611

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/brod_group_coordinator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,15 @@ terminate(Reason, #state{ connection = Connection

%%%_* Internal Functions =======================================================

% Exit the process if MemberPid is set to pid but it's not
% currently alive
-spec ensure_member_pid_alive(pid()) -> ok.
ensure_member_pid_alive(MemberPid) ->
case brod_utils:is_pid_alive(MemberPid) of
true -> ok;
false -> exit(member_pid_shutdown)
end.

-spec discover_coordinator(state()) -> {ok, state()}.
discover_coordinator(#state{ client = Client
, connection = Connection0
Expand Down Expand Up @@ -499,6 +508,7 @@ stabilize(#state{ rejoin_delay_seconds = RejoinDelaySeconds
log(State0, info, "re-joining group, reason:~p", [Reason]),

%% 1. unsubscribe all currently assigned partitions
ok = ensure_member_pid_alive(MemberPid),
ok = MemberModule:assignments_revoked(MemberPid),

%% 2. some brod_group_member implementations may wait for messages
Expand Down Expand Up @@ -674,6 +684,7 @@ sync_group(#state{ groupId = GroupId
%% get my partition assignments
Assignment = kpro:find(assignment, RspBody),
TopicAssignments = get_topic_assignments(State, Assignment),
ok = ensure_member_pid_alive(MemberPid),
ok = MemberModule:assignments_received(MemberPid, MemberId,
GenerationId, TopicAssignments),
NewState = State#state{is_in_group = true},
Expand Down Expand Up @@ -834,6 +845,7 @@ assign_partitions(State) when ?IS_LEADER(State) ->
Assignments =
case Strategy =:= callback_implemented of
true ->
ok = ensure_member_pid_alive(MemberPid),
MemberModule:assign_partitions(MemberPid, Members, AllPartitions);
false ->
do_assign_partitions(Strategy, Members, AllPartitions)
Expand Down