Allow to register a NetworkTopologyChange task

This commit is contained in:
Louis Dureuil
2025-09-23 16:34:28 +02:00
parent 0f3ef8de73
commit e0c97325d6
7 changed files with 57 additions and 3 deletions

View File

@@ -158,6 +158,9 @@ pub enum KindDump {
UpgradeDatabase { UpgradeDatabase {
from: (u32, u32, u32), from: (u32, u32, u32),
}, },
NetworkTopologyChange {
network: Option<meilisearch_types::enterprise_edition::network::Network>,
},
} }
impl From<Task> for TaskDump { impl From<Task> for TaskDump {
@@ -240,6 +243,9 @@ impl From<KindWithContent> for KindDump {
KindWithContent::UpgradeDatabase { from: version } => { KindWithContent::UpgradeDatabase { from: version } => {
KindDump::UpgradeDatabase { from: version } KindDump::UpgradeDatabase { from: version }
} }
KindWithContent::NetworkTopologyChange { network } => {
KindDump::NetworkTopologyChange { network }
}
} }
} }
} }

View File

@@ -234,6 +234,9 @@ impl<'a> Dump<'a> {
} }
} }
KindDump::UpgradeDatabase { from } => KindWithContent::UpgradeDatabase { from }, KindDump::UpgradeDatabase { from } => KindWithContent::UpgradeDatabase { from },
KindDump::NetworkTopologyChange { network: new_network } => {
KindWithContent::NetworkTopologyChange { network: new_network }
}
}, },
}; };

View File

@@ -317,6 +317,9 @@ fn snapshot_details(d: &Details) -> String {
Details::UpgradeDatabase { from, to } => { Details::UpgradeDatabase { from, to } => {
format!("{{ from: {from:?}, to: {to:?} }}") format!("{{ from: {from:?}, to: {to:?} }}")
} }
Details::NetworkTopologyChange { network: new_network } => {
format!("{{ new_network: {new_network:?} }}")
}
} }
} }

View File

@@ -73,6 +73,7 @@ impl From<KindWithContent> for AutobatchKind {
| KindWithContent::DumpCreation { .. } | KindWithContent::DumpCreation { .. }
| KindWithContent::Export { .. } | KindWithContent::Export { .. }
| KindWithContent::UpgradeDatabase { .. } | KindWithContent::UpgradeDatabase { .. }
| KindWithContent::NetworkTopologyChange { .. }
| KindWithContent::SnapshotCreation => { | KindWithContent::SnapshotCreation => {
panic!("The autobatcher should never be called with tasks that don't apply to an index.") 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) { 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 })), (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. // 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) => { (this, kind) if !index_already_exists && this.allow_index_creation() == Some(false) && kind.allow_index_creation() == Some(true) => {

View File

@@ -285,6 +285,7 @@ pub fn swap_index_uid_in_task(task: &mut Task, swap: (&str, &str)) {
| K::DumpCreation { .. } | K::DumpCreation { .. }
| K::Export { .. } | K::Export { .. }
| K::UpgradeDatabase { .. } | K::UpgradeDatabase { .. }
| K::NetworkTopologyChange { .. }
| K::SnapshotCreation => (), | K::SnapshotCreation => (),
}; };
if let Some(Details::IndexSwap { swaps }) = &mut task.details { if let Some(Details::IndexSwap { swaps }) = &mut task.details {
@@ -618,6 +619,9 @@ impl crate::IndexScheduler {
Details::UpgradeDatabase { from: _, to: _ } => { Details::UpgradeDatabase { from: _, to: _ } => {
assert_eq!(kind.as_kind(), Kind::UpgradeDatabase); assert_eq!(kind.as_kind(), Kind::UpgradeDatabase);
} }
Details::NetworkTopologyChange { .. } => {
assert_eq!(kind.as_kind(), Kind::NetworkTopologyChange);
}
} }
} }

View File

