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

Implement register_with_sync_manager for places #4617

Closed
bendk opened this issue Oct 28, 2021 · 3 comments
Closed

Implement register_with_sync_manager for places #4617

bendk opened this issue Oct 28, 2021 · 3 comments

Comments

@bendk
Copy link
Contributor

bendk commented Oct 28, 2021

Make places use register_with_sync_manager like the other components do. This will require a bit of care, since we are going to be doing UniFFI work for both places and sync-manager at the same time. Here's how I think it could work:

  • Implement PlacesApi.register_with_sync_manager
  • In the sync-manager branch: make setPlaces call register_with_sync_manager
  • In the places branch: include registerWithSyncManager in the UniFFI API
  • When we merge both, make the android code use registerWithSyncManager and delete the SyncManager.setPlaces method.

┆Issue is synchronized with this Jira Task
┆epic: Uniffi Sync Manager
┆sprintEndDate: 2021-12-10

@mhammond
Copy link
Member

This sounds fine, but it might even be possible to go further before the uniffi work is ready - particularly if what you outline end up being a bit of a problem. If we take inspiration from the metadata functions, we could add, say, void places_api_register_with_sync_manager(i64 handle); and the Rust code could obtain an Arc<PlacesApi> from the APIS static.

@bendk
Copy link
Contributor Author

bendk commented Nov 2, 2021

After trying to implement this I realize there's an underlying issues that needs to be resolved first: places tends to use regular refs, with lifetimes, while the other components use Arc<>. For example BookmarksEngine vs LoginsSyncEngine. This leads to several issues when trying to implement get_registered_sync_engine()

  • The sync engine is normally created from a Weak ref (logins uses Weak<LoginsStore>). However, this isn't going to work for BookmarksEngine or HistoryEngine, since you can't tie the lifetime to the Weak instance. It's possible to solve this. I currently have some code that refactors SyncConn then can creates BookmarksEngine / HistoryEngine with the lifetime of the SyncConn.
  • get_registered_sync_engine() normally returns an Option<Box<dyn SyncEngine>> with an implied 'static lifetime. Making a return signature that works with the lifetimes of BookmarksEngine / HistoryEngine was beyond my Rust knowledge. My normal go to of adding '_ to make Option<Box<dyn SyncEngine + '_>> didn't work. It's probably possible somehow, but I couldn't figure it out.

So I think we should try to refactor things to use Arc<> more. That would bring the places code closer to logins/autofill and also make it generally easier to use. Here's how I think this could hapen:

  • Refactor BookmorksEngine and HistoryEngine to use an Arc<PlacesDb> instead of &PlacesDb
  • Refactor PlacesApi.open_sync_connection() to return an Arc<> rather than the SyncConn class.

What do you all think about the plan? I guess the question is how does migrating to Arc<>s fit with the places UniFFI work. The one thing I want to avoid is refactoring this code, then refactoring it again as part of the UniFFI work.

@bendk bendk linked a pull request Nov 3, 2021 that will close this issue
4 tasks
@bendk
Copy link
Contributor Author

bendk commented Nov 3, 2021

It thought about this one some more and I think there's a fairly straightforward way to evolve this code. I laid out the overall plan and implemented the first step in #4627

bendk added a commit to bendk/application-services that referenced this issue Nov 8, 2021
- Changed the bookmarks/history sync engines to use an
  Arc<Mutex<PlacesDb>>, which matches the other engines better
- Made these sync engines create their own `SqlInterruptScope`.  The
  interrupt code is still not working, but I think this is the direction
  we want to go for mozilla#1684.  If not, it should be easy to replace.
- Removed the old `PlacesApi.open_sync_connection()` method and replaced it
  with the new `get_sync_connection()` method
- Lots of unit test updates.  I didn't take the time to understand these
  fully.  I just made changes until it compiled, didn't deadlock, and passed.
bendk added a commit to bendk/application-services that referenced this issue Nov 8, 2021
- Changed the bookmarks/history sync engines to use an
  Arc<Mutex<PlacesDb>>, which matches the other engines better
- Made these sync engines create their own `SqlInterruptScope`.  The
  interrupt code is still not working, but I think this is the direction
  we want to go for mozilla#1684.  If not, it should be easy to replace.
- Updated the `PlacesApi` syncing code to use the new sync engines.
  One thing to note here is that the SyncManager has its own system of
  managing the global state, so the fact that those methods update it
  outside of the Mutex lock that the `SyncEngine` takes is not a problem.
- Updated the importer code to use the new `get_sync_connection()`
  method.  The only difference here is that the importer code needs to
  lock the mutex, this replaces the old system where
  `open_sync_connection()` would return an error if a previously
  returned connection was still alive.
