Guest User

Untitled

a guest
May 22nd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. # historical snapshot point consensus in P2P networks
  2.  
  3. Algorithm for nodes in a p2p network to agree on a snapshot point - a point in which all the nodes had the same view of the network state. A network state is defined as both the 1) set of nodes which are part of the network and 2) their respective states. As a requirement, the snapshot point must be decided locally, based on the current and past network state in all nodes in the network.
  4.  
  5. This is a historical consensus algorithm for a replicated network of nodes, in which nodes have to all agree that at some point in time, all the replicas which are currently part of the network had the same local state.
  6.  
  7.  
  8. ## Network map and consensus points
  9.  
  10. The local nodes decide whether the consensus was reached based on their `netowrk map`, which is the local representation of the network state. A network map is represented as:
  11.  
  12. ```
  13. network_map = {
  14. N1: {
  15. N1: B1_state,
  16. N2: N2_state,
  17. },
  18. N2: {
  19. N1: N1_state,
  20. N2: N2_state,
  21. }
  22. }
  23. ```
  24.  
  25. Each node maintains a local `network_map`. This network map represents the the view of the network (nodes that currently are part of the network and their state) and also what is the state of the network that those nodes see.
  26.  
  27. A state is a set of all operations/transactions that lead to the current state. For example, If R1 have applied operation A, B and C, then its state is `R1_state = [A, B, C]`. The state in the `network_map` is cumulative and idempotent.
  28.  
  29. If all nodes eventually converge to the same state (i.e. eventually have the same set of operations applied locally), it is possible to deduce locally points in the past in which all nodes in the network had the same state. In these points - `consensus points` - we can ensure that all nodes had the same set of operations applied.
  30.  
  31.  
  32. ## Algorithm
  33.  
  34. Everytime a new node (Rn) joins the network, it gets a copy of the `network_map` of the first node (Rj) it communicates to. The node Rj also adds Rn to its network map.
  35.  
  36. Everytime a node changes its state, it updates its `network_map` accordingly and gossips the new state to the network.
  37.  
  38.  
  39. **1.Only one node N1 and one operation A**
  40.  
  41. N1_network_map (nm): {N1: [A]}
  42.  
  43.  
  44. **2. New node joins the network and receives state from N1**
  45.  
  46. N1_nm: `{N1: [A], N2: [A]}`
  47.  
  48. N2_nm: `{N1: [A], N2: [A]}`
  49.  
  50. **3. N2 changes its state locally and applies operation B**
  51.  
  52. N1_nm: `{N1: [A], N2: [A]}`
  53.  
  54. N2_nm: `{N1: [A], N2: [A, B]}`
  55.  
  56. **4. N2 gossips netmap to N1**
  57.  
  58. N1_nm: `{N1: [A, B], N2: [A, B]}`
  59.  
  60. N2_nm: `{N1: [A], N2: [A, B]}`
  61.  
  62. At this point in time, N1 understands that [A, B] is a valid `consensus point`. Because all replicas have applied those operations and have the same state. N2 doesn't know about it yet.
  63.  
  64. **5. N1 changes its state locally and applies operation C**
  65.  
  66. N1_nm: `{N1: [A, B, C], N2: [A, B]}`
  67.  
  68. N2_nm: `{N1: [A], N2: [A, B]}`
  69.  
  70. **6. N1 gossips netmap to N2**
  71.  
  72. N1_nm: `{N1: [A, B, C], N2: [A, B]}`
  73.  
  74. N2_nm: `{N1: [A, B, C], N2: [A, B]}`
  75.  
  76. At this point, N2 also understands that [A, B] is a valid `consensus point`.
  77.  
  78. Notice that node N1 and N2 recognized that a `consensus point` was reached at different times. But since we assume that nodes will eventually communicate with each other their local `network map` over time, every node in the network will agree in the same `consensus points`.
  79.  
  80. **7. N3 joins the network and receives state from N2**
  81.  
  82. N1_nm: `{N1: [A, B, C], N2: [A, B]}`
  83.  
  84. N2_nm: `{N1: [A, B, C], N2: [A, B]}`
  85.  
  86. N3_nm: `{N1: [A, B, C], N2: [A, B], N3: [A, B]}`
  87.  
  88. Notice that N3 `network map` is a copy of the N2 `network map` with an entry to itself.
  89.  
  90. **8. N3 applies locally operations D and E and N1 applies locally operation F**
  91.  
  92. N1_nm: `{N1: [A, B, C, F], N2: [A, B]}`
  93.  
  94. N2_nm: `{N1: [A, B, C], N2: [A, B]}`
  95.  
  96. N3_nm: `{N1: [A, B, C], N2: [A, B], N3: [A, B, D, E]}`
  97.  
  98. Notice that N1 doesn't know about N3 yet. All nodes agree that the snapshot point is still [A, B] (set of operations that all nodes visible in the network have applied locally)
  99.  
  100. **9. N3 gossips netmap to N1**
  101.  
  102. N1_nm: `{N1: [A, B, C, F, D, E], N2: [A, B], N3: [A, B, D, E]}`
  103.  
  104. N2_nm: `{N1: [A, B, C], N2: [A, B]}`
  105.  
  106. N3_nm: `{N1: [A, B, C], N2: [A, B], N3: [A, B, D, E]}`
  107.  
  108. **10. N2 applies local change G**
  109.  
  110. N1_nm: `{N1: [A, B, C, F, D, E], N2: [A, B], N3: [A, B, D, E]}`
  111.  
  112. N2_nm: `{N1: [A, B, C], N2: [A, B, G]}`
  113.  
  114. N3_nm: `{N1: [A, B, C], N2: [A, B], N3: [A, B, D, E]}`
  115.  
  116. **11. N3 gossips netmap to N2**
  117.  
  118. N1_nm: `{N1: [A, B, C, F, D, E], N2: [A, B], N3: [A, B, D, E]}`
  119.  
  120. N2_nm: `{N1: [A, B, C, F, D, E], N2: [A, B, G, C, F, D, E], N3: [A, B, D, E]}`
  121.  
  122. N3_nm: `{N1: [A, B, C], N2: [A, B], N3: [A, B, D, E]}`
  123.  
  124. **12. N2 gossips netmap to N3**
  125.  
  126.  
  127. N1_nm: `{N1: [A, B, C, F, D, E], N2: [A, B], N3: [A, B, D, E]}`
  128.  
  129. N2_nm: `{N1: [A, B, C, F, D, E], N2: [A, B, G, C, F, D, E], N3: [A, B, D, E]}`
  130.  
  131. N3_nm: `{N1: [A, B, C, F, D, E], N2: [A, B, C, D, E, F, G], N3: [A, B, C, D, E, F, G]}`
  132.  
  133. N3 now can consider [A, B, C, D, E, F, G] as snapshot point.
  134.  
  135.  
  136.  
  137. ## Applications: CRDT snapshotting and garbage collection
Add Comment
Please, Sign In to add comment