Skip to content

Commit

Permalink
rabbit_khepri: Fix force_reset/0 to work with stopped Ra system
Browse files Browse the repository at this point in the history
[Why]
This function blindly relied on the fact that the Ra `coordination`
system was not stopped by `rabbit` when it stopped. That Ra system is
finally correctly stopped in the parent commit. This breaks this
function and it must be adapted to work with the Ra system stopped.

This is even safer because the function deletes the Ra system directory
as its last step.

[How]
The Ra system data directory is queried from RabbitMQ configuration
instead of the running Ra system.

We add a couple assertions to ensure the conditions are the ones we
expect.
  • Loading branch information
dumbbell committed Jan 22, 2024
1 parent c6e0430 commit e030196
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions deps/rabbit/src/rabbit_khepri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,21 @@ reset() ->
%% @private

force_reset() ->
DataDir = maps:get(data_dir, ra_system:fetch(coordination)),
ok = rabbit_file:recursive_delete(filelib:wildcard(DataDir ++ "/*")).
%% The Ra `coordination' system is stopped at this point; we assert that
%% with the `ra_system:fetch/1' call below. Therefore, we take the data
%% directory from the configuration.
RaSystem = coordination,
?assertEqual(undefined, ra_system:fetch(RaSystem)),
Config = rabbit_ra_systems:get_config(RaSystem),
DataDir = maps:get(data_dir, Config),
?assert(string:length(DataDir) > 0), %% Assertion to not `rm -rf /'.
?LOG_INFO(
"Deleting Ra `coordination` system data directory as part of "
"Khepri reset: ~ts",
[DataDir],
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
Glob = filename:join(DataDir, "*"),
ok = rabbit_file:recursive_delete(filelib:wildcard(Glob)).

%% @private

Expand Down
1 change: 1 addition & 0 deletions deps/rabbit/src/rabbit_ra_systems.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

-export([setup/0,
setup/1,
get_config/1,
all_ra_systems/0,
are_running/0,
ensure_ra_system_started/1,
Expand Down

0 comments on commit e030196

Please sign in to comment.