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
}
}
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: