-
Notifications
You must be signed in to change notification settings - Fork 110
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
Rust client SDK ReducerInfo
enum
#25
Merged
Merged
Conversation
This file contains 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
This requires deriving `Debug` for tables and generated types. In the future, we should be careful that all spacetime types can derive `Debug`.
Prior to this commit, callbacks in the Rust client SDK shared access to the global ClientCache while running asynchronously. This meant that a long-running or delayed callback could observe the ClientCache in a state later than the one that caused the callback's invocation, and had no way to access the specific state for which it was invoked. With this commit, each `Invoke` message to the callback worker includes an `Arc<ClientCache>` snapshot of the DB state when that callback was invoked. The callback worker stores that state in a `thread_local`, and methods that inspect tables (e.g. `TableType::iter`) read the state out of the `thread_local` when it is present. This allows callbacks to observe exactly the state which caused their invocation, never a later state, while maintaining the C#-like API where `ClientCache` access is based on free functions or static trait methods.
With this commit, row callbacks (`on_insert`, `on_delete`, `on_update`) in the Rust client SDK take an additional argument, `Option<&ReducerEvent>`, where `ReducerEvent` is an enum generated by the CLI's codegen with a variant for each reducer defined in the module. Having the SDK pass around an autogenerated type in this way (without adding a bunch of `<ReducerEvent>` generic parameters everywhere) requires storing the `ReducerEvent` in an `Arc<dyn Any>`. This has the added tangential benefit of avoiding cloning the `ReducerEvent` for each row callback.
Centril
reviewed
Jun 27, 2023
jdetter
approved these changes
Jun 30, 2023
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.
This refactor looks good to me, I'm going to do a larger pass on the overall rust SDK later today 👍
cloutiertyler
pushed a commit
that referenced
this pull request
Aug 1, 2023
* `ReducerEvent` enum in Rust client SDK With this commit, row callbacks (`on_insert`, `on_delete`, `on_update`) in the Rust client SDK take an additional argument, `Option<&ReducerEvent>`, where `ReducerEvent` is an enum generated by the CLI's codegen with a variant for each reducer defined in the module. Having the SDK pass around an autogenerated type in this way (without adding a bunch of `<ReducerEvent>` generic parameters everywhere) requires storing the `ReducerEvent` in an `Arc<dyn Any>`. This has the added tangential benefit of avoiding cloning the `ReducerEvent` for each row callback.
cloutiertyler
pushed a commit
that referenced
this pull request
Aug 1, 2023
* `ReducerEvent` enum in Rust client SDK With this commit, row callbacks (`on_insert`, `on_delete`, `on_update`) in the Rust client SDK take an additional argument, `Option<&ReducerEvent>`, where `ReducerEvent` is an enum generated by the CLI's codegen with a variant for each reducer defined in the module. Having the SDK pass around an autogenerated type in this way (without adding a bunch of `<ReducerEvent>` generic parameters everywhere) requires storing the `ReducerEvent` in an `Arc<dyn Any>`. This has the added tangential benefit of avoiding cloning the `ReducerEvent` for each row callback.
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.
Description of Changes
Depends on #16 .
This PR adds an autogenerated
enum ReducerInfo
with a variant for each reducer defined by a module as an additional argument to row callbacks (on_insert
,on_delete
andon_update
).API
If the API is breaking, please state below what will break
Row callbacks in the Client SDK take an additional argument now, so an
_
will have to be added to closure arglists.