Berkeley DB:对于基于哈希的数据库,DB->compact() 总是失败
在一些记录被更改(缩小)、在数据库中留下“漏洞”后,我决定使用 Berkeley DB 的压缩功能来优化数据库的大小和缓存命中率。
然而,这不起作用。即使使用这段非常简单的简化代码也不行:
if (db->open(db, NULL, dbFile, NULL, DB_HASH, DB_CREATE | DB_TRUNCATE, 0)) {
// Error...
}
if (res = db->compact(db, NULL, NULL, NULL, NULL, DB_FREE_SPACE, NULL)) {
db->err(db, res, "Compacting failed");
}
我尝试指定第五个参数或省略标志,但每次仍然失败并显示 EINVAL(代码 22):
压缩失败:参数无效
(太糟糕了,没有更精确的错误消息;大多数 Berkeley DB 错误都有它们)
如果我用 DB_BTREE 替换 DB_HASH ,它就可以工作,这就是为什么我相信它与使用哈希数据库格式有关。但是,根据 文档,压缩哈希桌子应该可以正常工作。
有人知道什么可能会导致此错误吗?
PS:我使用的是 Berkeley DB 4.5.20。
I decided to use Berkeley DB's compaction feature to optimize the size and cache-hit rate of my databases after some records were altered (shrinked), leaving "holes" in the database.
However, it doesn't work. Not even with this very simple reduced piece of code:
if (db->open(db, NULL, dbFile, NULL, DB_HASH, DB_CREATE | DB_TRUNCATE, 0)) {
// Error...
}
if (res = db->compact(db, NULL, NULL, NULL, NULL, DB_FREE_SPACE, NULL)) {
db->err(db, res, "Compacting failed");
}
I tried specifing the fifth parameter or leaving out the flag, but still it fails with EINVAL (code 22) every time:
Compacting failed: Invalid argument
(too bad that there isn't a preciser error message; most Berkeley DB errors have them)
It works if I replace DB_HASH with DB_BTREE, which is why I believe it has something to do with using the hash db format. However, according to the documentation, compacting hash tables should work just fine.
Has anybody got an idea what might cause this error?
PS: I am using Berkeley DB 4.5.20.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我搜索了 Berkeley DB 最新几个版本的更改日志。 版本 5.0 的更改日志指出“为 DB->compact 接口添加了哈希数据库支持。[#16936] ”。尽管当前版本的在线文档表明 DB->compact 适用于 Btree、Recno 和 Hash 数据库,但支持5.0 版本中添加了 Hash。
您可能还想将您的问题发布到 Berkeley DB 论坛。
I searched through the change logs for the last several releases of Berkeley DB. The change log for release 5.0 states "Added hash databases support to the DB->compact interface. [#16936]". Although the online documentation for the current release says that DB->compact works for Btree, Recno and Hash databases, support for Hash was added in release 5.0.
You may also want to post your question to the Berkeley DB Forum.