Cassandra 批处理语句 - 执行顺序 [英] Cassandra batch statement - Execution order
问题描述
我有一个 Cassandra 的批处理语句,其中包含相同分区键的删除和插入语句,其中删除是第一条语句,插入是第二条语句.批处理语句如何执行这些语句?与我们添加语句的顺序相同吗?
I have a batch statement of Cassandra that contains a delete and an insert statement of same partition key, where delete is the first statement and insert is the second. How the batch statement executes these statements ? Is in the same order in which,we added the statements?
推荐答案
不,它不会按照指定的顺序执行它们.要强制特定的执行顺序,您可以添加 USING TIMESTAMP
子句.查看文档了解更多信息:http://docs.datastax.com/en/cql/3.1/cql/cql_reference/batch_r.html
No, it does not execute them in the order specified. To force a particular execution order, you can add the USING TIMESTAMP
clause. Check the docs for more information: http://docs.datastax.com/en/cql/3.1/cql/cql_reference/batch_r.html
使用时间戳如何维护执行顺序.例如如果上面的例子(删除和插入相同的分区键),最终结果应该是插入的记录.可以通过添加时间戳吗??
Using time stamp how it can maintain the order of execution . For Example if the above example (delete and insert for same partition key), the final result should be the inserted record. Is that possible by adding time-stamp ??
是的.我将结合上面链接中的示例和 DELETE 文档 进行演示,首先创建一个名为 purchases
的简单表,其中包含两个字段:
Yes. I'll combine examples from the link above and the DELETE documentation to demonstrate, and start by creating a simple table called purchases
with two fields:
CREATE TABLE purchases (user text PRIMARY KEY, balance bigint);
接下来,我将使用 INSERT 和 DELETE 执行批处理.我会最后执行 DELETE,但时间戳比 INSERT 早:
Next, I'll execute a batch with an INSERT and a DELETE. I'll do the DELETE last, but with an earlier timestamp than the INSERT:
BEGIN BATCH
INSERT INTO purchases (user, balance) VALUES ('user1', -8) USING TIMESTAMP 1432043350384;
DELETE FROM purchases USING TIMESTAMP 1432043345243 WHERE user='user1';
APPLY BATCH;
当我查询userid
时:
aploetz@cqlsh:stackoverflow2> SELECT user, balance, writetime(balance) FROM purchases WHERE user='user1';
user | balance | writetime(balance)
-------+---------+--------------------
user1 | -8 | 1432043350384
(1 rows)
如您所见,INSERT 持续存在,因为它具有最新的时间戳.而如果我只是从 cqlsh 提示符运行 INSERT 和 DELETE(按该顺序),查询将不会返回任何内容.
As you can see, the INSERT persisted because it had the latest timestamp. Whereas if I had simply run the INSERT and DELETE (in that order) from the cqlsh prompt, the query would have returned nothing.
这篇关于Cassandra 批处理语句 - 执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!