Skip to content

Commit

Permalink
rabbit_db: Run peer discovery from generic code
Browse files Browse the repository at this point in the history
... instead of `rabbit_mnesia`.

[Why]
We need it for both Mnesia and Khepri. So instead of calling it in
`rabbit_khepri` too, let's manage this from `rabbit_db` directly.
  • Loading branch information
dumbbell committed Dec 7, 2023
1 parent 2504eb7 commit e1261b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 12 additions & 0 deletions deps/rabbit/src/rabbit_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ init() ->

pre_init(IsVirgin),

case IsVirgin of
true ->
%% At this point, the database backend could change if the node
%% joins a cluster and that cluster uses a different database.
?LOG_INFO(
"DB: virgin node -> run peer discovery",
#{domain => ?RMQLOG_DOMAIN_DB}),
rabbit_peer_discovery:sync_desired_cluster();
false ->
ok
end,

Ret = case rabbit_khepri:is_enabled() of
true -> init_using_khepri();
false -> init_using_mnesia()
Expand Down
11 changes: 0 additions & 11 deletions deps/rabbit/src/rabbit_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,6 @@
init() ->
ensure_mnesia_running(),
ensure_mnesia_dir(),
%% If this node is virgin, we call peer discovery to see if this node
%% should start as a standalone node or if it should join a cluster.
case is_virgin_node() of
true ->
rabbit_log:info("Node database directory at ~ts is empty. "
"Assuming we need to join an existing cluster or initialise from scratch...",
[dir()]),
rabbit_peer_discovery:sync_desired_cluster();
false ->
ok
end,
%% Peer discovery may have been a no-op if it decided that all other nodes
%% should join this one. Therefore, we need to look at if this node is
%% still virgin and finish our init of Mnesia accordingly. In particular,
Expand Down

0 comments on commit e1261b9

Please sign in to comment.