Skip to content

Commit a66ea2d

Browse files
committed
rabbit_db: Skip reset if the node is already virgin
[Why] If we run `reset` again on an already virgin node, it will take decisions based on the wrong state. In particular, the previous use of Khepri or Mnesia is lost with the first reset. Therefore, the second reset wolud delete non-Khepri related files that belong to the coordination Ra system. This is particularily problematic with the previously documented way of joining two nodes using the CLI: rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl join_cluster $REMOTE_NODE rabbitmqctl start_app Indeed, `join_cluster` implies a reset. If the admin already reset the node as documented, `join_cluster` implied reset would delete too many files, breaking Khepri after the join if Khepri is used by the remote node. [How] In `rabbit_db:reset/0`, we skip the reset if the node is already virgin. Fixes #14748.
1 parent efaf7c4 commit a66ea2d

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

deps/rabbit/src/rabbit_db.erl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,21 @@ clear_init_finished() ->
128128
%% @doc Resets the database and the node.
129129

130130
reset() ->
131-
ok = case rabbit_khepri:is_enabled() of
132-
true -> reset_using_khepri();
133-
false -> reset_using_mnesia()
134-
end,
135-
post_reset().
131+
IsVirgin = is_virgin_node(),
132+
case IsVirgin of
133+
true ->
134+
?LOG_INFO(
135+
"DB: skipping resetting; node already virgin",
136+
#{domain => ?RMQLOG_DOMAIN_DB}),
137+
ok;
138+
false ->
139+
IsKhepriEnabled = rabbit_khepri:is_enabled(),
140+
ok = case IsKhepriEnabled of
141+
true -> reset_using_khepri();
142+
false -> reset_using_mnesia()
143+
end,
144+
post_reset()
145+
end.
136146

137147
reset_using_mnesia() ->
138148
?LOG_INFO(

0 commit comments

Comments
 (0)