From 91961273c23cd961b756a4ec2b02af509db7fa79 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 4 May 2022 15:16:13 -0400 Subject: [PATCH] fix: Remove unused Rust code in generated_types --- .../src/database_rules/lifecycle.rs | 213 ------------------ .../src/database_rules/partition.rs | 181 --------------- generated_types/src/lib.rs | 2 - generated_types/src/write_buffer.rs | 53 ----- 4 files changed, 449 deletions(-) delete mode 100644 generated_types/src/database_rules/lifecycle.rs delete mode 100644 generated_types/src/database_rules/partition.rs delete mode 100644 generated_types/src/write_buffer.rs diff --git a/generated_types/src/database_rules/lifecycle.rs b/generated_types/src/database_rules/lifecycle.rs deleted file mode 100644 index 1d3ccb4126..0000000000 --- a/generated_types/src/database_rules/lifecycle.rs +++ /dev/null @@ -1,213 +0,0 @@ -use crate::google::{FieldViolationExt, FromOptionalField, OptionalField}; -use std::convert::{TryFrom, TryInto}; -use std::num::{NonZeroU32, NonZeroU64, NonZeroUsize}; - -use data_types::database_rules::{ - LifecycleRules, MaxActiveCompactions, DEFAULT_CATALOG_TRANSACTIONS_UNTIL_CHECKPOINT, - DEFAULT_CATALOG_TRANSACTION_PRUNE_AGE, DEFAULT_LATE_ARRIVE_WINDOW_SECONDS, - DEFAULT_MUB_ROW_THRESHOLD, DEFAULT_PERSIST_AGE_THRESHOLD_SECONDS, - DEFAULT_PERSIST_ROW_THRESHOLD, DEFAULT_WORKER_BACKOFF_MILLIS, -}; - -use crate::google::FieldViolation; -use crate::influxdata::iox::management::v1 as management; - -impl From for management::LifecycleRules { - fn from(config: LifecycleRules) -> Self { - Self { - buffer_size_soft: config - .buffer_size_soft - .map(|x| x.get() as u64) - .unwrap_or_default(), - buffer_size_hard: config - .buffer_size_hard - .map(|x| x.get() as u64) - .unwrap_or_default(), - persist: config.persist, - immutable: config.immutable, - worker_backoff_millis: config.worker_backoff_millis.get(), - max_active_compactions_cfg: Some(config.max_active_compactions.into()), - catalog_transactions_until_checkpoint: config - .catalog_transactions_until_checkpoint - .get(), - catalog_transaction_prune_age: Some(config.catalog_transaction_prune_age.into()), - late_arrive_window_seconds: config.late_arrive_window_seconds.get(), - persist_row_threshold: config.persist_row_threshold.get() as u64, - persist_age_threshold_seconds: config.persist_age_threshold_seconds.get(), - mub_row_threshold: config.mub_row_threshold.get() as u64, - parquet_cache_limit: config - .parquet_cache_limit - .map(|v| v.get()) - .unwrap_or_default(), - } - } -} - -impl From for management::lifecycle_rules::MaxActiveCompactionsCfg { - fn from(max: MaxActiveCompactions) -> Self { - match max { - MaxActiveCompactions::MaxActiveCompactions(n) => Self::MaxActiveCompactions(n.get()), - MaxActiveCompactions::MaxActiveCompactionsCpuFraction { fraction, .. } => { - Self::MaxActiveCompactionsCpuFraction(fraction) - } - } - } -} - -impl TryFrom for LifecycleRules { - type Error = FieldViolation; - - fn try_from(proto: management::LifecycleRules) -> Result { - let persist_age_threshold_seconds = NonZeroU32::new(proto.persist_age_threshold_seconds) - .unwrap_or_else(|| NonZeroU32::new(DEFAULT_PERSIST_AGE_THRESHOLD_SECONDS).unwrap()); - - let late_arrive_window_seconds = NonZeroU32::new(proto.late_arrive_window_seconds) - .unwrap_or_else(|| NonZeroU32::new(DEFAULT_LATE_ARRIVE_WINDOW_SECONDS).unwrap()); - - if persist_age_threshold_seconds < late_arrive_window_seconds { - return Err(FieldViolation { - field: "persist_age_threshold_seconds".to_string(), - description: - "persist_age_threshold_seconds must not be less than late_arrive_window_seconds" - .to_string(), - }); - } - - Ok(Self { - buffer_size_soft: (proto.buffer_size_soft as usize).try_into().ok(), - buffer_size_hard: (proto.buffer_size_hard as usize).try_into().ok(), - persist: proto.persist, - immutable: proto.immutable, - worker_backoff_millis: NonZeroU64::new(proto.worker_backoff_millis) - .unwrap_or_else(|| NonZeroU64::new(DEFAULT_WORKER_BACKOFF_MILLIS).unwrap()), - max_active_compactions: proto - .max_active_compactions_cfg - .optional("max_active_compactions")? - .unwrap_or_default(), - catalog_transactions_until_checkpoint: NonZeroU64::new( - proto.catalog_transactions_until_checkpoint, - ) - .unwrap_or_else(|| { - NonZeroU64::new(DEFAULT_CATALOG_TRANSACTIONS_UNTIL_CHECKPOINT).unwrap() - }), - catalog_transaction_prune_age: match proto.catalog_transaction_prune_age { - Some(d) => d.try_into().scope("catalog_transaction_prune_age")?, - None => DEFAULT_CATALOG_TRANSACTION_PRUNE_AGE, - }, - late_arrive_window_seconds, - persist_row_threshold: NonZeroUsize::new(proto.persist_row_threshold as usize) - .unwrap_or_else(|| { - NonZeroUsize::new(DEFAULT_PERSIST_ROW_THRESHOLD as usize).unwrap() - }), - persist_age_threshold_seconds, - mub_row_threshold: NonZeroUsize::new(proto.mub_row_threshold as usize) - .unwrap_or_else(|| NonZeroUsize::new(DEFAULT_MUB_ROW_THRESHOLD).unwrap()), - parquet_cache_limit: NonZeroU64::new(proto.parquet_cache_limit), - }) - } -} - -impl TryFrom for MaxActiveCompactions { - type Error = FieldViolation; - - fn try_from( - value: management::lifecycle_rules::MaxActiveCompactionsCfg, - ) -> Result { - use management::lifecycle_rules::MaxActiveCompactionsCfg::*; - Ok(match value { - MaxActiveCompactions(n) => { - Self::MaxActiveCompactions(NonZeroU32::new(n).unwrap_field("")?) - } - MaxActiveCompactionsCpuFraction(fraction) => Self::new(fraction), - }) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn lifecycle_rules() { - let mut protobuf = management::LifecycleRules { - buffer_size_soft: 353, - buffer_size_hard: 232, - persist: true, - immutable: true, - worker_backoff_millis: 1000, - max_active_compactions_cfg: Some( - management::lifecycle_rules::MaxActiveCompactionsCfg::MaxActiveCompactions(8), - ), - catalog_transactions_until_checkpoint: 10, - catalog_transaction_prune_age: Some(pbjson_types::Duration { - seconds: 11, - nanos: 22, - }), - late_arrive_window_seconds: 23, - persist_row_threshold: 57, - persist_age_threshold_seconds: 60, - mub_row_threshold: 3454, - parquet_cache_limit: 10, - }; - - let config: LifecycleRules = protobuf.clone().try_into().unwrap(); - let back: management::LifecycleRules = config.clone().into(); - - assert_eq!( - config.buffer_size_soft.unwrap().get(), - protobuf.buffer_size_soft as usize - ); - assert_eq!( - config.buffer_size_hard.unwrap().get(), - protobuf.buffer_size_hard as usize - ); - assert_eq!(config.immutable, protobuf.immutable); - - assert_eq!(back.buffer_size_soft, protobuf.buffer_size_soft); - assert_eq!(back.buffer_size_hard, protobuf.buffer_size_hard); - assert_eq!(back.immutable, protobuf.immutable); - assert_eq!(back.worker_backoff_millis, protobuf.worker_backoff_millis); - assert_eq!( - back.max_active_compactions_cfg, - protobuf.max_active_compactions_cfg - ); - assert_eq!( - back.catalog_transactions_until_checkpoint, - protobuf.catalog_transactions_until_checkpoint - ); - assert_eq!( - back.catalog_transaction_prune_age, - protobuf.catalog_transaction_prune_age - ); - assert_eq!( - back.late_arrive_window_seconds, - protobuf.late_arrive_window_seconds - ); - assert_eq!(back.persist_row_threshold, protobuf.persist_row_threshold); - assert_eq!( - back.persist_age_threshold_seconds, - protobuf.persist_age_threshold_seconds - ); - assert_eq!(back.mub_row_threshold, protobuf.mub_row_threshold); - assert_eq!( - config.parquet_cache_limit.unwrap().get(), - protobuf.parquet_cache_limit - ); - assert_eq!(back.parquet_cache_limit, protobuf.parquet_cache_limit); - - protobuf.late_arrive_window_seconds = 20; - protobuf.persist_age_threshold_seconds = 4; - - let e = LifecycleRules::try_from(protobuf).unwrap_err().to_string(); - assert_eq!(e, "Violation for field \"persist_age_threshold_seconds\": persist_age_threshold_seconds must not be less than late_arrive_window_seconds"); - } - - #[test] - fn lifecycle_rules_default() { - let protobuf = management::LifecycleRules::default(); - let config: LifecycleRules = protobuf.try_into().unwrap(); - assert_eq!(config, LifecycleRules::default()); - - assert_eq!(config.max_active_compactions.get(), num_cpus::get() as u32); - } -} diff --git a/generated_types/src/database_rules/partition.rs b/generated_types/src/database_rules/partition.rs deleted file mode 100644 index 626e047dab..0000000000 --- a/generated_types/src/database_rules/partition.rs +++ /dev/null @@ -1,181 +0,0 @@ -use std::convert::TryFrom; - -use data_types::database_rules::{PartitionTemplate, RegexCapture, StrftimeColumn, TemplatePart}; - -use crate::google::protobuf::Empty; -use crate::google::{FieldViolation, FromOptionalField, FromRepeatedField, NonEmptyString}; -use crate::influxdata::iox::management::v1 as management; - -impl From for management::PartitionTemplate { - fn from(pt: PartitionTemplate) -> Self { - Self { - parts: pt.parts.into_iter().map(Into::into).collect(), - } - } -} - -impl TryFrom for PartitionTemplate { - type Error = FieldViolation; - - fn try_from(proto: management::PartitionTemplate) -> Result { - let parts = proto.parts.repeated("parts")?; - Ok(Self { parts }) - } -} - -impl From for management::partition_template::part::Part { - fn from(part: TemplatePart) -> Self { - use management::partition_template::part::ColumnFormat; - - match part { - TemplatePart::Table => Self::Table(Empty {}), - TemplatePart::Column(column) => Self::Column(column), - TemplatePart::RegexCapture(RegexCapture { column, regex }) => { - Self::Regex(ColumnFormat { - column, - format: regex, - }) - } - TemplatePart::StrftimeColumn(StrftimeColumn { column, format }) => { - Self::StrfTime(ColumnFormat { column, format }) - } - TemplatePart::TimeFormat(format) => Self::Time(format), - } - } -} - -impl TryFrom for TemplatePart { - type Error = FieldViolation; - - fn try_from(proto: management::partition_template::part::Part) -> Result { - use management::partition_template::part::{ColumnFormat, Part}; - - Ok(match proto { - Part::Table(_) => Self::Table, - Part::Column(column) => Self::Column(column.non_empty("column")?), - Part::Regex(ColumnFormat { column, format }) => Self::RegexCapture(RegexCapture { - column: column.non_empty("regex.column")?, - regex: format.non_empty("regex.format")?, - }), - Part::StrfTime(ColumnFormat { column, format }) => { - Self::StrftimeColumn(StrftimeColumn { - column: column.non_empty("strf_time.column")?, - format: format.non_empty("strf_time.format")?, - }) - } - Part::Time(format) => Self::TimeFormat(format.non_empty("time")?), - }) - } -} - -impl From for management::partition_template::Part { - fn from(part: TemplatePart) -> Self { - Self { - part: Some(part.into()), - } - } -} - -impl TryFrom for TemplatePart { - type Error = FieldViolation; - - fn try_from(proto: management::partition_template::Part) -> Result { - proto.part.required("part") - } -} - -#[cfg(test)] -mod tests { - use super::*; - use data_types::database_rules::DatabaseRules; - use std::convert::TryInto; - - #[test] - fn test_partition_template_default() { - let protobuf = management::DatabaseRules { - name: "database".to_string(), - partition_template: Some(management::PartitionTemplate { parts: vec![] }), - ..Default::default() - }; - - let rules: DatabaseRules = protobuf.clone().try_into().unwrap(); - let back: management::DatabaseRules = rules.clone().into(); - - assert_eq!(rules.partition_template.parts.len(), 0); - assert_eq!(protobuf.partition_template, back.partition_template); - } - - #[test] - fn test_partition_template_no_part() { - let protobuf = management::DatabaseRules { - name: "database".to_string(), - partition_template: Some(management::PartitionTemplate { - parts: vec![Default::default()], - }), - ..Default::default() - }; - - let res: Result = protobuf.try_into(); - let err = res.expect_err("expected failure"); - - assert_eq!(&err.field, "partition_template.parts.0.part"); - assert_eq!(&err.description, "Field is required"); - } - - #[test] - fn test_partition_template() { - use management::partition_template::part::{ColumnFormat, Part}; - - let protobuf = management::PartitionTemplate { - parts: vec![ - management::partition_template::Part { - part: Some(Part::Time("time".to_string())), - }, - management::partition_template::Part { - part: Some(Part::Table(Empty {})), - }, - management::partition_template::Part { - part: Some(Part::Regex(ColumnFormat { - column: "column".to_string(), - format: "format".to_string(), - })), - }, - ], - }; - - let pt: PartitionTemplate = protobuf.clone().try_into().unwrap(); - let back: management::PartitionTemplate = pt.clone().into(); - - assert_eq!( - pt.parts, - vec![ - TemplatePart::TimeFormat("time".to_string()), - TemplatePart::Table, - TemplatePart::RegexCapture(RegexCapture { - column: "column".to_string(), - regex: "format".to_string() - }) - ] - ); - assert_eq!(protobuf, back); - } - - #[test] - fn test_partition_template_empty() { - use management::partition_template::part::{ColumnFormat, Part}; - - let protobuf = management::PartitionTemplate { - parts: vec![management::partition_template::Part { - part: Some(Part::Regex(ColumnFormat { - ..Default::default() - })), - }], - }; - - let res: Result = protobuf.try_into(); - let err = res.expect_err("expected failure"); - - assert_eq!(&err.field, "parts.0.part.regex.column"); - assert_eq!(&err.description, "Field is required"); - } -} diff --git a/generated_types/src/lib.rs b/generated_types/src/lib.rs index 12ff4f5c2b..1c74bec382 100644 --- a/generated_types/src/lib.rs +++ b/generated_types/src/lib.rs @@ -215,8 +215,6 @@ pub mod google; pub mod delete_predicate; #[cfg(any(feature = "data_types_conversions", test))] pub mod ingester; -#[cfg(any(feature = "data_types_conversions", test))] -pub mod write_buffer; pub use prost::{DecodeError, EncodeError}; diff --git a/generated_types/src/write_buffer.rs b/generated_types/src/write_buffer.rs deleted file mode 100644 index fb81bd9f6c..0000000000 --- a/generated_types/src/write_buffer.rs +++ /dev/null @@ -1,53 +0,0 @@ -use crate::{ - google::{FieldViolation, FromOptionalField}, - influxdata::iox::write_buffer::v1 as write_buffer, -}; -use data_types::write_buffer::{ - WriteBufferConnection, WriteBufferCreationConfig, DEFAULT_N_SEQUENCERS, -}; -use std::{convert::TryFrom, num::NonZeroU32}; - -impl From for write_buffer::WriteBufferConnection { - fn from(v: WriteBufferConnection) -> Self { - Self { - r#type: v.type_, - connection: v.connection, - connection_config: v.connection_config.into_iter().collect(), - creation_config: v.creation_config.map(|x| x.into()), - } - } -} - -impl From for write_buffer::WriteBufferCreationConfig { - fn from(v: WriteBufferCreationConfig) -> Self { - Self { - n_sequencers: v.n_sequencers.get(), - options: v.options.into_iter().collect(), - } - } -} - -impl TryFrom for WriteBufferConnection { - type Error = FieldViolation; - - fn try_from(proto: write_buffer::WriteBufferConnection) -> Result { - Ok(Self { - type_: proto.r#type, - connection: proto.connection, - connection_config: proto.connection_config.into_iter().collect(), - creation_config: proto.creation_config.optional("creation_config")?, - }) - } -} - -impl TryFrom for WriteBufferCreationConfig { - type Error = FieldViolation; - - fn try_from(proto: write_buffer::WriteBufferCreationConfig) -> Result { - Ok(Self { - n_sequencers: NonZeroU32::try_from(proto.n_sequencers) - .unwrap_or_else(|_| NonZeroU32::try_from(DEFAULT_N_SEQUENCERS).unwrap()), - options: proto.options.into_iter().collect(), - }) - } -}