- Removed the old `PlacesApi.open_sync_connection()` method and replaced it
  with the new `get_sync_connection()` method
- Lots of unit test updates.  I didn't take the time to understand these
  fully.  I just made changes until it compiled, didn't deadlock, and passed.
bendk added a commit to bendk/application-services that referenced this issue Nov 11, 2021
- Changed the bookmarks/history sync engines to use an
  Arc<Mutex<PlacesDb>>, which matches the other engines better
- Made these sync engines create their own `SqlInterruptScope`.  The
  interrupt code is still not working, but I think this is the direction
  we want to go for mozilla#1684.  If not, it should be easy to replace.
- Updated the `PlacesApi` syncing code to use the new sync engines.
  One thing to note here is that the SyncManager has its own system of
  managing the global state, so the fact that those methods update it
  outside of the Mutex lock that the `SyncEngine` takes is not a problem.
- Updated the importer code to use the new `get_sync_connection()`
  method.  The only difference here is that the importer code needs to
  lock the mutex, this replaces the old system where
  `open_sync_connection()` would return an error if a previously
  returned connection was still alive.
- Removed the old `PlacesApi.open_sync_connection()` method and replaced it
  with the new `get_sync_connection()` method
- Lots of unit test updates.  I didn't take the time to understand these
  fully.  I just made changes until it compiled, didn't deadlock, and passed.
bendk added a commit to bendk/application-services that referenced this issue Nov 15, 2021
- Changed the bookmarks/history sync engines to use an
  Arc<Mutex<PlacesDb>>, which matches the other engines better
- Made these sync engines create their own `SqlInterruptScope`.  The
  interrupt code is still not working, but I think this is the direction
  we want to go for mozilla#1684.  If not, it should be easy to replace.
- Updated the `PlacesApi` syncing code to use the new sync engines.
  One thing to note here is that the SyncManager has its own system of
  managing the global state, so the fact that those methods update it
  outside of the Mutex lock that the `SyncEngine` takes is not a problem.
- Updated the importer code to use the new `get_sync_connection()`
  method.  The only difference here is that the importer code needs to
  lock the mutex, this replaces the old system where
  `open_sync_connection()` would return an error if a previously
  returned connection was still alive.
- Removed the old `PlacesApi.open_sync_connection()` method and replaced it
  with the new `get_sync_connection()` method
- Lots of unit test updates.  I didn't take the time to understand these
  fully.  I just made changes until it compiled, didn't deadlock, and passed.
bendk added a commit to bendk/application-services that referenced this issue Nov 17, 2021
- Changed the bookmarks/history sync engines to use an
  Arc<Mutex<PlacesDb>>, which matches the other engines better
- Made these sync engines create their own `SqlInterruptScope`.  The
  interrupt code is still not working, but I think this is the direction
  we want to go for mozilla#1684.  If not, it should be easy to replace.
- Updated the `PlacesApi` syncing code to use the new sync engines.
  One thing to note here is that the SyncManager has its own system of
  managing the global state, so the fact that those methods update it
  outside of the Mutex lock that the `SyncEngine` takes is not a problem.
- Updated the importer code to use the new `get_sync_connection()`
  method.  The only difference here is that the importer code needs to
  lock the mutex, this replaces the old system where
  `open_sync_connection()` would return an error if a previously
  returned connection was still alive.
- Removed the old `PlacesApi.open_sync_connection()` method and replaced it
  with the new `get_sync_connection()` method
- Lots of unit test updates.  I didn't take the time to understand these
  fully.  I just made changes until it compiled, didn't deadlock, and passed.
lougeniaC64 pushed a commit that referenced this issue Nov 24, 2021
- Changed the bookmarks/history sync engines to use an
  Arc<Mutex<PlacesDb>>, which matches the other engines better
- Made these sync engines create their own `SqlInterruptScope`.  The
  interrupt code is still not working, but I think this is the direction
  we want to go for #1684.  If not, it should be easy to replace.
- Updated the `PlacesApi` syncing code to use the new sync engines.
  One thing to note here is that the SyncManager has its own system of
  managing the global state, so the fact that those methods update it
  outside of the Mutex lock that the `SyncEngine` takes is not a problem.
- Updated the importer code to use the new `get_sync_connection()`
  method.  The only difference here is that the importer code needs to
  lock the mutex, this replaces the old system where
  `open_sync_connection()` would return an error if a previously
  returned connection was still alive.
- Removed the old `PlacesApi.open_sync_connection()` method and replaced it
  with the new `get_sync_connection()` method
- Lots of unit test updates.  I didn't take the time to understand these
  fully.  I just made changes until it compiled, didn't deadlock, and passed.
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 a pull request may close this issue.

3 participants