如何在Rocks DB上正确设置TTL? [英] How to set TTL on Rocks DB properly?

查看:730
本文介绍了如何在Rocks DB上正确设置TTL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Rocks DB与TTL一起使用.我初始化rock db的方式如下: options.setCreateIfMissing(true).setWriteBufferSize(8 * SizeUnit.KB) .setMaxWriteBufferNumber(3) .setCompressionType(CompressionType.LZ4_COMPRESSION).setKeepLogFileNum(1); db = TtlDB.open(options, this.dbpath, 10, false);

I am trying to use Rocks DB with TTL. The way I initialise rocks db is as below: options.setCreateIfMissing(true).setWriteBufferSize(8 * SizeUnit.KB) .setMaxWriteBufferNumber(3) .setCompressionType(CompressionType.LZ4_COMPRESSION).setKeepLogFileNum(1); db = TtlDB.open(options, this.dbpath, 10, false);

我已将TTL设置为10秒.但是,键值对不会在10秒后删除.这是怎么回事?

I have set TTL to 10 seconds. But, the key value pairs are not being deleted after 10 seconds. Whats happening here?

推荐答案

这是设计使然:

当要在非严格的"ttl"时间内从数据库中删除插入的键值时,应使用此API打开数据库,从而保证插入的键值将保留在数据库中在至少ttl的时间内,数据库将努力在插入键值ttl秒后尽快删除键值

This API should be used to open the db when key-values inserted are meant to be removed from the db in a non-strict 'ttl' amount of time therefore, this guarantees that key-values inserted will remain in the db for at least ttl amount of time and the db will make efforts to remove the key-values as soon as possible after ttl seconds of their insertion

-来自TTL上的 RocksDB Wiki页面.

这意味着仅在压缩期间删除值,并且在读取期间不检查陈旧性.

That means values are only removed during compaction, and staleness is not checked during reads.

RocksDB的优点之一是其源代码易于阅读.您要查看的文件是标题TtlDb来源.在标题中,您会找到消除陈旧值的压缩(压缩的Filter -contract在

One of the good things about RocksDB is that their source is quite readable. The files you would want to look at are the header and source for TtlDb. In the header you will find the compaction which removes stale values (the compaction's Filter-contract is documented well in its header). In the TtlDb source you verify for yourself that Get does not do any checks whether or not the value is stale. It just strips the timestamp (which just gets appended to the value on insert).

这篇关于如何在Rocks DB上正确设置TTL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