-
Notifications
You must be signed in to change notification settings - Fork 163
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
Update BindingCallbackThreadObserver to be one per sync client #6156
Conversation
992b676
to
1b738ce
Compare
3d1b750
to
f49ac5b
Compare
f5d2ff2
to
d6abd48
Compare
70af2c6
to
f60cc60
Compare
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.
CI reports a data race in Sync_MultipleSyncAgentsNotAllowed
. LGTM otherwise
There are some bootstrap tests failing. Are they related to these changes? |
Turns out it was a valid data race - I updated the test similar to how Jonathan updated other tests in test_sync.cpp to define the DefaultSocketProvider separately so |
src/realm/sync/client_base.hpp
Outdated
@@ -185,6 +186,10 @@ struct ClientConfig { | |||
// and creating WebSockets. If not provided the default implementation will be used. | |||
std::shared_ptr<sync::SyncSocketProvider> socket_provider; | |||
|
|||
// Optional thread observer for event loop thread events in the default SyncSocketProvider | |||
// implementation. It is not used for custom SyncSocketProvider implementations. | |||
std::shared_ptr<BindingCallbackThreadObserver> default_socket_provider_thread_observer; |
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.
does this really need shared lifetime management? could we just use a unique_ptr here?
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.
It could technically just be a unique_ptr, since the SyncClientConfig is required for each start of the sync client. The main question is whether the SDK would prefer to use a single shared ptr across all the apps or is it fine to define a separate observer instance for each app. @cmelchior, any preferences?
virtual ~BindingCallbackThreadObserver() = default; | ||
|
||
// Set the global thread observer with the provided (optional) callback functions | ||
static void set_global_thread_observer(std::unique_ptr<BindingCallbackThreadObserver>&& observer_ptr) |
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.
Do we really need to keep the old global API here? Currently this is used by just one SDK. @cmelchior, is adopting the new per-app API sufficiently complicated for java that we should support both APIs for now?
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.
No, it shouldn't be complicated. Removing this is fine 👍
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.
OK - I'll remove the global support and update the CAPI.
@@ -507,6 +510,10 @@ void DefaultSocketProvider::start() | |||
|
|||
m_logger_ptr->trace("Default event loop: start()"); | |||
REALM_ASSERT(m_state == State::Stopped); | |||
|
|||
// Reset the service so it can be run() again | |||
m_service.reset(); |
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.
Is this ever actually needed? Currently the default socket provider is only used once, except in testing.
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.
It was only for completeness if the default socket provider ever needed to be restarted. I can remove it.
I would say that we should start with unique ownership to start and see if
we need shared ownership later. Lots fewer ways to screw up with unique
ownership.
…On Mon, Feb 6, 2023 at 2:42 PM Michael Wilkerson-Barker < ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/realm/sync/client_base.hpp
<#6156 (comment)>:
> @@ -185,6 +186,10 @@ struct ClientConfig {
// and creating WebSockets. If not provided the default implementation will be used.
std::shared_ptr<sync::SyncSocketProvider> socket_provider;
+ // Optional thread observer for event loop thread events in the default SyncSocketProvider
+ // implementation. It is not used for custom SyncSocketProvider implementations.
+ std::shared_ptr<BindingCallbackThreadObserver> default_socket_provider_thread_observer;
It could technically just be a unique_ptr, since the SyncClientConfig is
required for each start of the sync client. The main question is whether
the SDK would prefer to use a single shared ptr across all the apps or is
it fine to define a separate observer instance for each app. @cmelchior
<https://github.com/cmelchior>, any preferences?
—
Reply to this email directly, view it on GitHub
<#6156 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABOVUMBPEZFBPAS4AT6QPLWWFHZHANCNFSM6AAAAAATMSEIKM>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
The description was updated - thanks
…On Fri, Feb 24, 2023 at 7:20 AM Daniel Tabacaru ***@***.***> wrote:
I guess the description needs an update
—
Reply to this email directly, view it on GitHub
<#6156 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZ2FARWSQF4PWCN7RCMC2YLWZCRP7ANCNFSM6AAAAAATMSEIKM>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
src/realm.h
Outdated
* @param user_data pointer to user defined data that is provided to each of the callback functions | ||
* @param free_userdata callback invoked when the user_data is to be freed | ||
*/ | ||
RLM_API void realm_sync_client_config_set_default_binding_thread_observer( |
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 thought we decided to just have the per-app version...
void BindingCallbackThreadObserver::call_will_destroy_thread( | ||
const std::shared_ptr<BindingCallbackThreadObserver>& observer_ptr) | ||
{ | ||
// Call into the observer ptr if not null, otherwise, use the global thread observer |
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.
It looks like there is no global observer? Do we still need these static functions?
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.
These were just helper functions... I'll remove them and just use the direct function calls in the default socket provider.
What, How & Why?
The
BindingCallbackThreadObserver
was originally a global instance that was shared across all sync client/default socket provider instances. The changes in this PR move theBindingCallbackThreadObserver
to be a shared_ptr parameter in theSyncClientConfig
, which allows for either a single instance to be shared across all sync clients or a unique instance per sync client. The observer class was also updated to allow optional implementations for the three functions, instead of a base class that required all three functions to be implemented.In addition, a C API test was added for the BindingCallbackThreadObserver to verify its operation (and some updates to the interface were needed).
NOTE: The BindingCallbackThreadObserver is only used by the default sync socket provider implementation. It is up to custom sync socket provider implementations to add their own support for threaded callbacks.
Fixes #6250
☑️ ToDos