Apache Cassandra 和 Azure Cosmos DB Cassandra API 一致性级别Apache Cassandra and Azure Cosmos DB Cassandra API consistency levels

适用于: Cassandra API

与 Azure Cosmos DB 不同,Apache Cassandra 本身并不提供精确定义的一致性保证。Unlike Azure Cosmos DB, Apache Cassandra does not natively provide precisely defined consistency guarantees. 与之相反,Apache Cassandra 提供一个写入一致性级别和一个读取一致性级别,以便进行高可用性、一致性和延迟方面的权衡。Instead, Apache Cassandra provides a write consistency level and a read consistency level, to enable the high availability, consistency, and latency tradeoffs. 使用 Azure Cosmos DB 的 Cassandra API 时:When using Azure Cosmos DB's Cassandra API:

  • Apache Cassandra 的写入一致性级别映射到在 Azure Cosmos 帐户上配置的默认一致性级别。The write consistency level of Apache Cassandra is mapped to the default consistency level configured on your Azure Cosmos account. 写入操作 (CL) 的一致性不能因请求的不同而(即按请求)更改。Consistency for a write operation (CL) can't be changed on a per-request basis.

  • Azure Cosmos DB 会将 Cassandra 客户端驱动程序指定的读取一致性级别动态映射到根据读取请求动态配置的某个 Azure Cosmos DB 一致性级别。Azure Cosmos DB will dynamically map the read consistency level specified by the Cassandra client driver to one of the Azure Cosmos DB consistency levels configured dynamically on a read request.

多区域写入与单区域写入Multi-region writes vs Single-region writes

默认情况下,Apache Cassandra 数据库是一个多主系统,不提供使用单区域进行写入并使用多区域复制进行读取的现成选项。Apache Cassandra database is a multi-master system by default, and does not provide an out-of-box option for single-region writes with multi-region replication for reads. 但是,Azure Cosmos DB 提供了允许单区域或多区域写入配置的全包式功能。However, Azure Cosmos DB provides turnkey ability to have either single region, or multi-region write configurations. 能够跨多个区域选择单区域写入配置的优点之一是可以避免跨区域冲突情况,并且可以选择跨多个区域保持强一致性。One of the advantages of being able to choose a single region write configuration across multiple regions is the avoidance of cross-region conflict scenarios, and the option of maintaining strong consistency across multiple regions.

使用单区域写入,你可以保持强一致性,同时可以通过自动故障转移跨区域保持一定级别的高可用性。With single-region writes, you can maintain strong consistency, while still maintaining a level of high availability across regions with automatic failover. 在此配置中,你仍然可以利用数据局部性,通过将每个请求降级到最终一致性来减少读取延迟。In this configuration, you can still exploit data locality to reduce read latency by downgrading to eventual consistency on a per request basis. 因此,与原生 Apache Cassandra 不同,Azure Cosmos DB 允许你以更细的粒度浏览 CAP 定理权衡范围Thus, unlike native Apache Cassandra, Azure Cosmos DB allows you to navigate the CAP Theorem trade-off spectrum with more granularity.

映射一致性级别Mapping consistency levels

Azure Cosmos DB 平台提供了一组包含五个明确定义、面向业务用例的一致性设置,这些设置与复制和 CAP 定理及 PACLC 定理定义的权衡相关。The Azure Cosmos DB platform provides a set of five well-defined, business use-case oriented consistency settings with respect to replication and the tradeoffs defined by the CAP theorem and PACLC theorem. 由于此方法与 Apache Cassandra 有很大不同,因此建议花时间查看并了解文档中的 Azure Cosmos DB 一致性设置。As this approach differs significantly from Apache Cassandra, we would recommend that you take time to review and understand Azure Cosmos DB consistency settings in our documentation.

下表说明了使用 Cassandra API 时 Apache Cassandra 与 Azure Cosmos DB 一致性级别之间的可能映射。The following table illustrates the possible mappings between Apache Cassandra and Azure Cosmos DB consistency levels when using Cassandra API. 这显示了针对单区域读取、多区域读取以及单区域写入和多区域写入的配置。This shows configurations for single region, multi-region reads with single-region writes, and multi-region writes.

备注

这些不是确切的映射。These are not exact mappings. 更确切地说,我们提供了与 Apache Cassandra 最接近的类似物,并在最右边的列中消除了任何定性差异的歧义。Rather, we have provided the closest analogues to Apache Cassandra, and disambiguated any qualitative differences in the rightmost column. 如上所述,我们建议查看 Azure Cosmos DB 的一致性设置As mentioned above, we recommend reviewing Azure Cosmos DB's consistency settings.

Cassandra 一致性帐户级映射

Cassandra 一致性动态映射

如果使用非常一致性以外的一致性级别配置了 Azure Cosmos 帐户,则可以通过查看概率有限过期 (PBS) 指标,找到客户端获得工作负荷的非常一致读取的概率。If your Azure Cosmos account is configured with a consistency level other than the strong consistency, you can find out the probability that your clients may get strong and consistent reads for your workloads by looking at the Probabilistically Bounded Staleness (PBS) metric. 此指标在 Azure 门户中公开,若要了解详细信息,请参阅监视概率有限过期性 (PBS) 指标This metric is exposed in the Azure portal, to learn more, see Monitor Probabilistically Bounded Staleness (PBS) metric.

概率有限过期表明了最终一致的最终程度。Probabilistic bounded staleness shows how eventual is your eventual consistency. 通过此指标可深入了解在 Azure Cosmos 帐户中目前配置的一致性级别之间获得更非常一致性的频率。This metric provides an insight into how often you can get a stronger consistency than the consistency level that you have currently configured on your Azure Cosmos account. 换句话说,可看到获得写入和读取区域组合的非常一致读取的概率(以毫秒计量)。In other words, you can see the probability (measured in milliseconds) of getting strongly consistent reads for a combination of write and read regions.

后续步骤Next steps

详细了解 Azure Cosmos DB 的多区域分发和一致性级别:Learn more about multiple-region distribution and consistency levels for Azure Cosmos DB: