mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-07 14:46:37 +00:00
Rework ordering.md document
This commit is contained in:
parent
c5cce8466c
commit
3fb6261ee9
@ -1,7 +1,11 @@
|
|||||||
# Odering in OrbitList
|
# Odering in OrbitList
|
||||||
|
|
||||||
|
Ordering in OrbitList is done with Interval Tree Clocks (https://github.com/ricardobcl/Interval-Tree-Clocks). Each node tracks a global sequence *seq* and a local version *ver*. When an item is added to a list, local version *ver* is increased by 1. Whenever a list is *joined* with another list (eg. upon sync), the global sequence *seq* is set to *Max(global.seq, local.seq)*. When adding an item to the list, the item has a reference to all *heads* where *head* is an item that is not referenced by any other item in the list.
|
||||||
|
|
||||||
|
### Graph
|
||||||
```
|
```
|
||||||
A B C
|
A B C
|
||||||
|
|
||||||
0.0
|
0.0
|
||||||
|
|
|
|
||||||
0.0 0.1
|
0.0 0.1
|
||||||
@ -20,6 +24,7 @@
|
|||||||
<--- Sync ALL
|
<--- Sync ALL
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Evolution of the state
|
||||||
Initial state:
|
Initial state:
|
||||||
```
|
```
|
||||||
A = []
|
A = []
|
||||||
@ -27,12 +32,13 @@ B = []
|
|||||||
C = []
|
C = []
|
||||||
```
|
```
|
||||||
|
|
||||||
Two nodes add events concurrently:
|
***Two nodes add events concurrently***
|
||||||
|
|
||||||
Add items to A:
|
Add items to A:
|
||||||
```
|
```
|
||||||
listA.add("mango")
|
listA.add("mango")
|
||||||
listA.add("banana")
|
listA.add("banana")
|
||||||
|
|
||||||
// "A": [
|
// "A": [
|
||||||
// { "id": "A", "seq": 0, "ver": 0, "prev": null}
|
// { "id": "A", "seq": 0, "ver": 0, "prev": null}
|
||||||
// { "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]}
|
// { "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]}
|
||||||
@ -44,6 +50,7 @@ Add items to C:
|
|||||||
listC.add("apple")
|
listC.add("apple")
|
||||||
listC.add("strawberry")
|
listC.add("strawberry")
|
||||||
listC.add("orange")
|
listC.add("orange")
|
||||||
|
|
||||||
// "C": [
|
// "C": [
|
||||||
// { "id": "C", "seq": 0, "ver": 0, "prev": null}
|
// { "id": "C", "seq": 0, "ver": 0, "prev": null}
|
||||||
// { "id": "C", "seq": 0, "ver": 1, "prev": ["C.0.0"]}
|
// { "id": "C", "seq": 0, "ver": 1, "prev": ["C.0.0"]}
|
||||||
@ -53,14 +60,15 @@ listC.add("orange")
|
|||||||
|
|
||||||
B receives a 'sync' from A and C:
|
B receives a 'sync' from A and C:
|
||||||
```
|
```
|
||||||
Sync: B <--> A
|
B.join(A)
|
||||||
Sync: B <--> C
|
B.join(C)
|
||||||
```
|
```
|
||||||
|
|
||||||
Add items to B:
|
Add items to B:
|
||||||
```
|
```
|
||||||
listB.add("pineapple")
|
listB.add("pineapple")
|
||||||
listB.add("papaya")
|
listB.add("papaya")
|
||||||
|
|
||||||
// "B": [
|
// "B": [
|
||||||
// { "id": "A", "seq": 0, "ver": 0, "prev": null}
|
// { "id": "A", "seq": 0, "ver": 0, "prev": null}
|
||||||
// { "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]}
|
// { "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]}
|
||||||
@ -74,11 +82,12 @@ listB.add("papaya")
|
|||||||
|
|
||||||
A receives a 'sync' from B:
|
A receives a 'sync' from B:
|
||||||
```
|
```
|
||||||
Sync: A <--> B
|
A.join(B)
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
listA.add("kiwi")
|
listA.add("kiwi")
|
||||||
|
|
||||||
// "B": [
|
// "B": [
|
||||||
// { "id": "A", "seq": 0, "ver": 0, "prev": null}
|
// { "id": "A", "seq": 0, "ver": 0, "prev": null}
|
||||||
// { "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]}
|
// { "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]}
|
||||||
@ -93,11 +102,12 @@ listA.add("kiwi")
|
|||||||
|
|
||||||
C receives a 'sync' from A:
|
C receives a 'sync' from A:
|
||||||
```
|
```
|
||||||
Sync: C <--> A
|
C.join(A)
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
listC.add("blueberry")
|
listC.add("blueberry")
|
||||||
|
|
||||||
// "C": [
|
// "C": [
|
||||||
// { "id": "A", "seq": 0, "ver": 0, "prev": null}
|
// { "id": "A", "seq": 0, "ver": 0, "prev": null}
|
||||||
// { "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]}
|
// { "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]}
|
||||||
@ -113,11 +123,11 @@ listC.add("blueberry")
|
|||||||
|
|
||||||
A receives a 'sync' from C, B receives a 'sync' from C:
|
A receives a 'sync' from C, B receives a 'sync' from C:
|
||||||
```
|
```
|
||||||
Sync: A <--> C
|
A.join(C)
|
||||||
Sync: B <--> C
|
B.join(C)
|
||||||
```
|
```
|
||||||
|
|
||||||
Data set converged (after sync ALL):
|
Converged data set:
|
||||||
```json
|
```json
|
||||||
{ "id": "A", "seq": 0, "ver": 0, "prev": null},
|
{ "id": "A", "seq": 0, "ver": 0, "prev": null},
|
||||||
{ "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]},
|
{ "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user