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

Re: LMDB: transactions across dbis, dbi lifetime



Martin Lucina wrote:
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?

Of course. Where in the quoted doc is it ever implied otherwise?

2. AFTER the initial transaction in which mdb_dbi_open() was called has
    been committed, can I freely use the dbi in subsequent transactions?

That is exactly what "resides in the shared environment, and may be used by other transactions" means.

    I.e. stash it away in a static variable?

Sure.

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...?

Why would you expect any subsequent abort to have any effect? This is the entire point of a transactional DB system - any event occurring in a transaction can only be committed once, or aborted once. No subsequent aborts can rollback anything from a prior commit.

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




--
  -- Howard Chu
  CTO, Symas Corp.           http://www.symas.com
  Director, Highland Sun     http://highlandsun.com/hyc/
  Chief Architect, OpenLDAP  http://www.openldap.org/project/