From 0cc997018404456284bf1da9a4718169073ce7ca Mon Sep 17 00:00:00 2001 From: "shiro.lee" Date: Thu, 4 Jul 2024 19:00:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecstore/src/disks_layout.rs | 2 +- ecstore/src/endpoint.rs | 46 ++++++++++++++++++++++--------------- ecstore/src/lib.rs | 6 ++--- ecstore/src/utils/net.rs | 2 +- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/ecstore/src/disks_layout.rs b/ecstore/src/disks_layout.rs index 261a239c3..772c48fdc 100644 --- a/ecstore/src/disks_layout.rs +++ b/ecstore/src/disks_layout.rs @@ -37,7 +37,7 @@ impl PoolDisksLayout { self.layout.len() } - pub fn as_cmd_line(&self) -> &str { + pub fn get_cmd_line(&self) -> &str { &self.cmd_line } } diff --git a/ecstore/src/endpoint.rs b/ecstore/src/endpoint.rs index 5ee20f3cf..08f8dddad 100644 --- a/ecstore/src/endpoint.rs +++ b/ecstore/src/endpoint.rs @@ -18,7 +18,7 @@ pub enum EndpointType { } /// enum for setup type. -#[derive(Debug)] +#[derive(PartialEq, Eq)] pub enum SetupType { /// FS setup type enum. FS, @@ -80,6 +80,7 @@ impl TryFrom<&str> for Endpoint { let mut is_local = false; let url = match Url::parse(value) { + #[allow(unused_mut)] Ok(mut url) => { // URL style of endpoint. // Valid URL style endpoint is @@ -206,6 +207,14 @@ impl Endpoint { _ => String::new(), } } + + fn host_port(&self) -> String { + match (self.url.host(), self.url.port()) { + (Some(host), Some(port)) => format!("{}:{}", host, port), + (Some(host), None) => format!("{}", host), + _ => String::new(), + } + } } /// list of same type of endpoint. @@ -235,8 +244,8 @@ impl TryFrom<&[String]> for Endpoints { /// returns new endpoint list based on input args. fn try_from(args: &[String]) -> Result { - let mut endpoint_type; - let mut schema; + let mut endpoint_type = None; + let mut schema = None; let mut endpoints = Vec::with_capacity(args.len()); let mut uniq_set = HashSet::with_capacity(args.len()); @@ -249,11 +258,11 @@ impl TryFrom<&[String]> for Endpoints { // All endpoints have to be same type and scheme if applicable. if i == 0 { - endpoint_type = endpoint.get_type(); - schema = endpoint.url.scheme(); - } else if endpoint.get_type() != endpoint_type { + endpoint_type = Some(endpoint.get_type()); + schema = Some(endpoint.url.scheme().to_owned()); + } else if Some(endpoint.get_type()) != endpoint_type { return Err(Error::from_string("mixed style endpoints are not supported")); - } else if endpoint.url.scheme() != schema { + } else if Some(endpoint.url.scheme()) != schema.as_deref() { return Err(Error::from_string("mixed scheme is not supported")); } @@ -346,9 +355,9 @@ impl PoolEndpointList { for pool in pool_endpoints.iter() { for ep in pool.as_ref() { if let Some(host) = ep.url.host_str() { - unique_args.insert(host); + unique_args.insert(host.to_owned()); } else { - unique_args.insert(format!("localhost:{}", server_addr.port()).as_str()); + unique_args.insert(format!("localhost:{}", server_addr.port())); } } } @@ -419,25 +428,25 @@ impl EndpointServerPools { return Err(Error::from_string("Invalid arguments specified")); } - let mut pool_eps = PoolEndpointList::create_pool_endpoints(server_addr, disks_layout)?; + let pool_eps = PoolEndpointList::create_pool_endpoints(server_addr, disks_layout)?; let mut ret: EndpointServerPools = Vec::with_capacity(pool_eps.as_ref().len()).into(); - for (i, eps) in pool_eps.as_mut().into_iter().enumerate() { + for (i, eps) in pool_eps.inner.into_iter().enumerate() { let layout = disks_layout.get_layout(i); let set_count = layout.map_or(0, |v| v.count()); - let drives_per_set = layout.map_or(0, |v| v.as_ref().get(0).map_or(0, |v| v.len())); - let cmd_line = layout.map_or(String::new(), |v| v.as_cmd_line().to_owned()); + let drives_per_set = layout.map_or(0, |v| v.as_ref().first().map_or(0, |v| v.len())); + let cmd_line = layout.map_or(String::new(), |v| v.get_cmd_line().to_owned()); let ep = PoolEndpoints { legacy: disks_layout.legacy, set_count, drives_per_set, - endpoints: *eps, + endpoints: eps, cmd_line, platform: String::new(), }; - ret.add(ep); + ret.add(ep)?; } Ok((ret, pool_eps.setup_type)) @@ -469,12 +478,11 @@ impl EndpointServerPools { for pool in self.0.iter() { for ep in pool.endpoints.as_ref() { - let host = ep.grid_host(); - let n = node_map.entry(host).or_insert(Node { + let n = node_map.entry(ep.host_port()).or_insert(Node { url: ep.url.clone(), pools: vec![], is_local: ep.is_local, - grid_host: host, + grid_host: ep.grid_host(), }); if let Some(pool_idx) = ep.pool_idx { @@ -485,7 +493,7 @@ impl EndpointServerPools { } } - let mut nodes: Vec = node_map.into_iter().map(|(_, n)| n).collect(); + let mut nodes: Vec = node_map.into_values().collect(); nodes.sort_by(|a, b| a.grid_host.cmp(&b.grid_host)); diff --git a/ecstore/src/lib.rs b/ecstore/src/lib.rs index 7335ba9a7..a584e34e9 100644 --- a/ecstore/src/lib.rs +++ b/ecstore/src/lib.rs @@ -9,9 +9,9 @@ mod erasure; pub mod error; mod file_meta; mod format; -mod peer; -mod sets; -pub mod store; +// mod peer; +// mod sets; +// pub mod store; pub mod store_api; mod store_init; mod utils; diff --git a/ecstore/src/utils/net.rs b/ecstore/src/utils/net.rs index 81441512e..e11690b45 100644 --- a/ecstore/src/utils/net.rs +++ b/ecstore/src/utils/net.rs @@ -35,7 +35,7 @@ pub fn check_local_server_addr(server_addr: &str) -> Result { } } - return Err(Error::from_string("host in server address should be this server")); + Err(Error::from_string("host in server address should be this server")) } pub fn split_host_port(s: &str) -> Result<(String, u16)> {