From e0c97325d6f5d733e41b182883cc4bf3fed11e00 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Tue, 23 Sep 2025 16:34:28 +0200 Subject: [PATCH] Allow to register a NetworkTopologyChange task --- crates/dump/src/lib.rs | 6 ++++ crates/index-scheduler/src/dump.rs | 3 ++ crates/index-scheduler/src/insta_snapshot.rs | 3 ++ .../src/scheduler/autobatcher.rs | 3 +- crates/index-scheduler/src/utils.rs | 4 +++ crates/meilisearch-types/src/task_view.rs | 11 +++++++ crates/meilisearch-types/src/tasks.rs | 30 +++++++++++++++++-- 7 files changed, 57 insertions(+), 3 deletions(-) diff --git a/crates/dump/src/lib.rs b/crates/dump/src/lib.rs index a926388b3..efd26adf9 100644 --- a/crates/dump/src/lib.rs +++ b/crates/dump/src/lib.rs @@ -158,6 +158,9 @@ pub enum KindDump { UpgradeDatabase { from: (u32, u32, u32), }, + NetworkTopologyChange { + network: Option, + }, } impl From for TaskDump { @@ -240,6 +243,9 @@ impl From for KindDump { KindWithContent::UpgradeDatabase { from: version } => { KindDump::UpgradeDatabase { from: version } } + KindWithContent::NetworkTopologyChange { network } => { + KindDump::NetworkTopologyChange { network } + } } } } diff --git a/crates/index-scheduler/src/dump.rs b/crates/index-scheduler/src/dump.rs index e5e7a5d8c..c0f710e3d 100644 --- a/crates/index-scheduler/src/dump.rs +++ b/crates/index-scheduler/src/dump.rs @@ -234,6 +234,9 @@ impl<'a> Dump<'a> { } } KindDump::UpgradeDatabase { from } => KindWithContent::UpgradeDatabase { from }, + KindDump::NetworkTopologyChange { network: new_network } => { + KindWithContent::NetworkTopologyChange { network: new_network } + } }, }; diff --git a/crates/index-scheduler/src/insta_snapshot.rs b/crates/index-scheduler/src/insta_snapshot.rs index df043ad87..e44e241a3 100644 --- a/crates/index-scheduler/src/insta_snapshot.rs +++ b/crates/index-scheduler/src/insta_snapshot.rs @@ -317,6 +317,9 @@ fn snapshot_details(d: &Details) -> String { Details::UpgradeDatabase { from, to } => { format!("{{ from: {from:?}, to: {to:?} }}") } + Details::NetworkTopologyChange { network: new_network } => { + format!("{{ new_network: {new_network:?} }}") + } } } diff --git a/crates/index-scheduler/src/scheduler/autobatcher.rs b/crates/index-scheduler/src/scheduler/autobatcher.rs index a88a9f0bf..c5f07804c 100644 --- a/crates/index-scheduler/src/scheduler/autobatcher.rs +++ b/crates/index-scheduler/src/scheduler/autobatcher.rs @@ -73,6 +73,7 @@ impl From for AutobatchKind { | KindWithContent::DumpCreation { .. } | KindWithContent::Export { .. } | KindWithContent::UpgradeDatabase { .. } + | KindWithContent::NetworkTopologyChange { .. } | KindWithContent::SnapshotCreation => { panic!("The autobatcher should never be called with tasks that don't apply to an index.") } @@ -287,7 +288,7 @@ impl BatchKind { }; match (self, autobatch_kind) { - // We don't batch any of these operations + // We don't batch any of these operations (this, K::IndexCreation | K::IndexUpdate | K::IndexSwap | K::DocumentEdition) => Break((this, BatchStopReason::TaskCannotBeBatched { kind, id })), // We must not batch tasks that don't have the same index creation rights if the index doesn't already exists. (this, kind) if !index_already_exists && this.allow_index_creation() == Some(false) && kind.allow_index_creation() == Some(true) => { diff --git a/crates/index-scheduler/src/utils.rs b/crates/index-scheduler/src/utils.rs index 2617aba99..dde6c8e67 100644 --- a/crates/index-scheduler/src/utils.rs +++ b/crates/index-scheduler/src/utils.rs @@ -285,6 +285,7 @@ pub fn swap_index_uid_in_task(task: &mut Task, swap: (&str, &str)) { | K::DumpCreation { .. } | K::Export { .. } | K::UpgradeDatabase { .. } + | K::NetworkTopologyChange { .. } | K::SnapshotCreation => (), }; if let Some(Details::IndexSwap { swaps }) = &mut task.details { @@ -618,6 +619,9 @@ impl crate::IndexScheduler { Details::UpgradeDatabase { from: _, to: _ } => { assert_eq!(kind.as_kind(), Kind::UpgradeDatabase); } + Details::NetworkTopologyChange { .. } => { + assert_eq!(kind.as_kind(), Kind::NetworkTopologyChange); + } } } diff --git a/crates/meilisearch-types/src/task_view.rs b/crates/meilisearch-types/src/task_view.rs index cbc29a11b..23160759f 100644 --- a/crates/meilisearch-types/src/task_view.rs +++ b/crates/meilisearch-types/src/task_view.rs @@ -7,6 +7,7 @@ use time::{Duration, OffsetDateTime}; use utoipa::ToSchema; use crate::batches::BatchId; +use crate::enterprise_edition::network::Network; use crate::error::ResponseError; use crate::settings::{Settings, Unchecked}; use crate::tasks::{ @@ -142,6 +143,9 @@ pub struct DetailsView { pub old_index_uid: Option, #[serde(skip_serializing_if = "Option::is_none")] pub new_index_uid: Option, + // network + #[serde(skip_serializing_if = "Option::is_none")] + pub network: Option, } impl DetailsView { @@ -314,6 +318,10 @@ impl DetailsView { // We should never be able to batch multiple renames at the same time. (Some(left), Some(_right)) => Some(left), }, + network: match (&self.network, &other.network) { + (None, None) => None, + (_, Some(network)) | (Some(network), None) => Some(network.clone()), + }, } } } @@ -415,6 +423,9 @@ impl From
for DetailsView { upgrade_to: Some(format!("v{}.{}.{}", to.0, to.1, to.2)), ..Default::default() }, + Details::NetworkTopologyChange { network: new_network } => { + DetailsView { network: new_network, ..Default::default() } + } } } } diff --git a/crates/meilisearch-types/src/tasks.rs b/crates/meilisearch-types/src/tasks.rs index d0f668255..dedaf1e7f 100644 --- a/crates/meilisearch-types/src/tasks.rs +++ b/crates/meilisearch-types/src/tasks.rs @@ -15,6 +15,7 @@ use utoipa::{schema, ToSchema}; use uuid::Uuid; use crate::batches::BatchId; +use crate::enterprise_edition::network::Network; use crate::error::ResponseError; use crate::index_uid_pattern::IndexUidPattern; use crate::keys::Key; @@ -58,6 +59,7 @@ impl Task { | TaskDeletion { .. } | Export { .. } | UpgradeDatabase { .. } + | NetworkTopologyChange { .. } | IndexSwap { .. } => None, DocumentAdditionOrUpdate { index_uid, .. } | DocumentEdition { index_uid, .. } @@ -94,7 +96,8 @@ impl Task { | KindWithContent::DumpCreation { .. } | KindWithContent::SnapshotCreation | KindWithContent::Export { .. } - | KindWithContent::UpgradeDatabase { .. } => None, + | KindWithContent::UpgradeDatabase { .. } + | KindWithContent::NetworkTopologyChange { .. } => None, } } } @@ -170,6 +173,9 @@ pub enum KindWithContent { UpgradeDatabase { from: (u32, u32, u32), }, + NetworkTopologyChange { + network: Option, + }, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)] @@ -206,6 +212,7 @@ impl KindWithContent { KindWithContent::SnapshotCreation => Kind::SnapshotCreation, KindWithContent::Export { .. } => Kind::Export, KindWithContent::UpgradeDatabase { .. } => Kind::UpgradeDatabase, + KindWithContent::NetworkTopologyChange { .. } => Kind::NetworkTopologyChange, } } @@ -218,6 +225,7 @@ impl KindWithContent { | TaskCancelation { .. } | TaskDeletion { .. } | Export { .. } + | NetworkTopologyChange { .. } | UpgradeDatabase { .. } => vec![], DocumentAdditionOrUpdate { index_uid, .. } | DocumentEdition { index_uid, .. } @@ -325,6 +333,9 @@ impl KindWithContent { versioning::VERSION_PATCH, ), }), + KindWithContent::NetworkTopologyChange { network: new_network } => { + Some(Details::NetworkTopologyChange { network: new_network.clone() }) + } } } @@ -407,6 +418,9 @@ impl KindWithContent { versioning::VERSION_PATCH, ), }), + KindWithContent::NetworkTopologyChange { network: new_network } => { + Some(Details::NetworkTopologyChange { network: new_network.clone() }) + } } } } @@ -469,6 +483,9 @@ impl From<&KindWithContent> for Option
{ versioning::VERSION_PATCH, ), }), + KindWithContent::NetworkTopologyChange { network: new_network } => { + Some(Details::NetworkTopologyChange { network: new_network.clone() }) + } } } } @@ -579,6 +596,7 @@ pub enum Kind { SnapshotCreation, Export, UpgradeDatabase, + NetworkTopologyChange, } impl Kind { @@ -597,7 +615,8 @@ impl Kind { | Kind::DumpCreation | Kind::Export | Kind::UpgradeDatabase - | Kind::SnapshotCreation => false, + | Kind::SnapshotCreation + | Kind::NetworkTopologyChange => false, } } } @@ -618,6 +637,7 @@ impl Display for Kind { Kind::SnapshotCreation => write!(f, "snapshotCreation"), Kind::Export => write!(f, "export"), Kind::UpgradeDatabase => write!(f, "upgradeDatabase"), + Kind::NetworkTopologyChange => write!(f, "networkTopologyChange"), } } } @@ -653,6 +673,8 @@ impl FromStr for Kind { Ok(Kind::Export) } else if kind.eq_ignore_ascii_case("upgradeDatabase") { Ok(Kind::UpgradeDatabase) + } else if kind.eq_ignore_ascii_case("networkTopologyChange") { + Ok(Kind::NetworkTopologyChange) } else { Err(ParseTaskKindError(kind.to_owned())) } @@ -738,6 +760,9 @@ pub enum Details { from: (u32, u32, u32), to: (u32, u32, u32), }, + NetworkTopologyChange { + network: Option, + }, } #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, ToSchema)] @@ -805,6 +830,7 @@ impl Details { | Self::Dump { .. } | Self::Export { .. } | Self::UpgradeDatabase { .. } + | Self::NetworkTopologyChange { .. } | Self::IndexSwap { .. } => (), }