Roughlyspeaking, the gap between strict serializability (which we useinterchangeably with linearizability) and CockroachDB's defaultisolation level (serializable) is that with linearizable transactions,causality is preserved. That
is, if one transaction (say, creating a postingfor a user) waits for its predecessor (creating the user in the first place) tocomplete, one would hope that the logical timestamp assigned to the former islarger than that of the latter. In practice, in distributed
databases this maynot hold, the reason typically being that clocks across a distributed systemare not perfectly synchronized and the "later" transaction touches apart disjoint from that on which the first transaction ran, resulting in clockswith disjoint information
to decide on the commit timestamps.
粗略来讲,严格序列化(我们使用另一个术语“线性化”来替代)和CockroachDB的默认隔离级别(序列化)的区别是:线性化事务保留了因果性。也就是说,如果一个事务(比方说,为用户创建一个帖子)等待它的前序事务(先创建该用户)完成,赋予前者的逻辑时间戳要大于后者。实际上,在分布式数据库系统中这可能无法保持,典型原因是跨越分布式系统的时钟无法精确同步,导致后面的事务与前面的事务运行节点时间有部分脱节,导致使用脱节信息的时钟来确定提交的时间戳。
In practice,in CockroachDB many transactional workloads are actually linearizable, thoughthe precise conditions are too involved to outline them here.
实践中,在CockroachDB中许多事务负载实际上是线性化的,尽管精确条件也被牵扯到这里的要点讨论中。
Causality istypically not required for many transactions, and so it is advantageous to payfor it only when it is needed. CockroachDB implements thisvia causality tokens: When committing a transaction, a causalitytoken can be retrieved and
passed to the next transaction, ensuring that thesetwo transactions get assigned increasing logical timestamps.
Additionally,as better synchronized clocks become a standard commodity offered by cloudproviders, CockroachDB can provide global linearizability by doing much thesame that Google's
Spanner does: wait out themaximum clock
offset
aftercommitting, but before returning to the client.
典型情况下,许多事务不需要因果性,因此只有需要时才会为此优势付出代价。CockroachDB通过因果令牌来实现:当提交一个事务时,检索因果令牌并传递给下一个事务,以确保这两个事务得到递增的逻辑时间戳。此外,通过云提供者提供了一个更好的同步时钟,它成了标准设施,CockroachDB会提供全局线性能力,很像 Google'sSpanner的做法:在返回客户端前,提交后静静地等待最大时钟补偿。
See the blogpost below for much more in-depth information.
更深入的信息请参见下面的微博:
https://www.cockroachlabs.com/blog/living-without-atomic-clocks/ |