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

Re: lmdb - atomic actions

howard - thank you for the prompt reply and for putting this wonderful library together.

to clarify my understanding, can you elaborate a little on the locking lmdb tx provide cross threads and processes? in particular

1. do they provide a writer lock by default and one needs to flag MDB_TXN_RDONLY when a writer lock is not required?

2. given that mdb_txn_begin is a precursor to most other actions, are these locks "data store"  wide?  is there some other mechanism to lock a key/value pair or cursor so not to delay access to other keys? or is the basic assumption such is unnecessary?

thank again!

On Jul 24, 2013, at 1:52 PM, Howard Chu <hyc@symas.com> wrote:

Tomer Doron wrote:
wondering what the best strategy to achieve atomic updates with LMDB.

what i am trying to achieve is a read then update atomic action given a
highly concurrent use case,  for example, if a key/value pair represents a
counter, how does one increment or decrement the counter atomically.

i am pretty sure mdb_get -> mdv_set sequence is not atomic, wondering if
mdb_cursor_get -> mdv_cursor_put sequence is? perhaps a certain flag is
required on the get action to achieve a lock? in my bdb implementation i
used lockers to achieve this.

Transactions are atomic. Whatever operations you perform in a single transaction will occur atomically. BDB-style locking is unnecessary.

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