@@ -7,6 +7,7 @@ use time::{Duration, OffsetDateTime};
use utoipa::ToSchema; use utoipa::ToSchema;
use crate::batches::BatchId; use crate::batches::BatchId;
use crate::enterprise_edition::network::Network;
use crate::error::ResponseError; use crate::error::ResponseError;
use crate::settings::{Settings, Unchecked}; use crate::settings::{Settings, Unchecked};
use crate::tasks::{ use crate::tasks::{
@@ -142,6 +143,9 @@ pub struct DetailsView {
pub old_index_uid: Option<String>, pub old_index_uid: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub new_index_uid: Option<String>, pub new_index_uid: Option<String>,
// network
#[serde(skip_serializing_if = "Option::is_none")]
pub network: Option<Network>,
} }
impl DetailsView { impl DetailsView {
@@ -314,6 +318,10 @@ impl DetailsView {
// We should never be able to batch multiple renames at the same time. // We should never be able to batch multiple renames at the same time.
(Some(left), Some(_right)) => Some(left), (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<Details> for DetailsView {
upgrade_to: Some(format!("v{}.{}.{}", to.0, to.1, to.2)), upgrade_to: Some(format!("v{}.{}.{}", to.0, to.1, to.2)),
..Default::default() ..Default::default()
}, },
Details::NetworkTopologyChange { network: new_network } => {
DetailsView { network: new_network, ..Default::default() }
}
} }
} }
} }

View File

