Skip to content

Commit

Permalink
Update Khepri from 0.14.0 to 0.15.0
Browse files Browse the repository at this point in the history
Release notes:
https://github.com/rabbitmq/khepri/releases/tag/v0.15.0

The `favor` default value is now `low_latency`. Therefore, we don't need
to specify it explicitly anymore.
  • Loading branch information
dumbbell committed Aug 21, 2024
1 parent 36aa94a commit 5273939
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 42 deletions.
8 changes: 5 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,13 @@ erlang_package.hex_package(
version = "1.4.1",
)

erlang_package.hex_package(
erlang_package.git_package(
name = "khepri",
build_file = "@rabbitmq-server//bazel:BUILD.khepri",
sha256 = "dccfaeb3583a04722e2258911f7f906ce67f8efac80504be4923aaafae6d4e21",
version = "0.14.0",
#sha256 = "dccfaeb3583a04722e2258911f7f906ce67f8efac80504be4923aaafae6d4e21",
#version = "0.14.0",
repository = "rabbitmq/khepri",
branch = "main",
)

erlang_package.hex_package(
Expand Down
6 changes: 1 addition & 5 deletions deps/rabbit/src/rabbit_db_maintenance.erl
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,7 @@ get_consistent_in_mnesia(Node) ->

get_consistent_in_khepri(Node) ->
Path = khepri_maintenance_path(Node),
%% FIXME: Ra consistent queries are 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. That's why we force a local query for now.
%Options = #{favor => consistent},
Options = #{favor => local},
Options = #{favor => consistency},
case rabbit_khepri:get(Path, Options) of
{ok, #node_maintenance_state{status = Status}} ->
Status;
Expand Down
51 changes: 18 additions & 33 deletions deps/rabbit/src/rabbit_khepri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ wait_for_leader(_Timeout, 0) ->
wait_for_leader(Timeout, Retries) ->
rabbit_log:info("Waiting for Khepri leader for ~tp ms, ~tp retries left",
[Timeout, Retries - 1]),
Options = #{timeout => Timeout,
favor => low_latency},
Options = #{timeout => Timeout},
case khepri:exists(?STORE_ID, [], Options) of
Exists when is_boolean(Exists) ->
rabbit_log:info("Khepri leader elected"),
Expand Down Expand Up @@ -917,50 +916,46 @@ cas(Path, Pattern, Data) ->
?STORE_ID, Path, Pattern, Data, ?DEFAULT_COMMAND_OPTIONS).

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

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

foreach(Path, Pred) ->
khepri:foreach(?STORE_ID, Path, Pred, #{favor => low_latency}).
khepri:foreach(?STORE_ID, Path, Pred).

filter(Path, Pred) ->
khepri:filter(?STORE_ID, Path, Pred, #{favor => low_latency}).
khepri:filter(?STORE_ID, Path, Pred).

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

get(Path, Options) ->
Options1 = Options#{favor => low_latency},
khepri:get(?STORE_ID, Path, Options1).
khepri:get(?STORE_ID, Path, Options).

get_many(PathPattern) ->
khepri:get_many(?STORE_ID, PathPattern, #{favor => low_latency}).
khepri:get_many(?STORE_ID, PathPattern).

adv_get(Path) ->
khepri_adv:get(?STORE_ID, Path, #{favor => low_latency}).
khepri_adv:get(?STORE_ID, Path).

adv_get_many(PathPattern) ->
khepri_adv:get_many(?STORE_ID, PathPattern, #{favor => low_latency}).
khepri_adv:get_many(?STORE_ID, PathPattern).

match(Path) ->
match(Path, #{}).

match(Path, Options) ->
Options1 = Options#{favor => low_latency},
khepri:get_many(?STORE_ID, Path, Options1).
khepri:get_many(?STORE_ID, Path, Options).

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

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

list_child_nodes(Path) ->
Options = #{props_to_return => [child_names],
favor => low_latency},
Options = #{props_to_return => [child_names]},
case khepri_adv:get_many(?STORE_ID, Path, Options) of
{ok, Result} ->
case maps:values(Result) of
Expand All @@ -974,8 +969,7 @@ list_child_nodes(Path) ->
end.

count_children(Path) ->
Options = #{props_to_return => [child_list_length],
favor => low_latency},
Options = #{props_to_return => [child_list_length]},
case khepri_adv:get_many(?STORE_ID, Path, Options) of
{ok, Map} ->
lists:sum([L || #{child_list_length := L} <- maps:values(Map)]);
Expand Down Expand Up @@ -1026,18 +1020,9 @@ transaction(Fun) ->
transaction(Fun, ReadWrite) ->
transaction(Fun, ReadWrite, #{}).

transaction(Fun, ReadWrite, Options0) ->
%% If the transaction is read-only, use the same default options we use
%% for most queries.
DefaultQueryOptions = case ReadWrite of
ro ->
#{favor => low_latency};
_ ->
#{}
end,
Options1 = maps:merge(DefaultQueryOptions, Options0),
Options = maps:merge(?DEFAULT_COMMAND_OPTIONS, Options1),
case khepri:transaction(?STORE_ID, Fun, ReadWrite, Options) of
transaction(Fun, ReadWrite, Options) ->
Options1 = maps:merge(?DEFAULT_COMMAND_OPTIONS, Options),
case khepri:transaction(?STORE_ID, Fun, ReadWrite, Options1) of
ok -> ok;
{ok, Result} -> Result;
{error, Reason} -> throw({error, Reason})
Expand Down
2 changes: 1 addition & 1 deletion rabbitmq-components.mk
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ dep_credentials_obfuscation = hex 3.4.0
dep_cuttlefish = hex 3.4.0
dep_gen_batch_server = hex 0.8.8
dep_jose = hex 1.11.10
dep_khepri = hex 0.14.0
dep_khepri = git https://github.com/rabbitmq/khepri main # XXX
dep_khepri_mnesia_migration = hex 0.5.0
dep_prometheus = hex 4.11.0
dep_ra = hex 2.13.6
Expand Down

0 comments on commit 5273939

Please sign in to comment.