Skip to content

Transactions must not keep a reference to the environment #359

@Kerollmops

Description

@Kerollmops

I noticed that LMDB already exposes the environment associated with a transaction with the mdb_txn_env function.

https://github.com/LMDB/lmdb/blob/40d3741b7d40ba4c75cb91dd9987ce692d376d71/libraries/liblmdb/lmdb.h#L1019-L1023

We should no longer store a Cow<Arc<EnvInner>> there; instead, use the above function to get the env.

heed/heed/src/txn.rs

Lines 56 to 60 in 345db35

struct RoTxnInner<'e> {
/// Makes the struct covariant and !Sync
pub(crate) txn: Option<NonNull<ffi::MDB_txn>>,
env: Cow<'e, Arc<EnvInner>>,
}

We can simply change the RoTxn::env_mut_ptr method to use the above function.

heed/heed/src/txn.rs

Lines 103 to 105 in 345db35

pub(crate) fn env_mut_ptr(&self) -> NonNull<ffi::MDB_env> {
self.inner.env.env_mut_ptr()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions