Skip to content

Commit

Permalink
QQ: refactor add_member method to pass dialyzer
Browse files Browse the repository at this point in the history
And be less confusing around the arguments that add_member/4 actually
takes.
  • Loading branch information
kjnilsson committed Jan 27, 2025
1 parent 113b16b commit e58b8eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion deps/rabbit/src/rabbit_queue_type_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ run_checks([C | Checks], Q) ->
Err
end.

-spec erpc_call(node(), module(), atom(), list(), non_neg_integer()) ->
-spec erpc_call(node(), module(), atom(), list(), non_neg_integer() | infinity) ->
term() | {error, term()}.
erpc_call(Node, M, F, A, _Timeout)
when Node =:= node() ->
Expand Down
36 changes: 22 additions & 14 deletions deps/rabbit/src/rabbit_quorum_queue.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,10 @@ get_sys_status(Proc) ->

end.

add_member(VHost, Name, Node, Membership, Timeout) when is_binary(VHost) ->
add_member(VHost, Name, Node, Membership, Timeout)
when is_binary(VHost) andalso
is_binary(Name) andalso
is_atom(Node) ->
QName = #resource{virtual_host = VHost, name = Name, kind = queue},
rabbit_log:debug("Asked to add a replica for queue ~ts on node ~ts",
[rabbit_misc:rs(QName), Node]),
Expand All @@ -1324,7 +1327,7 @@ add_member(VHost, Name, Node, Membership, Timeout) when is_binary(VHost) ->
[rabbit_misc:rs(QName), Node]),
ok;
false ->
add_member(Q, Node, Membership, Timeout)
do_add_member(Q, Node, Membership, Timeout)
end
end;
{ok, _Q} ->
Expand All @@ -1333,16 +1336,21 @@ add_member(VHost, Name, Node, Membership, Timeout) when is_binary(VHost) ->
E
end.

add_member(VHost, Name, Node, Timeout) when is_binary(VHost) ->
%% NOTE needed to pass mixed cluster tests.
add_member(VHost, Name, Node, promotable, Timeout).

add_member(Q, Node) ->
add_member(Q, Node, promotable).
do_add_member(Q, Node, promotable, ?MEMBER_CHANGE_TIMEOUT).

add_member(Q, Node, Membership) ->
add_member(Q, Node, Membership, ?MEMBER_CHANGE_TIMEOUT).
do_add_member(Q, Node, Membership, ?MEMBER_CHANGE_TIMEOUT).

add_member(VHost, Name, Node, Timeout) when is_binary(VHost) ->
%% NOTE needed to pass mixed cluster tests.
add_member(VHost, Name, Node, promotable, Timeout);
add_member(Q, Node, Membership, Timeout) when ?amqqueue_is_quorum(Q) ->

do_add_member(Q, Node, Membership, Timeout)
when ?is_amqqueue(Q) andalso
?amqqueue_is_quorum(Q) andalso
is_atom(Node) ->
{RaName, _} = amqqueue:get_pid(Q),
QName = amqqueue:get_name(Q),
%% TODO parallel calls might crash this, or add a duplicate in quorum_nodes
Expand All @@ -1354,12 +1362,12 @@ add_member(Q, Node, Membership, Timeout) when ?amqqueue_is_quorum(Q) ->
case ra:start_server(?RA_SYSTEM, Conf) of
ok ->
ServerIdSpec =
case rabbit_feature_flags:is_enabled(quorum_queue_non_voters) of
true ->
maps:with([id, uid, membership], Conf);
false ->
maps:get(id, Conf)
end,
case rabbit_feature_flags:is_enabled(quorum_queue_non_voters) of
true ->
maps:with([id, uid, membership], Conf);
false ->
maps:get(id, Conf)
end,
case ra:add_member(Members, ServerIdSpec, Timeout) of
{ok, {RaIndex, RaTerm}, Leader} ->
Fun = fun(Q1) ->
Expand Down

0 comments on commit e58b8eb

Please sign in to comment.