diff --git a/ecstore/src/endpoint.rs b/ecstore/src/endpoint.rs index 6a37514ab..7b6cef1c4 100644 --- a/ecstore/src/endpoint.rs +++ b/ecstore/src/endpoint.rs @@ -52,7 +52,7 @@ pub struct Node { } /// any type of endpoint. -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, Clone)] pub struct Endpoint { pub url: url::Url, pub is_local: bool, @@ -221,7 +221,7 @@ impl Endpoint { } /// list of same type of endpoint. -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct Endpoints(Vec); impl AsRef> for Endpoints { @@ -546,7 +546,7 @@ impl PoolEndpointList { /// represent endpoints in a given pool /// along with its setCount and setDriveCount. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct PoolEndpoints { // indicates if endpoints are provided in non-ellipses style pub legacy: bool, @@ -558,7 +558,7 @@ pub struct PoolEndpoints { } /// list of list of endpoints -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct EndpointServerPools(Vec); impl From> for EndpointServerPools { @@ -631,6 +631,14 @@ impl EndpointServerPools { Ok(()) } + /// returns true if the first endpoint is local. + pub fn first_local(&self) -> bool { + self.0 + .first() + .and_then(|v| v.endpoints.as_ref().first()) + .map_or(false, |v| v.is_local) + } + /// returns a sorted list of nodes in this cluster pub fn get_nodes(&self) -> Vec { let mut node_map = HashMap::new(); diff --git a/ecstore/src/lib.rs b/ecstore/src/lib.rs index a584e34e9..7335ba9a7 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/peer.rs b/ecstore/src/peer.rs index 7e61af877..cf23ffcc5 100644 --- a/ecstore/src/peer.rs +++ b/ecstore/src/peer.rs @@ -14,7 +14,7 @@ type Client = Arc>; #[async_trait] pub trait PeerS3Client: Debug + Sync + Send + 'static { async fn make_bucket(&self, bucket: &str, opts: &MakeBucketOptions) -> Result<()>; - fn get_pools(&self) -> Vec; + fn get_pools(&self) -> Vec; } #[derive(Debug)] @@ -53,7 +53,7 @@ impl S3PeerSys { #[async_trait] impl PeerS3Client for S3PeerSys { - fn get_pools(&self) -> Vec { + fn get_pools(&self) -> Vec { unimplemented!() } async fn make_bucket(&self, bucket: &str, opts: &MakeBucketOptions) -> Result<()> { @@ -80,7 +80,7 @@ impl PeerS3Client for S3PeerSys { let mut per_pool_errs = Vec::with_capacity(self.clients.len()); for (j, cli) in self.clients.iter().enumerate() { let pools = cli.get_pools(); - let idx = i as i32; + let idx = i; if pools.contains(&idx) { per_pool_errs.push(errors[j].as_ref()); } @@ -99,11 +99,11 @@ impl PeerS3Client for S3PeerSys { pub struct LocalPeerS3Client { pub local_disks: Vec, pub node: Node, - pub pools: Vec, + pub pools: Vec, } impl LocalPeerS3Client { - fn new(local_disks: Vec, node: Node, pools: Vec) -> Self { + fn new(local_disks: Vec, node: Node, pools: Vec) -> Self { Self { local_disks, node, @@ -114,7 +114,7 @@ impl LocalPeerS3Client { #[async_trait] impl PeerS3Client for LocalPeerS3Client { - fn get_pools(&self) -> Vec { + fn get_pools(&self) -> Vec { self.pools.clone() } async fn make_bucket(&self, bucket: &str, opts: &MakeBucketOptions) -> Result<()> { @@ -154,18 +154,18 @@ impl PeerS3Client for LocalPeerS3Client { #[derive(Debug)] pub struct RemotePeerS3Client { pub node: Node, - pub pools: Vec, + pub pools: Vec, } impl RemotePeerS3Client { - fn new(node: Node, pools: Vec) -> Self { + fn new(node: Node, pools: Vec) -> Self { Self { node, pools } } } #[async_trait] impl PeerS3Client for RemotePeerS3Client { - fn get_pools(&self) -> Vec { + fn get_pools(&self) -> Vec { unimplemented!() } async fn make_bucket(&self, _bucket: &str, _opts: &MakeBucketOptions) -> Result<()> { diff --git a/ecstore/src/store.rs b/ecstore/src/store.rs index dfdeaa0f5..bf3145d3c 100644 --- a/ecstore/src/store.rs +++ b/ecstore/src/store.rs @@ -29,20 +29,21 @@ pub struct ECStore { impl ECStore { pub async fn new(address: String, endpoints: Vec) -> Result { - let layouts = DisksLayout::try_from(endpoints.as_slice())?; + let layouts = DisksLayout::try_from(endpoints.as_slice()).map_err(|v| Error::msg(v))?; let mut deployment_id = None; - let (endpoint_pools, _) = EndpointServerPools::create_server_endpoints(address.as_str(), &layouts)?; + let (endpoint_pools, _) = + EndpointServerPools::create_server_endpoints(address.as_str(), &layouts).map_err(|v| Error::msg(v))?; - let mut pools = Vec::with_capacity(endpoint_pools.len()); - let mut disk_map = HashMap::with_capacity(endpoint_pools.len()); + let mut pools = Vec::with_capacity(endpoint_pools.as_ref().len()); + let mut disk_map = HashMap::with_capacity(endpoint_pools.as_ref().len()); - let first_is_local = endpoint_pools.first_is_local(); + let first_is_local = endpoint_pools.first_local(); let mut local_disks = Vec::new(); - for (i, pool_eps) in endpoint_pools.iter().enumerate() { + for (i, pool_eps) in endpoint_pools.as_ref().iter().enumerate() { // TODO: read from config parseStorageClass let partiy_count = store_init::default_partiy_count(pool_eps.drives_per_set);