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

SubscribeMulti + UnsubscribeMulti, multiplicities #249

Merged
merged 10 commits into from
Feb 25, 2025

Conversation

kazimuth
Copy link
Contributor

@kazimuth kazimuth commented Feb 14, 2025

Description of Changes

Add SubscribeMulti and UnsubscribeMulti from upstream.
Fix unsubscribe bug found by testing against Bitcraft: Calling UnsubscribeThen with any (non-null) callback would result in an exception incorrectly telling the user that Unsubscribe had been called twice.
Multiplicity support is implemented with unit tests + manual testing of quickstart-chat.
Also, rows in the client cache are now looked up by primary key if available, which I suspect is going to be a large performance boost.

API

  • This is an API breaking change to the SDK

If the API is breaking, please state below what will break

Requires SpacetimeDB PRs

List any PRs here that are required for this SDK change to work

Testsuite

If you would like to run the your SDK changes in this PR against a specific SpacetimeDB branch, specify that here. This can be a branch name or a link to a PR.

SpacetimeDB branch name: jgilles/final-cs-codegen-changes

Testing

Write instructions for a test that you performed for this PR

  • unit tests
  • Working with Ryan to add a test suite.
  • blackholio

@kazimuth kazimuth changed the title Unsubscribe fixF Unsubscribe fix Feb 14, 2025
@kazimuth kazimuth added api-break bug Something isn't working and removed api-break labels Feb 14, 2025
@bfops bfops changed the base branch from release/v1.0.0 to master February 18, 2025 18:29
@bfops
Copy link
Collaborator

bfops commented Feb 18, 2025

I changed the base branch to master; I'll re-cut the release branch when things settle down.

@bfops
Copy link
Collaborator

bfops commented Feb 18, 2025

Out of curiosity, why did the DLLs need updating?

@kazimuth kazimuth changed the title Unsubscribe fix SubscribeMulti + UnsubscribeMulti, multiplicities Feb 19, 2025
Copy link

Some missing or dangling .meta found. Fix commits are needed.

Status File
Not committed src/SpacetimeDB/ClientApi/SubscribeMulti.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/SubscribeMultiApplied.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/UnsubscribeMulti.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/UnsubscribeMultiApplied.g.cs.meta

1 similar comment
Copy link

Some missing or dangling .meta found. Fix commits are needed.

Status File
Not committed src/SpacetimeDB/ClientApi/SubscribeMulti.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/SubscribeMultiApplied.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/UnsubscribeMulti.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/UnsubscribeMultiApplied.g.cs.meta

Copy link

Some missing or dangling .meta found. Fix commits are needed.

Status File
Not committed src/MultiDictionary.cs.meta
Not committed src/SpacetimeDB/ClientApi/SubscribeMulti.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/SubscribeMultiApplied.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/UnsubscribeMulti.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/UnsubscribeMultiApplied.g.cs.meta

3 similar comments
Copy link

Some missing or dangling .meta found. Fix commits are needed.

Status File
Not committed src/MultiDictionary.cs.meta
Not committed src/SpacetimeDB/ClientApi/SubscribeMulti.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/SubscribeMultiApplied.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/UnsubscribeMulti.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/UnsubscribeMultiApplied.g.cs.meta

Copy link

Some missing or dangling .meta found. Fix commits are needed.

Status File
Not committed src/MultiDictionary.cs.meta
Not committed src/SpacetimeDB/ClientApi/SubscribeMulti.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/SubscribeMultiApplied.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/UnsubscribeMulti.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/UnsubscribeMultiApplied.g.cs.meta

Copy link

Some missing or dangling .meta found. Fix commits are needed.

Status File
Not committed src/MultiDictionary.cs.meta
Not committed src/SpacetimeDB/ClientApi/SubscribeMulti.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/SubscribeMultiApplied.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/UnsubscribeMulti.g.cs.meta
Not committed src/SpacetimeDB/ClientApi/UnsubscribeMultiApplied.g.cs.meta

