Skip to content

Commit fe73d97

Browse files
committed
rabbit_khepri: Ensure RabbitMQ is stopped before resetting with Khepri
1 parent fdc91dd commit fe73d97

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

deps/rabbit/src/rabbit_khepri.erl

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,16 +585,30 @@ remove_down_member(NodeToRemove) ->
585585
%% @private
586586

587587
reset() ->
588-
%% Rabbit should be stopped, but Khepri needs to be running. Restart it.
589-
ok = setup(),
590-
ok = khepri_cluster:reset(?RA_CLUSTER_NAME),
591-
ok = khepri:stop(?RA_CLUSTER_NAME).
588+
case rabbit:is_running() of
589+
false ->
590+
%% Rabbit should be stopped, but Khepri needs to be running.
591+
%% Restart it.
592+
ok = setup(),
593+
ok = khepri_cluster:reset(?RA_CLUSTER_NAME),
594+
ok = khepri:stop(?RA_CLUSTER_NAME);
595+
true ->
596+
throw({error, rabbitmq_unexpectedly_running})
597+
end.
592598

593599
%% @private
594600

595601
force_reset() ->
596-
DataDir = maps:get(data_dir, ra_system:fetch(coordination)),
597-
ok = rabbit_file:recursive_delete(filelib:wildcard(DataDir ++ "/*")).
602+
case rabbit:is_running() of
603+
false ->
604+
ok = khepri:stop(?RA_CLUSTER_NAME),
605+
DataDir = maps:get(data_dir, ra_system:fetch(coordination)),
606+
ok = ra_system:ensure_ra_system_stopped(coordination),
607+
ok = rabbit_file:recursive_delete(
608+
filelib:wildcard(DataDir ++ "/*"));
609+
true ->
610+
throw({error, rabbitmq_unexpectedly_running})
611+
end.
598612

599613
%% @private
600614

deps/rabbit/src/rabbit_ra_systems.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
all_ra_systems/0,
1717
are_running/0,
1818
ensure_ra_system_started/1,
19+
ensure_ra_system_stopped/1,
1920
ensure_started/0,
2021
ensure_stopped/0]).
2122

0 commit comments

Comments
 (0)