Skip to content

khepri_machine: Add API to wait for a behaviour to be effective#374

Draft
dumbbell wants to merge 3 commits intomainfrom
add-api-to-wait-for-feature
Draft

khepri_machine: Add API to wait for a behaviour to be effective#374
dumbbell wants to merge 3 commits intomainfrom
add-api-to-wait-for-feature

Conversation

@dumbbell
Copy link
Collaborator

Why

In the client code of the Khepri state machine, we need to know what version of the state machine is currently effective in the cluster before we can send some new commands. This is to avoid sending a new command to a member of the cluster that runs an older version of Khepri, causing it to possibly crash.

So far, we always had a fallback code path: if the new behaviour is not supported by the cluster, we could use an old way of doing somethin, or not doing it at all (keeping the old behaviour).

In a future patch, we will need to return an error to the caller to indicate the cluster is not ready for the behaviour it wants. Therefore, we need an API to allow the client code of the state machine (or the caller) to wait for a specific behaviour to be supported by the cluster.

How

The patch consists of three commits. The first one refactors the mapping between a given behaviour and the state machine version it wa introduced in.

The remaining two commits add functions to wait for the cluster to run a minimum version or a support a specific behaviour:

  1. khepri_machine:wait_for_effective_machine_version/2
  2. khepri_machine:wait_for_effective_behaviour/2; this relies on the refactored behaviour/version mapping and the wait_for_effective_machine_version/2

@dumbbell dumbbell added this to the v0.18.0 milestone Mar 13, 2026
@dumbbell dumbbell self-assigned this Mar 13, 2026
@dumbbell dumbbell added the enhancement New feature or request label Mar 13, 2026
@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 70.58824% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.77%. Comparing base (8ccc68c) to head (827cd68).

Files with missing lines Patch % Lines
src/khepri_machine.erl 76.92% 6 Missing ⚠️
src/khepri_cluster.erl 50.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #374      +/-   ##
==========================================
- Coverage   89.97%   89.77%   -0.20%     
==========================================
  Files          22       22              
  Lines        3531     3560      +29     
==========================================
+ Hits         3177     3196      +19     
- Misses        354      364      +10     
Flag Coverage Δ
erlang-26 89.74% <70.58%> (-0.03%) ⬇️
erlang-27 89.74% <70.58%> (-0.03%) ⬇️
erlang-28 89.57% <70.58%> (-0.37%) ⬇️
os-ubuntu-latest 89.77% <70.58%> (-0.03%) ⬇️
os-windows-latest 89.77% <70.58%> (-0.18%) ⬇️

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

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

[Why]
It is responsible for the mapping from an API behaviour to the state
machine version the API behaviour was introduced in. We will be able to
use it in a future API.

The `does_api_comply_with/2` function is simplified by using
`api_behaviour_to_machine_version/1`.
[Why]
It allows to wait that a Khepri store runs the given machine version or
more.
[Why]
It allows to wait that a Khepri store supports a specific behaviour.
@dumbbell dumbbell force-pushed the add-api-to-wait-for-feature branch from 7bef340 to 827cd68 Compare March 13, 2026 18:37
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.

1 participant