For the reading, the panic isn’t happening inside Sanakirja, but inside Parking_lot.
This sounds like you’re opening a very large number of readers at the same time, and keep them all open. I’d be curious to see your code for that, and know more about the exact scenario: how long do you have to wait before you see these crashes?
For the writing, this sounds like a bug, although I don’t quite know where it comes from. If you can, I’d be interested to see your database just after this happens (having it just before would be great too), or at least have some way to reproduce.
If you can run with RUST_LOG="sanakirja=debug" RUST_BACKTRACE=1
, it would also be useful to see the output of that.
Clone the project, put thousands of .txt files under ./txt, and then run ./train/train.sh You can see the error recurring.
Currently I am busy writing another project, and I will give you a minimal version of the code to reproduce the bug when I have time.
Thanks! I’m seeing unexpected things when I look at your sdb
, such as:
let tx = &self.0;
match tx.root_db::<K, V, P>(id) {
None => {
let mut w = Env::mut_txn_begin(tx.env_borrow()).unwrap();
let tree = create_db_::<_, K, V, P>(&mut w).unwrap();
w.set_root(id, tree.db);
w.commit().unwrap();
tree
}
Some(tree) => tree,
}
This is very strange, a Db
can’t exist outside of a transaction. You can think of a Db
as a pointer to a small part of a large block of allocated memory (the Txn
). Once the Txn
is gone, it is as if the memory didn’t exist anymore.
Unfortunately, the Rust typesystem is a bit weak to express all the things we want to do with Db
, such as storing a Db
inside another Db
.
I can definitely try to have a closer look at sdb
, because I think you’re seeing a standard case of corruption here.
I upgrade sdb, now use tx.root_db::<K, V, P>(id).unwrap()
in ReadTx and create db when program init ( https://github.com/rmw-link/sdb/blob/daddcc5ae2802c6d41ebdd5f0772607d77e0d2b6/sdb/src/lib.rs#L374 ).
Now use train program ( https://github.com/gcxfd/rmw-utf8/blob/3d05df8a05e701e78ceb8bd0f1f0de0e07dd21ca/train/src/main.rs#L193 )
somethings error
0.00 sec/txt 1 ../txt/jianshu/61/b4/61b4fc52d20d.txt
0.00 sec/txt 101 ../txt/jianshu/df/94/df94be185870.txt
0.00 sec/txt 201 ../txt/jianshu/1f/a1/1fa1a1d0d077.txt
thread '<unnamed>' panicked at 'assertion failed: btree::del::del(self, &mut db, &f, None)?', /Users/z/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/sanakirja-1.2.5/src/environment/muttxn.rs:405:9
stack backtrace:
0: rust_begin_unwind
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:50:5
3: <sanakirja::environment::muttxn::MutTxn<E,T> as sanakirja_core::AllocPage>::alloc_page
4: sanakirja_core::btree::page::put::put
5: sanakirja_core::btree::put::put
6: sdb::dbpage::DbPage<K,V,P,RK,RV>::put
7: <rayon::iter::map_with::MapWithFolder<C,U,F> as rayon::iter::plumbing::Folder<T>>::consume
8: <rayon::iter::par_bridge::IterParallelProducer<Iter> as rayon::iter::plumbing::UnindexedProducer>::fold_with
9: rayon::iter::plumbing::bridge_unindexed_producer_consumer
10: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
11: rayon_core::registry::WorkerThread::wait_until_cold
12: rayon_core::registry::ThreadBuilder::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
0.00 sec/txt 301 ../txt/jianshu/55/0d/550d7016a044.txt
somethings error
0.00 sec/txt 1 ../txt/jianshu/61/b4/61b4fc52d20d.txt
0.00 sec/txt 101 ../txt/jianshu/df/94/df94be185870.txt
thread '<unnamed>' panicked at 'assertion failed: btree::del::del(self, &mut db, &f, None)?', /Users/z/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/sanakirja-1.2.5/src/environment/muttxn.rs:405:9
stack backtrace:
0: rust_begin_unwind
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:50:5
3: <sanakirja::environment::muttxn::MutTxn<E,T> as sanakirja_core::AllocPage>::alloc_page
4: sanakirja_core::btree::page::put::put
5: sanakirja_core::btree::put::put
6: sdb::dbpage::DbPage<K,V,P,RK,RV>::put
7: <rayon::iter::map_with::MapWithFolder<C,U,F> as rayon::iter::plumbing::Folder<T>>::consume
8: <rayon::iter::par_bridge::IterParallelProducer<Iter> as rayon::iter::plumbing::UnindexedProducer>::fold_with
9: rayon::iter::plumbing::bridge_unindexed_producer_consumer
10: rayon_core::registry::in_worker
11: rayon::iter::plumbing::bridge_unindexed_producer_consumer
12: rayon_core::registry::in_worker
13: rayon::iter::plumbing::bridge_unindexed_producer_consumer
14: rayon_core::registry::in_worker
15: rayon::iter::plumbing::bridge_unindexed_producer_consumer
16: rayon_core::registry::in_worker
17: rayon::iter::plumbing::bridge_unindexed_producer_consumer
18: rayon_core::registry::in_worker
19: rayon::iter::plumbing::bridge_unindexed_producer_consumer
20: rayon_core::join::join_context::{{closure}}
21: rayon_core::unwind::halt_unwinding
22: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
23: rayon_core::registry::WorkerThread::wait_until_cold
24: rayon_core::registry::ThreadBuilder::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at 'assertion failed: btree::del::del(self, &mut db, &f, None)?', /Users/z/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/sanakirja-1.2.5/src/environment/muttxn.rs:405:9
stack backtrace:
0: rust_begin_unwind
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:50:5
3: <sanakirja::environment::muttxn::MutTxn<E,T> as sanakirja_core::AllocPage>::alloc_page
4: sanakirja_core::btree::page::put::put
5: sanakirja_core::btree::put::put
6: sdb::dbpage::DbPage<K,V,P,RK,RV>::put
7: <rayon::iter::map_with::MapWithFolder<C,U,F> as rayon::iter::plumbing::Folder<T>>::consume
8: <rayon::iter::par_bridge::IterParallelProducer<Iter> as rayon::iter::plumbing::UnindexedProducer>::fold_with
9: rayon::iter::plumbing::bridge_unindexed_producer_consumer
10: rayon_core::registry::in_worker
11: rayon::iter::plumbing::bridge_unindexed_producer_consumer
12: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
13: rayon_core::registry::WorkerThread::wait_until_cold
14: rayon_core::registry::ThreadBuilder::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at 'assertion failed: btree::del::del(self, &mut db, &f, None)?', /Users/z/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/sanakirja-1.2.5/src/environment/muttxn.rs:405:9
stack backtrace:
0: rust_begin_unwind
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:50:5
3: <sanakirja::environment::muttxn::MutTxn<E,T> as sanakirja_core::AllocPage>::alloc_page
4: sanakirja_core::btree::page::put::put
5: sanakirja_core::btree::put::put
6: sdb::dbpage::DbPage<K,V,P,RK,RV>::put
7: <rayon::iter::map_with::MapWithFolder<C,U,F> as rayon::iter::plumbing::Folder<T>>::consume
8: <rayon::iter::par_bridge::IterParallelProducer<Iter> as rayon::iter::plumbing::UnindexedProducer>::fold_with
9: rayon::iter::plumbing::bridge_unindexed_producer_consumer
10: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
11: rayon_core::registry::WorkerThread::wait_until_cold
12: rayon_core::registry::ThreadBuilder::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at 'assertion failed: btree::del::del(self, &mut db, &f, None)?', /Users/z/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/sanakirja-1.2.5/src/environment/muttxn.rs:405:9
stack backtrace:
0: rust_begin_unwind
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:50:5
3: <sanakirja::environment::muttxn::MutTxn<E,T> as sanakirja_core::AllocPage>::alloc_page
4: sanakirja_core::btree::page::put::put
5: sanakirja_core::btree::put::put
6: sdb::dbpage::DbPage<K,V,P,RK,RV>::put
7: <rayon::iter::map_with::MapWithFolder<C,U,F> as rayon::iter::plumbing::Folder<T>>::consume
8: <rayon::iter::par_bridge::IterParallelProducer<Iter> as rayon::iter::plumbing::UnindexedProducer>::fold_with
9: rayon::iter::plumbing::bridge_unindexed_producer_consumer
10: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
11: rayon_core::registry::WorkerThread::wait_until_cold
12: rayon_core::registry::ThreadBuilder::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at 'assertion failed: btree::del::del(self, &mut db, &f, None)?', /Users/z/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/sanakirja-1.2.5/src/environment/muttxn.rs:405:9
stack backtrace:
0: rust_begin_unwind
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:50:5
3: <sanakirja::environment::muttxn::MutTxn<E,T> as sanakirja_core::AllocPage>::alloc_page
4: sanakirja_core::btree::page::put::put
5: sanakirja_core::btree::put::put
6: sdb::dbpage::DbPage<K,V,P,RK,RV>::put
7: <rayon::iter::map_with::MapWithFolder<C,U,F> as rayon::iter::plumbing::Folder<T>>::consume
8: <rayon::iter::par_bridge::IterParallelProducer<Iter> as rayon::iter::plumbing::UnindexedProducer>::fold_with
9: rayon::iter::plumbing::bridge_unindexed_producer_consumer
10: rayon_core::registry::in_worker
11: rayon::iter::plumbing::bridge_unindexed_producer_consumer
12: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
13: rayon_core::registry::WorkerThread::wait_until_cold
14: rayon_core::registry::ThreadBuilder::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at 'assertion failed: btree::del::del(self, &mut db, &f, None)?', /Users/z/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/sanakirja-1.2.5/src/environment/muttxn.rs:405:9
stack backtrace:
0: rust_begin_unwind
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:50:5
3: <sanakirja::environment::muttxn::MutTxn<E,T> as sanakirja_core::AllocPage>::alloc_page
4: sanakirja_core::btree::page::put::put
5: sanakirja_core::btree::put::put
6: sdb::dbpage::DbPage<K,V,P,RK,RV>::put
7: <rayon::iter::map_with::MapWithFolder<C,U,F> as rayon::iter::plumbing::Folder<T>>::consume
8: <rayon::iter::par_bridge::IterParallelProducer<Iter> as rayon::iter::plumbing::UnindexedProducer>::fold_with
9: rayon::iter::plumbing::bridge_unindexed_producer_consumer
10: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
11: rayon_core::registry::WorkerThread::wait_until_cold
12: rayon_core::registry::ThreadBuilder::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at 'assertion failed: btree::del::del(self, &mut db, &f, None)?', /Users/z/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/sanakirja-1.2.5/src/environment/muttxn.rs:405:9
stack backtrace:
0: rust_begin_unwind
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:50:5
3: <sanakirja::environment::muttxn::MutTxn<E,T> as sanakirja_core::AllocPage>::alloc_page
4: sanakirja_core::btree::page::put::put
5: sanakirja_core::btree::put::put
6: sdb::dbpage::DbPage<K,V,P,RK,RV>::put
7: <rayon::iter::map_with::MapWithFolder<C,U,F> as rayon::iter::plumbing::Folder<T>>::consume
8: <rayon::iter::par_bridge::IterParallelProducer<Iter> as rayon::iter::plumbing::UnindexedProducer>::fold_with
9: rayon::iter::plumbing::bridge_unindexed_producer_consumer
10: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
11: rayon_core::registry::WorkerThread::wait_until_cold
12: rayon_core::registry::ThreadBuilder::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at 'assertion failed: btree::del::del(self, &mut db, &f, None)?', /Users/z/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/sanakirja-1.2.5/src/environment/muttxn.rs:405:9
stack backtrace:
0: rust_begin_unwind
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:50:5
3: <sanakirja::environment::muttxn::MutTxn<E,T> as sanakirja_core::AllocPage>::alloc_page
4: sanakirja_core::btree::page::put::put
5: sanakirja_core::btree::put::put
6: sdb::dbpage::DbPage<K,V,P,RK,RV>::put
7: <rayon::iter::map_with::MapWithFolder<C,U,F> as rayon::iter::plumbing::Folder<T>>::consume
8: <rayon::iter::par_bridge::IterParallelProducer<Iter> as rayon::iter::plumbing::UnindexedProducer>::fold_with
9: rayon::iter::plumbing::bridge_unindexed_producer_consumer
10: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
11: rayon_core::registry::WorkerThread::wait_until_cold
12: rayon_core::registry::ThreadBuilder::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at 'assertion failed: btree::del::del(self, &mut db, &f, None)?', /Users/z/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/sanakirja-1.2.5/src/environment/muttxn.rs:405:9
stack backtrace:
0: rust_begin_unwind
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:50:5
3: <sanakirja::environment::muttxn::MutTxn<E,T> as sanakirja_core::AllocPage>::alloc_page
4: sanakirja_core::btree::page::put::put
5: sanakirja_core::btree::put::put
6: sdb::dbpage::DbPage<K,V,P,RK,RV>::put
7: <rayon::iter::map_with::MapWithFolder<C,U,F> as rayon::iter::plumbing::Folder<T>>::consume
8: <rayon::iter::par_bridge::IterParallelProducer<Iter> as rayon::iter::plumbing::UnindexedProducer>::fold_with
9: rayon::iter::plumbing::bridge_unindexed_producer_consumer
10: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
11: rayon_core::registry::WorkerThread::wait_until_cold
12: rayon_core::join::join_recover_from_panic
13: rayon_core::registry::in_worker
14: rayon::iter::plumbing::bridge_unindexed_producer_consumer
15: rayon_core::registry::in_worker
16: rayon::iter::plumbing::bridge_unindexed_producer_consumer
17: rayon_core::registry::in_worker
18: rayon::iter::plumbing::bridge_unindexed_producer_consumer
19: rayon_core::registry::in_worker
20: rayon::iter::plumbing::bridge_unindexed_producer_consumer
21: rayon_core::registry::in_worker
22: rayon::iter::plumbing::bridge_unindexed_producer_consumer
23: rayon_core::join::join_context::{{closure}}
24: rayon_core::unwind::halt_unwinding
25: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
26: rayon_core::registry::WorkerThread::wait_until_cold
27: rayon_core::registry::ThreadBuilder::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread 'main' panicked at 'assertion failed: btree::del::del(self, &mut db, &f, None)?', /Users/z/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/sanakirja-1.2.5/src/environment/muttxn.rs:405:9
stack backtrace:
0: rust_begin_unwind
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/6d820866a27b1949e237be79b9c8c0145fe728b7/library/core/src/panicking.rs:50:5
3: <sanakirja::environment::muttxn::MutTxn<E,T> as sanakirja_core::AllocPage>::alloc_page
4: sanakirja_core::btree::page_unsized::put::put
5: sanakirja_core::btree::put::put
6: sdb::dbpage::DbPage<K,V,P,RK,RV>::upsert
7: train::word_huffman
8: train::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
I added the train txt into git repo ,
so just git clone https://github.com/gcxfd/rmw-utf8.git
and
cd train
rm -rf cache && ./train.sh
can see error
crash on read
crash on write