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

Replace wait_for_async_ret with handle_async_ret for handling async Ra events #229

Merged
merged 2 commits into from
Oct 31, 2023

Conversation

the-mikedavis
Copy link
Member

This is similar to wait_for_async_ret/1,2 except that the caller is expected to receive the Ra event. This is necessary because the Ra event sent when a batch of commands is applied includes a list of correlation and result pairs, making it impossible to use a selective receive to look for a single correlation ID.

We could alternatively map the ra_event message into some other value like {ok, Correlations} | {error, CorrelationId} but this isn't much easier to work with than the ra_events themselves and would be brittle for changes to ra_event. Instead we leave it to the caller to receive and handle the events. This function is then responsible only for calling internal functions to update the cached leader for the given store ID.

I've also added deprecations for wait_for_async_ret/1,2 since it can't be used to reliably find if a given correlation ID was applied. Instead we should prefer to have the caller receive the Ra event and handle the correlation IDs within.

@the-mikedavis the-mikedavis added the enhancement New feature or request label Oct 16, 2023
@the-mikedavis the-mikedavis added this to the v0.9.0 milestone Oct 16, 2023
@the-mikedavis the-mikedavis self-assigned this Oct 16, 2023
@codecov
Copy link

codecov bot commented Oct 16, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (f8a969d) 88.82% compared to head (a25e695) 88.84%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #229      +/-   ##
==========================================
+ Coverage   88.82%   88.84%   +0.01%     
==========================================
  Files          20       20              
  Lines        2891     2887       -4     
==========================================
- Hits         2568     2565       -3     
+ Misses        323      322       -1     
Flag Coverage Δ
erlang-24 87.73% <60.00%> (-0.09%) ⬇️
erlang-25 87.77% <60.00%> (+0.01%) ⬆️
erlang-26 88.50% <60.00%> (+0.05%) ⬆️
os-ubuntu-latest 88.84% <60.00%> (+0.01%) ⬆️
os-windows-latest 88.53% <60.00%> (-0.02%) ⬇️

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

Files Coverage Δ
src/khepri_adv.erl 100.00% <ø> (ø)
src/khepri.erl 89.76% <60.00%> (-0.82%) ⬇️

... and 2 files with indirect coverage changes

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

@the-mikedavis the-mikedavis marked this pull request as draft October 16, 2023 09:47
@the-mikedavis the-mikedavis marked this pull request as ready for review October 16, 2023 12:58
src/khepri.erl Outdated Show resolved Hide resolved
src/khepri.erl Show resolved Hide resolved
@the-mikedavis the-mikedavis changed the title Add khepri:handle_async_ret/2 for handling async Ra events Replace wait_for_async_ret with handle_async_ret for handling async Ra events Oct 31, 2023
This is similar to `wait_for_async_ret/1,2` except that the caller is
expected to `receive` the Ra event. This is necessary because the Ra
event sent when a batch of commands is applied includes a list of
correlation and result pairs, making it impossible to use a selective
receive to look for a single correlation ID.

We could alternatively map the `ra_event` message into some other value
like `{ok, Correlations} | {error, CorrelationId}` but this isn't much
easier to work with than the `ra_event`s themselves and would be brittle
for changes to `ra_event`. Instead we leave it to the caller to receive
and handle the events. This function is then responsible only for
calling internal functions to update the cached leader for the given
store ID.
See the parent commit: `wait_for_async_ret/1,2` used a selective receive
to find whether a given correlation ID was applied. The `ra_event`
emitted when a batch is applied gives all correlation and result pairs
applied in the batch though, making it impossible to reliably find a
single correlation ID. We should instead have the caller perform the
`receive` to find the applied/rejected event and handle all of the
correlation IDs found within.

So this change removes `wait_for_async_ret/1,2` in favor of the
`handle_async_ret/2` function added in the parent commit.
@dumbbell dumbbell merged commit f843e4a into main Oct 31, 2023
12 checks passed
@dumbbell dumbbell deleted the md-handle-async-ret branch October 31, 2023 15:54
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

2 participants