diff --git a/quickwit/quickwit-config/src/index_config/mod.rs b/quickwit/quickwit-config/src/index_config/mod.rs index bd20a1a23ba..af6a506b19f 100644 --- a/quickwit/quickwit-config/src/index_config/mod.rs +++ b/quickwit/quickwit-config/src/index_config/mod.rs @@ -520,7 +520,8 @@ impl TestableForRegression for IndexConfig { } /// Represents an update to one of the updatable index configuration attribute. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(tag = "field", content = "config")] pub enum IndexConfigUpdate { SearchSettings(SearchSettings), IndexingSettings(IndexingSettings), diff --git a/quickwit/quickwit-metastore/src/metastore/mod.rs b/quickwit/quickwit-metastore/src/metastore/mod.rs index 043413cbf0a..04f262e33f7 100644 --- a/quickwit/quickwit-metastore/src/metastore/mod.rs +++ b/quickwit/quickwit-metastore/src/metastore/mod.rs @@ -38,7 +38,6 @@ use quickwit_proto::metastore::{ IndexMetadataRequest, IndexMetadataResponse, ListIndexesMetadataResponse, ListSplitsRequest, ListSplitsResponse, MetastoreError, MetastoreResult, MetastoreService, MetastoreServiceClient, MetastoreServiceStream, PublishSplitsRequest, StageSplitsRequest, UpdateIndexRequest, - UpdatedIndexConfig, }; use quickwit_proto::types::{IndexUid, SplitId}; use time::OffsetDateTime; @@ -182,14 +181,14 @@ impl CreateIndexResponseExt for CreateIndexResponse { /// Helper trait to build a [`UpdateIndexRequest`] and deserialize its payload. pub trait UpdateIndexRequestExt { - /// Creates a new [`UpdateIndexRequest`] from an [`IndexUpdate`]. + /// Creates a new [`UpdateIndexRequest`] from an [`IndexConfigUpdate`]. fn try_from_index_config_update( index_uid: impl Into, update: &IndexConfigUpdate, ) -> MetastoreResult; /// Deserializes the `config_json` field of an [`UpdateIndexRequest`] into - /// the appropriate variant of `IndexUpdate`. + /// the appropriate variant of `IndexConfigUpdate`. fn deserialize_index_config_update(&self) -> MetastoreResult; } @@ -199,61 +198,14 @@ impl UpdateIndexRequestExt for UpdateIndexRequest { update: &IndexConfigUpdate, ) -> MetastoreResult { let index_uid = Some(index_uid.into()); - let update_request = match update { - IndexConfigUpdate::IndexingSettings(s) => UpdateIndexRequest { - index_uid, - target_config: UpdatedIndexConfig::IndexingSettings.into(), - config_json: Some(serde_utils::to_json_str(s)?), - }, - IndexConfigUpdate::SearchSettings(s) => UpdateIndexRequest { - index_uid, - target_config: UpdatedIndexConfig::SearchSettings.into(), - config_json: Some(serde_utils::to_json_str(s)?), - }, - IndexConfigUpdate::RetentionPolicy(s) => UpdateIndexRequest { - index_uid, - target_config: UpdatedIndexConfig::RetentionPolicy.into(), - config_json: s.as_ref().map(serde_utils::to_json_str).transpose()?, - }, - }; - - Ok(update_request) + Ok(UpdateIndexRequest { + index_uid, + updated_config_json: serde_utils::to_json_str(update)?, + }) } fn deserialize_index_config_update(&self) -> MetastoreResult { - let config_ref_opt = self.config_json.as_ref(); - match self.target_config { - x if x == UpdatedIndexConfig::IndexingSettings as i32 => { - let indexing_settings = config_ref_opt - .map(|json| serde_utils::from_json_str(json)) - .transpose()? - .ok_or(MetastoreError::JsonDeserializeError { - struct_name: "IndexingSettings".to_owned(), - message: "Should not be empty".to_owned(), - })?; - Ok(IndexConfigUpdate::IndexingSettings(indexing_settings)) - } - x if x == UpdatedIndexConfig::SearchSettings as i32 => { - let search_settings = config_ref_opt - .map(|json| serde_utils::from_json_str(json)) - .transpose()? - .ok_or(MetastoreError::JsonDeserializeError { - struct_name: "IndexingSettings".to_owned(), - message: "Should not be empty".to_owned(), - })?; - Ok(IndexConfigUpdate::SearchSettings(search_settings)) - } - x if x == UpdatedIndexConfig::RetentionPolicy as i32 => { - let retention_policy = config_ref_opt - .map(|json| serde_utils::from_json_str(json)) - .transpose()?; - Ok(IndexConfigUpdate::RetentionPolicy(retention_policy)) - } - _ => Err(MetastoreError::JsonDeserializeError { - struct_name: "IndexUpdate".to_owned(), - message: "Unexpected target config".to_owned(), - }), - } + serde_utils::from_json_str(&self.updated_config_json) } } diff --git a/quickwit/quickwit-proto/protos/quickwit/metastore.proto b/quickwit/quickwit-proto/protos/quickwit/metastore.proto index 80d59d3ee64..2b156317718 100644 --- a/quickwit/quickwit-proto/protos/quickwit/metastore.proto +++ b/quickwit/quickwit-proto/protos/quickwit/metastore.proto @@ -210,8 +210,8 @@ enum UpdatedIndexConfig { message UpdateIndexRequest { quickwit.common.IndexUid index_uid = 1; - UpdatedIndexConfig target_config = 2; - optional string config_json = 3; + // JSON representation of the updated config field. + string updated_config_json = 2; } message ListIndexesMetadataRequest { diff --git a/quickwit/quickwit-proto/src/codegen/quickwit/quickwit.metastore.rs b/quickwit/quickwit-proto/src/codegen/quickwit/quickwit.metastore.rs index 47ec880c7cc..7a72d62c93a 100644 --- a/quickwit/quickwit-proto/src/codegen/quickwit/quickwit.metastore.rs +++ b/quickwit/quickwit-proto/src/codegen/quickwit/quickwit.metastore.rs @@ -26,10 +26,9 @@ pub struct CreateIndexResponse { pub struct UpdateIndexRequest { #[prost(message, optional, tag = "1")] pub index_uid: ::core::option::Option, - #[prost(enumeration = "UpdatedIndexConfig", tag = "2")] - pub target_config: i32, - #[prost(string, optional, tag = "3")] - pub config_json: ::core::option::Option<::prost::alloc::string::String>, + /// JSON representation of the updated config field. + #[prost(string, tag = "2")] + pub updated_config_json: ::prost::alloc::string::String, } #[derive(serde::Serialize, serde::Deserialize, utoipa::ToSchema)] #[allow(clippy::derive_partial_eq_without_eq)]