Hi fellow monks,

I've been wrangling with BerkeleyDB today trying to get a grip on how to do concurrent access with this database in order to provide a web interface to a legacy database. I am using BerkeleyDB.pm v0.25 with BerkeleyDB v4.2.

I'm using the DB_INIT_CDB and DB_INIT_MPOOL flags to Initialize locking for the Berkeley DB Concurrent Data Store. I found an example on the web from Paul M. who wrote BerkeleyDB which shows how to request a write lock. So far, so good.

My problem comes when I want to use this lock. There is not much in the BerkeleyDB.pm pod that explains using the DB_WRITECURSOR flag so I have resorted to the docs at sleepycat.com(1).

To my tired eyes, it seems that these docs are saying that I need to use a cursor to get a write lock. OK, but once I open a cursor, the docs say that I should not call db_put. OK, so let's try c_put. Unfortunately, that only appears to overwrite or duplicate the record under the cursor. I want to insert a new record. I do not see any flag available for doing that.

Could someone familiar with concurrency in BerkeleyDB please shed some light on this issue for me? Some example code would be excellent!

Update: I finally figured out the proper incantantation of flags needed to get BerkeleyDB to operate safely in a multi-process environment. See node #330510 "Testing DB concurrency with BerkeleyDB" for more details.

Many Thanks,
William

(1) Berkeley DB Concurrent Data Store applications


In reply to Concurrent access with BerkeleyDB by knowmad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.