Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ra_server: Add a new last_applied state query #462

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ra_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2445,6 +2445,8 @@ state_query(initial_members, #{log := Log}) ->
_ ->
error
end;
state_query(last_applied, State) ->
maps:get(last_applied, State, undefined);
state_query(Query, _State) ->
{error, {unknown_query, Query}}.

Expand Down
4 changes: 2 additions & 2 deletions src/ra_server_proc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1188,9 +1188,9 @@ perform_or_delay_local_query(
%% If the condition is set to `{applied, {Index, Term}}', the query is
%% added to a list of pending queries. It will be evaluated once that
%% index is applied locally.
Leader = determine_leader(RaftState, State),
case maps:get(condition, Options, undefined) of
undefined ->
Leader = determine_leader(RaftState, State),
Reply = perform_local_query(QueryFun, Leader, ServerState, Conf),
{keep_state, State, [{reply, From, Reply}]};
Condition ->
Expand All @@ -1207,7 +1207,7 @@ perform_or_delay_local_query(
perform_pending_queries(_RaftState, #state{pending_queries = []} = State) ->
{State, []};
perform_pending_queries(RaftState, State) ->
#{last_applied := LastApplied} = do_state_query(overview, State),
LastApplied = do_state_query(last_applied, State),
perform_pending_queries(RaftState, LastApplied, State, []).

perform_pending_queries(RaftState, LastApplied,
Expand Down
Loading