批量更新cassandra与轻量级事务 [英] batch update cassandra with lightweight transaction

查看:979
本文介绍了批量更新cassandra与轻量级事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cassandra 2.2.3,并想用两个语句进行批量更新。两者都使用轻量级事务。

I am using cassandra 2.2.3 and want to make a batch update with two statements. Both using a lightweight transaction.

BEGIN BATCH
UPDATE account SET values['balance'] = 11 WHERE id = 1 IF values['balance'] = 10;
UPDATE account SET values['balance'] = 11 WHERE id = 2 IF values['balance'] = 10;
APPLY BATCH;

批次返回以下错误:

InvalidRequest: code=2200 [Invalid query] message="Batch with conditions cannot span multiple partitions".

我知道不可能在where子句中的各种PK上进行批处理,因为分区,但为什么不可能在同一个PK上做一个批处理?问题是IF语句,删除它们,批处理正在工作。

I understand that it is not possible to make a batch on various PKs in the where clause because of the partitions, but why it is not possible to do a batch on the same PK? The problems are the IF statements, removing them, the batch is working.

那么是否有成功执行这样的批量更新的解决方案?或任何解决方法?

So is there a solution to successfully execute such a batch update? Or any workaround?

编辑:
这是我的模式:

This is my schema:

CREATE TABLE booking.account (
 id int PRIMARY KEY,
 values map<varchar, decimal>,
 timestampCreate timestamp,
 timestampUpdate timestamp
);


推荐答案


不能在
的where子句中对各种PK进行批处理,因为分区,但为什么不可能
在同一PK上做批处理?

I understand that it is not possible to make a batch on various PKs in the where clause because of the partitions, but why it is not possible to do a batch on the same PK?

您可以在where子句中对各种PK进行批处理,但不建议(请参阅 Cassandra:批量载入不含Batch关键字)。

You could make a batch on various PKs in the where clause, However this is not recommended (Please refer to Cassandra: Batch loading without the Batch keyword).

这里的问题是条件更新(if语句)。引自 datastax cql参考

The problem here is conditional update (the if statement). Quote from datastax cql reference.


在Cassandra 2.0.6及更高版本中,您可以批量导入条件更新
作为Cassandra 2.0中的轻量级事务。只有更新
到同一个分区才能包含在批处理中,因为基于Paxos实现的

分区的粒度上工作。可以将具有条件的更新与
不匹配的更新进行分组,但是当批处理中的单个语句使用条件时,使用单个Paxos提议提交
整个批处理,如同所有
包含在批处理中的条件适用。

In Cassandra 2.0.6 and later, you can batch conditional updates introduced as lightweight transactions in Cassandra 2.0. Only updates made to the same partition can be included in the batch because the underlying Paxos implementation works at the granularity of the partition. You can group updates that have conditions with those that do not, but when a single statement in a batch uses a condition, the entire batch is committed using a single Paxos proposal, as if all of the conditions contained in the batch apply.

那么你真的需要批处理语句吗?请阅读此使用和误用批次

So do you really need batch statement? Read this Using and misusing batches

这篇关于批量更新cassandra与轻量级事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