Skip to content

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.

gefjon added 4 commits June 20, 2023 17:24
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
bfops pushed a commit that referenced this pull request Jul 16, 2025
When the primary key is of type Identity we were still doing ===
comparison by using the Map data structure. This commit introduces a
different data structure called OperationsMap which can also use isEqual
to compare keys if isEqual function is available
bfops pushed a commit that referenced this pull request Jul 17, 2025
Co-authored-by: Steve <steve@codefics.com>
bfops pushed a commit that referenced this pull request Aug 7, 2025
When the primary key is of type Identity we were still doing ===
comparison by using the Map data structure. This commit introduces a
different data structure called OperationsMap which can also use isEqual
to compare keys if isEqual function is available
bfops pushed a commit that referenced this pull request Aug 7, 2025
Co-authored-by: Steve <steve@codefics.com>
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.

4 participants