Skip to content

v0.23.0

Choose a tag to compare

@Kerollmops Kerollmops released this 22 Oct 08:00
407de3c

heed & heed3

This release is breaking regarding the way we open databases. It is no longer possible to produce undefined behaviors when opening or creating databases. The LMDB documentation specifies that a transaction that opened or created a database must commit or abort before any other transaction can open or create a database. This wasn't enforced in previous versions of heed nor heed3.

To ensure a safe usage of LMDB we broke the database opening/creating API.

let mut wtxn = env.write_txn()?;
let database = env.create_database(&mut wtxn, Some("my-db"))?;

// At this point you can use the database everywhere in the program
// even though you haven't committed it, yet.

wtxn.commit()?;

The former API let you use uncommitted databases outside the transaction scope resulting in EINVAL errors and was allowing multiple transactions to open/create databases concurrently, resulting in undefined behavior. The new API disallow both behaviors but introduces a more complex API.

let wtxn = env.write_txn()?;
let database = env
    .create_databases_and_commit(wtxn, |dbo, wtxn| {
        let db = dbo.create_database(wtxn, Some("my-db"))?;
    
        // At this point you can use the database but it is tied to the wtxn
        // transaction and therefore, can't be used outside this closure.
    
        // The only way to use it outside of the current transaction
        // is to commit it by returning it from this very closure.
        Ok(CommitOrAbort::<_, ()>::Commit(db))
    })?
    .unwrap_commit();

// At this point you can use the database everywhere in the program.