mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-04 05:06:37 +00:00
Rework ordering.md document
This commit is contained in:
parent
c5cce8466c
commit
3fb6261ee9
@ -1,7 +1,11 @@
|
||||
# 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
|
||||
|
||||
0.0
|
||||
|
|
||||
0.0 0.1
|
||||
@ -20,6 +24,7 @@
|
||||
<--- Sync ALL
|
||||
```
|
||||
|
||||
### Evolution of the state
|
||||
Initial state:
|
||||
```
|
||||
A = []
|
||||
@ -27,12 +32,13 @@ B = []
|
||||
C = []
|
||||
```
|
||||
|
||||
Two nodes add events concurrently:
|
||||
***Two nodes add events concurrently***
|
||||
|
||||
Add items to A:
|
||||
```
|
||||
listA.add("mango")
|
||||
listA.add("banana")
|
||||
|
||||
// "A": [
|
||||
// { "id": "A", "seq": 0, "ver": 0, "prev": null}
|
||||
// { "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]}
|
||||
@ -44,6 +50,7 @@ Add items to C:
|
||||
listC.add("apple")
|
||||
listC.add("strawberry")
|
||||
listC.add("orange")
|
||||
|
||||
// "C": [
|
||||
// { "id": "C", "seq": 0, "ver": 0, "prev": null}
|
||||
// { "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:
|
||||
```
|
||||
Sync: B <--> A
|
||||
Sync: B <--> C
|
||||
B.join(A)
|
||||
B.join(C)
|
||||
```
|
||||
|
||||
Add items to B:
|
||||
```
|
||||
listB.add("pineapple")
|
||||
listB.add("papaya")
|
||||
|
||||
// "B": [
|
||||
// { "id": "A", "seq": 0, "ver": 0, "prev": null}
|
||||
// { "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]}
|
||||
@ -74,11 +82,12 @@ listB.add("papaya")
|
||||
|
||||
A receives a 'sync' from B:
|
||||
```
|
||||
Sync: A <--> B
|
||||
A.join(B)
|
||||
```
|
||||
|
||||
```
|
||||
listA.add("kiwi")
|
||||
|
||||
// "B": [
|
||||
// { "id": "A", "seq": 0, "ver": 0, "prev": null}
|
||||
// { "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]}
|
||||
@ -93,11 +102,12 @@ listA.add("kiwi")
|
||||
|
||||
C receives a 'sync' from A:
|
||||
```
|
||||
Sync: C <--> A
|
||||
C.join(A)
|
||||
```
|
||||
|
||||
```
|
||||
listC.add("blueberry")
|
||||
|
||||
// "C": [
|
||||
// { "id": "A", "seq": 0, "ver": 0, "prev": null}
|
||||
// { "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:
|
||||
```
|
||||
Sync: A <--> C
|
||||
Sync: B <--> C
|
||||
A.join(C)
|
||||
B.join(C)
|
||||
```
|
||||
|
||||
Data set converged (after sync ALL):
|
||||
Converged data set:
|
||||
```json
|
||||
{ "id": "A", "seq": 0, "ver": 0, "prev": null},
|
||||
{ "id": "A", "seq": 0, "ver": 1, "prev": ["A.0.0"]},
|
||||
|
Loading…
x
Reference in New Issue
Block a user