Skip to content

rabbit_khepri: Retry register_projections during boot #11741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion deps/rabbit/src/rabbit_khepri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ setup(_) ->
case khepri:start(?RA_SYSTEM, RaServerConfig) of
{ok, ?STORE_ID} ->
wait_for_leader(),
register_projections(),
wait_for_register_projections(),
?LOG_DEBUG(
"Khepri-based " ?RA_FRIENDLY_NAME " ready",
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
Expand Down Expand Up @@ -295,6 +295,21 @@ wait_for_leader(Timeout, Retries) ->
throw(Reason)
end.

wait_for_register_projections() ->
wait_for_register_projections(retry_timeout(), retry_limit()).

wait_for_register_projections(_Timeout, 0) ->
exit(timeout_waiting_for_khepri_projections);
wait_for_register_projections(Timeout, Retries) ->
rabbit_log:info("Waiting for Khepri projections for ~tp ms, ~tp retries left",
[Timeout, Retries - 1]),
try
register_projections()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would retry registering all projections again if it fails. I think that's probably ok since I expect the first projection would be the only one to time out but we could make this a little more clever and fold over the list of projections to register and the retry number. Feel free to ignore though, it seems very unlikely to be hit in practice

catch
throw : timeout ->
wait_for_register_projections(Timeout, Retries -1)
end.

%% @private

can_join_cluster(DiscoveryNode) when is_atom(DiscoveryNode) ->
Expand Down
4 changes: 4 additions & 0 deletions deps/rabbitmq_cli/lib/rabbitmq/cli/default_output.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ defmodule RabbitMQ.CLI.DefaultOutput do
{:error, RabbitMQ.CLI.Core.ExitCodes.exit_tempfail(), khepri_timeout_error(node_name)}
end

defp format_khepri_output({:error, :timeout_waiting_for_khepri_projections}, %{node: node_name}) do
{:error, RabbitMQ.CLI.Core.ExitCodes.exit_tempfail(), khepri_timeout_error(node_name)}
end

defp format_khepri_output(result, _opts) do
result
end
Expand Down
Loading