Skip to content

Commit c7dffa8

Browse files
committed
rabbit_vhost: Emit vhost_deleted only if the vhost was actually deleted
This was the case before the reorganize of the code made in #6430 and therefore a regression in the mentionned pull request. This patch restores the behavior. Note that this is already like that for internal users. Thus, the behavior and `rabbit_db_*` are consistent.
1 parent cf196fe commit c7dffa8

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

deps/rabbit/src/rabbit_db_vhost.erl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,12 @@ with_fun_in_mnesia_tx(VHostName, TxFun)
297297
%% delete().
298298
%% -------------------------------------------------------------------
299299

300-
-spec delete(VHostName) -> ok when
301-
VHostName :: vhost:name().
302-
%% @doc Deletes a virtual host record.
300+
-spec delete(VHostName) -> Existed when
301+
VHostName :: vhost:name(),
302+
Existed :: boolean().
303+
%% @doc Deletes a virtual host record from the database.
303304
%%
304-
%% @returns `ok', even if the record didn't exist before. It throws an
305+
%% @returns a boolean indicating if the vhost existed or not. It throws an
305306
%% exception if the transaction fails.
306307
%%
307308
%% @private
@@ -315,5 +316,6 @@ delete_in_mnesia(VHostName) ->
315316
fun() -> delete_in_mnesia_tx(VHostName) end).
316317

317318
delete_in_mnesia_tx(VHostName) ->
319+
Existed = mnesia:wread({?MNESIA_TABLE, VHostName}) =/= [],
318320
mnesia:delete({?MNESIA_TABLE, VHostName}),
319-
ok.
321+
Existed.

deps/rabbit/src/rabbit_vhost.erl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,15 @@ delete(VHost, ActingUser) ->
286286
_ = rabbit_runtime_parameters:clear_vhost(VHost, ActingUser),
287287
_ = [rabbit_policy:delete(VHost, proplists:get_value(name, Info), ActingUser)
288288
|| Info <- rabbit_policy:list(VHost)],
289-
ok = rabbit_db_vhost:delete(VHost),
290-
ok = rabbit_event:notify(vhost_deleted, [{name, VHost},
291-
{user_who_performed_action, ActingUser}]),
289+
case rabbit_db_vhost:delete(VHost) of
290+
true ->
291+
ok = rabbit_event:notify(
292+
vhost_deleted,
293+
[{name, VHost},
294+
{user_who_performed_action, ActingUser}]);
295+
false ->
296+
ok
297+
end,
292298
%% After vhost was deleted from the database, we try to stop vhost
293299
%% supervisors on all the nodes.
294300
rabbit_vhost_sup_sup:delete_on_all_nodes(VHost),

0 commit comments

Comments
 (0)