[pybsddb] Transactions

Matt Chaput matt at whoosh.ca
Thu Jan 16 20:07:06 CET 2014


Hi PyBSDDBers!

I’m trying to use a BTree with single-writer/multi-reader transactional semantics: I want readers to see a snapshot of the moment they were opened, and changes made to writers to not be visible until they commit (and it’s OK if readers have to be re-opened).

Just using bsddb3.btopen() *seems* to give me something very close to this automatically: if I open a “writer” and make changes, they aren’t visible in “readers” until the “writer” is closed and the “readers” are re-opened.

However, the one thing this doesn’t seem to allow is aborting/rolling back the changes made in a writer.

I tried using the bsddb.db API so I could use DBEnv.txn_begin() to get a transaction, but besides the code being harder to write, my test (writing just 50,000 keys) is *20x* slower with a transaction.

So, some questions:

* Am I correct in my belief that the _DBWithCursor helper object is giving me the semantics I want “for free”?

* Is there a way I can use some attribute or method on _DBWithCursor, _DBWithCursor.db, etc. to abort its transaction?

* If I need to use the low-level bsddb3.db API, can anyone suggest fixes for a horrible slowdown in put()s when I pass a transaction?

  I tried opening the DBEnv with flags:

    db.DB_INIT_TXN | db.DB_INIT_LOCK | db.DB_INIT_MPOOL | db.DB_TXN_NOSYNC

  and the DB_BTREE DB with flags:

    db.DB_MULTIVERSION

  (When I found the DB_TXN_NOSYNC flag I really thought it was the answer, but it made no difference. But maybe I’m not using it right.)

Thanks very much!

Matt



More information about the pybsddb mailing list