Skip to content

Commit 4d8fa17

Browse files
committed
rabbit: Stop Khepri store and Ra systems in stop/1
[Why] The Khepri store and the coordinators are Ra servers and thus run under the Ra supervision tree. Therefore we need to explicitly stop them otherwise they will continue to run after `rabbit` was stopped. Likewise, the Ra systems are under the Ra supervision tree. We also need to stop them. [How] We need to stop Ra servers and Ra systems that we started but live under the Ra supervision tree. The order is important: 1. The `quorum_queues` Ra system because it may host Ra servers that depend on Khepri. 2. The stream coordinator because it depends on Khepri. 3. The Khepri store; it could be stopped automatically with the termination of the underlying Ra system, but Khepri needs to do some cleanup too. 4. The remaining Ra systems.
1 parent 5abeb75 commit 4d8fa17

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

deps/rabbit/src/rabbit.erl

+15
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,21 @@ stop(State) ->
10791079
[] -> rabbit_prelaunch:set_stop_reason(normal);
10801080
_ -> rabbit_prelaunch:set_stop_reason(State)
10811081
end,
1082+
1083+
%% We need to stop Ra servers and Ra systems that we started but live
1084+
%% under the Ra supervision tree. The order is important:
1085+
%% 1. The `quorum_queues` Ra system because it may host Ra servers that
1086+
%% depend on Khepri.
1087+
%% 2. The stream coordinator because it depends on Khepri.
1088+
%% 3. The Khepri store; it could be stopped automatically with the
1089+
%% termination of the underlying Ra system, but Khepri needs to do some
1090+
%% cleanup too.
1091+
%% 4. The remaining Ra systems.
1092+
rabbit_ra_systems:ensure_ra_system_stopped(quorum_queues),
1093+
_ = rabbit_stream_coordinator:stop(),
1094+
rabbit_khepri:stop(),
1095+
rabbit_ra_systems:ensure_stopped(),
1096+
10821097
rabbit_db:clear_init_finished(),
10831098
rabbit_boot_state:set(stopped),
10841099
ok.

deps/rabbit/src/rabbit_khepri.erl

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696

9797
-export([setup/0,
9898
setup/1,
99+
stop/0,
99100
can_join_cluster/1,
100101
add_member/2,
101102
remove_member/1,
@@ -287,6 +288,9 @@ wait_for_leader(Timeout, Retries) ->
287288
throw(Reason)
288289
end.
289290

291+
stop() ->
292+
ok = khepri:stop(?RA_CLUSTER_NAME).
293+
290294
%% @private
291295

292296
can_join_cluster(DiscoveryNode) when is_atom(DiscoveryNode) ->

deps/rabbit/src/rabbit_ra_systems.erl

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
are_running/0,
1818
ensure_ra_system_started/1,
1919
ensure_started/0,
20+
ensure_ra_system_stopped/1,
2021
ensure_stopped/0]).
2122

2223
-type ra_system_name() :: atom().

0 commit comments

Comments
 (0)