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

Re: lmdb: is read operation permitted inside the write transaction?



On 12/05/15 19:36, Howard Chu wrote:
Dmytro Milinevskyy wrote:
Basically I need to have an opportunity to call mdb_get while in write
transaction.
The sequence is smth like:
  - txn = mdb_txn_begin(flags=0)
  for i in 0..x:
    - v = mdb_get(txn, i)
    - mdb_put(txn, x+i, v)
    - mdb_put(txn, i, v+1)
  - mdb_txn_commit(txn)

Will it be always valid data?

Yes.

...No.  I expect he means v = the MDB_val returned by mdb_get().
mdb_put() can modify the data it points at.

See the MDB_val documentation in ldmb.h:
 * Values returned from the database are valid only until a subsequent
 * update operation, or the end of the transaction. Do not modify or
 * free them, they commonly point into the database itself.