开发者

Berkeley DB: DB->compact() always fails for hash-based databases

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 开发者_如何学Goshould work just fine.

Has anybody got an idea what might cause this error?

PS: I am using Berkeley DB 4.5.20.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