nimdbx icon indicating copy to clipboard operation
nimdbx copied to clipboard

Open a collection inside a write transaction

Open aleclarson opened this issue 4 years ago • 3 comments

I'm getting this error:

MDBX_BUSY: Another write transaction is running, or environment is already used while opening with MDBX_EXCLUSIVE flag

Is there a workaround for this?

aleclarson avatar Jul 15 '21 04:07 aleclarson

Strangely, the readme for libmdbx lists this as a feature:

Nested write transactions.

..yet the error message implies write transactions cannot be nested.

aleclarson avatar Jul 15 '21 16:07 aleclarson

The docs for libmdbx say otherwise (emphasis mine):

A transaction and its cursors must only be used by a single thread, and a thread may only have a single transaction at a time.

https://erthink.github.io/libmdbx/group__c__transactions.html#ga9621bd463ec9efb2373f25dfb016938a

aleclarson avatar Jul 15 '21 17:07 aleclarson

Ah, the devil is in the details. The parent argument to mdbx_txn_begin is what "nested write transactions" refers to. In other words, the nesting must be explicit.

If this parameter is non-NULL, the new transaction will be a nested transaction, with the transaction indicated by parent as its parent. Transactions may be nested to any level. A parent transaction and its cursors may not issue any other operations than mdbx_txn_commit and mdbx_txn_abort() while it has active child transactions.

aleclarson avatar Jul 15 '21 17:07 aleclarson