Azure Cosmos DB 一致性保证

Azure CosmosDB Consistency guaranty

Microsoft 在其 documentation 中针对 Consistent 前缀一致性 声明如下:

In consistent prefix option, updates that are returned contain some prefix of all the updates, with no gaps. Consistent prefix consistency level guarantees that reads never see out-of-order writes.

下面有两段,他们说:

Below are the consistency guarantees for Consistent Prefix:

  • Consistency for clients in same region for an account with single write region = Consistent Prefix

  • Consistency for clients in different regions for an account with single write region = Consistent Prefix

  • Consistency for clients writing to a single region for an account with multiple write region = Consistent Prefix

  • Consistency for clients writing to multiple regions for an account with multiple write region = Eventual

我真的不明白客户端如何为具有多个写入区域的帐户写入多个区域可以有最终一致性保证。由于 Consistent prefix consistency 保证读取永远不会看到乱序写入,因此下面的语句(多次写入)应该是错误的,因为它保证 Eventual consistency.

有人可以帮我弄清楚我错过了什么吗?

通常,一致性保证是在假设它是单区域写入(单主)的情况下编写的。由于 Cosmos DB 提供了多区域写入(多主)能力,因此一致性保证需要进一步解释以详细说明服务在不同数量的读者和写入者下的行为,包括多区域写入(多主)。

当您有多个编写器并使用多区域写入时,在帐户中配置的区域内本地写入的数据将在本地提交,然后通过 WAN 复制并合并到主要区域。一旦数据在主要区域中合并,它就会被复制回完全提交到帐户中的每个其他区域。

因为这发生在 WAN 上,所以无法保证写入多个次要区域的数据将按照在本地提交的顺序精确地复制和合并到主要区域。数据在 WAN 中并不总是以相同的速率和速度复制。这既是因为区域之间的距离不同,也是因为 WAN 有时会有些不稳定。

因此,当使用多个写入器的多区域写入时,读取器只能获得最终一致性保证。