Cassandra Batch语句-多表

Cassandra Batch statement-Multiple tables

我想使用批处理语句从我的数据库中的 3 tables 中删除一行以确保原子性。分区键在所有 3 table 中都是相同的。在我读到的有关批处理语句的所有示例中,所有查询都是针对单个 table?就我而言,使用批处理语句是个好主意吗?或者,我应该避免它吗?

我正在使用 Cassandra-3.11.2 并使用 C++ 驱动程序执行我的查询。

是的,可以使用batch来保证原子性。单个分区批处理速度更快(相同的 table 和相同的分区键)但仅适用于有限数量的分区(在您的情况下为三个)没关系。但不要将其用于性能优化(例如:减少多个请求)。如果你需要原子性,你可以使用它。

您可以在下方查看 links:

Cassandra batch query performance on tables having different partition keys
Cassandra batch query vs single insert performance

已编辑

In my case, the tables are different but the partition key is the same in all 3 tables. So is this a special case of single partition batch or is it something entirely different.

不同table的分区也不同。所以这是一个多分区批处理。 LOGGED 批处理用于确保不同分区(不同的 table 或不同的分区键)的原子性。 UNLOGGED 批处理用于确保单个分区批处理的原子性和隔离性。如果使用 UNLOGGED 批处理进行多分区批处理的原子性将得不到保证。默认为 LOGGED 批次。对于单个分区批处理,默认值为 UNLOGGED。导致单分区批处理被视为单行突变。对于单行更新,不需要使用 LOGGED 批处理。要了解 LOGGEDUNLOGGED 批次,我在下面分享了一个 link。

Multi partition batches should only be used to achieve atomicity for a few writes on different tables. Apart from this they should be avoided because they’re too expensive.

Single partition batches can be used to achieve atomicity and isolation. They’re not much more expensive than normal writes.

但是您可以使用多分区 LOGGED 批处理,因为分区是有限的。

非常有用的批处理文档,提供了所有详细信息。读到这里,所有的困惑都会迎刃而解。

Cassandra - to BATCH or not to BATCH

分区键令牌与行分区

Table 分区和分区键令牌不同。分区键用于决定数据所在的节点。对于相同的行键,分区标记是相同的,因此驻留在同一个节点中。对于不同的分区键或相同的键不同的 tables 它们是不同的行突变。您无法通过对不同分区键或不同 table 的一次查询获取数据,即使对于相同的键也是如此。协调器节点必须将其视为不同的请求或突变,并分别从复制节点请求实际数据。它是 C* 存储数据的内部结构。

Every table even has it's own directory structure making it clear that a partition from one table will never interact with the partition of another.

要了解 C* 如何映射数据的详细信息,请检查此 link:

Understanding How CQL3 Maps to Cassandra's Internal Data Structure