本文是《如何学习分布式系统》中,关于一致性模型的相关介绍。
Sequential Consistency的定义
Sequential Consistency的精确定义来自于Leslie Lamport老哥(以后我们会多次提到他)。
他本来是定义了基于共享内存的多CPU并行计算的一致性模型,但是也可以推广到分布式系统中,实际上多CPU并行计算也都可以认为是分布式系统。
模型的定义是
the result of any execution is the same as if the operations of all the processors were executed in some sequential order, and the operations of each individual processor appear in this sequence in the order specified by its program
放到分布式系统里,意思就是不管系统怎么运行,得到的结果就好像把所有节点的所有操作按照某个sequential order排序后运行,但是在这个sequential order顺序中,来自同一个节点的操作仍然保持着它们在节点中被指定的顺序。
Sequential Consistency的例子
Leslie Lamport老哥的说法一贯的佶屈聱牙,我们通过几个例子来看一下。图中从左向右表示物理时间,W(a)表示写入数据a,R(a)表示读出数据a。