Skip to content

Commit f8b29ea

Browse files
committed
rabbit_db_cluster: Figure out members list even if Mnesia is stopped
[Why] If Mnesia is stopped and the local node is a disk-less member, the list returned by `mnesia:system_info(db_nodes)` will be empty. This is problematic for any users of this list of members obviously. [How] The `members_using_mnesia/0` function copies the logic of `rabbit_mnesia:cluster_status/1` but simplifies it to only work with all members (not running members or disk members). Therefore, if Mnesia is not running, we look at the cluster status files stored on disk. If they are missing, the code falls back to a list made of the local node name only.
1 parent 4c602b7 commit f8b29ea

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

deps/rabbit/src/rabbit_db_cluster.erl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
-module(rabbit_db_cluster).
99

1010
-include_lib("kernel/include/logger.hrl").
11-
-include_lib("stdlib/include/assert.hrl").
1211

1312
-include_lib("rabbit_common/include/logging.hrl").
1413

@@ -103,7 +102,25 @@ members() ->
103102
members_using_mnesia().
104103

105104
members_using_mnesia() ->
106-
mnesia:system_info(db_nodes).
105+
case rabbit_mnesia:is_running() andalso rabbit_table:is_present() of
106+
true ->
107+
%% If Mnesia is running locally and some tables exist, we can know
108+
%% the database was initialized and we can query the list of
109+
%% members.
110+
mnesia:system_info(db_nodes);
111+
false ->
112+
try
113+
%% When Mnesia is not running, we fall back to reading the
114+
%% cluster status files stored on disk, if they exist.
115+
{Members, _, _} = rabbit_node_monitor:read_cluster_status(),
116+
Members
117+
catch
118+
throw:{error, _Reason}:_Stacktrace ->
119+
%% If we couldn't read those files, we consider that only
120+
%% this node is part of the "cluster".
121+
[node()]
122+
end
123+
end.
107124

108125
-spec disc_members() -> Members when
109126
Members :: [node()].

deps/rabbit/src/rabbit_mnesia.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
%% Various queries to get the status of the db
2121
status/0,
22+
is_running/0,
2223
is_clustered/0,
2324
on_running_node/1,
2425
is_process_alive/1,

0 commit comments

Comments
 (0)