Skip to content

Commit f257e11

Browse files
committed
rabbit_khepri: Retry register_projections during boot
Gives some time to form a majority during the boot process, allowing nodes to boot more easily
1 parent 2c96bcc commit f257e11

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

deps/rabbit/src/rabbit_khepri.erl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ setup(_) ->
252252
case khepri:start(?RA_SYSTEM, RaServerConfig) of
253253
{ok, ?STORE_ID} ->
254254
wait_for_leader(),
255-
register_projections(),
255+
wait_for_register_projections(),
256256
?LOG_DEBUG(
257257
"Khepri-based " ?RA_FRIENDLY_NAME " ready",
258258
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
@@ -295,6 +295,21 @@ wait_for_leader(Timeout, Retries) ->
295295
throw(Reason)
296296
end.
297297

298+
wait_for_register_projections() ->
299+
wait_for_register_projections(retry_timeout(), retry_limit()).
300+
301+
wait_for_register_projections(_Timeout, 0) ->
302+
exit(timeout_waiting_for_khepri_projections);
303+
wait_for_register_projections(Timeout, Retries) ->
304+
rabbit_log:info("Waiting for Khepri projections for ~tp ms, ~tp retries left",
305+
[Timeout, Retries - 1]),
306+
try
307+
register_projections()
308+
catch
309+
throw : {timeout, _ServerId} ->
310+
wait_for_register_projections(Timeout, Retries -1)
311+
end.
312+
298313
%% @private
299314

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

0 commit comments

Comments
 (0)