fix the index deletion when the index doesn’t exists but would be created by one of the autobatched tasks

This commit is contained in:
Irevoire 2022-10-20 13:18:25 +02:00 committed by Clément Renault
parent f816dc5221
commit f1acafcf1c
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
2 changed files with 52 additions and 4 deletions

View file

@ -74,6 +74,7 @@ pub(crate) enum Batch {
IndexDeletion {
index_uid: String,
tasks: Vec<Task>,
index_has_been_created: bool,
},
IndexSwap {
task: Task,
@ -444,6 +445,7 @@ impl IndexScheduler {
}
BatchKind::IndexDeletion { ids } => Ok(Some(Batch::IndexDeletion {
index_uid,
index_has_been_created: must_create_index,
tasks: self.get_existing_tasks(rtxn, ids)?,
})),
BatchKind::IndexSwap { id } => {
@ -796,18 +798,25 @@ impl IndexScheduler {
}
Batch::IndexDeletion {
index_uid,
index_has_been_created,
mut tasks,
} => {
let wtxn = self.env.write_txn()?;
let number_of_documents = {
// it's possible that the index doesn't exist
let number_of_documents = || -> Result<u64> {
let index = self.index_mapper.index(&wtxn, &index_uid)?;
let index_rtxn = index.read_txn()?;
index.number_of_documents(&index_rtxn)?
};
Ok(index.number_of_documents(&index_rtxn)?)
}()
.unwrap_or_default();
// The write transaction is directly owned and commited inside.
self.index_mapper.delete_index(wtxn, &index_uid)?;
match self.index_mapper.delete_index(wtxn, &index_uid) {
Ok(()) => (),
Err(Error::IndexNotFound(_)) if index_has_been_created => (),
Err(e) => return Err(e),
}
// We set all the tasks details to the default value.
for task in &mut tasks {