Skip to content

khepri_machine: Use process dict instead of persistent_term to track the need for a fence preliminary query#317

Merged
dumbbell merged 2 commits into
mainfrom
fix-skip-fence-preliminary-logic
Mar 13, 2025
Merged

khepri_machine: Use process dict instead of persistent_term to track the need for a fence preliminary query#317
dumbbell merged 2 commits into
mainfrom
fix-skip-fence-preliminary-logic

Conversation

@dumbbell
Copy link
Copy Markdown
Collaborator

Why

There was a small bug with our use of the persistent_term: it should have been a key per store ID and process PID combination, not just per store ID.

But anyway, a persistent_term is designed for a value that is mostly read, rarely written to. This was not the case here.

How

I thought about using an ETS table instead but it had a problem: if the calling process is on a different node that the one running Khepri, Khepri can't create an ETS table on that remote node. Each call could initialize that table if it didn’t exist, but this would be too much overhead in that code path to my taste. Moreover, we would have to put in place a cleaning mechanism for processes that exited if they still had an entry in that ETS table.

The solution retained is the use of the calling process dictionary. It is fast, can handle frequent updates and will be automatically cleaned up when the process exits. It also does not need an initial setup.

... as the arbitrary fence preliminary query.

[Why]
It allows to distinguish it from the other arbitrary query used in
`fence/2` during debugging session.
... to track the need for a fence preliminary query.

[Why]
There was a small bug with our use of the persistent_term: it should
have been a key per store ID and process PID combination, not just per
store ID.

But anyway, a persistent_term is designed for a value that is mostly
read, rarely written to. This was not the case here.

[How]
I thought about using an ETS table instead but it had a problem: if the
calling process is on a different node that the one running Khepri,
Khepri can't create an ETS table on that remote node. Each call could
initialize that table if it didn’t exist, but this would be too much
overhead in that code path to my taste. Moreover, we would have to put
in place a cleaning mechanism for processes that exited if they still
had an entry in that ETS table.

The solution retained is the use of the calling process dictionary. It
is fast, can handle frequent updates and will be automatically cleaned
up when the process exits. It also does not need an initial setup.
@dumbbell dumbbell added the bug Something isn't working label Mar 13, 2025
@dumbbell dumbbell added this to the v0.17.0 milestone Mar 13, 2025
@dumbbell dumbbell self-assigned this Mar 13, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.20%. Comparing base (d03a8ff) to head (0808b11).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #317      +/-   ##
==========================================
+ Coverage   89.14%   89.20%   +0.06%     
==========================================
  Files          22       22              
  Lines        3299     3299              
==========================================
+ Hits         2941     2943       +2     
+ Misses        358      356       -2     
Flag Coverage Δ
erlang-26 89.14% <100.00%> (+0.12%) ⬆️
erlang-27 89.05% <100.00%> (+0.06%) ⬆️
os-ubuntu-latest 89.17% <100.00%> (+0.09%) ⬆️
os-windows-latest 89.08% <100.00%> (+0.12%) ⬆️

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.

@dumbbell dumbbell marked this pull request as ready for review March 13, 2025 12:00
@dumbbell dumbbell merged commit 376422f into main Mar 13, 2025
@dumbbell dumbbell deleted the fix-skip-fence-preliminary-logic branch March 13, 2025 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant