I'm adding BDB replication to some legacy code and had to implement transactions. Apparently, they've tried that before (a alot of transaction code is still there, but was uncommented) and had performance issues (don't ask, I have no idea :).<p>
Anyway, I read the manual and thought that DB_LOG_INMEMORY might help because we have plenty of memory in the machine(s)...<p>
The code now creates the environment (db_env_create(&envp)) sets DB_LOG_INMEMORY (envp->set_flags()), sets up the log memory buffer (envp->set_lg_bsize()), sets up the in-memory cache (envp->set_cachesize()) and then sets internal lock detection (envp->set_lk_detect()). It then opens the table environment with the following flags: 'DB_CREATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_RECOVER|DB_INIT_LOCK|DB_INIT_LOG|DB_THREAD'.
AFter this, it sets the transaction log directory (envp->set_lg_dir()).<p>
The table pointer is then created (db_create(&dbp)) and opened with the following flags: 'DB_THREAD|DB_CREATE|DB_AUTO_COMMIT|DB_READ_UNCOMMITTED'.<p>
After all dbp->put()'s (protected by transactions and commited properly) the table is closed (including any secondary indexes) with dbp->close() and 'uninitialized' with envp->close().<p>
All this SEEMED to work, but when the read client then tried to open the database(s), it couldn't because it got 'Invalid argument' in dbp->open(). (naturaly with DB_CREATE changed to DB_READ :).
Disabling the DB_LOG_INMEMORY part, everything is working flavlessly (although a lot of log.* files are created :).<p>
So my question is: What am I missing? The DB->close() documentation seems to indicate that all this (flushing logs etc) is taken care of automatically:<p>
The DB->close method flushes any cached database information to disk, closes any open cursors, frees any allocated resources, and closes any underlying files.
And so is DB_ENV->close():<p>
The DB_ENV->close method closes the Berkeley DB environment, freeing any allocated resources and closing any underlying subsystems.
What I <b>am</b> doing is call DB->open() with a filename (because I want the actual database <i>on disk</i> but the log <i>in memory</i>). Am I missunderstanding something here?!
Now that I have managed to get transactions AND replication working (see thread Regenerate a replica the project manager asks me to take a second stab at this. We don't really want/need durability (transactions was disabled long ago because of this but reenabled/rewritten because of replication), so: How do i open a database from disk, but then keep it in memory only?
I've seen references that this should be possible ('move the database into memory' or something like this) but I haven't seen any examples...