Skip to content

Commit

Permalink
Merge pull request #12739 from rabbitmq/fix-khepri-reset
Browse files Browse the repository at this point in the history
Fix RabbitMQ reset when using Khepri
  • Loading branch information
dumbbell authored Nov 15, 2024
2 parents 248d7a9 + 2938338 commit 44e74ce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
32 changes: 26 additions & 6 deletions deps/rabbit/src/rabbit_khepri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -585,16 +585,36 @@ remove_down_member(NodeToRemove) ->
%% @private

reset() ->
%% Rabbit should be stopped, but Khepri needs to be running. Restart it.
ok = setup(),
ok = khepri_cluster:reset(?RA_CLUSTER_NAME),
ok = khepri:stop(?RA_CLUSTER_NAME).
case rabbit:is_running() of
false ->
%% Rabbit should be stopped, but Khepri needs to be running.
%% Restart it.
ok = setup(),
ok = khepri_cluster:reset(?RA_CLUSTER_NAME),
ok = khepri:stop(?RA_CLUSTER_NAME),

_ = file:delete(rabbit_guid:filename()),
ok;
true ->
throw({error, rabbitmq_unexpectedly_running})
end.

%% @private

force_reset() ->
DataDir = maps:get(data_dir, ra_system:fetch(coordination)),
ok = rabbit_file:recursive_delete(filelib:wildcard(DataDir ++ "/*")).
case rabbit:is_running() of
false ->
ok = khepri:stop(?RA_CLUSTER_NAME),
DataDir = maps:get(data_dir, ra_system:fetch(?RA_SYSTEM)),
ok = rabbit_ra_systems:ensure_ra_system_stopped(?RA_SYSTEM),
ok = rabbit_file:recursive_delete(
filelib:wildcard(DataDir ++ "/*")),

_ = file:delete(rabbit_guid:filename()),
ok;
true ->
throw({error, rabbitmq_unexpectedly_running})
end.

%% @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 @@ -16,6 +16,7 @@
all_ra_systems/0,
are_running/0,
ensure_ra_system_started/1,
ensure_ra_system_stopped/1,
ensure_started/0,
ensure_stopped/0]).

Expand Down

0 comments on commit 44e74ce

Please sign in to comment.