default_time_to_live 如何删除 Cassandra 中没有墓碑的行?

How default_time_to_live would delete rows without tombstones in Cassandra?

来自How is data deleted?

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.

这也回答了

If a table has default_time_to_live on it then rows that exceed this time limit are deleted immediately without tombstones being written.

并在 LastPickle 的 post 中发表评论 About deletes and tombstones

Another clue to explore would be to use the TTL as a default value if that's a good fit. TTLs set at the table level with 'default_time_to_live' should not generate any tombstone at all in C*3.0+. Not tested on my hand, but I read about this.

我用 LeveledCompactionStrategy:

做了我能想到的最简单的测试
CREATE KEYSPACE IF NOT EXISTS temp WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'};

CREATE TABLE IF NOT EXISTS temp.test_ttl (
    key text,
    value text,
    PRIMARY KEY (key)
) WITH  compaction = { 'class': 'LeveledCompactionStrategy'}
  AND default_time_to_live = 180;
  1. INSERT INTO temp.test_ttl (key,value) VALUES ('k1','v1');
  2. nodetool flush temp
  3. sstabledump mc-1-big-Data.db
  4. 等待 180 秒 (default_time_to_live)
  5. sstabledump mc-1-big-Data.db 墓碑尚未创建
  6. nodetool compact temp
  7. sstabledump mc-2-big-Data.db tombstone 已创建(由于 gc_grace_seconds 而未在压缩时删除)

测试使用 apache cassandra 3.0.13

从示例中我得出结论,default_time_to_live 不需要墓碑是不正确的,至少对于版本 3.0.13 是这样。 然而,这是一个非常简单的测试,我强制使用 nodetool compact 进行主要压缩,因此我可能不会重新创建 default_time_to_live 魔术发挥作用的场景。

但是C*怎么删除没有墓碑呢?为什么这应该与每次插入使用 TTL 不同?

据我所知,墓碑记录和 TTL 过期的记录之间没有太大区别。在您的情况下,强制主要压缩将 TTL 过期记录转换为墓碑,但由于 gc_grace_seconds 而未被清除。据此presentation,tombstones/ttl-expired-records走开:

  • 从未如此 gc_grace_seconds 旧
  • 在压缩期间,对于一个 tombstone/ttl 超过 gc_grace,它的分区键根据给定 table
  • 的所有其他 SSTables 的布隆过滤器进行检查
  • 如果存在布隆过滤器冲突,逻辑删除将保留,即使冲突是误报。
  • 如果有任何数据,甚至任何 SSTable 中该分区的其他逻辑删除,逻辑删除都不会被清除
  • 如果布隆过滤器表明该分区键上没有重叠的可能性,则墓碑将被清理。

所以从技术上讲,tombstone/ttl 可能会在 gc_grace 之后消失,但不能保证。

我在我们的博客 (The Last Pickle Blog) 上回答这个问题时被您提到的文档所愚弄。我可能回答得太快了,尽管我写了这个东西'to explore',甚至说我没有明确尝试过。

Another clue to explore would be to use the TTL as a default value if that's a good fit. TTLs set at the table level with 'default_time_to_live' should not generate any tombstone at all in C*3.0+. Not tested on my hand, but I read about this.

所以我上面这句话是错误的。基本上,默认值可以在查询级别被 TTL 覆盖,我不知道 Cassandra 如何在没有墓碑的情况下处理这个问题。

From the example I conclude that isn't true that default_time_to_live not require tombstones, at least for version 3.0.13.

另外,很高兴看到您不相信我或 Datastax 文档,而是自己尝试了。这绝对是正确的方法。

But how would C* delete without tombstones? Why this should be a different scenario to using TTL per insert?

是的,正是这样,

C*heers.


阿兰·罗德里格斯 - @arodream - alain@thelastpickle.com 法国/西班牙

最后的泡菜 - Apache Cassandra 咨询 http://www.thelastpickle.com