The 2P-Set Conflict-Free Replicated Data Type (CRDT) supports two phases for each possible element: in the first phase an element can be added to the set and the subsequent additions are ignored; in the second phase an element can be removed after which it will stay removed forever regardless of subsequent additions and removals. We generalize the 2P-Set to support an infinite sequence of alternating additions and removals of the same element. In the presence of concurrent additions and removals on different replicas, all replicas will eventually converge to the longest sequence of alternating additions and removals that follows causal history. The idea of converging on the longest-causal sequence of opposite operations had already been suggested in the context of an undo-redo framework but the design was neither given a name nor fully developed. In this paper, we present the full design directly, using nothing more than the basic formulation of state-based CRDTs. We also show the connection between the set-based definition of 2P-Set and the counter-based definition of the $\infty$P-Set with simple reasoning. We then give detailed proofs of convergence. The underlying \textit{grow-only dictionary of grow-only counters} on which the $\infty$P-Set is built may be used to build other state-based CRDTs. In addition, this paper should be useful as a pedagogical example for designing state-based CRDTs, and might help raise the profile of CRDTs based on \textit{longest sequence wins}.
翻译:2P-Set冲突无关复制数据类型支持每个可能元素有两个阶段:第一个阶段可以将元素添加到集合中,会忽略后续添加;第二个阶段可以将元素删除,之后不管有没有后续添加或删除,该元素都将永远被删除。本文将2P-Set进行扩展,支持对同一元素进行无限次的交替添加和删除。在不同副本同时进行添加和删除的情况下,所有副本最终会收敛于根据因果历史遵循最长交替添加和删除序列。在撤销-重做框架中提出了在相反操作的最长序列上进行收敛的想法,但该设计没有被命名或完全开发。本文直接展示该设计的完整设计,仅使用基本的状态CRDTs公式,因此本文也可以作为设计状态CRDTs的教学示例,还可以帮助提升基于“最长序列获胜”的CRDTs的知名度。我们还展示了2P-Set的基于集合的定义与$\infty$P-Set的基于计数器的定义之间的联系,并给出了详细的收敛证明。基于$\infty$P-Set构建的潜在的“只增不减的计数器的只增不减的字典”可以用于构建其他基于状态的CRDTs。