Skip to content

Commit

Permalink
Use json enum instead of hand written proto enum
Browse files Browse the repository at this point in the history
  • Loading branch information
rdettai committed May 7, 2024
1 parent fa8b3f5 commit c98ed8e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 62 deletions.
3 changes: 2 additions & 1 deletion quickwit/quickwit-config/src/index_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
62 changes: 7 additions & 55 deletions quickwit/quickwit-metastore/src/metastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IndexUid>,
update: &IndexConfigUpdate,
) -> MetastoreResult<UpdateIndexRequest>;

/// 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<IndexConfigUpdate>;
}

Expand All @@ -199,61 +198,14 @@ impl UpdateIndexRequestExt for UpdateIndexRequest {
update: &IndexConfigUpdate,
) -> MetastoreResult<UpdateIndexRequest> {
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<IndexConfigUpdate> {
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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions quickwit/quickwit-proto/protos/quickwit/metastore.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c98ed8e

Please sign in to comment.