tidb-incubator / tidis

A distributed transactional large-scale NoSQL database powered by TiKV
Apache License 2.0
444 stars 30 forks source link

Is there an active expiration for ttl other than the lazy expiration in Tidis ? #95

Closed iamwuyunfeng closed 1 year ago

iamwuyunfeng commented 1 year ago

I am trying to understand how Tidis implements redis protocol. I known that an get command for a string will check its ttl and delete it if expired, but what if a key has outlived its ttl and is never accessed after it's set ? In other Redis alike products, like Tendis, will use rocksdb's compaction filter to delete those keys in compaction, or launch a background thread to periodically scan those expired keys and delete them. I do notice that the Db set() method would use a BTreeMap to track keys with ttl, but I don't see there is any releationship between the Db set method and the ttl releated commands such as expire or setex, it seems that the latter would directly write kv into TiKV without using any TiKV's ttl interface ? Besides, the set() method of Db is marked as dead_code and is written in 3 years ago, I assume that is the legacy code from Tidis 1.0 ? So is the lazy expiration the only way to delete expired keys in Tidis or am I missing anything ?

yongman commented 1 year ago

Tidis does not support active key expiration yet. But we can trigger the keys expiration using scan command to scan all keyspace.

This feature can be added later.

iamwuyunfeng commented 1 year ago

Tidis does not support active key expiration yet. But we can trigger the keys expiration using scan command to scan all keyspace.

This feature can be added later.

I see, thanks. @yongman