Skip to content

Commit 6ea19b9

Browse files
committed
rabbit_khepri: Use local queries exclusively
[Why] Ra consistent queries are currently fragile in the sense that the query function may run on a remote node and the function reference or MFA may not be valid on that node: * A different Erlang compiler may produce difference function references for the same module source code. We observed a difference between Erlang/OTP 25.x and Erlang/OTP 26.x compilers for instance. * There is no way to be sure that the remote function copy, whether it is described by a function reference of an MFA tuple, is the same as the copy local to the caller. Indeed, the remote node may run a different version after an upgrade to one of the local or remote nodes. [How] That's why we force local queries for now. This is fine for now, especially that we use Khepri projections in many places and they are local by design.
1 parent d5624d9 commit 6ea19b9

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

deps/rabbit/src/rabbit_khepri.erl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ wait_for_leader(Timeout, Retries) ->
276276
rabbit_log:info("Waiting for Khepri leader for ~tp ms, ~tp retries left",
277277
[Timeout, Retries - 1]),
278278
Options = #{timeout => Timeout,
279-
favor => compromise},
279+
favor => low_latency},
280280
case khepri:exists(?STORE_ID, [], Options) of
281281
Exists when is_boolean(Exists) ->
282282
rabbit_log:info("Khepri leader elected"),
@@ -858,20 +858,24 @@ cas(Path, Pattern, Data) ->
858858
?STORE_ID, Path, Pattern, Data, ?DEFAULT_COMMAND_OPTIONS).
859859

860860
fold(Path, Pred, Acc) ->
861-
khepri:fold(?STORE_ID, Path, Pred, Acc).
861+
khepri:fold(?STORE_ID, Path, Pred, Acc, #{favor => low_latency}).
862862

863863
fold(Path, Pred, Acc, Options) ->
864-
khepri:fold(?STORE_ID, Path, Pred, Acc, Options).
864+
Options1 = Options#{favor => low_latency},
865+
khepri:fold(?STORE_ID, Path, Pred, Acc, Options1).
865866

866-
foreach(Path, Pred) -> khepri:foreach(?STORE_ID, Path, Pred).
867+
foreach(Path, Pred) ->
868+
khepri:foreach(?STORE_ID, Path, Pred, #{favor => low_latency}).
867869

868-
filter(Path, Pred) -> khepri:filter(?STORE_ID, Path, Pred).
870+
filter(Path, Pred) ->
871+
khepri:filter(?STORE_ID, Path, Pred, #{favor => low_latency}).
869872

870873
get(Path) ->
871874
khepri:get(?STORE_ID, Path, #{favor => low_latency}).
872875

873876
get(Path, Options) ->
874-
khepri:get(?STORE_ID, Path, Options).
877+
Options1 = Options#{favor => low_latency},
878+
khepri:get(?STORE_ID, Path, Options1).
875879

876880
get_many(PathPattern) ->
877881
khepri:get_many(?STORE_ID, PathPattern, #{favor => low_latency}).
@@ -882,14 +886,19 @@ adv_get(Path) ->
882886
match(Path) ->
883887
match(Path, #{}).
884888

885-
match(Path, Options) -> khepri:get_many(?STORE_ID, Path, Options).
889+
match(Path, Options) ->
890+
Options1 = Options#{favor => low_latency},
891+
khepri:get_many(?STORE_ID, Path, Options1).
886892

887893
exists(Path) -> khepri:exists(?STORE_ID, Path, #{favor => low_latency}).
888894

889-
list(Path) -> khepri:get_many(?STORE_ID, Path ++ [?KHEPRI_WILDCARD_STAR]).
895+
list(Path) ->
896+
khepri:get_many(
897+
?STORE_ID, Path ++ [?KHEPRI_WILDCARD_STAR], #{favor => low_latency}).
890898

891899
list_child_nodes(Path) ->
892-
Options = #{props_to_return => [child_names]},
900+
Options = #{props_to_return => [child_names],
901+
favor => low_latency},
893902
case khepri_adv:get_many(?STORE_ID, Path, Options) of
894903
{ok, Result} ->
895904
case maps:values(Result) of
@@ -903,7 +912,8 @@ list_child_nodes(Path) ->
903912
end.
904913

905914
count_children(Path) ->
906-
Options = #{props_to_return => [child_list_length]},
915+
Options = #{props_to_return => [child_list_length],
916+
favor => low_latency},
907917
case khepri_adv:get_many(?STORE_ID, Path, Options) of
908918
{ok, Map} ->
909919
lists:sum([L || #{child_list_length := L} <- maps:values(Map)]);

0 commit comments

Comments
 (0)