TTL of Scylla

Synopsis
It is not always clear under which circumstances data is deleted when using Time to Live (TTL) and gc_grace_seconds arguments in table definitions. This article clarifies what may not be apparent. It corrects some assumptions you may have that are not exactly true.

Facts About Expiring Data
When compaction is running on an SSTable and it scans a piece of data that has expired the following happens:

If the data time stamp + gc_grace_seconds is less than or equal to the current time (now), the data is thrown away and a tombstone is not created.

If not, a tombstone is created and its timestamp is the same as its corresponding data. This means that the tombstone is going to be deleted after (at least) gc_grace_seconds from the time when the corresponding data element has been written.

For example:

In this example there is an expired cell that becomes a tombstone, note how the tombstone’s local_deletion_time is the expired cell’s timestamp.

“rows” : [
{
“type” : “row”,
“position” : 120,
“liveness_info” : { “tstamp” : “2017-04-09T17:07:12.702597Z”,
“ttl” : 20, “expires_at” : “2017-04-09T17:07:32Z”, “expired” : true },
“cells” : [
{ “name” : “country”, “value” : “1” },
]
Is compacted into:

“rows” : [
{
“type” : “row”,
“position” : 79,
“cells” : [
{ “name” : “country”, “deletion_info” :
{ “local_delete_time” : “2017-04-09T17:07:12Z” },
“tstamp” : “2017-04-09T17:07:12.702597Z”
},
]
If you set the TTL to be greater than the gc_grace_seconds, the expired data will never generate a tombstone.

Example: When Time Window Compaction Strategy (TWCS) estimates if a particular SSTable can be deleted it is going to treat expired data similarly as a tombstone:

gc grace seconds: 0
sstable A: token range: [10, 10], timestamp range: [1, 1], ttl: 2, max deletion time: 3 (1+2)
sstable B: token range: [10, 10], timestamp range: [1, 5], ttl: 2, max deletion time: 7 (5+2)
now: 6
From this you can see that:

SSTable A is fully expired because its max deletion time (3) is lower than now (6).

SSTable B is NOT fully expired because its max deletion time (7) is greater than now (6).

SSTable A will be added as a candidate for fully expired SSTable and will be purged.

During Compaction:

Compaction sees that SSTable B overlaps with SSTable A in token range.

Compaction also sees that SSTable A overlaps with B in timestamp range, and it thinks that SSTable A could have a tombstone that shadows data in SSTable B.

Compaction decides not to purge SSTable A even though it’s fully expired.

If you use updates in conjunction with TWCS, it may prevent the “window compacted” SSTables from being deleted when they should have been. However, when the corresponding data expires (in all SSTables), all relevant SSTables are will be deleted during the next compaction.

Additional Information
How to Change gc_grace_seconds for a Table

Expiring Data with Time to Live (TTL)

CQL Reference: Table Options
https://opensource.docs.scylladb.com/stable/kb/ttl-facts.html

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Scylla是一个高性能的分布式NoSQL数据库,它基于Apache Cassandra的设计理念,并进行了优化和改进。下面是一个简单的Scylla使用教程: 1. 安装Scylla:可以从Scylla官方网站下载适合你操作系统的安装包,并按照官方文档提供的步骤进行安装。 2. 配置Scylla:安装完成后,你需要编辑Scylla的配置文件以满足你的需求。配置文件位于/etc/scylla/scylla.yaml(Linux)或者C:\Program Files\ScyllaDB\scylla.yaml(Windows)。 3. 启动Scylla:在完成配置后,你可以使用以下命令启动Scylla数据库: ``` sudo systemctl start scylla-server # Linux scylla --developer-mode # Windows ``` 4. 连接到Scylla:你可以使用CQL shell(cqlsh)连接到Scylla数据库,并执行CQL语句进行数据操作。以下是连接到Scylla的命令: ``` cqlsh <Scylla节点IP地址> ``` 5. 创建Keyspace和表:在连接到Scylla后,你可以使用CQL语句创建Keyspace和表。例如,创建一个名为mykeyspace的Keyspace和一个名为mytable的表: ``` CREATE KEYSPACE mykeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}; USE mykeyspace; CREATE TABLE mytable (id INT PRIMARY KEY, name TEXT); ``` 6. 插入和查询数据:使用CQL语句可以插入和查询数据。以下是一个插入数据的示例: ``` INSERT INTO mytable (id, name) VALUES (1, 'John'); ``` 以下是一个查询数据的示例: ``` SELECT * FROM mytable WHERE id = 1; ``` 这只是一个简单的Scylla使用教程,你可以根据自己的需求进一步学习和探索Scylla的功能和特性。如果你有更具体的问题或者需要更深入的教程,请告诉我。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值