Skip to content

Commit

Permalink
rabbit_runtime_parameters: Handle timeout failures in clear functions
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis committed May 13, 2024
1 parent ca55031 commit 6add459
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 20 deletions.
12 changes: 7 additions & 5 deletions deps/rabbit/src/rabbit_db_rtparams.erl
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ get_all_in_khepri(VHostName, Comp) ->
%% delete().
%% -------------------------------------------------------------------

-spec delete(Key) -> ok when
Key :: atom().
-spec delete(Key) -> Ret when
Key :: atom(),
Ret :: ok | rabbit_khepri:timeout_error().
%% @doc Deletes the global runtime parameter named `Key'.
%%
%% @private
Expand All @@ -235,10 +236,11 @@ delete(Key) when is_atom(Key) ->
#{mnesia => fun() -> delete_in_mnesia(Key) end,
khepri => fun() -> delete_in_khepri(Key) end}).

-spec delete(VHostName, Comp, Name) -> ok when
-spec delete(VHostName, Comp, Name) -> Ret when
VHostName :: vhost:name() | '_',
Comp :: binary() | '_',
Name :: binary() | atom() | '_'.
Name :: binary() | atom() | '_',
Ret :: ok | rabbit_khepri:timeout_error().
%% @doc Deletes the non-global runtime parameter named `Name' for the given
%% virtual host and component.
%%
Expand Down Expand Up @@ -281,7 +283,7 @@ delete_matching_in_mnesia_tx(VHostName, Comp, Name) ->

delete_in_khepri(Key) ->
Path = khepri_rp_path(Key),
ok = rabbit_khepri:delete(Path).
rabbit_khepri:delete(Path).

delete_matching_in_khepri(VHostName, Comp, Name) ->
Key = {?any(VHostName), ?any(Comp), ?any(Name)},
Expand Down
59 changes: 46 additions & 13 deletions deps/rabbit/src/rabbit_runtime_parameters.erl
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,19 @@ clear_global(Key, ActingUser) ->
not_found ->
{error_string, "Parameter does not exist"};
_ ->
ok = rabbit_db_rtparams:delete(KeyAsAtom),
event_notify(parameter_cleared, none, global,
[{name, KeyAsAtom},
{user_who_performed_action, ActingUser}])
case rabbit_db_rtparams:delete(KeyAsAtom) of
ok ->
event_notify(parameter_cleared, none, global,
[{name, KeyAsAtom},
{user_who_performed_action, ActingUser}]),
ok;
{error, timeout} ->
Msg = rabbit_misc:format(
"Could not delete global runtime parameter '~ts' "
"because the operation timed out",
[Key]),
{error_string, Msg}
end
end.

clear_vhost(VHostName, ActingUser) when is_binary(VHostName) ->
Expand All @@ -247,10 +256,24 @@ clear_vhost(VHostName, ActingUser) when is_binary(VHostName) ->
Err
end.

-spec clear_component(Component, ActingUser) -> Ret when
Component :: binary(),
ActingUser :: rabbit_types:username(),
Ret :: ok_or_error_string().

clear_component(<<"policy">>, _) ->
{error_string, "policies may not be cleared using this method"};
clear_component(Component, _ActingUser) ->
ok = rabbit_db_rtparams:delete('_', Component, '_').
case rabbit_db_rtparams:delete('_', Component, '_') of
ok ->
ok;
{error, timeout} ->
Msg = rabbit_misc:format(
"Could not delete component '~ts' because the operation "
"timed out",
[Component]),
{error_string, Msg}
end.

-spec clear_any(rabbit_types:vhost(), binary(), binary(), rabbit_types:username())
-> ok_thunk_or_error_string().
Expand All @@ -259,14 +282,24 @@ clear_any(VHost, Component, Name, ActingUser) ->
case lookup(VHost, Component, Name) of
not_found -> {error_string, "Parameter does not exist"};
_ ->
rabbit_db_rtparams:delete(VHost, Component, Name),
case lookup_component(Component) of
{ok, Mod} -> event_notify(
parameter_cleared, VHost, Component,
[{name, Name},
{user_who_performed_action, ActingUser}]),
Mod:notify_clear(VHost, Component, Name, ActingUser);
_ -> ok
case rabbit_db_rtparams:delete(VHost, Component, Name) of
ok ->
case lookup_component(Component) of
{ok, Mod} ->
event_notify(
parameter_cleared, VHost, Component,
[{name, Name},
{user_who_performed_action, ActingUser}]),
Mod:notify_clear(VHost, Component, Name, ActingUser);
_ ->
ok
end;
{error, timeout} ->
Msg = rabbit_misc:format(
"Could not delete parameter '~ts' because the "
"operation timed out",
[Name]),
{error_string, Msg}
end
end.

Expand Down
4 changes: 2 additions & 2 deletions deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2081,8 +2081,8 @@ clear_policy(Config, Node, Name) ->
clear_policy(Config, Node, Name, <<"acting-user">>).

clear_policy(Config, Node, Name, Username) ->
rpc(Config, Node,
rabbit_policy, delete, [<<"/">>, Name, Username]).
ok = rpc(Config, Node,
rabbit_policy, delete, [<<"/">>, Name, Username]).

set_operator_policy(Config, Node, Name, Pattern, ApplyTo, Definition) ->
ok = rpc(Config, Node,
Expand Down

0 comments on commit 6add459

Please sign in to comment.