Description
I am developing a B+ plus tree which its page size is controlled by generic typing arrays.
Before I put it on large scale, I did tried to write tests and it works. When I tried to set the page size as large as 240000
. I got stack overflow error. I have nailed the problem to one function and write a test for it but the behaviour looks strange to me. The test code, which is:
const LARGE_PAGE_SIZE: usize = 240000;
struct LargeKeySlice {
inner: [EntryKey; LARGE_PAGE_SIZE]
}
type LargePtrSlice = [NodeCellRef; LARGE_PAGE_SIZE + 1];
type LargeLevelBPlusTree = BPlusTree<LargeKeySlice, LargePtrSlice>;
#[test]
#[should_panic]
fn large_page() {
// this test should panic but not stack overflow
env_logger::init();
debug!("testing");
ExtNode::<LargeKeySlice, LargePtrSlice>::new(Id::rand(), smallvec!(0));
}
It have a debug
macro which will print testing
before the new
function to be invoked. The test case actually overflows stack without printing testing
. If we replace the new
function with panic!()
, it will pass the test with testing
been printed. The most interesting part is, if we clear the new
function and make an explicit panic, it still overflow stack.
If we decrease LARGE_PAGE_SIZE
to 24000
, the test case will panic without overflow stack, which is exactly what I expected. This problem does not seems like my problem for the new
function have not been invoked during the stack overflow.
Because I have no clue about how this happened, I was unable to replicate this issue on playground. As far as my attempt, this works without stack overflow
Feel free to checkout and play around by
cargo test --package neb --lib index::btree::test::large_page -- --nocapture
Error
thread 'main' has overflowed its stack
fatal runtime error: stack overflow
error: process didn't exit successfully: `/Users/shisoft/Documents/OSS Projects/Nebuchadnezzar/target/debug/deps/neb-96fd92871c91115d 'index::lsmtree::test::insertions' --nocapture --test-threads=1` (signal: 6, SIGABRT: process abort signal)
Rust Version
rustc 1.34.0-nightly (f6fac4225 2019-02-03)