-
Notifications
You must be signed in to change notification settings - Fork 20
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
Update all projections on snapshot installation #290
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #290 +/- ##
==========================================
- Coverage 89.68% 89.67% -0.01%
==========================================
Files 21 21
Lines 3140 3187 +47
==========================================
+ Hits 2816 2858 +42
- Misses 324 329 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
7f5ea0e
to
083d65c
Compare
A new `fold/3` will be created in the child commit which will fold over all payloads. `fold_matching/5` is more specific in what it matches - it takes a path and a tree and finds the matching payloads.
9df6398
to
09f2b9f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch looks good to me. Great work!
Could you just please squash the commit adding khepri_pattern_tree:fold()
into the commit that uses it? This addition goes with it and is only tested with it. What do you think?
Ra 2.14.0 expands the `snapshot_installed` callback to pass the state before the snapshot and snapshot metadata for the old state. We'll use this in the child commit to "diff" the old and new states and find updates we need to make to projections and projection tables.
When a snapshot is installed the machine state is "swapped" from the state before the snapshot to the one contained in the snapshot. This swap jumps over potentially many commands in the log which we would have used to trigger projections. When we install a snapshot we need to update the projection state but it's not as straightforward as when "restoring" projections (on machine recovery for example) because the projection tables will already exist and potentially contain records. When we detect that a snapshot has been installed we need to diff the old and new states to find which projections have changed themselves and also update their associated projection tables. This commit also introduces `khepri_pattern_tree:fold/3`: a more generic version of `fold_matching/5` which folds over all payloads in the tree rather than those which match a path. This is used in `khepri_machine` to collect all projections in the tree into a `sets:set()`.
09f2b9f
to
7dde526
Compare
I squashed the |
When a snapshot is installed the machine state is "swapped" from the state before the snapshot to the one contained in the snapshot. This swap jumps over potentially many commands in the log which we would have used to trigger projections. When we install a snapshot we need to update the projection state but it's not as straightforward as when "restoring" projections (on machine recovery for example) because the projection tables will already exist and potentially contain records.
When we detect that a snapshot has been installed we need to diff the old and new states to find which projections have changed themselves and also update their associated projection tables.
This requires a change in Ra to expose the old machine state and version in the
snapshot_installed
callback: rabbitmq/ra#467