Skip to content

Commit

Permalink
Merge pull request #296 from rabbitmq/md/is_store_running-whereis
Browse files Browse the repository at this point in the history
Use `erlang:whereis/1` for checking if a store is running
  • Loading branch information
dumbbell authored Sep 12, 2024
2 parents 2d04459 + ef07168 commit 15e7119
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/khepri_cluster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1576,11 +1576,12 @@ get_store_ids() ->
%% @doc Indicates if `StoreId' is running or not.

is_store_running(StoreId) ->
ThisNode = node(),
RaServer = khepri_cluster:node_to_member(StoreId, ThisNode),
Timeout = khepri_app:get_default_timeout(),
KeyMetrics = ra:key_metrics(RaServer, Timeout),
Runs = maps:get(state, KeyMetrics) =/= noproc,
%% FIXME: Ra has no API to know if a Ra server is running or not. We could
%% use a public API such as `ra:key_metrics/2', but unfortunately, it is
%% not as efficient as querying the process directly. Therefore, we bypass
%% Ra and rely on the fact that the server ID is internally a registered
%% process name and resolve it to determine if it is running.
Runs = erlang:whereis(StoreId) =/= undefined,

%% 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 Down

0 comments on commit 15e7119

Please sign in to comment.