I'm trying to use the with_ttl option to automatically delete older records.
Menziess opened this issue · 1 comments
Menziess commented
After inserting a record, waiting for the desired ttl seconds, the record still exists.
Are there other ways to handle automatic deletion of older records other than manually finding and deleting them?
Congyuwang commented
Hi, surprise to me as well. See this link: https://github.com/facebook/rocksdb/wiki/Time-to-Live
It appears that ttl in rocksdb means it will at least live that long. and the value is deleted only during compaction. So expired value may get deleted in the process when more values inserted during compaction.
From RocksDB
- Expired TTL values are deleted in compaction only:(Timestamp+ttl<time_now)
- Get/Iterator may return expired entries(compaction not run on them yet)
- Different TTL may be used during different Opens
- read_only=true opens in the usual read-only mode. Compactions will not be triggered(neither manual nor automatic), so no expired entries removed
Some warnings:
- Calling DB::Open directly to re-open a db created by this API will get corrupt values(timestamp suffixed) and no ttl effect will be there during the second Open, so use this API consistently to open the db
- Be careful when passing ttl with a small positive value because the whole database may be deleted in a small amount of time