cberner / redb

An embedded key-value database in pure Rust
https://www.redb.org
Apache License 2.0
3.07k stars 137 forks source link

A failed assertion on `Database::compact()` #798

Closed fluiderson closed 2 months ago

fluiderson commented 2 months ago
use redb::{Database, TableDefinition};

fn main() {
    example();
    example();
}

fn example() {
    let mut db = Database::create("example.db").unwrap();

    let write_tx = db.begin_write().unwrap();
    let read_tx = db.begin_read().unwrap();

    let mut write_table = write_tx
        .open_table::<&str, &str>(TableDefinition::new("example"))
        .unwrap();

    write_table.insert("example", "example").unwrap();

    // drop(read_tx);
    drop(write_table);

    write_tx.commit().unwrap();
    db.compact().unwrap();
}

After running that with cargo r, I get the output:

thread 'main' panicked at /home/fluid/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redb-2.1.0/src/db.rs:427:9:
assertion failed: self.mem.get_freed_root().is_none()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

To fix that, uncomment the line dropping a read transaction. Note that I execute example() twice, the panic doesn't present at the first compaction, only at subsequent ones.

System info:

$ cargo pkgid redb
registry+https://github.com/rust-lang/crates.io-index#redb@2.1.0
$ rustc -V
rustc 1.77.2 (25ef9e3d8 2024-04-09)
$ uname -sm
Linux x86_64