Skip to content

Commit 5eafdb4

Browse files
committed
rabbit_khepri: Send a command instead of query for awaiting leadership
1 parent 0870c59 commit 5eafdb4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

deps/rabbit/src/rabbit_khepri.erl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,15 @@ wait_for_leader(_Timeout, 0) ->
294294
wait_for_leader(Timeout, Retries) ->
295295
rabbit_log:info("Waiting for Khepri leader for ~tp ms, ~tp retries left",
296296
[Timeout, Retries - 1]),
297-
Options = #{timeout => Timeout,
298-
favor => low_latency},
299-
case khepri:exists(?STORE_ID, [], Options) of
300-
Exists when is_boolean(Exists) ->
297+
%% We use a command (delete) rather than a query to check that a leader
298+
%% has been elected. Khepri defaults to running queries against the local
299+
%% member and local queries do not require an elected leader. In order to
300+
%% apply a command though, the cluster must have a leader. So to await
301+
%% leadership we send a command that should no-op: a delete of some node
302+
%% that we will never use.
303+
Options = ?DEFAULT_COMMAND_OPTIONS#{timeout => Timeout},
304+
case khepri:delete(?STORE_ID, [does_not_exist], Options) of
305+
ok ->
301306
rabbit_log:info("Khepri leader elected"),
302307
ok;
303308
{error, timeout} -> %% Khepri >= 0.14.0

0 commit comments

Comments
 (0)