@@ -276,7 +276,7 @@ wait_for_leader(Timeout, Retries) ->
276
276
rabbit_log :info (" Waiting for Khepri leader for ~tp ms, ~tp retries left" ,
277
277
[Timeout , Retries - 1 ]),
278
278
Options = #{timeout => Timeout ,
279
- favor => compromise },
279
+ favor => low_latency },
280
280
case khepri :exists (? STORE_ID , [], Options ) of
281
281
Exists when is_boolean (Exists ) ->
282
282
rabbit_log :info (" Khepri leader elected" ),
@@ -524,9 +524,14 @@ ensure_ra_system_started() ->
524
524
% % cluster.
525
525
% %
526
526
% % 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.
527
529
528
530
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 .
530
535
531
536
-spec locally_known_members () -> Members when
532
537
Members :: [ra :server_id ()].
@@ -536,18 +541,28 @@ members() ->
536
541
% % The membership is as it is known to the local Ra server and may be
537
542
% % inconsistent compared to the "official" membership as seen by the Ra
538
543
% % leader.
544
+ % %
545
+ % % The returned list is empty if there was an error.
539
546
540
547
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 .
542
552
543
553
-spec nodes () -> Nodes when
544
554
Nodes :: [node ()].
545
555
% % @doc Returns the list of Erlang nodes that are part of the cluster.
546
556
% %
547
557
% % 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.
548
560
549
561
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 .
551
566
552
567
-spec locally_known_nodes () -> Nodes when
553
568
Nodes :: [node ()].
@@ -556,9 +571,14 @@ nodes() ->
556
571
% % The membership is as it is known to the local Ra server and may be
557
572
% % inconsistent compared to the "official" membership as seen by the Ra
558
573
% % leader.
574
+ % %
575
+ % % The returned list is empty if there was an error.
559
576
560
577
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 .
562
582
563
583
-spec get_ra_cluster_name () -> RaClusterName when
564
584
RaClusterName :: ra :cluster_name ().
@@ -838,20 +858,24 @@ cas(Path, Pattern, Data) ->
838
858
? STORE_ID , Path , Pattern , Data , ? DEFAULT_COMMAND_OPTIONS ).
839
859
840
860
fold (Path , Pred , Acc ) ->
841
- khepri :fold (? STORE_ID , Path , Pred , Acc ).
861
+ khepri :fold (? STORE_ID , Path , Pred , Acc , #{ favor => low_latency } ).
842
862
843
863
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 ).
845
866
846
- foreach (Path , Pred ) -> khepri :foreach (? STORE_ID , Path , Pred ).
867
+ foreach (Path , Pred ) ->
868
+ khepri :foreach (? STORE_ID , Path , Pred , #{favor => low_latency }).
847
869
848
- filter (Path , Pred ) -> khepri :filter (? STORE_ID , Path , Pred ).
870
+ filter (Path , Pred ) ->
871
+ khepri :filter (? STORE_ID , Path , Pred , #{favor => low_latency }).
849
872
850
873
get (Path ) ->
851
874
khepri :get (? STORE_ID , Path , #{favor => low_latency }).
852
875
853
876
get (Path , Options ) ->
854
- khepri :get (? STORE_ID , Path , Options ).
877
+ Options1 = Options #{favor => low_latency },
878
+ khepri :get (? STORE_ID , Path , Options1 ).
855
879
856
880
get_many (PathPattern ) ->
857
881
khepri :get_many (? STORE_ID , PathPattern , #{favor => low_latency }).
@@ -862,14 +886,19 @@ adv_get(Path) ->
862
886
match (Path ) ->
863
887
match (Path , #{}).
864
888
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 ).
866
892
867
893
exists (Path ) -> khepri :exists (? STORE_ID , Path , #{favor => low_latency }).
868
894
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 }).
870
898
871
899
list_child_nodes (Path ) ->
872
- Options = #{props_to_return => [child_names ]},
900
+ Options = #{props_to_return => [child_names ],
901
+ favor => low_latency },
873
902
case khepri_adv :get_many (? STORE_ID , Path , Options ) of
874
903
{ok , Result } ->
875
904
case maps :values (Result ) of
@@ -883,7 +912,8 @@ list_child_nodes(Path) ->
883
912
end .
884
913
885
914
count_children (Path ) ->
886
- Options = #{props_to_return => [child_list_length ]},
915
+ Options = #{props_to_return => [child_list_length ],
916
+ favor => low_latency },
887
917
case khepri_adv :get_many (? STORE_ID , Path , Options ) of
888
918
{ok , Map } ->
889
919
lists :sum ([L || #{child_list_length := L } <- maps :values (Map )]);
0 commit comments