Skip to content

Commit 6d3c9a8

Browse files
authored
Merge pull request #10443 from rabbitmq/use-local-khepri-queries
Use local Khepri queries only
2 parents ab65dc9 + af0728c commit 6d3c9a8

File tree

5 files changed

+68
-26
lines changed

5 files changed

+68
-26
lines changed

MODULE.bazel

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bazel_dep(
4949

5050
bazel_dep(
5151
name = "rabbitmq_ra",
52-
version = "2.7.1",
52+
version = "2.7.3",
5353
repo_name = "ra",
5454
)
5555

@@ -295,15 +295,15 @@ erlang_package.hex_package(
295295
erlang_package.hex_package(
296296
name = "khepri",
297297
build_file = "@rabbitmq-server//bazel:BUILD.khepri",
298-
sha256 = "da618ec76abd188620c8fbdc16cb8eb94b09055a657c488da7fab160d49abcbe",
299-
version = "0.10.1",
298+
sha256 = "0f90ad4d163493abf8bc03ab161a8c65795fe5578fe16a5a1d27846185e68aaf",
299+
version = "0.11.0",
300300
)
301301

302-
erlang_package.git_package(
302+
erlang_package.hex_package(
303303
name = "khepri_mnesia_migration",
304304
build_file = "@rabbitmq-server//bazel:BUILD.khepri_mnesia_migration",
305-
commit = "56d7d123cc3e9dce309582b4d45ea58f3580ee71",
306-
repository = "rabbitmq/khepri_mnesia_migration",
305+
sha256 = "996f7db1f094a3d5e72ff9e3a2db4fd1895872a1fcbc223b91671bcbc047b03b",
306+
version = "0.3.0",
307307
)
308308

309309
erlang_package.hex_package(
@@ -338,8 +338,8 @@ erlang_package.hex_package(
338338
name = "ra_alt",
339339
build_file = "@rabbitmq-server//bazel:BUILD.ra",
340340
pkg = "ra",
341-
sha256 = "20ba906dc4feb824f07facca227b5a4f9bf7435eb21f469028112313a64a8490",
342-
version = "2.7.1",
341+
sha256 = "6f2b912a779f4efa4deea762b65192ed6e87111c7d98cbbe8a29576964739147",
342+
version = "2.7.3",
343343
)
344344

345345
erlang_package.git_package(

deps/rabbit/src/rabbit_db_maintenance.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,12 @@ get_consistent_in_mnesia(Node) ->
155155

156156
get_consistent_in_khepri(Node) ->
157157
Path = khepri_maintenance_path(Node),
158-
case rabbit_khepri:get(Path, #{favor => consistency}) of
158+
%% FIXME: Ra consistent queries are fragile in the sense that the query
159+
%% function may run on a remote node and the function reference or MFA may
160+
%% not be valid on that node. That's why we force a local query for now.
161+
%Options = #{favor => consistent},
162+
Options = #{favor => local},
163+
case rabbit_khepri:get(Path, Options) of
159164
{ok, #node_maintenance_state{status = Status}} ->
160165
Status;
161166
_ ->

deps/rabbit/src/rabbit_khepri.erl

Lines changed: 44 additions & 14 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"),
@@ -524,9 +524,14 @@ ensure_ra_system_started() ->
524524
%% cluster.
525525
%%
526526
%% The membership is as it is known to the Ra leader in the cluster.
527+
%%
528+
%% The returned list is empty if there was an error.
527529

528530
members() ->
529-
khepri_cluster:members(?RA_CLUSTER_NAME).
531+
case khepri_cluster:members(?RA_CLUSTER_NAME) of
532+
{ok, Members} -> Members;
533+
{error, _Reason} -> []
534+
end.
530535

531536
-spec locally_known_members() -> Members when
532537
Members :: [ra:server_id()].
@@ -536,18 +541,28 @@ members() ->
536541
%% The membership is as it is known to the local Ra server and may be
537542
%% inconsistent compared to the "official" membership as seen by the Ra
538543
%% leader.
544+
%%
545+
%% The returned list is empty if there was an error.
539546

540547
locally_known_members() ->
541-
khepri_cluster:locally_known_members(?RA_CLUSTER_NAME).
548+
case khepri_cluster:locally_known_members(?RA_CLUSTER_NAME) of
549+
{ok, Members} -> Members;
550+
{error, _Reason} -> []
551+
end.
542552

543553
-spec nodes() -> Nodes when
544554
Nodes :: [node()].
545555
%% @doc Returns the list of Erlang nodes that are part of the cluster.
546556
%%
547557
%% The membership is as it is known to the Ra leader in the cluster.
558+
%%
559+
%% The returned list is empty if there was an error.
548560

549561
nodes() ->
550-
khepri_cluster:nodes(?RA_CLUSTER_NAME).
562+
case khepri_cluster:nodes(?RA_CLUSTER_NAME) of
563+
{ok, Nodes} -> Nodes;
564+
{error, _Reason} -> []
565+
end.
551566

552567
-spec locally_known_nodes() -> Nodes when
553568
Nodes :: [node()].
@@ -556,9 +571,14 @@ nodes() ->
556571
%% The membership is as it is known to the local Ra server and may be
557572
%% inconsistent compared to the "official" membership as seen by the Ra
558573
%% leader.
574+
%%
575+
%% The returned list is empty if there was an error.
559576

560577
locally_known_nodes() ->
561-
khepri_cluster:locally_known_nodes(?RA_CLUSTER_NAME).
578+
case khepri_cluster:locally_known_nodes(?RA_CLUSTER_NAME) of
579+
{ok, Nodes} -> Nodes;
580+
{error, _Reason} -> []
581+
end.
562582

563583
-spec get_ra_cluster_name() -> RaClusterName when
564584
RaClusterName :: ra:cluster_name().
@@ -838,20 +858,24 @@ cas(Path, Pattern, Data) ->
838858
?STORE_ID, Path, Pattern, Data, ?DEFAULT_COMMAND_OPTIONS).
839859

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

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

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

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

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

853876
get(Path, Options) ->
854-
khepri:get(?STORE_ID, Path, Options).
877+
Options1 = Options#{favor => low_latency},
878+
khepri:get(?STORE_ID, Path, Options1).
855879

856880
get_many(PathPattern) ->
857881
khepri:get_many(?STORE_ID, PathPattern, #{favor => low_latency}).
@@ -862,14 +886,19 @@ adv_get(Path) ->
862886
match(Path) ->
863887
match(Path, #{}).
864888

865-
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).
866892

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

869-
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}).
870898

871899
list_child_nodes(Path) ->
872-
Options = #{props_to_return => [child_names]},
900+
Options = #{props_to_return => [child_names],
901+
favor => low_latency},
873902
case khepri_adv:get_many(?STORE_ID, Path, Options) of
874903
{ok, Result} ->
875904
case maps:values(Result) of
@@ -883,7 +912,8 @@ list_child_nodes(Path) ->
883912
end.
884913

885914
count_children(Path) ->
886-
Options = #{props_to_return => [child_list_length]},
915+
Options = #{props_to_return => [child_list_length],
916+
favor => low_latency},
887917
case khepri_adv:get_many(?STORE_ID, Path, Options) of
888918
{ok, Map} ->
889919
lists:sum([L || #{child_list_length := L} <- maps:values(Map)]);

deps/rabbit/src/rabbit_maintenance.erl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99

1010
-include_lib("rabbit_common/include/rabbit.hrl").
1111

12+
%% FIXME: Ra consistent queries are currently fragile in the sense that the
13+
%% query function may run on a remote node and the function reference or MFA
14+
%% may not be valid on that node. That's why consistent queries in this module
15+
%% are in fact local queries when Khepri is enabled.
16+
%%
17+
%% See `rabbit_db_maintenance:get_consistent_in_khepri/1'.
18+
1219
-export([
1320
is_enabled/0,
1421
drain/0,

rabbitmq-components.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ dep_accept = hex 0.3.5
115115
dep_cowboy = hex 2.11.0
116116
dep_cowlib = hex 2.12.1
117117
dep_credentials_obfuscation = hex 3.4.0
118-
dep_khepri = hex 0.10.0
119-
dep_khepri_mnesia_migration = hex 0.2.1
118+
dep_khepri = hex 0.11.0
119+
dep_khepri_mnesia_migration = hex 0.3.0
120120
dep_looking_glass = git https://github.com/rabbitmq/looking_glass.git main
121121
dep_prometheus = hex 4.11.0
122-
dep_ra = hex 2.7.1
122+
dep_ra = hex 2.7.3
123123
dep_ranch = hex 2.1.0
124124
dep_recon = hex 2.5.3
125125
dep_redbug = hex 2.0.7

0 commit comments

Comments
 (0)