This content has been marked as final. Show 3 replies
You forgot to add some flags to dbenv->open, like DB_INIT_LOCK, DB_INIT_LOG, DB_INIT_MPOOL (http://www.oracle.com/technology/documentation/berkeley-db/db/ref/transapp/env_open.html). Anyway, I think that the best thing for you to do is to read the following Berkeley DB docs:
Berkeley DB Reference Guide - http://www.oracle.com/technology/documentation/berkeley-db/db/ref/toc.html
Berkeley DB: C Handle Methods - http://www.oracle.com/technology/documentation/berkeley-db/db/api_c/frame.html
Architecting Transactional Data Store applications - http://www.oracle.com/technology/documentation/berkeley-db/db/ref/transapp/app.html
Bogdan Coman, Oracle
Thanks a lot for taking your precious time to review my code, Bogdan.
I run an attempt using the additional flags you were suggesting but they didn't improve results.
Your pointers to the DB Reference and C API sound a little bit like RTFM. In fact, I didn't read all the stuff there but a good portion of it before I was asking for help ;-) The FAQ entry I mentioned leads exactly to the "Architecting Transactional Data Store" topic.
The code was modeled after the "The third way to architect Transactional Data Store applications is as a group of unrelated processes" using the DB_REGISTER flag.
It seems to take a senior expert to get my simple requirement done :-(
All I know now is I'm not alone:
Problem with multiple processes and DB_REGISTER
Re: Problem with multiple processes and DB_REGISTER
Does anybody has the code for developing multi-process program .thank you.
Re: does anybody has the code for developping multi-process program .thank you.
Any more ideas what to try next?
You forgot to add some flags to dbenv->open, likeGot it. DB_INIT_MPOOL and DB_INIT_LOCK were required.
DB_INIT_LOCK, DB_INIT_LOG, DB_INIT_MPOOL
Also important is the need to pass dbenv to db_create().
All fixed, see
Only one minor issue remains. The creation of the database does not work as I expected it when attempted by parallel running processes. If I try, like the original test.sh did, then some processes fail with "File exists" error. My assumption is that early processes recognize the DB is missing and needs creation. The fastest process wins the race, works as designed. The immediate followers fail, which is behavior I did not expect. The very slow processes find the DB and do not attempt to create it, also works as designed. My current workaround is to do first time database access, which includes DB_CREATE, by a single process only. If the described behavior is correct then I wonder whether there is another flag available to prevent the error or if it is good BDB programming practice to just retry on "File exists" error?