3 Replies Latest reply: Jul 30, 2007 12:32 PM by 579183 RSS

    multiple writer processes with Berkeley DB

    579183
      I’m evaluating Berkeley DB usability when multiple unrelated processes try to write to the same database. My attempts to create a small working example failed badly and I’m unsure whether the multiple writer approach is something that isn’t supposed to work at all or if there is a bug in the DB or my understanding of the concept or API ...

      My code opens an environment and a database pair ten times in a loop, writing hundred records for each iteration. Running the example ten times in a row results in the expected 10000 records. However, running the example ten times in parallel causes all kinds of problems from error messages “DB_PAGE_NOTFOUND”, “Requested page not found”, “fatal region error detected” etc. to lost data and segmentation faults. Same issue on FreeBSD/x86, FreeBSD/amd64, RHEL4/ix86 and Solaris9/SPARC64. Environment and DB were placed on local filesystem.

      The code is pretty much verbatim taken from the reference manual with hints from the FAQ
      How can I architect a multi-process Berkeley DB application ...?
      http://www.oracle.com/technology/products/berkeley-db/faq/db_faq.html#4

      Berkeley DB version used db-4.5.20.2-20070507.src.rpm
      http://www.openpkg.org/product/packages/?package=db
      http://cvs.openpkg.org/fileview?f=openpkg-src/db/db.spec&v=1.77

      Berkeley DB stress test batch and probe
      http://thomas.lotterer.net/openpkg/db-4.5.20.2-20070507/test.sh
      http://thomas.lotterer.net/openpkg/db-4.5.20.2-20070507/probe.c

      What am I doing wrong?
        • 1. Re: multiple writer processes with Berkeley DB
          Bogdan Coman-Oracle
          Hi Thomas,

          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

          Best Regards,
          Bogdan Coman, Oracle
          • 2. Re: multiple writer processes with Berkeley DB
            579183
            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?
            • 3. Re: multiple writer processes with Berkeley DB
              579183
              You forgot to add some flags to dbenv->open, like
              DB_INIT_LOCK, DB_INIT_LOG, DB_INIT_MPOOL
              Got it. DB_INIT_MPOOL and DB_INIT_LOCK were required.
              Also important is the need to pass dbenv to db_create().

              All fixed, see
              http://thomas.lotterer.net/openpkg/db-4.5.20.2-20070507/fix.patch

              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?