]> git.ipfire.org Git - thirdparty/pdns.git/commit
lmdb-safe: Remove the read-only transactions counter 15844/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 15 Jul 2025 10:32:18 +0000 (12:32 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 15 Jul 2025 10:32:18 +0000 (12:32 +0200)
commit2fbb728f496f3f6aa27afff534b562333db39f82
treed25fa471e225e913534536c1caf955d2be3dfed3
parent14d675b3daca870f0acf84dfad9cc79eadb868f3
lmdb-safe: Remove the read-only transactions counter

LMDB requires:
- a transaction and its cursors must only be used by a single thread
- a thread may only have a single transaction at a time
- but, if `MDB_NOTLS` is in use, this does not apply to read-only transactions.

The first and second points are the reasons why we are keeping track
of transactions, but because of the third point we cannot be strict
with regard to read-only transactions, unless we keep track of whether
the `MDB_NOTLS` flag is in use.

I recently noticed that I made a mistake in c340aa91bf37d8105d2b2390eecbadfca88c1d27, and `MDBEnv::getROTX()` now returns the number of read-write
transactions instead of the number of read-only transactions. It
also noticed that `MDBEnv::getROTX()` is actually not used, and we
only enforce that a thread that already has a read-write transaction
cannot open another transaction.
Since `MDBEnv::getROTX()` is not used, it makes not much sense to
bear the cost of tracking read-only transactions so this commit removes
the read-only transactions counter.

Another option would be to make lmdb-safe stricter: if we kept track
of whether the `MDB_NOTLS` flag is in use, we could enforce:
- only one transaction when `MDB_NOTLS` is NOT in use. We then
 need to check both counters when opening a new transaction.
- only one read-write transaction but several read-only transaction
 allowed when `MDB_NOTLS` is in use.

Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
ext/lmdb-safe/lmdb-safe.cc
ext/lmdb-safe/lmdb-safe.hh