I have a coupled main and a (temporary and auxiliary) database in a BerkeleyDB JE environment. The problem is as follows:
- I am using transactions, and atomicity must span both the main and the aux DB
- therefore, as I understand the docs, I have to use a single environment (transactions cannot span several environments)
- So the two databases share one directory. But do they also share the same files?
- Because the aux DB can grow very big, and I want to wipe it at the start of the application.
- I have used
e.truncateDatabase(txn, name, false)
to do so - But it appears the database directory never shrinks, so if in every application run the aux DB uses e.g. 500 MB, then after four runs, the directory is already 2 GB, irrespective of the truncation. Also I cannot see distinct files for main and aux DB
How can I really wipe the aux database, so that the disk space is freed? This is also a performance problem, because with those several GB large directories, BDB has serious trouble starting up and winding down. Can I force BDB to use separate files, so I can just delete a particular file?
Somehow this single environment seems at the root of the problem. For example, I would love to increase performance by giving the aux DB setTxnNoSync()
but then this will also affect the main DB.
If I use setTemporary
on the aux DB, I get a runtime exception, apparently it is disallowed to use transactions with a temporary database!?
java.lang.IllegalArgumentException: Attempted to open Database aux and two ore more of the following exclusive properties are true: deferredWrite, temporary, transactional