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_cluster: Make join/3 idempotent #219

Merged
merged 1 commit into from
Jul 27, 2023
Merged

Conversation

dumbbell
Copy link
Member

Why

If khepri_cluster:join/3 is called twice in a row, the join succeeds because the joining node is reset before it joins the cluster again. This is not exactly idempotent, but the end result is the same.

However if the joining node was reset somehow (e.g. its data directory was lost) and therefore thinks it is a standalone store, calling khepri_cluster:join/1 again would return {error, already_member}.

It is more comfortable if the function just does what it takes to achieve the wanted result of expanding the cluster.

How

The {error, already_member} error is caught and the function returns ok instead. Behind the scene, Ra did the correct thing and the joining node is back in the cluster.

[Why]
If `khepri_cluster:join/3` is called twice in a row, the join succeeds
because the joining node is reset before it joins the cluster again.
This is not exactly idempotent, but the end result is the same.

However if the joining node was reset somehow (e.g. its data directory
was lost) and therefore thinks it is a standalone store, calling
`khepri_cluster:join/1` again would return `{error, already_member}`.

It is more comfortable if the function just does what it takes to
achieve the wanted result of expanding the cluster.

[How]
The `{error, already_member}` error is caught and the function returns
`ok` instead. Behind the scene, Ra did the correct thing and the joining
node is back in the cluster.
@dumbbell dumbbell added the enhancement New feature or request label Jul 27, 2023
@dumbbell dumbbell added this to the v0.8.0 milestone Jul 27, 2023
@dumbbell dumbbell self-assigned this Jul 27, 2023
@codecov
Copy link

codecov bot commented Jul 27, 2023

Codecov Report

Patch coverage: 66.66% and project coverage change: -0.14% ⚠️

Comparison is base (296427d) 89.36% compared to head (73b4c94) 89.23%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #219      +/-   ##
==========================================
- Coverage   89.36%   89.23%   -0.14%     
==========================================
  Files          20       20              
  Lines        2822     2825       +3     
==========================================
- Hits         2522     2521       -1     
- Misses        300      304       +4     
Flag Coverage Δ
erlang-24 88.35% <66.66%> (+0.08%) ⬆️
erlang-25 88.10% <66.66%> (-0.13%) ⬇️
erlang-26 88.74% <66.66%> (-0.10%) ⬇️
os-ubuntu-latest 89.16% <66.66%> (-0.21%) ⬇️
os-windows-latest 88.10% <66.66%> (+0.01%) ⬆️

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

Files Changed Coverage Δ
src/khepri_cluster.erl 80.69% <66.66%> (-0.14%) ⬇️

... and 2 files with indirect coverage changes

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

@dumbbell dumbbell marked this pull request as ready for review July 27, 2023 06:17
@dumbbell dumbbell merged commit 585970f into main Jul 27, 2023
10 checks passed
@dumbbell dumbbell deleted the make-join-idempotent branch July 27, 2023 06:18
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

1 participant