Example of offline operation with simple merge
Again, let's assume a shared space which is implementing a 2x2 colorgrid. There is a single data object named "grid", and the default data is:
{
"0": "ffffff",
"1": "ffffff",
"2": "ffffff",
"3": "ffffff"
}
The owner will store an initial state packet that matches the following:
{
"sequence": 0,
"mimetype": "application/json",
"name": "grid",
"op": "add",
"path": "/",
"data": {
"0": "ffffff",
"1": "ffffff",
"2": "ffffff",
"3": "ffffff"
}
}
For this example, the member is disconnected wishes to update space with id "2" to the color "ff0000". The operation will be created and queued on the member as the following:
{
"mimetype": "application/json",
"name": "grid",
"op": "replace",
"path": "/2",
"data": "ff0000"
}
The member then reconnects to the owner and delivers a connect request. The connect request indicates that the sequence number received is 0. As a result, the owner will deliver a connect response. In this response, the member learns that the most recent sequence on the owner is 2, because there were some edits made while this member was disconnected. The owner will automatically send the missing operations to the member. The following will be received by the member:
[
{
"sequence": 1,
"mimetype": "application/json",
"name": "grid",
"op": "replace",
"path": "/3",
"data": "ff0000"
},
{
"sequence": 2,
"mimetype": "application/json",
"name": "grid",
"op": "replace",
"path": "/4",
"data": "ff0000"
}
]
The member will temporarily revert the uncommitted operation and apply the 2 operations from the owner. While applying the missed operations, the member notices that the path
element of the operations don't conflict with the uncommitted operation. The member will then immediately apply the uncommitted operation back, and send it to the owner:
{
"mimetype": "application/json",
"name": "grid",
"op": "replace",
"path": "/2",
"data": "ff0000"
}
The member making this change should not consider it accepted or committed at this point. The owner will receive this operation, and will store this packet in the list. The entire list of operations stored by the owner now looks like this:
{
"max_sequence": 1,
"operations": [
{
"sequence": 0,
"mimetype": "application/json",
"name": "grid",
"op": "add",
"path": "/",
"data": {
"0": "ffffff",
"1": "ffffff",
"2": "ffffff",
"3": "ffffff"
},
{
"sequence": 1,
"mimetype": "application/json",
"name": "grid",
"op": "replace",
"path": "/3",
"data": "ff0000"
},
{
"sequence": 2,
"mimetype": "application/json",
"name": "grid",
"op": "replace",
"path": "/4",
"data": "ff0000"
},
{
"sequence": 3,
"mimetype": "application/json",
"name": "grid",
"op": "replace",
"path": "/2",
"data": "ff0000"
}
]
}
At this point, the owner should deliver this operation (sequence 3) to all members connected to the shared space.