mozilla / application-services

Firefox Application Services
https://mozilla.github.io/application-services/
Other
608 stars 224 forks source link

Generic Sync:investigate sync abstraction #2029

Closed cse-test-sync closed 4 years ago

cse-test-sync commented 4 years ago

This largely is implementing the algorithm/algorithms for sync and conflict resolution described in the remerge spec.

It also requires implementing vector clocks and the like, if that's not done as part of local storage.

┆Issue is synchronized with this Jira Story ┆Story Points: 3 ┆Epic: chrome.sync.storage (Generic Sync) prototype ┆Sprint: SYNC - end 2019-12-20

linabutler commented 4 years ago

@thomcc and I talked about how we could integrate Remerge into Desktop last week. Conceptually, it's pretty similar to how the Desktop machinery works today: we need a way to handle resetting sync IDs, feeding incoming records into the store, and uploading outgoing records. The additional meta-collections mean we have to pass those records around, too, but I don't think that complicates things.

Things we can and can't use on Desktop:

One way to approach the integration is something like bug 1596322 suggests, and pass cleartext JSON strings back and forth. We'd add a skeleton, subclassable RemergeEngine to JS (it'll look a lot like BufferedBookmarksEngine, and add a Rust XPCOM component that takes care of updating the mirror, merging, and fetching staged records for upload.

For the storage part, we can provide a CRUD-style API that also takes JSON strings. (We could reflect it as an XPCOM interface instead, but using interfaces for simple structs like NativeRecord is super kludgey). On the JS side, we'll provide a wrapper to make this more ergonomic.

Aside: If you're thinking, hey, this sounds a lot like ffi_support JSON, you're right! XPCOM is an FFI, with additional memory and type safety guarantees. XPCOM methods can take JS objects directly, via in jsval parameters, but the Rust XPCOM bindings don't support those.

So the integration would look something like:

Our glue crate is also going to need to handle:

I'll close this issue in favor of the Bugzilla bug, since we'll use that for the prototype, and don't want to fork the discussion. This comment is specifically so we can document the plan in Jira/GH for tracking.