@kazimuth
Copy link
Contributor Author

Blackholio tested on clockworklabs/Blackholio#22

@kazimuth
Copy link
Contributor Author

@bfops uhh what branch should this be based on?

@joshua-spacetime
Copy link
Contributor

@kazimuth if I'm reading this correctly, inserts are applied to the cache before deletes, correct?

@kazimuth
Copy link
Contributor Author

kazimuth commented Feb 21, 2025

Good catch -- but that loop is accumulating into a MultiDictionaryDelta, which is a collection of key-value pairs with signed multiplicities. Since the multiplicities can go negative, you're allowed to remove a row before you insert it; in general, the order Adds and Removes are applied to a MultiDictionaryDelta doesn't matter. The resulting delta will have the same effect when Applied to a MultiDictionary. The proptest ShuffleDelta tests this.

I should definitely comment about this, thank you.

@kazimuth
Copy link
Contributor Author

kazimuth commented Feb 21, 2025

@bfops , possibly the DLLs did NOT need updating and I did it unnecessarily. I just ran my update-everything script out of habit, but I can undo that.

Update: Done.

@kazimuth
Copy link
Contributor Author

@rekhoff I'm wondering if we should put that multiplicity test into its own PR. I think we probably want to merge this and add that test later. It will require some git-fu I can help out with.

@kazimuth kazimuth force-pushed the jgilles/unsubscribe-fix branch from fce7dc6 to 333efc0 Compare February 21, 2025 15:14
Warning message fix (thanks Jeff)

Update for new Subscribe/UnsubscribeMulti

thanks zeke

Add MultiDictionary; update dispatching logic still wrong

Add even more wacky data structures

WHOOOOOO

Fix MultiDictionary bug

More asserts and comments

Tests passing

Better errors, purge dead package

Test

Update for blackholio

Update blackholio

Fix comment

Remove dead

One more dead

COMMENT

More comments

Added a multiplicity test example

Creates a small sample program with a Rust server and C# client that tests various subscriptions and outputs the results to the CLI.

Make sure we insert before we delete

Fix more comments

Add CRDT test for MultiDictionaryDelta

Revert "Added a multiplicity test example"

This reverts commit ff10925.

Undo DLL changes
@kazimuth kazimuth force-pushed the jgilles/unsubscribe-fix branch from 333efc0 to 2fde31b Compare February 21, 2025 15:17
@kazimuth
Copy link
Contributor Author

kazimuth commented Feb 21, 2025

@rekhoff, I moved your code to the branch rekhoff/multiplicity-example and rebased it. Would appreciate if you could open a PR with that code based at this branch.

@kazimuth kazimuth force-pushed the jgilles/unsubscribe-fix branch from 3854092 to 2fde31b Compare February 21, 2025 16:55
@gefjon gefjon requested a review from rekhoff February 21, 2025 19:00
@gefjon
Copy link
Contributor

gefjon commented Feb 21, 2025

John: What's the story on the subscription helper?
James: That can go away now. Also, I want to test this against BitCraft.

@rekhoff
Copy link
Contributor

rekhoff commented Feb 21, 2025

@rekhoff, I moved your code to the branch rekhoff/multiplicity-example and rebased it. Would appreciate if you could open a PR with that code based at this branch.

PR 254 opened for multiplicity test.

@kazimuth
Copy link
Contributor Author

Now based on clockworklabs/SpacetimeDB#2303

Copy link
Contributor

@rekhoff rekhoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed code. Looks correct and well commented. No issues found.

Copy link
Contributor

@joshua-spacetime joshua-spacetime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed the MultiDictionary and Table cache changes for tracking multiplicities and invoking row callbacks. Just a small logging nit, but otherwise the logic is correct.

As for the rest of the changes, I'll defer to @rekhoff.

@kazimuth kazimuth merged commit 3afdedc into master Feb 25, 2025
6 checks passed
@kazimuth kazimuth deleted the jgilles/unsubscribe-fix branch February 25, 2025 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working release-1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants