Cassandra - table 处的 TTL 和使用 TTL 插入数据有什么区别

Cassandra - What is difference between TTL at table and inserting data with TTL

我有一个 Cassandra 2.1 集群,我们通过 Java 使用 TTL 插入数据,因为保留数据的要求是 30 天。 但这会导致问题,因为带有墓碑的旧数据文件保留在磁盘上。这导致磁盘 space 被不需要的数据占用。修复需要很长时间才能清除此数据(单个节点最多 3 天) 有没有更好的删除数据的方法?

我在 datastax 上遇到过这个

Cassandra allows you to set a default_time_to_live property for an entire table. Columns and rows marked with regular TTLs are processed as described above; but when a record exceeds the table-level TTL, Cassandra deletes it immediately, without tombstoning or compaction. https://docs.datastax.com/en/cassandra/3.0/cassandra/dml/dmlAboutDeletes.html?hl=tombstone

如果我将TTL设置为table级别而不是每次插入时都设置,是否会更有效地删除数据? 另外,文档是针对 Cassandra 3 的,所以我是否必须升级到更新的版本才能获得任何好处?

设置 default_time_to_live 将默认的 ttl 应用于 table 中的所有行和列 - 如果没有设置单独的 ttl(并且 cassandra 在所有节点上都有正确的 ntp 时间),cassandra 可以轻松地安全地删除这些数据。

但请记住一些事情:您的应用程序仍然可以在 table 中为单行设置特定的 ttl - 然后将应用正常处理。最重要的是,即使数据被处理,它也不会立即被删除——sstables 仍然是 immutable,但是墓碑会在压缩过程中被删除。

什么可以真正帮助你 - 只是猜测 - 是一个合适的压缩策略:

http://docs.datastax.com/en/archived/cassandra/3.x/cassandra/dml/dmlHowDataMaintain.html#dmlHowDataMaintain__twcs-compaction

TimeWindowCompactionStrategy (TWCS) 推荐用于时间序列和即将到期的 TTL 工作负载。

The TimeWindowCompactionStrategy (TWCS) is similar to DTCS with simpler settings. TWCS groups SSTables using a series of time windows. During compaction, TWCS applies STCS to uncompacted SSTables in the most recent time window. At the end of a time window, TWCS compacts all SSTables that fall into that time window into a single SSTable based on the SSTable maximum timestamp. Once the major compaction for a time window is completed, no further compaction of the data will ever occur. The process starts over with the SSTables written in the next time window.

这对正确选择时间有很大帮助 windows。最后压缩的 sstable 中的所有数据将具有大致相等的 ttl 值(提示:不要进行无序插入或手动 ttls!)。 Cassandra 在 sstable 元数据中保留最年轻的 ttl 值,当那个时间过去时,cassandra 会简单地删除整个 table,因为所有数据现在都已过时。无需压实。

你运行你的维修情况如何?增加的?满的?死神?您的集群的节点和数据有多大?

快速回答是肯定的。它的实现方式是直接从磁盘中删除SStable/s。删除 SStable 而无需压缩会更快地清理磁盘 space。但是您需要确保特定 sstable 中的所有数据比 table.

的全局配置的 TTL "older"

这是您引用的段落中提到的feature。它是为 Cassandra 2.0 实现的,所以它应该是 2.1

的一部分