khepri icon indicating copy to clipboard operation
khepri copied to clipboard

Always pass exported functions to Ra queries

Open dumbbell opened this issue 1 year ago • 3 comments

Why

Using fun() is fragile if it has to be executed on a remote node. Indeed, the remote node may have another version of the module hosting the function and the function reference may be invalid.

How

There are two parts:

  1. We always use an exported function inside Khepri.
  2. We ensure that the caller of folding APIs passes MFA if they request leader or consistent queries. fun() are only accepted for local queries.

Fixes #238.

dumbbell avatar Jan 12 '24 14:01 dumbbell

Codecov Report

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

Comparison is base (b75785f) 88.74% compared to head (f02a92b) 89.37%.

Files Patch % Lines
src/khepri_machine.erl 95.23% 2 Missing :warning:
src/khepri.erl 96.55% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #242      +/-   ##
==========================================
+ Coverage   88.74%   89.37%   +0.63%     
==========================================
  Files          20       21       +1     
  Lines        2896     3079     +183     
==========================================
+ Hits         2570     2752     +182     
- Misses        326      327       +1     
Flag Coverage Δ
erlang-24 88.34% <98.66%> (+0.66%) :arrow_up:
erlang-25 88.34% <98.66%> (+0.66%) :arrow_up:
erlang-26 88.98% <98.66%> (+0.62%) :arrow_up:
os-ubuntu-latest 89.34% <98.66%> (+0.60%) :arrow_up:
os-windows-latest 89.08% <98.66%> (+0.68%) :arrow_up:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jan 12 '24 14:01 codecov[bot]

The patch is finished but I would like to test it with RabbitMQ before merging it.

dumbbell avatar Jan 18 '24 16:01 dumbbell

I have second thoughts on the fact that MFAs are good enough as a solution to execute code remotely. Yes, with the current patch, we ensure that a query won’t break because the function reference is invalid on another node. But that doesn’t mean that the function exported remotely is the same as the local one. This is quite unintuitive.

Thinking out loud here; if a leader query was requested, what about we check the cursor on the leader, wait for the local cursor to catch up, then execute the query function locally? Don’t we have the same consistency guaranty? It may take more time to answer the query though, because the catch up can be longer than a remote execution.

dumbbell avatar Jan 19 '24 09:01 dumbbell

This pull request was superseded by #260.

dumbbell avatar Jul 23 '24 09:07 dumbbell