Cassandra ttl在行 [英] Cassandra ttl on a row

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

问题描述

我知道Cassandra的列上有TTL。但是是否也可以在行上设置TTL?在每个列上设置TTL不能解决我的问题,如下面的用例所示:

I know that there are TTLs on columns in Cassandra. But is it also possible to set a TTL on a row? Setting a TTL on each column doesn't solve my problem as can be seen in the following usecase:

在某一时刻,进程要删除一个具有TTL的完整行(假设行A,TTL为1周)。

At some point a process wants to delete a complete row with a TTL (let's say row "A" with TTL 1 week). It could do this by replacing all existing columns with the same content but with a TTL of 1 week.

可能会有另一个进程正在运行同时在插入新列或替换没有TTL的现有行的行A,因为该进程不知道该行将被删除(它并行运行)。因此,在1周后,除了这些新插入的行之外,由于TTL的行A的所有列将被删除。

But there may be another process running concurrently on that row "A" which inserts new columns or replaces existing ones without a TTL because that process can't know that the row is to be deleted (it runs concurrently!). So after 1 week all columns of row "A" will be deleted because of the TTL except for these newly inserted ones. And I also want them to be deleted.

那么,还是会有Cassandra支持这个用例,还是我自己实现呢?

So is there or will there be Cassandra support for this use case or do I have to implement something on my own?

种类问题
Stefan

Kind Regards
Stefan

推荐答案

没有办法在Cassandra中的一行上设置TTL。 TTL的设计用于删除单独的列,当他们的生命周期知道他们写的时候。

There is no way of setting a TTL on a row in Cassandra currently. TTLs are designed for deleting individual columns when their lifetime is known when they are written.

您可以通过延迟您的过程实现您想要的,而不是想插入一个TTL的1周,运行一个星期后,删除该行。行删除具有以下语义:任何刚刚插入的列都将被删除,但刚刚插入的列将不会被删除。

You could achieve what you want by delaying your process - instead of wanting to insert a TTL of 1 week, run it a week later and delete the row. Row deletes have the following semantics: any column inserted just before will get deleted but columns inserted just after won't be.

如果将来插入的列仍然需要要删除,你可以在将来插入一个时间戳记删除,以确保这一点,但要非常小心:如果你后来想插入到那行,你不能,列只会消失,当写到那一行(直到墓碑是垃圾收集)。

If columns that are inserted in the future still need to be deleted you could insert a row delete with a timestamp in the future to ensure this but be very careful: if you later wanted to insert into that row you couldn't, columns would just disappear when written to that row (until the tombstone is garbage collected).

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

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