Cassandra 将 TTL 添加到现有条目

标签 cassandra cassandra-2.0 cqlsh ttl

如何更新整个表并为每个条目设置 TTL?

当前场景(Cassandra 2.0.11):

表:

CREATE TABLE external_users (
  external_id text,
  type int,
  user_id text,
  PRIMARY KEY (external_id, type)
) 

目前此表中有大约 40mio 条目,我想添加一个 TTL,假设为 86 400 秒(1 天)。 对于使用 TTL(86400) 或更新当前条目的新条目来说没有问题,但如何为每个现有条目应用 ttl?

我的想法是选择所有数据并使用一个小脚本更新每一行。我只是想知道是否有更简单的方法来实现这一点(因为即使批量更新,这也需要一段时间并且需要付出很大的努力)

提前致谢

最佳答案

无法更改 C* 中现有数据的 TTL。 TTL 只是一个内部列属性,它与所有其他列数据一起写入不可变的 SSTable。引用自the docs :

If you want to change the TTL of expiring data, you have to re-insert the data with a new TTL. In Cassandra, the insertion of data is actually an insertion or update operation, depending on whether or not a previous version of the data exists.

关于Cassandra 将 TTL 添加到现有条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30591321/

相关文章:

concurrency - Cassandra 中的柜台设计

cassandra - 在 Cassandra 中插入特殊字符

mongodb - Hbase 数据应该如何才能快速查询响应?

Cassandra - 如何检索最近的值

cassandra - 如何更改 Cassandra 中的 PARTITION KEY 列?

cassandra - 无法删除行键

Cassandra - 写入不会失败,但不会插入值

database - Cassandra 中的删除读取和删除突变

cassandra - 在 cassandra 上禁用压缩和 gc 宽限期

Cassandra 配置由 cqlsh 进行