CRDT:可变树形层级结构

  • At a high level, each node in the tree has a parent pointer that can be mutated to reparent that node somewhere else in the tree. However, just syncing the latest parent pointer for each node doesn't work, as the resulting graph is not necessarily a tree. For example, one peer might parent A under B while another peer parents B under A, causing a cycle in the graph:

    在高层次上,树中的每个节点都有一个父指针,可被变更以将该节点重新指定到树的其他位置。然而,仅同步每个节点的最新父指针并不奏效,因为得到的图不一定是树。例如,一个对等节点可能将 A 的父节点设为 B,而另一个对等节点将 B 的父节点设为 A,从而在图中形成环:

    R C A B Valid treeR C A B Parent cycle
    R C A B Valid treeR C A B Parent cycle
  • To prevent cycles in the tree, we may need to "revert" the effect of one or more parent pointer changes if they are causing a cycle. The algorithm that decides which parent pointer changes to revert must be consistent across peers so that every peer ends up with the same tree. To do this, we need to have each node keep track of all parents that it has ever had. This parent history is what is synced between peers.

    为防止树中出现环,我们可能需要“回退”一个或多个父指针更改,如果它们正在导致环。决定回退哪些父指针更改的算法必须在各对等节点间保持一致,以便每个对等节点最终得到相同的树。为此,需要让每个节点记录它曾经拥有过的所有父节点。这个父历史就是在对等节点之间同步的内容。

    Specifically each node keeps an edge map where the key is a parent node (i.e. an "edge" in the graph) and the value is an integer counter. The counter can be used to tell which map entries are more recent. To set node X as a child of node Y, set the value for Y in the edge map for node X to 1 more than the greatest counter value in the edge map for node X so far.

    具体而言,每个节点维护一个边映射,其中键是父节点(即图中的“边”),值是一个整数计数器。该计数器可用于判断哪些映射项更新。要将节点 X 设置为节点 Y 的子节点,将节点 X 的边映射中 Y 的值设为该映射中当前最大计数器值加 1。

    R C A B Original tree A={C: 0} B={C: 0}

    C={R: 0}

    R C A B Parent cycle
    A={C: 0, B: 1}
    B={C: 0, A: 1}
    C={R: 0}
    R C A B Revert A→B back to A→C
    A={C: 0, B: 1}
    B={C: 0, A: 1}
    C={R: 0}
    R C A B Original tree A={C: 0} B={C: 0}

    C={R: 0}

    R C A B Parent cycle
    A={C: 0, B: 1}
    B={C: 0, A: 1}
    C={R: 0}
    R C A B Revert A→B back to A→C
    A={C: 0, B: 1}
    B={C: 0, A: 1}
    C={R: 0}
  • To determine what a given peer considers to be the parent for each node in the tree:

    要确定给定节点认为树中每个...

开通本站会员,查看完整译文。

Home - Wiki
Copyright © 2011-2025 iteam. Current version is 2.146.0. UTC+08:00, 2025-10-02 14:31
浙ICP备14020137号-1 $Map of visitor$