Handle deleted projections tables while triggering projections#293
Merged
Conversation
The test case in this change shows an example that can cause an error log. One client of Khepri sends an `unregister_projections` command while another sends many changes which affect a projection which is being unregistered. Using async commands makes the error much more likely to occur. Ra applies committed commands in a batch and then handles all effects created by the batch. In this scenario the `unregister_projections` command may end up being applied by Ra in a batch with the async commands and the resulting effects list will contain aux effects to trigger projections (casued by the async commands) and an aux effect to unregister the projection. Some trigger aux effects may come later in the list than the `unregister_projections` effect and so their projection table will be deleted. In this case we want to perform a no-op for the trigger effect. We already no-op these effects because we wrap ETS calls in `try` expressions. This change avoids an error log caused by ETS calls attempting to insert or delete records in an `undefined` table.
2b672cb to
cead845
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #293 +/- ##
==========================================
+ Coverage 89.64% 89.68% +0.03%
==========================================
Files 21 21
Lines 3187 3188 +1
==========================================
+ Hits 2857 2859 +2
+ Misses 330 329 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
dumbbell
reviewed
Sep 11, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The test case in this change shows an example that can cause an error log. One client of Khepri sends an
unregister_projectionscommand while another sends many changes which affect a projection which is being unregistered. Using async commands makes the error much more likely to occur.Ra applies committed commands in a batch and then handles all effects created by the batch. In this scenario the
unregister_projectionscommand may end up being applied by Ra in a batch with the async commands and the resulting effects list will contain aux effects to trigger projections (casued by the async commands) and an aux effect to unregister the projection. Some trigger aux effects may come later in the list than theunregister_projectionseffect and so their projection table will be deleted. In this case we want to perform a no-op for the trigger effect.We already no-op these effects because we wrap ETS calls in
tryexpressions. This change avoids an error log caused by ETS calls attempting to insert or delete records in anundefinedtable.Example error log...
This is from the commontest output of the added test case before the fix in
khepri_projection.erl: