Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Wiezzel opened this issue Sep 26, 2024 · 0 comments
Open

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

Wiezzel opened this issue Sep 26, 2024 · 0 comments

Comments

@Wiezzel
Copy link

Wiezzel commented Sep 26, 2024

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
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant