Cassandra批处理语句 - 执行顺序 [英] Cassandra batch statement - Execution order
问题描述
我有一个Cassandra的批处理语句,其中包含一个具有相同分区键的delete和insert语句,其中delete是第一个语句,insert是第二个语句。批处理语句如何执行这些语句?是否按照相同的顺序,我们添加了语句?
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文档> a>来演示,开始创建一个名为购买
的简单表格,其中包含两个字段:
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
:
When I query for userid
:
aploetz@cqlsh:stackoverflow2> SELECT user, balance, writetime(balance) FROM purchases WHERE user='user1';
user | balance | writetime(balance)
-------+---------+--------------------
user1 | -8 | 1432043350384
(1 rows)
如您所见,因为它有最新的时间戳。而如果我只是从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屋!