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

khepri_machine: Use cached leader for async commands #228

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

the-mikedavis
Copy link
Member

@the-mikedavis the-mikedavis commented Oct 4, 2023

Async commands will fail to be applied unless they're sent to the cluster's current leader. With this change we always try to use the cached leader from synchronous commands if available and use the local member if the leader isn't cached. The caller can then update the cached leader value when the async response says that the command was sent against a non-leader member, like so:

receive
    {ra_event,
     FromId,
     {rejected, {not_leader, MaybeLeader, CorrelationId}}} ->
        ok = khepri_cluster:cache_leader_if_changed(
               StoreId, FromId, MaybeLeader),
        %% ... retry the command for `CorrelationId' ...
        ok
end

Async commands will fail to be applied unless they're sent to the
cluster's current leader. With this change we always try to use the
cached leader from synchronous commands if available and use the local
member if the leader isn't cached. The caller can then update the cached
leader value when the async response says that the command was sent
against a non-leader member, like so:

    receive
        {ra_event,
         FromId,
         {rejected, {not_leader, MaybeLeader, CorrelationId}}} ->
            ok = khepri_cluster:cache_leader_if_changed(
                   StoreId, FromId, MaybeLeader),
            %% ... retry the command for `CorrelationId' ...
            ok
    end
@the-mikedavis the-mikedavis added the enhancement New feature or request label Oct 4, 2023
@the-mikedavis the-mikedavis added this to the v0.9.0 milestone Oct 4, 2023
@the-mikedavis the-mikedavis self-assigned this Oct 4, 2023
@codecov
Copy link

codecov bot commented Oct 4, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (8a75f9d) 88.85% compared to head (e503414) 88.93%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #228      +/-   ##
==========================================
+ Coverage   88.85%   88.93%   +0.07%     
==========================================
  Files          20       20              
  Lines        2890     2891       +1     
==========================================
+ Hits         2568     2571       +3     
+ Misses        322      320       -2     
Flag Coverage Δ
erlang-24 87.82% <100.00%> (+0.14%) ⬆️
erlang-25 87.82% <100.00%> (+0.07%) ⬆️
erlang-26 88.61% <100.00%> (+0.17%) ⬆️
os-ubuntu-latest 88.89% <100.00%> (+0.10%) ⬆️
os-windows-latest 88.51% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/khepri_machine.erl 95.30% <100.00%> (+0.48%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@the-mikedavis the-mikedavis marked this pull request as ready for review October 4, 2023 19:15
@dumbbell dumbbell merged commit ae50ffd into main Oct 11, 2023
12 checks passed
@dumbbell dumbbell deleted the md-use-cached-leader-for-async-commands branch October 11, 2023 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants