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

Write/Commit Async API #2899

Merged
merged 30 commits into from
May 23, 2022
Merged

Write/Commit Async API #2899

merged 30 commits into from
May 23, 2022

Conversation

LaPeste
Copy link
Contributor

@LaPeste LaPeste commented Apr 1, 2022

Description

This PR adds Write/Commit Async API.

The only thing that testing in this PR doesn't do is checking if cancelling while waiting for an async transaction does indeed cancel the queued callback in CORE. I don't see an easy way of testing this with the current implementation. My expectation is that this aspect is going to be easier to test when we introduce CancellationTokens in async calls. There will be a PR for this coming soon ™️.

TODO

  • Changelog entry
  • Write API documentation
  • Tests (if applicable)
  • Manually close the JIRA ticket once it's merged as there was not a github issue to link this PR to.

@cla-bot cla-bot bot added the cla: yes label Apr 1, 2022
Copy link
Member

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

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

Reviewed the implementation, but haven't looked at the tests or docs. @fealebenpae can you double check the native code to make sure we haven't missed something.

return handle_errors(ex, [&]() {
return realm->async_begin_transaction([tcs_ptr, ex]()
{
s_handle_write_commit_async(tcs_ptr, ex);
Copy link
Member

Choose a reason for hiding this comment

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

We should not be reusing ex here.

Copy link
Member

Choose a reason for hiding this comment

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

We can't pass ex in because it's a reference to a stack-allocated variable in C#, and the callback to async_begin_transaction can be called some time in the future (like if the write lock is held by another thread or process) when the variable no longer exists in C# and it'll crash if we try to access it. If async_begin_transaction doesn't pass in an std::exception_ptr to its callback like async_commit_transaction then we simply don't need the NativeException argument to s_handle_write_commit_async. If you need to reuse the callback type then just initialize a dummy NativeException with NoError.

return handle_errors(ex, [&]() {
return realm->async_begin_transaction([tcs_ptr, ex]()
{
s_handle_write_commit_async(tcs_ptr, ex);
Copy link
Member

Choose a reason for hiding this comment

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

We can't pass ex in because it's a reference to a stack-allocated variable in C#, and the callback to async_begin_transaction can be called some time in the future (like if the write lock is held by another thread or process) when the variable no longer exists in C# and it'll crash if we try to access it. If async_begin_transaction doesn't pass in an std::exception_ptr to its callback like async_commit_transaction then we simply don't need the NativeException argument to s_handle_write_commit_async. If you need to reuse the callback type then just initialize a dummy NativeException with NoError.

@LaPeste LaPeste changed the title [WIP] Write/Commit Async API Write/Commit Async API May 8, 2022
@LaPeste LaPeste marked this pull request as ready for review May 8, 2022 11:46
@LaPeste LaPeste requested review from nirinchev and fealebenpae May 8, 2022 11:46
Copy link
Member

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

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

Looks pretty close to being done - I have some style comments and a bunch of questions around the tests, but the core feature seems sound to me.

@LaPeste LaPeste requested a review from nirinchev May 11, 2022 09:35
@LaPeste LaPeste merged commit 41dbc5e into main May 23, 2022
@LaPeste LaPeste deleted the ac/async-write-commit branch May 23, 2022 11:09
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants