Cassandra ttl 连续 [英] Cassandra ttl on a row

查看:20
本文介绍了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 周).它可以通过替换具有相同内容但 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.

但是 可能有另一个进程在A"行上同时运行,它插入新列或替换没有 TTL 的现有列,因为该进程不知道要删除该行(它同时运行!).因此,1 周后,除了这些新插入的列之外,A"行的所有列都将因 TTL 被删除.我也希望它们被删除.

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?

亲切的问候
斯蒂芬

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.

您可以通过延迟过程来实现您想要的 - 而不是想要插入 1 周的 TTL,而是在一周后运行它并删除该行.行删除具有以下语义:之前插入的任何列都会被删除,但之后插入的列不会被删除.

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天全站免登陆