原子批次在Cassandra [英] Atomic Batch in Cassandra

查看:229
本文介绍了原子批次在Cassandra的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑Cassandra中的以下批处理语句:

  BEGIN BATCH 
INSERT INTO用户(userID, )VALUES('user2','ch @ ngem3b','second user')

UPDATE users SET password ='ps22dhds'WHERE userID ='user2'

DELETE * FROM users WHERE userID ='user2'
INSERT INTO用户(userID,密码,名称)VALUES('user2','ch @ ngem3c','Andrew')
APPLY BATCH;如果Cassandra批处理中的上述语句确保行级隔离(userID是行关键字),那么它将作为row key是否相同?

解决方案

需要注意的一个重要的事情是,在一个批处理中,



这意味着您写的所有四个语句

  INSERT INTO用户(userID,password,name)VALUES('user2','ch @ ngem3b','second user')

UPDATE users SET password ='ps22dhds'WHERE userID = 'user2'

DELETE * FROM users WHERE userID ='user2'

INSERT INTO用户(userID,密码,名称)VALUES('user2','ch @ ngem3c' ,'Andrew')

所有都发生在同一时间,在这种情况下,使用改性细胞。



基本上C *会看到

  INSERT('user2','ch @ ngem3b','second user')
INSERT('user2','ps22dhds','second user')
INSERT('user2','Tombstone','Tombstone')
INSERT('user2','ch @ ngem3c','Andrew')

在这种情况下,由于它们都有相同的时间戳C *通过选择单元格的最大值来解决冲突,你会得到,(除非我得到了字节在这里排序错误)

 ('user2','ps22dhds','second user')

而不是这种操作,考虑使用C *中的检查和设置(CAS)操作。



http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0


Consider the following batch statement in Cassandra:

 BEGIN BATCH
 INSERT INTO users (userID, password, name) VALUES ('user2', 'ch@ngem3b', 'second user')

 UPDATE users SET password = 'ps22dhds' WHERE userID = 'user2'

 DELETE * FROM users WHERE userID = 'user2'
 INSERT INTO users (userID, password, name) VALUES ('user2', 'ch@ngem3c', 'Andrew')
 APPLY BATCH;

Will the above statements in Cassandra batch ensures row-level isolation (userID is the row key) as the row key is the same?

解决方案

One important thing to note is that within a batch without timestamps specified per statement all of the statements will be executed at the same timestamp.

This means all four statements you wrote

INSERT INTO users (userID, password, name) VALUES ('user2', 'ch@ngem3b', 'second user')

UPDATE users SET password = 'ps22dhds' WHERE userID = 'user2'

DELETE * FROM users WHERE userID = 'user2'

INSERT INTO users (userID, password, name) VALUES ('user2', 'ch@ngem3c', 'Andrew')

All happen at the same time, in this case the highest value for the commonly modified cell is used. While all four statements are applied the outcome is most likely not what you are expecting.

Basically C* will see

INSERT ('user2', 'ch@ngem3b', 'second user')
INSERT ('user2', 'ps22dhds', 'second user')
INSERT ('user2', 'Tombstone', 'Tombstone')
INSERT ('user2', 'ch@ngem3c', 'Andrew')

In this case since they all have the same timestamp C* resolves the conflict by choosing the largest value for the cells and you will end up with, (unless I got the byte ordering wrong here)

('user2', 'ps22dhds', 'second user')

Instead for this kind of operation consider using the Check And Set (CAS) operations in C*.

http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0

这篇关于原子批次在Cassandra的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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