Introduce an indexation abortion function when indexing documents

This commit is contained in:
Kerollmops 2022-10-05 17:41:07 +02:00
parent fad0de4581
commit 6603437cb1
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
14 changed files with 379 additions and 136 deletions

View file

@ -138,15 +138,17 @@ impl<'a, 'i> Transform<'a, 'i> {
})
}
pub fn read_documents<R, F>(
pub fn read_documents<R, FP, FA>(
&mut self,
reader: EnrichedDocumentsBatchReader<R>,
wtxn: &mut heed::RwTxn,
progress_callback: F,
progress_callback: FP,
should_abort: FA,
) -> Result<usize>
where
R: Read + Seek,
F: Fn(UpdateIndexingStep) + Sync,
FP: Fn(UpdateIndexingStep) + Sync,
FA: Fn() -> bool + Sync,
{
let (mut cursor, fields_index) = reader.into_cursor_and_fields_index();
@ -165,6 +167,10 @@ impl<'a, 'i> Transform<'a, 'i> {
while let Some(enriched_document) = cursor.next_enriched_document()? {
let EnrichedDocument { document, document_id } = enriched_document;
if should_abort() {
return Err(Error::InternalError(InternalError::AbortedIndexation));
}
// drop_and_reuse is called instead of .clear() to communicate to the compiler that field_buffer
// does not keep references from the cursor between loop iterations
let mut field_buffer_cache = drop_and_reuse(field_buffer);