-
Notifications
You must be signed in to change notification settings - Fork 158
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
Notify when db read transaction is advaced. #5704
Conversation
I am not sure about naming, but this should do, in order to notify SDKs when DB read transaction is advanced. I still need to add tests around this. Furthermore, I have just infer what I think it is needed inside core to implement this feature. |
Is the intention for this to be C API-only feature? Most SDKs still use the C++ API, so it would be beneficial to have it exposed in C++ as well. |
Yep, I am trying to understand where the other callbacks are added following what we do in the coordinator... |
OK, it seems to me that the The context factory is set via: If this is the case, we can either import the Context implementation inside core (if it does not contain any platform specific code) or maybe define a new virtual function for registering a callback (although this won't solve the problem, since the logic has been put inside |
@tgoyne can you please advise on how cocoa implements |
BindingContext is there specifically to expose hooks to the SDKs and inherently can't be implemented in core (we used to call the SDKs "bindings" and the type was never renamed). https://github.com/realm/realm-swift/blob/master/Realm/RLMRealmUtil.mm#L98 is Cocoa's implementation (which isn't terribly interesting since just calls the actual implementations of things).
|
Ok, but this means that we can't have this logic for notifying the SDKs that are consuming core via C++ built inside Unless you want to code this inside Cocoa and JS will have to do the same, |
There is already |
I believe we are trying to solve a slightly different problem. |
For context, the problem with |
I think we need to agree on when to put this changes, if we do it inside |
This doesn't do the requested thing. SDKs which are using BindingContext directly rather than the C API will indeed have to implement whatever thing it is they want to do. The BindingContext API leaves it up to the SDK to manage callbacks, and changing that should be part of a larger project to redesign/remove BindingContext entirely. |
@tgoyne fixed the erroneous comparison between apples and pears (let me know what you think). Please, a look again. The only thing I am not 100% sure is that the C API consumers will have to register this listener while within a write transaction, which seems a bit odd. Otherwise, they won't be able to get the last valid snapshot (since no transaction would be in progress). |
|
||
auto& refresh_callbacks = CBindingContext::get(*realm).realm_pending_refresh_callbacks(); | ||
return new realm_refresh_callback_token(realm, | ||
refresh_callbacks.add(current_snap_version.value(), std::move(func))); |
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.
We can't use .value()
because it requires too high of a deployment target, and it's not needed because the optional not having a value is checked above.
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.
would * operator work here?
Co-authored-by: Thomas Goyne <thomas.goyne@mongodb.com>
…realm-core into nc/notify_when_advanced_to_latest
…hen_advanced_to_latest
@tgoyne can we get at the bottom of this review. I think this is ready to be merged. |
Co-authored-by: James Stone <james.stone@mongodb.com>
|
||
if (!latest_snapshot_version) | ||
return nullptr; | ||
|
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.
I think this might be a good place to check if (realm->is_frozen())
and return an error or nullptr.
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.
LGTM
…hen_advanced_to_latest
What, How & Why?
Implement a mechanism for notifying SDKs when db read transaction version is bumped.
Fixes: #5246
☑️ ToDos