From 493a8cff3155e5ba61e9896475d59c9f5c209076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Mon, 24 Oct 2022 08:12:03 +0200 Subject: [PATCH] Adjust task details correctly following index swap --- index-scheduler/src/lib.rs | 13 +++++++++ .../swap_indexes/second_swap_processed.snap | 2 +- index-scheduler/src/utils.rs | 29 +++++++++++++++---- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index b4a38f49c..a208214d8 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -1373,12 +1373,20 @@ mod tests { for task in to_enqueue { let _ = index_scheduler.register(task).unwrap(); + index_scheduler.assert_internally_consistent(); } handle.wait_till(Breakpoint::AfterProcessing); + index_scheduler.assert_internally_consistent(); + handle.wait_till(Breakpoint::AfterProcessing); + index_scheduler.assert_internally_consistent(); + handle.wait_till(Breakpoint::AfterProcessing); + index_scheduler.assert_internally_consistent(); + handle.wait_till(Breakpoint::AfterProcessing); + index_scheduler.assert_internally_consistent(); snapshot!(snapshot_index_scheduler(&index_scheduler), name: "initial_tasks_processed"); @@ -1387,14 +1395,19 @@ mod tests { swaps: vec![("a".to_owned(), "b".to_owned()), ("c".to_owned(), "d".to_owned())], }) .unwrap(); + index_scheduler.assert_internally_consistent(); handle.wait_till(Breakpoint::AfterProcessing); + index_scheduler.assert_internally_consistent(); snapshot!(snapshot_index_scheduler(&index_scheduler), name: "first_swap_processed"); index_scheduler .register(KindWithContent::IndexSwap { swaps: vec![("a".to_owned(), "c".to_owned())] }) .unwrap(); + index_scheduler.assert_internally_consistent(); + handle.wait_till(Breakpoint::AfterProcessing); + index_scheduler.assert_internally_consistent(); snapshot!(snapshot_index_scheduler(&index_scheduler), name: "second_swap_processed"); } diff --git a/index-scheduler/src/snapshots/lib.rs/swap_indexes/second_swap_processed.snap b/index-scheduler/src/snapshots/lib.rs/swap_indexes/second_swap_processed.snap index 543a0afa4..7cb38dbbd 100644 --- a/index-scheduler/src/snapshots/lib.rs/swap_indexes/second_swap_processed.snap +++ b/index-scheduler/src/snapshots/lib.rs/swap_indexes/second_swap_processed.snap @@ -10,7 +10,7 @@ source: index-scheduler/src/lib.rs 1 {uid: 1, status: succeeded, details: { primary_key: Some("id") }, kind: IndexCreation { index_uid: "c", primary_key: Some("id") }} 2 {uid: 2, status: succeeded, details: { primary_key: Some("id") }, kind: IndexCreation { index_uid: "d", primary_key: Some("id") }} 3 {uid: 3, status: succeeded, details: { primary_key: Some("id") }, kind: IndexCreation { index_uid: "a", primary_key: Some("id") }} -4 {uid: 4, status: succeeded, details: { indexes: [("a", "b"), ("c", "d")] }, kind: IndexSwap { swaps: [("c", "b"), ("a", "d")] }} +4 {uid: 4, status: succeeded, details: { indexes: [("c", "b"), ("a", "d")] }, kind: IndexSwap { swaps: [("c", "b"), ("a", "d")] }} 5 {uid: 5, status: succeeded, details: { indexes: [("a", "c")] }, kind: IndexSwap { swaps: [("a", "c")] }} ---------------------------------------------------------------------- ### Status: diff --git a/index-scheduler/src/utils.rs b/index-scheduler/src/utils.rs index f95d5c782..ee24fc593 100644 --- a/index-scheduler/src/utils.rs +++ b/index-scheduler/src/utils.rs @@ -5,7 +5,7 @@ use std::ops::Bound; use meilisearch_types::heed::types::{DecodeIgnore, OwnedType}; use meilisearch_types::heed::{Database, RoTxn, RwTxn}; use meilisearch_types::milli::{CboRoaringBitmapCodec, BEU32}; -use meilisearch_types::tasks::{Kind, KindWithContent, Status}; +use meilisearch_types::tasks::{Details, Kind, KindWithContent, Status}; use roaring::{MultiOps, RoaringBitmap}; use time::OffsetDateTime; @@ -270,6 +270,22 @@ pub fn swap_index_uid_in_task(task: &mut Task, swap: (&str, &str)) { | K::DumpCreation { .. } | K::Snapshot => {} }; + match &mut task.details { + Some(details) => match details { + Details::IndexSwap { swaps } => { + for (lhs, rhs) in swaps.iter_mut() { + if lhs == swap.0 || lhs == swap.1 { + index_uids.push(lhs); + } + if rhs == swap.0 || rhs == swap.1 { + index_uids.push(rhs); + } + } + } + _ => {} + }, + None => {} + } for index_uid in index_uids { if index_uid == swap.0 { *index_uid = swap.1.to_owned(); @@ -279,8 +295,6 @@ pub fn swap_index_uid_in_task(task: &mut Task, swap: (&str, &str)) { } } #[cfg(test)] -use meilisearch_types::tasks::Details; -#[cfg(test)] impl IndexScheduler { /// Asserts that the index scheduler's content is internally consistent. pub fn assert_internally_consistent(&self) { @@ -347,9 +361,12 @@ impl IndexScheduler { } match details { Some(details) => match details { - Details::IndexSwap { swaps } => { - todo!() - } + Details::IndexSwap { swaps: sw1 } => match &kind { + KindWithContent::IndexSwap { swaps: sw2 } => { + assert_eq!(&sw1, sw2); + } + _ => panic!(), + }, Details::DocumentAdditionOrUpdate { received_documents, indexed_documents } => { assert_eq!(kind.as_kind(), Kind::DocumentAdditionOrUpdate); if let Some(indexed_documents) = indexed_documents {