Skip to content

Commit dd49cbe

Browse files
committed
Mnesia: Ask to leave a cluster and retry to join if cluster already consider node a member.
Khepri: no-op. Khepri is less strict already, and rabbit_khepri:can_join would accept a join request from a node that is already a member
1 parent 9439756 commit dd49cbe

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

deps/rabbit/src/rabbit_db_cluster.erl

+22
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,28 @@ join(RemoteNode, NodeType)
214214
end;
215215
{ok, already_member} ->
216216
{ok, already_member};
217+
{error, {inconsistent_cluster, Msg}} = Error ->
218+
case rabbit_khepri:is_enabled() of
219+
true ->
220+
Error;
221+
false ->
222+
%% rabbit_mnesia:can_join_cluster/1 notice inconsistent_cluster,
223+
%% as RemoteNode thinks this node is already in the cluster.
224+
%% Attempt to leave the RemoteNode cluster, the discovery cluster,
225+
%% and simply retry the operation.
226+
rabbit_log:info("Mnesia: node ~tp thinks it's clustered "
227+
"with node ~tp, but ~tp disagrees. ~tp will ask "
228+
"to leave the cluster and try again.",
229+
[RemoteNode, node(), node(), node()]),
230+
try
231+
ok = rabbit_mnesia:leave_discover_cluster(RemoteNode),
232+
join(RemoteNode, NodeType)
233+
catch
234+
_ ->
235+
rabbit_log:error(Msg),
236+
Error
237+
end
238+
end;
217239
{error, _} = Error ->
218240
Error
219241
end.

deps/rabbit/src/rabbit_mnesia.erl

+13-10
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
-export([node_info/0, remove_node_if_mnesia_running/1]).
7474

7575
%% Used internally in `rabbit_db_cluster'.
76-
-export([members/0]).
76+
-export([members/0, leave_discover_cluster/1]).
7777

7878
%% Used internally in `rabbit_khepri'.
7979
-export([mnesia_and_msg_store_files/0]).
@@ -179,7 +179,6 @@ can_join_cluster(DiscoveryNode) ->
179179
{ok, already_member};
180180
false ->
181181
Msg = format_inconsistent_cluster_message(DiscoveryNode, node()),
182-
rabbit_log:error(Msg),
183182
{error, {inconsistent_cluster, Msg}}
184183
end
185184
end.
@@ -923,15 +922,19 @@ remove_node_if_mnesia_running(Node) ->
923922
end
924923
end.
925924

926-
leave_cluster() ->
927-
case rabbit_nodes:nodes_excl_me(cluster_nodes(all)) of
928-
[] -> ok;
929-
AllNodes -> case lists:any(fun leave_cluster/1, AllNodes) of
930-
true -> ok;
931-
false -> e(no_running_cluster_nodes)
932-
end
933-
end.
925+
leave_discover_cluster(DiscoveryNode) ->
926+
{ClusterNodes, _, _} = discover_cluster([DiscoveryNode]),
927+
leave_cluster(rabbit_nodes:nodes_excl_me(ClusterNodes)).
934928

929+
leave_cluster() ->
930+
leave_cluster(rabbit_nodes:nodes_excl_me(cluster_nodes(all))).
931+
leave_cluster([]) ->
932+
ok;
933+
leave_cluster(Nodes) when is_list(Nodes) ->
934+
case lists:any(fun leave_cluster/1, Nodes) of
935+
true -> ok;
936+
false -> e(no_running_cluster_nodes)
937+
end;
935938
leave_cluster(Node) ->
936939
case rpc:call(Node,
937940
rabbit_mnesia, remove_node_if_mnesia_running, [node()]) of

0 commit comments

Comments
 (0)