Skip to content

Commit

Permalink
rabbit: Stop Khepri store and Ra systems in stop/1
Browse files Browse the repository at this point in the history
[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.
  • Loading branch information
dumbbell committed Jan 22, 2024
1 parent 8061575 commit c6e0430
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions deps/rabbit/src/rabbit.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,21 @@ stop(State) ->
[] -> rabbit_prelaunch:set_stop_reason(normal);
_ -> rabbit_prelaunch:set_stop_reason(State)
end,

%% 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.
rabbit_ra_systems:ensure_ra_system_stopped(quorum_queues),
_ = rabbit_stream_coordinator:stop(),
rabbit_khepri:stop(),
rabbit_ra_systems:ensure_stopped(),

rabbit_db:clear_init_finished(),
rabbit_boot_state:set(stopped),
ok.
Expand Down
4 changes: 4 additions & 0 deletions deps/rabbit/src/rabbit_khepri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@

-export([setup/0,
setup/1,
stop/0,
can_join_cluster/1,
add_member/2,
remove_member/1,
Expand Down Expand Up @@ -287,6 +288,9 @@ wait_for_leader(Timeout, Retries) ->
throw(Reason)
end.

stop() ->
ok = khepri:stop(?RA_CLUSTER_NAME).

%% @private

can_join_cluster(DiscoveryNode) when is_atom(DiscoveryNode) ->
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 @@ -17,6 +17,7 @@
are_running/0,
ensure_ra_system_started/1,
ensure_started/0,
ensure_ra_system_stopped/1,
ensure_stopped/0]).

-type ra_system_name() :: atom().
Expand Down

0 comments on commit c6e0430

Please sign in to comment.