Skip to content

Commit

Permalink
Merge pull request #292 from rabbitmq/optimize-is_store_running
Browse files Browse the repository at this point in the history
khepri_cluster: Use key metrics to determine if a Ra server is running
  • Loading branch information
dumbbell authored Sep 9, 2024
2 parents c5d02f4 + b47b2fa commit e31b236
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/khepri_cluster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1560,11 +1560,9 @@ get_store_ids() ->
is_store_running(StoreId) ->
ThisNode = node(),
RaServer = khepri_cluster:node_to_member(StoreId, ThisNode),
Runs = case ra:ping(RaServer, khepri_app:get_default_timeout()) of
{pong, _} -> true;
{error, _} -> false;
timeout -> false
end,
Timeout = khepri_app:get_default_timeout(),
KeyMetrics = ra:key_metrics(RaServer, Timeout),
Runs = maps:get(state, KeyMetrics) =/= noproc,

%% We know the real state of the Ra server. In the case the Ra server
%% stopped behind the back of Khepri, we update the cached list of running
Expand All @@ -1575,6 +1573,10 @@ is_store_running(StoreId) ->
ok;
false when not Runs ->
ok;
false when Runs ->
%% This function was called between the start of the Ra server and
%% the record of its configuration. This is a race, but that's ok.
ok;
true when not Runs ->
?LOG_DEBUG(
"Ra server for store ~s stopped behind the back of Khepri",
Expand Down

0 comments on commit e31b236

Please sign in to comment.