Reeywhaar / nut

Port of Bolt DB in Rust
MIT License
44 stars 7 forks source link

Transaction rollback will panic if bucket ref not dropped #2

Closed laohanlinux closed 2 years ago

laohanlinux commented 2 years ago
    let mut db = db_mock().build().unwrap();
    let mut tx = db.begin_rw_tx().unwrap();
    {
        let  bucket = tx.create_bucket(b"widgets").unwrap();
    }
    let bu = tx.bucket(b"widgets").unwrap();
    tx.rollback().unwrap();

panic code

    pub(crate) fn close(&self) -> Result<(), Error> {
        let mut db = self.db()?;
        let tx = db.remove_tx(self)?;

        *tx.0.db.write() = WeakDB::new();
        tx.0.root.try_write().unwrap().clear();
        tx.0.pages.try_write().unwrap().clear();
        Ok(())
    }
Reeywhaar commented 2 years ago

Well, it seems I should have made tx.bucket(&self) to take &mut self tx to forbid tx usage until bucked dropped. Right now I won't do anything with it, but I'll think about it conceptually. Thank you for report!