Cassandra - 批量太大

Cassandra - Batch too large

我有一个必须添加到采购订单的产品列表。采购订单有一个序列号,添加产品后,它们的状态应更改为表明这些产品已外购。

1 个采购订单中处理的产品的典型数量为 500。

在数据库上 - 我有 2 个表 -> 1 个用于产品,另一个用于采购订单。这意味着我需要完成 500 次更新和 1 次插入。 当我尝试在 BatchStatement 中执行此操作时,出现错误 - 批量太大。

各方面的建议告诉我应该使用多个异步查询。然而,我担心的是整个操作的原子性。 根据我的要求,请提出最好的前进方式。

提前致谢。

这很有趣。将大量插入(> 10)插入批处理(以实现原子性)确实会是一个糟糕的性能,因此提高批处理限制并不是一个真正的选择。

由于 Cassandra 也在单行级别管理原子性,您可以通过将 table 添加到 "bookmark" 您的采购订单来更改您的模型来利用它,在那里您只在一行中存储两者将采购订单 ID 和项目放入映射中,因此您的查询具有幂等性。然后,您可以展开或 post 处理此 table 以根据需要继续您的工作流程。

My concern however is atomicity of the entire operation. Please suggest what would be the best way forward given my requirement.

请注意,Cassandra 批处理不提供隔离 (http://www.datastax.com/dev/blog/atomic-batches-in-cassandra-1-2):

Note that we mean “atomic” in the database sense that if any part of the batch succeeds, all of it will. No other guarantees are implied; in particular, there is no isolation; other clients will be able to read the first updated rows from the batch, while others are in progress.

因此,如果您需要隔离,正如@xmas79 回答的那样,您应该将产品和采购订单一起存储在一个 table。

如果隔离和性能不是关键,您可以尝试调整 Cassandra yaml 并增加 batch_size_fail_threshold_in_kb 参数

的值

Fail any batch exceeding this value. 50kb (10x warn threshold) by default.