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

532 views Asked by At

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.

1

There are 1 answers

0
dsegleau On BEST ANSWER

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.