-
Notifications
You must be signed in to change notification settings - Fork 41
Data Exchange
-
deviceId
: The primary key for a client, encoded as an array with a single integer-valued element, shared across platforms. When a device creates or joins a "Sync Chain", it assigns itself thedeviceId
. -
Browser object: Browser-specific representation of a syncable object (differs between platforms).
-
Sync object: Platform-independent representation of a syncable object (cf., Data formats), encoded as JSON.
-
SyncRecord
: An action (create, update, or delete), adeviceId
, and an associated sync object. -
objectId
: The primary key for an object, encoded as a UUID, shared across platforms. Prior to uploading a created object, the client library assigns the objectId.
Note that, at present, the iOS platform does not implement the retry algorithm (or retry store) described in these procedures.
-
The user creates (or joins) a "Sync Chain", which causes the browser to generate (or import) a symmetric key seed.
The browser may allow the user to choose which collections to sync; however, as of this writing, there is only one supported collection "BookMarks".
-
The browser determines its own
deviceId
(see below) -
The browser uploads new
SyncRecords
, with the client library assigning each an objectId. -
The Browser retrieves all existing
SyncRecords
.
-
The browser periodically checks whether any browser objects have been created, modified or deleted after the corresponding sync object was retrieved.
However, the iOS platform does uploads "on demand", instead of maintain a send queue.
-
For each such browser object, a coresponding
SyncRecord
is created. -
Each
SyncRecord
is uploaded. -
The browser records a time-to-retry timestamp and
SyncRecord
in a retry store. -
If the client library is capable of reporting the result of the underlying S3
POST
operation, then if thePOST
operation subsequently succeeds, the associatedSyncRecords
are removed from the retry store.(At present, no client library implementations offer this functionality.)
-
The browser periodically checks to see id the retry store is empty.
-
If so, or if none of the
SyncRecords
in the retry store have an expired time-to-retry timestamp in the past, processing completes; otherwise: -
The browser uploads exactly those
SyncRecords
, and updates the time-to-retry timestamp for associated entries in the retry store.The retry algorithm is at the browser's discretion, e.g., linear (every 2 minutes) or exponential, etc.
-
If the client library is capable of reporting the result of the underlying S3
POST
operation, then if thePOST
operation subsequently succeeds, the associatedSyncRecords
are removed from the retry store.
-
The browser periodically requests any
SyncRecords
created since the last receiveed timestamp.On initial synchronization, an epoch value for timestamp is used.
Optionally, the browser may also specify the maximum number of records to return. (On mobile platforms, no more than 300 records are retrieved at a time.)
n2. If no records are returned, processing completes; otherwise:
-
The browser identifies and preserves the most recent timestamp in the record set.
-
The browser examines each
SyncRecord
, and if thedeviceId
matches the browser's identity, removes the corresponding entry (if any) from the retry store. -
The browser presents the record set to the synchronization library, along with the browser object store.
Tohe synchronization library must process all
SyncRecords
in the record set, including those with the browser'sdeviceId
(cf., Conflict Resolution) -
The synchronization library harmonizes the
SyncRecords
based on the browser object store. resolves any conflicts, e.g.,- converting an update record for a non-existent browser object to a creation record;
- combining multiple update records to a single update record for a browser object; or,
- removal of deletion records for a non-existent browser object.
-
The browser than applies the resulting
SyncRecords
to its browser object store. -
The browser repeats this procedure using the timestamp value identified in Step 3.
Processing of SyncRecords
occurs asynchronously with respect to other browser activities.
For example:
-
Device 1 changes a bookmark resulting in a update
SyncRecord
(eventually) being uploaded. -
Device 2 receives the
SyncRecord
and executes Step 5 of the retrieval procedure. -
Prior to Step 7 of the retrieval procedure completing, device 2 changes the same bookmark, and an update
SyncRecord
is generated. -
When Step 7 of the retrieval procedure completes, the bookmark on device 2 is overwritten with the the
SyncRecord
from device 1 -- the bookmark no longer reflects the change made by device 2 moments earlier. -
Device 2 (eventually) receives the
SyncRecord
that it generated, and upon completion of its Step 7 of the retrieval procedure, the bookmark reflects the change made by device 2.
NB: This procedure contains a race-condition. A new procedure is being developed, along with a recovery algorithm.
-
If the client is creating the "Sync Chain", it assigns itself a
deviceId
of 0 and no processing completes; otherwise: -
The Browser retrieves all existing
SyncRecords
, and examines each that contains a creation of aDevice
object. -
For each
SyncRecord
, it finds the largestdeviceId
present. -
It assigns itself a
deviceId
equal to the sum of the largest value observed and one.