[Date Prev][Date Next]
[lmdb] MDB_BAD_DBI error upon mdb_txn_commit (newbie question)
- To: email@example.com
- Subject: [lmdb] MDB_BAD_DBI error upon mdb_txn_commit (newbie question)
- From: HLaw <firstname.lastname@example.org>
- Date: Fri, 27 Mar 2015 01:48:19 +0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=u2z+RqgD7w83c6CYAlPS2PSoCA5svXzDs18qkClxIJ0=; b=q7kb9JLZJqBU3Yovk1h2qe9FlMEh66Y/1cqNLmurf2jxrtTTDUONQJjPe5ZhoTKr9r qBXJHoV87O4AftIJnd0X6UxG569fxBt2jrQEhLYkMN8UTv8E5RrGbl9avOVMscBoyQJZ ItjpaBjB1OvNY0e/ydVzKdceZlSA3btj+Ef0WufmW/uC9//dwBcrvBrPEZb5scspQZ0R 0hLxORuV84Yava8cLvoFSltZKb1Yv6Bk/4kYoCAQuOAJCNeEMUzv+FoJceJ5wODN1TZc ZH9lCE7gVuJBYiL6kqwzSO8I8yeQqawSvlHzUUQVGUgxZTQ7nr2U45cTe7/pAKoVo6h0 Snww==
- User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0
I am new to lmdb and my apologies if this is on something obvious.
I encountered the MDB_BAD_DBI error in a simple single process,
multi-threaded program using lmdb. The scenario is :
* One thread doing a relatively long write transaction
mdb_txn_begin -> mdb_dbi_open on several database -> (write) ->
* Another thread (or other threads) of the same process doing short
mdb_txn_begin -> mdb_dbi_open on some of the database above ->
(read) -> mdb_txn_commit
As per the advice in the document I do not close the database directly.
Also the environment created / opened is shared by all threads, being in
the same process.
All is fine when these threads execute separately, but if the read
transaction thread(s) open the database and commit within the time span
of the write transaction in another thread, the above error occurs upon
attempt to commit the write transaction.
I have done a search on the MDB_BAD_DBI error and noticed the commit below.
Upon a brief look into this and the source of lmdb, my understanding is
that the error is due to the increment of lmdb's internal sequence
numbers of the database kept by the environment (by the read thread when
the read transaction commits). When the write thread subsequently tries
to commit, the database sequence number kept privately by the write
transaction (copied from the environment when the transaction began)
does not match that of the environment, causing the error.
To avoid this in a single process multi-threaded environment, it seems
that no read transactions could commit on databases while they are
involved in a write transaction, i.e. I need to complete all read
transactions before a write transaction on the same database could
begin. Alternatively, to have concurrent read transactions with a
write transaction, the read transactions have to take place in a
separate process (such that they would not share the same environment
and caught by the above error).
Grateful if anyone could kindly enlighten me on whether the
understanding is correct, or if I am doing something contrary to the how
lmdb should be used.
Thank you very much.
- H Law