Skip to content

Commit 95449bd

Browse files
committed
rabbit_db_cluster: Check rabbit is stopped in forget_node()
[Why] `rabbit_mnesia` indirectly checks that `rabbit` is stopped on the remote node because `mnesia:del_table_copy()` requires that Mnesia is stopped to delete the schema. However, this is not specific to Mnesia and we want `rabbit` to be stopped when we use Khepri in the future. [How] We use `rabbit:is_running(Node)` to query the status of RabbitMQ on the remote node to forget. This is not atomic so there is a small chance that RabbitMQ is restarted between the check and the actual forget. Note: `rabbit_mnesia` also removes some queues and emit a "left cluster" event after a successful forget. However, this part was not moved because other parts of the module rely on this in RPC calls. To keep nodes compatibles, the calls are left in place. They will be duplicated for Khepri.
1 parent 3184821 commit 95449bd

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

deps/rabbit/src/rabbit_db_cluster.erl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,17 @@ join_using_mnesia(ClusterNodes, NodeType) when is_list(ClusterNodes) ->
109109
%% @doc Removes `Node' from the cluster.
110110

111111
forget_member(Node, RemoveWhenOffline) ->
112-
rabbit_db:run(
113-
#{mnesia =>
114-
fun() -> forget_member_using_mnesia(Node, RemoveWhenOffline) end}).
112+
case rabbit:is_running(Node) of
113+
false ->
114+
rabbit_db:run(
115+
#{mnesia => fun() ->
116+
forget_member_using_mnesia(
117+
Node, RemoveWhenOffline)
118+
end
119+
});
120+
true ->
121+
{error, {failed_to_remove_node, Node, rabbit_still_running}}
122+
end.
115123

116124
forget_member_using_mnesia(Node, RemoveWhenOffline) ->
117125
rabbit_mnesia:forget_cluster_node(Node, RemoveWhenOffline).

deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/forget_cluster_node_command.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ForgetClusterNodeCommand do
5858
end
5959

6060
case ret do
61+
{:error, {:failed_to_remove_node, ^atom_name, :rabbit_still_running}} ->
62+
{:error,
63+
"RabbitMQ on node #{node_to_remove} must be stopped with 'rabbitmqctl -n #{node_to_remove} stop_app' before it can be removed"}
64+
6165
{:error, {:failed_to_remove_node, ^atom_name, {:active, _, _}}} ->
6266
{:error,
6367
"RabbitMQ on node #{node_to_remove} must be stopped with 'rabbitmqctl -n #{node_to_remove} stop_app' before it can be removed"}

0 commit comments

Comments
 (0)