gpt4 book ai didi

cassandra - Cassandra中如何保证不同表上的数据一致性?

转载 作者:行者123 更新时间:2023-12-04 01:08:09 26 4
gpt4 key购买 nike

我是 Cassandra 的新手,我读过 Cassandra 鼓励非规范化和数据重复。这让我有点困惑。
让我们想象一下下面的场景:

我有一个包含四个表的键空间:A、B、C 和 D。

CREATE TABLE A (
tableID int,
column1 int,
column2 varchar,
column3 varchar,
column4 varchar,
column5 varchar,
PRIMARY KEY (column1, tableID)
);

让我们假设其他表(B、C、D)与表 A 具有相同的结构和相同的数据,只是具有不同的主键,以便响应其他查询。

如果我升级表 A 中的一行,如何确保具有相同数据的其他表中的数据一致性?

最佳答案

Cassandra 提供 BATCH以此目的。来自 documentation :

A BATCH statement combines multiple data modification language (DML) statements (INSERT, UPDATE, DELETE) into a single logical operation, and sets a client-supplied timestamp for all columns written by the statements in the batch. Batching multiple statements can save network exchanges between the client/server and server coordinator/replicas. However, because of the distributed nature of Cassandra, spread requests across nearby nodes as much as possible to optimize performance. Using batches to optimize performance is usually not successful, as described in Using and misusing batches section. For information about the fastest way to load data, see "Cassandra: Batch loading without the Batch keyword."

Batches are atomic by default. In the context of a Cassandra batch operation, atomic means that if any of the batch succeeds, all of it will. To achieve atomicity, Cassandra first writes the serialized batch to the batchlog system table that consumes the serialized batch as blob data. When the rows in the batch have been successfully written and persisted (or hinted) the batchlog data is removed. There is a performance penalty for atomicity. If you do not want to incur this penalty, prevent Cassandra from writing to the batchlog system by using the UNLOGGED option: BEGIN UNLOGGED BATCH


UNLOGGED BATCH 几乎总是不可取的,我相信在 future 的版本中会被删除。正常批次提供您想要的功能。

关于cassandra - Cassandra中如何保证不同表上的数据一致性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34231718/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com