handle the panic happening in milli

This commit is contained in:
Tamo 2023-05-29 13:39:26 +02:00
parent 99e9057684
commit 67a583bedf
No known key found for this signature in database
GPG Key ID: 20CD8020AFA88D69

View File

@ -34,7 +34,6 @@ struct Opt {
/// diskutil erasevolume HFS+ 'RAM Disk' `hdiutil attach -nobrowse -nomount ram://4194304 # create it /// diskutil erasevolume HFS+ 'RAM Disk' `hdiutil attach -nobrowse -nomount ram://4194304 # create it
/// ///
/// hdiutil detach /dev/:the_disk /// hdiutil detach /dev/:the_disk
///
#[clap(long)] #[clap(long)]
path: Option<PathBuf>, path: Option<PathBuf>,
} }
@ -60,14 +59,17 @@ fn main() {
let indexer_config = IndexerConfig::default(); let indexer_config = IndexerConfig::default();
let index_documents_config = IndexDocumentsConfig::default(); let index_documents_config = IndexDocumentsConfig::default();
std::thread::scope(|s| {
loop { loop {
let v: Vec<u8> = std::iter::repeat_with(|| fastrand::u8(..)).take(1000).collect(); let v: Vec<u8> =
std::iter::repeat_with(|| fastrand::u8(..)).take(1000).collect();
let mut data = Unstructured::new(&v); let mut data = Unstructured::new(&v);
let batches = <[Batch; 5]>::arbitrary(&mut data).unwrap(); let batches = <[Batch; 5]>::arbitrary(&mut data).unwrap();
// will be used to display the error once a thread crashes // will be used to display the error once a thread crashes
let dbg_input = format!("{:#?}", batches); let dbg_input = format!("{:#?}", batches);
let handle = s.spawn(|| {
let mut wtxn = index.write_txn().unwrap(); let mut wtxn = index.write_txn().unwrap();
for batch in batches { for batch in batches {
@ -90,8 +92,7 @@ fn main() {
milli::documents::documents_batch_reader_from_objects( milli::documents::documents_batch_reader_from_objects(
documents, documents,
); );
let (b, _added) = let (b, _added) = builder.add_documents(documents).unwrap();
builder.add_documents(documents).expect(&dbg_input);
builder = b; builder = b;
} }
Operation::DeleteDoc(id) => { Operation::DeleteDoc(id) => {
@ -101,16 +102,19 @@ fn main() {
} }
} }
} }
builder.execute().expect(&dbg_input); builder.execute().unwrap();
// after executing a batch we check if the database is corrupted // after executing a batch we check if the database is corrupted
let res = index.search(&wtxn).execute().expect(&dbg_input); let res = index.search(&wtxn).execute().unwrap();
index.documents(&wtxn, res.documents_ids).expect(&dbg_input); index.documents(&wtxn, res.documents_ids).unwrap();
progression.fetch_add(1, Ordering::Relaxed); progression.fetch_add(1, Ordering::Relaxed);
} }
wtxn.abort().unwrap(); wtxn.abort().unwrap();
});
handle.join().expect(&dbg_input);
} }
}); });
});
handles.push(handle); handles.push(handle);
} }