Skip to content

Commit bd21a69

Browse files
Merge branch 'binarin-rabbitmq-server-fix-join-cluster-when-already-member' into stable
2 parents 079ac7f + ab1ed2c commit bd21a69

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/rabbit_mnesia.erl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,17 @@ join_cluster(DiscoveryNode, NodeType) ->
200200
{error, Reason}
201201
end;
202202
true ->
203-
rabbit_log:info("Already member of cluster: ~p~n", [ClusterNodes]),
204-
{ok, already_member}
203+
%% DiscoveryNode thinks that we are part of a cluster, but
204+
%% do we think so ourselves?
205+
case are_we_clustered_with(DiscoveryNode) of
206+
true ->
207+
rabbit_log:info("Asked to join a cluster but already a member of it: ~p~n", [ClusterNodes]),
208+
{ok, already_member};
209+
false ->
210+
Msg = format_inconsistent_cluster_message(DiscoveryNode, node()),
211+
rabbit_log:error(Msg),
212+
{error, {inconsistent_cluster, Msg}}
213+
end
205214
end.
206215

207216
%% return node to its virgin state, where it is not member of any
@@ -788,9 +797,7 @@ check_nodes_consistency(Node, RemoteStatus = {RemoteAllNodes, _, _}) ->
788797
{ok, RemoteStatus};
789798
false ->
790799
{error, {inconsistent_cluster,
791-
rabbit_misc:format("Node ~p thinks it's clustered "
792-
"with node ~p, but ~p disagrees",
793-
[node(), Node, Node])}}
800+
format_inconsistent_cluster_message(node(), Node)}}
794801
end.
795802

796803
check_mnesia_or_otp_consistency(_Node, unsupported, OTP) ->
@@ -896,6 +903,9 @@ is_only_clustered_disc_node() ->
896903
node_type() =:= disc andalso is_clustered() andalso
897904
cluster_nodes(disc) =:= [node()].
898905

906+
are_we_clustered_with(Node) ->
907+
lists:member(Node, mnesia_lib:all_nodes()).
908+
899909
me_in_nodes(Nodes) -> lists:member(node(), Nodes).
900910

901911
nodes_incl_me(Nodes) -> lists:usort([node()|Nodes]).
@@ -946,3 +956,8 @@ error_description(removing_node_from_offline_node) ->
946956
"from must be a disc node and all the other nodes must be offline.";
947957
error_description(no_running_cluster_nodes) ->
948958
"You cannot leave a cluster if no online nodes are present.".
959+
960+
format_inconsistent_cluster_message(Thinker, Dissident) ->
961+
rabbit_misc:format("Node ~p thinks it's clustered "
962+
"with node ~p, but ~p disagrees",
963+
[Thinker, Dissident, Dissident]).

0 commit comments

Comments
 (0)