@@ -15,6 +15,7 @@ use utoipa::{schema, ToSchema};
use uuid::Uuid; use uuid::Uuid;
use crate::batches::BatchId; use crate::batches::BatchId;
use crate::enterprise_edition::network::Network;
use crate::error::ResponseError; use crate::error::ResponseError;
use crate::index_uid_pattern::IndexUidPattern; use crate::index_uid_pattern::IndexUidPattern;
use crate::keys::Key; use crate::keys::Key;
@@ -58,6 +59,7 @@ impl Task {
| TaskDeletion { .. } | TaskDeletion { .. }
| Export { .. } | Export { .. }
| UpgradeDatabase { .. } | UpgradeDatabase { .. }
| NetworkTopologyChange { .. }
| IndexSwap { .. } => None, | IndexSwap { .. } => None,
DocumentAdditionOrUpdate { index_uid, .. } DocumentAdditionOrUpdate { index_uid, .. }
| DocumentEdition { index_uid, .. } | DocumentEdition { index_uid, .. }
@@ -94,7 +96,8 @@ impl Task {
| KindWithContent::DumpCreation { .. } | KindWithContent::DumpCreation { .. }
| KindWithContent::SnapshotCreation | KindWithContent::SnapshotCreation
| KindWithContent::Export { .. } | KindWithContent::Export { .. }
| KindWithContent::UpgradeDatabase { .. } => None, | KindWithContent::UpgradeDatabase { .. }
| KindWithContent::NetworkTopologyChange { .. } => None,
} }
} }
} }
@@ -170,6 +173,9 @@ pub enum KindWithContent {
UpgradeDatabase { UpgradeDatabase {
from: (u32, u32, u32), from: (u32, u32, u32),
}, },
NetworkTopologyChange {
network: Option<Network>,
},
} }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
@@ -206,6 +212,7 @@ impl KindWithContent {
KindWithContent::SnapshotCreation => Kind::SnapshotCreation, KindWithContent::SnapshotCreation => Kind::SnapshotCreation,
KindWithContent::Export { .. } => Kind::Export, KindWithContent::Export { .. } => Kind::Export,
KindWithContent::UpgradeDatabase { .. } => Kind::UpgradeDatabase, KindWithContent::UpgradeDatabase { .. } => Kind::UpgradeDatabase,
KindWithContent::NetworkTopologyChange { .. } => Kind::NetworkTopologyChange,
} }
} }
@@ -218,6 +225,7 @@ impl KindWithContent {
| TaskCancelation { .. } | TaskCancelation { .. }
| TaskDeletion { .. } | TaskDeletion { .. }
| Export { .. } | Export { .. }
| NetworkTopologyChange { .. }
| UpgradeDatabase { .. } => vec![], | UpgradeDatabase { .. } => vec![],
DocumentAdditionOrUpdate { index_uid, .. } DocumentAdditionOrUpdate { index_uid, .. }
| DocumentEdition { index_uid, .. } | DocumentEdition { index_uid, .. }
@@ -325,6 +333,9 @@ impl KindWithContent {
versioning::VERSION_PATCH, versioning::VERSION_PATCH,
), ),
}), }),
KindWithContent::NetworkTopologyChange { network: new_network } => {
Some(Details::NetworkTopologyChange { network: new_network.clone() })
}
} }
} }
@@ -407,6 +418,9 @@ impl KindWithContent {
versioning::VERSION_PATCH, versioning::VERSION_PATCH,
), ),
}), }),
KindWithContent::NetworkTopologyChange { network: new_network } => {
Some(Details::NetworkTopologyChange { network: new_network.clone() })
}
} }
} }
} }
@@ -469,6 +483,9 @@ impl From<&KindWithContent> for Option<Details> {
versioning::VERSION_PATCH, versioning::VERSION_PATCH,
), ),
}), }),
KindWithContent::NetworkTopologyChange { network: new_network } => {
Some(Details::NetworkTopologyChange { network: new_network.clone() })
}
} }
} }
} }
@@ -579,6 +596,7 @@ pub enum Kind {
SnapshotCreation, SnapshotCreation,
Export, Export,
UpgradeDatabase, UpgradeDatabase,
NetworkTopologyChange,
} }
impl Kind { impl Kind {
@@ -597,7 +615,8 @@ impl Kind {
| Kind::DumpCreation | Kind::DumpCreation
| Kind::Export | Kind::Export
| Kind::UpgradeDatabase | Kind::UpgradeDatabase
| Kind::SnapshotCreation => false, | Kind::SnapshotCreation
| Kind::NetworkTopologyChange => false,
} }
} }
} }
@@ -618,6 +637,7 @@ impl Display for Kind {
Kind::SnapshotCreation => write!(f, "snapshotCreation"), Kind::SnapshotCreation => write!(f, "snapshotCreation"),
Kind::Export => write!(f, "export"), Kind::Export => write!(f, "export"),
Kind::UpgradeDatabase => write!(f, "upgradeDatabase"), Kind::UpgradeDatabase => write!(f, "upgradeDatabase"),
Kind::NetworkTopologyChange => write!(f, "networkTopologyChange"),
} }
} }
} }
@@ -653,6 +673,8 @@ impl FromStr for Kind {
Ok(Kind::Export) Ok(Kind::Export)
} else if kind.eq_ignore_ascii_case("upgradeDatabase") { } else if kind.eq_ignore_ascii_case("upgradeDatabase") {
Ok(Kind::UpgradeDatabase) Ok(Kind::UpgradeDatabase)
} else if kind.eq_ignore_ascii_case("networkTopologyChange") {
Ok(Kind::NetworkTopologyChange)
} else { } else {
Err(ParseTaskKindError(kind.to_owned())) Err(ParseTaskKindError(kind.to_owned()))
} }
@@ -738,6 +760,9 @@ pub enum Details {
from: (u32, u32, u32), from: (u32, u32, u32),
to: (u32, u32, u32), to: (u32, u32, u32),
}, },
NetworkTopologyChange {
network: Option<Network>,
},
} }
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, ToSchema)] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, ToSchema)]
@@ -805,6 +830,7 @@ impl Details {
| Self::Dump { .. } | Self::Dump { .. }
| Self::Export { .. } | Self::Export { .. }
| Self::UpgradeDatabase { .. } | Self::UpgradeDatabase { .. }
| Self::NetworkTopologyChange { .. }
| Self::IndexSwap { .. } => (), | Self::IndexSwap { .. } => (),
} }