[Date Prev][Date Next] [Chronological] [Thread] [Top]

LMDB: transactions across dbis, dbi lifetime



Hi,

I'm having trouble understanding the interaction between txns and dbis in
LMDB. Quoting from the docs for mdb_dbi_open():

    The database handle will be private to the current transaction until
    the transaction is successfully committed. If the transaction is
    aborted the handle will be closed automatically. 
    
    After a successful commit the handle will reside in the shared
    environment, and may be used by other transactions. This function must
    not be called from multiple concurrent transactions. A transaction that
    uses this function must finish (either commit or abort) before any
    other transaction may use this function.

1. Is it legal to:
   
   a. begin a txn
   b. open a bunch of dbis in that txn.
   c. perform some operations (get/put) on distinct dbis.
   d. commit the txn.

   In other words, may a txn span multiple dbis?

2. AFTER the initial transaction in which mdb_dbi_open() was called has
   been committed, can I freely use the dbi in subsequent transactions?
   I.e. stash it away in a static variable?

3. Is the dbi still valid if a subsequent transaction on it is aborted with
   mdb_txn_abort()? The first part of the quoted paragraph suggests not...?

I have tested at least points 1. and 2. above and "it seems to work" but
I'd like to verify that this is actually expected usage.

I've not particularly tested for point 3. but it would make programming to
the API rather hard if I had to reopen dbis whenever a higher level
operation fails.

Martin