Skip to content

Commit

Permalink
rabbit_khepri: Ensure RabbitMQ is stopped before resetting with Khepri
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbbell committed Nov 15, 2024
1 parent 248d7a9 commit e41d766
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
26 changes: 20 additions & 6 deletions deps/rabbit/src/rabbit_khepri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -585,16 +585,30 @@ 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);
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(coordination)),
ok = ra_system:ensure_ra_system_stopped(coordination),
ok = rabbit_file:recursive_delete(
filelib:wildcard(DataDir ++ "/*"));
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 e41d766

Please sign in to comment.