[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: Multiple threads and mdb_dbi_open
- To: Harry B <harrysungod@gmail.com>
- Subject: Re: Multiple threads and mdb_dbi_open
- From: Howard Chu <hyc@symas.com>
- Date: Fri, 12 Sep 2014 01:06:21 +0100
- Cc: openldap-technical@openldap.org
- In-reply-to: <CAMG7=yULMDxTkWa5WYkCX_gDyNhR99_Z7wASisYLnv2gbFc_qA@mail.gmail.com>
- References: <CAMG7=yVevhhEB3QCXqu01+4vXC8qvVS9PCyCtGNZJQ4MPORpiw@mail.gmail.com> <541231AC.8060006@symas.com> <CAMG7=yULMDxTkWa5WYkCX_gDyNhR99_Z7wASisYLnv2gbFc_qA@mail.gmail.com>
- User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0 SeaMonkey/2.27a1
Harry B wrote:
Let me rephrase and see if I understand correctly.
1. If I have 10 threads (but only one database), then I would need to create
10 dbi handles to the same DB and then use them as required from each thread
making sure no two threads share the same DBI handle?
No. Re-read the documentation that you linked. It very clearly states that if
you open the same DB multiple times you will get the same handle back, so why
would you ever try to open it 10 times for 10 threads??
It also says very clearly that after the handle is persisted into the shared
environment it may be used by other transactions.
2. Inside each thread, I would open a new transaction (as required for the
then relevant/appropriate read/write operation), but I would use a DBI handle
obtained in the main thread even though that DBI was created using a different
transaction handle that the one we are about to use for the current thread?
Thanks
--
Harry
On Thu, Sep 11, 2014 at 4:35 PM, Howard Chu <hyc@symas.com
<mailto:hyc@symas.com>> wrote:
Harry B wrote:
Hello,
As per the documentation here
http://symas.com/mdb/doc/__group__mdb.html#__gac08cad5b096925642ca359a6d6f0__562a
<http://symas.com/mdb/doc/group__mdb.html#gac08cad5b096925642ca359a6d6f0562a>
I see the following,
"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."
This seems to imply that after one txn has begun on an environment, I
cannot
create another txn or dbi until the first one has finished - that
doesn't seem
to be right.
If I have multi-threaded app, what is the expected sequence for
creation of
Environment, Transaction, and DBI handles?
Before starting any other threads:
Create the environment.
Open a transaction.
Open all DBI handles the app will need.
Commit the transaction.
After that use the DBI handles freely among any transactions/threads.
--
-- Howard Chu
CTO, Symas Corp. http://www.symas.com
Director, Highland Sun http://highlandsun.com/hyc/
Chief Architect, OpenLDAP http://www.openldap.org/project/