https://bugs.openldap.org/show_bug.cgi?id=10127
Issue ID: 10127 Summary: Thread Safety in LMDB with MDB_NOTLS and Readonly Cursors Product: LMDB Version: unspecified Hardware: All OS: All Status: UNCONFIRMED Keywords: needs_review Severity: normal Priority: --- Component: liblmdb Assignee: bugs@openldap.org Reporter: xiaoya2wei@gmail.com Target Milestone: ---
Greetings LMDB Community,
I am delving into the thread-safety aspects of LMDB, specifically regarding the use of readonly cursors across multiple threads. With the MDB_NOTLS flag enabled, which disables thread-local storage, my understanding is that readonly transactions may be shared between threads, provided there is proper synchronization to prevent concurrent access.
Building upon this, I seek clarity on the following: Can multiple threads safely access a single readonly cursor derived from such a synchronized readonly transaction when MDB_NOTLS is enabled?
Upon reviewing the LMDB source code, I noticed that cursors are tied to transactions (see mdb.c#L1335). This suggests that if threads can synchronously share a transaction, they might also share a cursor associated with it for data retrieval.
I recognize my analysis might be superficial, and I'm open to corrections. Your insights on this matter would be greatly appreciated to enhance my understanding of LMDB's concurrency mechanisms.
Thank you in advance for your assistance!
https://bugs.openldap.org/show_bug.cgi?id=10127
Howard Chu hyc@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Howard Chu hyc@openldap.org --- As the docs clearly state, a transaction may only be used by one thread at a time.
http://www.lmdb.tech/doc/group__mdb.html#gad7ea55da06b77513609efebd44b26920
MDB_NOTLS merely allows a read txn to serially be used by other threads at different times.
https://bugs.openldap.org/show_bug.cgi?id=10127
--- Comment #2 from xiaoya2wei@gmail.com --- (In reply to Howard Chu from comment #1)
As the docs clearly state, a transaction may only be used by one thread at a time.
http://www.lmdb.tech/doc/group__mdb.html#gad7ea55da06b77513609efebd44b26920
MDB_NOTLS merely allows a read txn to serially be used by other threads at different times.
Hi Howard,
Thanks for the response and I really appreciate it. In fact I was a bit confused about that "Cursors may not span transactions", which is partly why I decide to explicitly ask this question here.
So to be crystal transparent, even if MDB_NOTLS is set, a cursor opened by a readonly txn still has to stay with one single thread for its entire lifetime, an d cannot be used by another thread even at a different time. Is my understanding correct?
Thanks for the time again!
Best, Xiaoya
https://bugs.openldap.org/show_bug.cgi?id=10127
--- Comment #3 from Howard Chu hyc@openldap.org --- The ITS is for bug reports only. Send questions to the openldap-technical mailing list. This ticket is closed.
https://bugs.openldap.org/show_bug.cgi?id=10127
Quanah Gibson-Mount quanah@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords|needs_review | Status|RESOLVED |VERIFIED