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

panicked at 'attempt to subtract with overflow' #9

Closed
0xAAE opened this issue Apr 23, 2021 · 1 comment · Fixed by #10
Closed

panicked at 'attempt to subtract with overflow' #9

0xAAE opened this issue Apr 23, 2021 · 1 comment · Fixed by #10

Comments

@0xAAE
Copy link

0xAAE commented Apr 23, 2021

The following code panics with
thread 'main' panicked at 'attempt to subtract with overflow', .../jammdb-0.5.0/src/page.rs:107:25:

const TEST_DB: &str = "tmp.db";
fn main() {
    let _ = std::fs::remove_file(TEST_DB);
    {
        let db = jammdb::DB::open(TEST_DB).unwrap();
        {
            let tx = db.tx(true).unwrap();
            let root = tx.get_or_create_bucket("ROOT").unwrap();
            tx.commit().unwrap();
        }
        {
            let tx = db.tx(true).unwrap();
            let root = tx.get_or_create_bucket("ROOT").unwrap();
            let child = root.get_or_create_bucket("CHILD").unwrap();
            tx.commit().unwrap(); // panic! is here, page.rs:107: self.overflow = num_pages - 1;  and num_pages is 0
        }
    }
    let _ = std::fs::remove_file(TEST_DB);
}

If I do all stuff in the single transaction everything is OK

fn main() {
    let _ = std::fs::remove_file(TEST_DB);
    {
        let db = jammdb::DB::open(TEST_DB).unwrap();
        {
            let tx = db.tx(true).unwrap();
            let root = tx.get_or_create_bucket("ROOT").unwrap();
            // remove tx.commit() + db.tx()
            let root = tx.get_or_create_bucket("ROOT").unwrap();
            let child = root.get_or_create_bucket("CHILD").unwrap();
            tx.commit().unwrap();
        }
    }
    let _ = std::fs::remove_file(TEST_DB);
}

Unfortunately, the problem prevents me from using nested buckets at all

@pjtatlow
Copy link
Owner

Hey thanks for finding this, I should have some time later today to take a closer look, I'll let you know what I find!

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

Successfully merging a pull request may close this issue.

2 participants