Skip to content

Commit 8f7f7b3

Browse files
committed
WIP
1 parent 32aaf70 commit 8f7f7b3

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

deps/rabbit/src/rabbit_db.erl

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
is_virgin_node/0, is_virgin_node/1,
2222
dir/0,
2323
ensure_dir_exists/0,
24+
wipe_data_dir/0,
2425
is_init_finished/0,
2526
clear_init_finished/0]).
2627

@@ -128,21 +129,11 @@ clear_init_finished() ->
128129
%% @doc Resets the database and the node.
129130

130131
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.
132+
ok = case rabbit_khepri:is_enabled() of
133+
true -> reset_using_khepri();
134+
false -> reset_using_mnesia()
135+
end,
136+
post_reset().
146137

147138
reset_using_mnesia() ->
148139
?LOG_INFO(
@@ -205,8 +196,15 @@ force_load_on_next_boot_using_mnesia() ->
205196
rabbit_mnesia:force_load_next_boot().
206197

207198
post_reset() ->
199+
%% We stop all Ra systems because their files are about to be removed.
200+
rabbit_ra_systems:ensure_stopped(),
201+
202+
%% We reset the state of feature flags, both in memory and on disk. The
203+
%% state recorded on disk would be deleted with the wipe below anyway.
208204
rabbit_feature_flags:reset(),
209205

206+
wipe_data_dir(),
207+
210208
%% The cluster status files that RabbitMQ uses when Mnesia is the database
211209
%% are initially created from rabbit_prelaunch_cluster. However, it will
212210
%% only be done once the `rabbit` app is restarted. Meanwhile, they are
@@ -219,6 +217,17 @@ post_reset() ->
219217

220218
ok.
221219

220+
wipe_data_dir() ->
221+
DataDir = dir(),
222+
Glob = filename:join(DataDir, "*"),
223+
FilesToRemove = filelib:wildcard(Glob),
224+
?LOG_DEBUG(
225+
"DB: wipe files in data directory `~ts`:~p",
226+
[DataDir, FilesToRemove],
227+
#{domain => ?RMQLOG_DOMAIN_DB}),
228+
ok = rabbit_file:recursive_delete(FilesToRemove),
229+
ok.
230+
222231
%% -------------------------------------------------------------------
223232
%% is_virgin_node().
224233
%% -------------------------------------------------------------------

deps/rabbit/src/rabbit_mnesia.erl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,8 @@ wipe() ->
257257
%% Erlang system with nodes while not being in an Mnesia cluster
258258
%% with them. We don't handle that well.
259259
[erlang:disconnect_node(N) || N <- cluster_nodes(all)],
260-
%% remove persisted messages and any other garbage we find
261-
ok = rabbit_file:recursive_delete(filelib:wildcard(dir() ++ "/*")),
262-
ok = rabbit_node_monitor:reset_cluster_status(),
260+
%% Historically performed by this function, the data dir is wiped by
261+
%% `rabbit_db' now. Likewise for the cluster status reset.
263262
ok.
264263

265264
-spec change_cluster_node_type(rabbit_db_cluster:node_type()) -> 'ok'.

0 commit comments

Comments
 (0)