Skip to content
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 6 commits into from
Jun 30, 2023
Merged

Conversation

gefjon
Copy link
Contributor

@gefjon gefjon commented Jun 27, 2023

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 and on_update).

API

  • This is a breaking change to the module API
  • This is a breaking change to the ClientAPI

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.

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.
@gefjon gefjon requested review from Centril and jdetter June 27, 2023 15:53
Copy link
Collaborator

@jdetter jdetter left a 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 👍

@gefjon gefjon merged commit 8abe08b into master Jun 30, 2023
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.
@cloutiertyler cloutiertyler deleted the phoebe/client-sdk-reducer-info branch August 1, 2023 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants