Skip to content

Deleting data directory while DB is open doesn't raise any errors #36

@Wiezzel

Description

@Wiezzel

When the database directory is removed while a DB is open, none of the DB operations raise any errors. The data seems to be stored correctly. But when the DB is opened again, the data is (obviously) gone. That kind of silent failure is confusing for the user.

Steps to reproduce:

fn delete_db_dir() {
    let path = PathBuf::from_str("./db").unwrap();
    let db = libmdbx::Database::<libmdbx::WriteMap>::open(&path).unwrap();
    std::fs::remove_dir_all(&path);

    {
        let tx = db.begin_rw_txn().unwrap();
        let table = tx.open_table(None).unwrap();
        tx.put(&table, "key", "data", Default::default()).unwrap();
        tx.commit().unwrap();
    }

    {
        let tx = db.begin_ro_txn().unwrap();
        let table = tx.open_table(None).unwrap();
        let data: Vec<u8> = tx.get(&table, "key".as_bytes()).unwrap().unwrap();
    }

    drop(db);
    let db = libmdbx::Database::<libmdbx::WriteMap>::open(&path).unwrap();

    {
        let tx = db.begin_ro_txn().unwrap();
        let table = tx.open_table(None).unwrap();
        let data: Vec<u8> = tx.get(&table, "key".as_bytes()).unwrap().unwrap();  // panic: called `Option::unwrap()` on a `None` value
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions