Skip to content

Commit 9f5c1c5

Browse files
f4z3rbjester
authored andcommitted
docs: update sync process documentation
1 parent e6d6694 commit 9f5c1c5

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

docs/syncing/index.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Syncing
55
Concepts
66
--------
77

8-
The **store** holds serialized versions of syncable models. This includes both data that is on the current device and data synced from other devices.
8+
The **store** holds serialized versions of syncable models. This includes both data that is on the current device and data synced from other devices. The store is represented as a standard Django model, containing syncable models as JSON.
99

1010
The **outgoing buffer** and **incoming buffer** mirror the schema of the store. They also include a transfer session ID which used to identify sets of data that are being synced as a coherent group to other Morango instances.
1111

@@ -15,11 +15,14 @@ Process
1515

1616
Syncing is the actual exchange of data in a sync session. The general steps for syncing data are:
1717

18-
1. **Serialization** - serializing data that is associated with Django models in the Application layer, and storing it in JSON format in a record in the Store
19-
2. **Queuing/Buffering** - storing serialized records and their modification history to a separate Buffers data structure
20-
3. **Transfer/chunking of data** - the actual transfer of data over a request/response cycle in chunks of 500 records at a time
21-
4. **Dequeuing** - merging the data received in the receiving buffers to the receiving store and record-max counter
22-
5. **Deserialization** - merging data from the receiving Store into the Django models in the Application layer
18+
1. **Serialization** - serializing data that is associated with Django models in the Application layer, and storing it in JSON format in a record in the Store. The serialized data in the store is versioned via a counter (described in `Counters <../counters#counters>`__).
19+
2. **Queuing/Buffering** - storing serialized records and their modification history to a separate Buffers data structure. This Django model only contains the changes to be synced with the other Morango instance. This is in contrast to the Store, which contains all data, regardless of what is getting transferred in this sync session.
20+
3. **Transfer/chunking of data** - the actual transfer of data over a request/response cycle in a set of chunked records. If both sides support it, the chunked records are compressed before being sent of the network. The actual transfer is done over HTTP.
21+
4. **Dequeuing** - merging the data received in the receiving buffers to the receiving store and record-max counter. During this step, the data from the incoming buffer is merged into the store on the receiving side. Merge conflicts in case of version splits can be solved automatically. As new data is written into the store, the dirty bit on that object is set to indicate that the data needs to be deserialized and pushed to the Application Layer.
22+
5. **Deserialization** - merging data from the receiving Store into the Django models in the Application layer. Data marked as stale in the Application Layer (where a newer version is available in the Store, on a record with the dirty bit set), the data in the store is deserialized from JSON into a Django model and integrated into the Application Layer.
23+
24+
The individual steps of the syncing process are implemented in `morango/sync/operations.py <https://github.com/learningequality/morango/blob/HEAD/morango/sync/operations.py>`_. They are implemented as operations that are registered for every process step described above. A project using Morango can define their own operations and register them to be executed as part of an arbitrary step in the process via configuration options such as ``MORANGO_INITIALIZE_OPERATIONS``.
25+
2326

2427
In the illustration below, the application layer (on the right) is where app data resides as Django models, and the Morango layer (on the left) is where the Morango stores, counters, and buffers reside. *Instance A* (on the top) is sending data to *Instance B* (on the bottom). Application Django models in *Instance A* are serialized in JSON format and saved to the store. Data is queued in the buffers on *Instance A*, and then transmitted to the corresponding buffers on *Instance B*. The data is then integrated into the store and Django app models on *Instance B*.
2528

@@ -53,6 +56,8 @@ Signals
5356

5457
During the sync process, Morango fires a few different signals from ``signals`` in ``PullClient`` and ``PushClient``. These can be used to track the progress of the sync.
5558

59+
The operations described in the previous section are triggered via such a signal, which has the operations attached to it. The ``SyncSignal`` definition can be found under `morango/sync/utils.py <https://github.com/learningequality/morango/blob/HEAD/morango/sync/utils.py>`_.
60+
5661
There are four signal groups:
5762

5863
- ``session``
@@ -66,6 +71,8 @@ Each signal group has 3 stages that can be fired:
6671
- ``in_progress``
6772
- ``completed``
6873

74+
The ``SessionController`` is responsible to register the configured operations to the corresponding signal, and triggers the individual steps when its ``proceed_to`` function is called.
75+
6976
For a push or pull sync lifecycle, the order of the fired signals would be as follows:
7077

7178
1) Session started

0 commit comments

Comments
 (0)