From fb8f8d22c03ff8c9655e27cd1cafadc269fd26f5 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Thu, 5 May 2022 11:20:28 -0400 Subject: [PATCH] fix: Remove now-unused ServerId. Fixes #4451 --- clap_blocks/src/lib.rs | 1 - clap_blocks/src/run_config.rs | 19 +----- clap_blocks/src/server_id.rs | 14 ----- data_types/src/lib.rs | 1 - data_types/src/server_id.rs | 106 ---------------------------------- generated_types/src/google.rs | 12 ---- 6 files changed, 1 insertion(+), 152 deletions(-) delete mode 100644 clap_blocks/src/server_id.rs delete mode 100644 data_types/src/server_id.rs diff --git a/clap_blocks/src/lib.rs b/clap_blocks/src/lib.rs index 22d75fbc29..a9db994261 100644 --- a/clap_blocks/src/lib.rs +++ b/clap_blocks/src/lib.rs @@ -7,6 +7,5 @@ pub mod ingester; pub mod object_store; pub mod querier; pub mod run_config; -pub mod server_id; pub mod socket_addr; pub mod write_buffer; diff --git a/clap_blocks/src/run_config.rs b/clap_blocks/src/run_config.rs index 799a3a2429..93685ae621 100644 --- a/clap_blocks/src/run_config.rs +++ b/clap_blocks/src/run_config.rs @@ -1,7 +1,7 @@ use trace_exporters::TracingConfig; use trogging::cli::LoggingConfig; -use crate::{object_store::ObjectStoreConfig, server_id::ServerIdConfig, socket_addr::SocketAddr}; +use crate::{object_store::ObjectStoreConfig, socket_addr::SocketAddr}; /// The default bind address for the HTTP API. pub const DEFAULT_API_BIND_ADDR: &str = "127.0.0.1:8080"; @@ -20,10 +20,6 @@ pub struct RunConfig { #[clap(flatten)] pub(crate) tracing_config: TracingConfig, - /// object store config - #[clap(flatten)] - pub(crate) server_id_config: ServerIdConfig, - /// The address on which IOx will serve HTTP API requests. #[clap( long = "--api-bind", @@ -69,21 +65,11 @@ impl RunConfig { &mut self.tracing_config } - /// Get a reference to the run config's server id config. - pub fn server_id_config(&self) -> &ServerIdConfig { - &self.server_id_config - } - /// Get a reference to the run config's logging config. pub fn logging_config(&self) -> &LoggingConfig { &self.logging_config } - /// Get a mutable reference to the run config's server id config. - pub fn server_id_config_mut(&mut self) -> &mut ServerIdConfig { - &mut self.server_id_config - } - /// set the http bind address pub fn with_http_bind_address(mut self, http_bind_address: SocketAddr) -> Self { self.http_bind_address = http_bind_address; @@ -108,9 +94,6 @@ impl RunConfig { Self { logging_config, tracing_config, - // TODO: server_id isn't used in NG; this field should be removed when OG is removed - // https://github.com/influxdata/influxdb_iox/issues/4451 - server_id_config: ServerIdConfig { server_id: None }, http_bind_address, grpc_bind_address, max_http_request_size, diff --git a/clap_blocks/src/server_id.rs b/clap_blocks/src/server_id.rs deleted file mode 100644 index 042b303bf7..0000000000 --- a/clap_blocks/src/server_id.rs +++ /dev/null @@ -1,14 +0,0 @@ -use data_types::server_id::ServerId; - -/// CLI config for server ID. -#[derive(Debug, Clone, clap::Parser)] -pub struct ServerIdConfig { - /// The identifier for the server. - /// - /// Used for writing to object storage and as an identifier that is added to - /// replicated writes, write buffer segments, and Chunks. Must be unique in - /// a group of connected or semi-connected IOx servers. Must be a nonzero - /// number that can be represented by a 32-bit unsigned integer. - #[clap(long = "--server-id", env = "INFLUXDB_IOX_ID")] - pub server_id: Option, -} diff --git a/data_types/src/lib.rs b/data_types/src/lib.rs index 7da948f108..29f1a56182 100644 --- a/data_types/src/lib.rs +++ b/data_types/src/lib.rs @@ -15,7 +15,6 @@ pub mod consistent_hasher; pub mod error; pub mod job; pub mod partition_metadata; -pub mod server_id; pub mod timestamp; pub mod write_buffer; pub mod write_summary; diff --git a/data_types/src/server_id.rs b/data_types/src/server_id.rs deleted file mode 100644 index 2a8606e6b0..0000000000 --- a/data_types/src/server_id.rs +++ /dev/null @@ -1,106 +0,0 @@ -use snafu::{OptionExt, ResultExt, Snafu}; -use std::{ - convert::TryFrom, - fmt, - num::{NonZeroU32, ParseIntError}, - str::FromStr, -}; - -#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] -pub struct ServerId(NonZeroU32); - -impl ServerId { - pub fn new(id: NonZeroU32) -> Self { - Self(id) - } - - pub fn get(&self) -> NonZeroU32 { - self.0 - } - - pub fn get_u32(&self) -> u32 { - self.0.get() - } -} - -impl FromStr for ServerId { - type Err = Error; - - fn from_str(value: &str) -> Result { - let value: u32 = value.parse().context(UnableToParseSnafu { value })?; - Self::try_from(value) - } -} - -impl TryFrom for ServerId { - type Error = Error; - - fn try_from(value: u32) -> Result { - NonZeroU32::new(value) - .map(Self) - .context(ValueMayNotBeZeroSnafu) - .map_err(Into::into) - } -} - -impl fmt::Display for ServerId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.0.fmt(f) - } -} - -#[derive(Debug, Snafu)] -pub struct Error(InnerError); - -#[derive(Debug, Snafu)] -enum InnerError { - #[snafu(display("The server ID may not be zero"))] - ValueMayNotBeZero, - - #[snafu(display("Could not parse {} as a non-zero 32-bit unsigned number", value))] - UnableToParse { - source: ParseIntError, - value: String, - }, -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn cannot_be_zero() { - assert!(matches!( - ServerId::try_from(0), - Err(Error(InnerError::ValueMayNotBeZero)) - )); - } - - #[test] - fn can_be_nonzero() { - let value = 2; - let server_id = ServerId::try_from(value).unwrap(); - assert_eq!(server_id.get_u32(), value); - } - - #[test] - fn can_be_parsed_from_a_string() { - assert!(matches!( - "0".parse::(), - Err(Error(InnerError::ValueMayNotBeZero)), - )); - assert!(matches!( - "moo".parse::(), - Err(Error(InnerError::UnableToParse { source: _, value })) if value == "moo", - )); - - let server_id = "1337".parse::().unwrap(); - assert_eq!(server_id.get_u32(), 1337); - } - - #[test] - fn can_be_displayed() { - let server_id = ServerId::try_from(42).unwrap(); - assert_eq!("42", format!("{}", server_id)); - } -} diff --git a/generated_types/src/google.rs b/generated_types/src/google.rs index 521f23b75b..6c92b29da2 100644 --- a/generated_types/src/google.rs +++ b/generated_types/src/google.rs @@ -233,7 +233,6 @@ pub enum ResourceType { DatabaseUuid, Job, Router, - ServerId, Unknown(String), } @@ -247,7 +246,6 @@ impl ResourceType { Self::Chunk => "chunk", Self::Job => "job", Self::Router => "router", - Self::ServerId => "server_id", Self::Unknown(unknown) => unknown, } } @@ -263,7 +261,6 @@ impl From for ResourceType { "chunk" => Self::Chunk, "job" => Self::Job, "router" => Self::Router, - "server_id" => Self::ServerId, _ => Self::Unknown(s), } } @@ -417,8 +414,6 @@ pub fn decode_not_found(status: &tonic::Status) -> impl Iterator String { match self { - Self::ServerIdNotSet => "server id must be set".to_string(), Self::DatabaseImmutable => "database must be mutable".to_string(), Self::ServerInvalidState(description) => description.clone(), Self::DatabaseInvalidState(description) => description.clone(), @@ -460,11 +454,6 @@ impl PreconditionViolation { impl From for rpc::precondition_failure::Violation { fn from(v: PreconditionViolation) -> Self { match v { - PreconditionViolation::ServerIdNotSet => Self { - r#type: "server_id".to_string(), - subject: "influxdata.com/iox".to_string(), - description: v.description(), - }, PreconditionViolation::ServerInvalidState(_) => Self { r#type: "state".to_string(), subject: "influxdata.com/iox".to_string(), @@ -516,7 +505,6 @@ impl From for rpc::precondition_failure::Violation { impl From for PreconditionViolation { fn from(v: rpc::precondition_failure::Violation) -> Self { match (v.r#type.as_str(), v.subject.as_str()) { - ("server_id", "influxdata.com/iox") => PreconditionViolation::ServerIdNotSet, ("state", "influxdata.com/iox") => { PreconditionViolation::ServerInvalidState(v.description) }