Yaakov Belch
Yaakov Belch

Reputation: 4863

lmdb: Can I access different named databases in the same transaction?

I want to write a lot of data to a lmdb data base with several named (sub) data bases. I run into the following problem:

I rather would like to keep one long-running write transaction for all write operations and commit it once --- when all the work is done.

Is this possible with lmdb (if yes, at which point did I err in my analysis)?

Upvotes: 0

Views: 2049

Answers (2)

sidnt
sidnt

Reputation: 300

you err in your analysis at this point

  • This implies: To write to another named data base, I need to open a different transaction.

One transaction handle can be used to open multiple subdatabases in an lmdb environment.

Note: a single transaction can open multiple databases. Ref

Upvotes: 1

cmollekopf
cmollekopf

Reputation: 131

You can open as many named databases within the same write transaction as you like.

So:

  • Open write transaction
  • Open named databases as required and write to them
  • Commit your transaction

As long as you take into account that you can only ever have one write-transaction at a time (read-only transactions are no problem), and that your other transactions will only see the result of your write-transaction once you commit, you can of course have one long-running write transaction.

Upvotes: 1

Related Questions