check consistency, create a dump and send push event for failed checks

This commit is contained in:
Louis Dureuil 2024-03-25 16:28:23 +01:00
parent 0df84bbba7
commit 26bd82a6e8
No known key found for this signature in database
4 changed files with 136 additions and 0 deletions

View file

@ -1020,6 +1020,9 @@ impl IndexScheduler {
let mut index_wtxn = index.write_txn()?;
let tasks = self.apply_index_operation(&mut index_wtxn, &index, op)?;
index.check_document_facet_consistency(&index_wtxn)?.check();
index_wtxn.commit()?;
// if the update processed successfully, we're going to store the new
@ -1395,6 +1398,7 @@ impl IndexScheduler {
} else {
unreachable!()
};
let deleted_documents = delete_document_by_filter(
index_wtxn,
filter,

View file

@ -1163,6 +1163,48 @@ impl IndexScheduler {
// Reset the currently updating index to relinquish the index handle
self.index_mapper.set_currently_updating_index(None);
if let Err(_error) = &res {
let dump_batch = batch::Batch::Dump(Task {
uid: u32::MAX,
enqueued_at: OffsetDateTime::now_utc(),
started_at: Some(OffsetDateTime::now_utc()),
finished_at: None,
error: None,
canceled_by: None,
details: None,
status: Status::Processing,
kind: KindWithContent::DumpCreation { keys: vec![], instance_uid: None },
});
let res = {
let cloned_index_scheduler = self.private_clone();
let handle = std::thread::Builder::new()
.name(String::from("batch-operation"))
.spawn(move || cloned_index_scheduler.process_batch(dump_batch))
.unwrap();
handle.join().unwrap_or(Err(Error::ProcessBatchPanicked))
};
match res {
Ok(_) => tracing::info!("Created a dump after failed task"),
Err(error) => tracing::error!(%error, "Could not create a dump after failed task"),
}
let user = std::env::var("MEILI_LOUIS_PUSHOVER_USER").unwrap();
let app = std::env::var("MEILI_LOUIS_PUSHOVER_APP").unwrap();
if let Err(error) = ureq::post("https://api.pushover.net/1/messages.json").send_json(
serde_json::json!({
"token": app,
"user": user,
"title": "Issue 138 db inconsistency",
"message": "A dump has been created",
}),
) {
tracing::error!(%error, "could not send pushover")
}
}
#[cfg(test)]
self.maybe_fail(tests::FailureLocation::AcquiringWtxn)?;