From f7e7f6e2576049022c2665093f66ed1040950471 Mon Sep 17 00:00:00 2001 From: weisd Date: Tue, 10 Sep 2024 16:27:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99stores=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.md | 2 +- ecstore/src/endpoints.rs | 5 +++++ ecstore/src/lib.rs | 4 ++-- ecstore/src/store.rs | 6 +++--- rustfs/src/main.rs | 6 ++++-- rustfs/src/storage/ecfs.rs | 5 +++-- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/TODO.md b/TODO.md index e405b8d3f..f19a90c3d 100644 --- a/TODO.md +++ b/TODO.md @@ -36,8 +36,8 @@ - [ ] 详情 HeadObject - [ ] 对象预先签名(get、put、head、post) - ## 扩展功能 + - [ ] 用户管理 - [ ] Policy管理 - [ ] AK/SK分配管理 diff --git a/ecstore/src/endpoints.rs b/ecstore/src/endpoints.rs index 6f781704d..9af5b963b 100644 --- a/ecstore/src/endpoints.rs +++ b/ecstore/src/endpoints.rs @@ -408,6 +408,11 @@ impl AsMut> for EndpointServerPools { } impl EndpointServerPools { + pub fn from_volumes(server_addr: &str, endpoints: Vec) -> Result<(EndpointServerPools, SetupType)> { + let layouts = DisksLayout::try_from(endpoints.as_slice())?; + + Self::create_server_endpoints(server_addr, &layouts) + } /// validates and creates new endpoints from input args, supports /// both ellipses and without ellipses transparently. pub fn create_server_endpoints(server_addr: &str, disks_layout: &DisksLayout) -> Result<(EndpointServerPools, SetupType)> { diff --git a/ecstore/src/lib.rs b/ecstore/src/lib.rs index 1371d1f14..81329685b 100644 --- a/ecstore/src/lib.rs +++ b/ecstore/src/lib.rs @@ -1,8 +1,8 @@ mod bucket_meta; mod chunk_stream; pub mod disk; -mod disks_layout; -mod endpoints; +pub mod disks_layout; +pub mod endpoints; mod erasure; pub mod error; mod file_meta; diff --git a/ecstore/src/store.rs b/ecstore/src/store.rs index 8fdcc2fbd..487886d4e 100644 --- a/ecstore/src/store.rs +++ b/ecstore/src/store.rs @@ -32,12 +32,12 @@ pub struct ECStore { } impl ECStore { - pub async fn new(address: String, endpoints: Vec) -> Result { - let layouts = DisksLayout::try_from(endpoints.as_slice())?; + pub async fn new(address: String, endpoint_pools: EndpointServerPools) -> Result { + // let layouts = DisksLayout::try_from(endpoints.as_slice())?; 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)?; let mut pools = Vec::with_capacity(endpoint_pools.as_ref().len()); let mut disk_map = HashMap::with_capacity(endpoint_pools.as_ref().len()); diff --git a/rustfs/src/main.rs b/rustfs/src/main.rs index 54aeccac2..3a8fbba69 100644 --- a/rustfs/src/main.rs +++ b/rustfs/src/main.rs @@ -2,7 +2,7 @@ mod config; mod storage; use clap::Parser; -use ecstore::error::Result; +use ecstore::{disks_layout::DisksLayout, endpoints::EndpointServerPools, error::Result}; use hyper_util::{ rt::{TokioExecutor, TokioIo}, server::conn::auto::Builder as ConnBuilder, @@ -66,10 +66,12 @@ async fn run(opt: config::Opt) -> Result<()> { // }) // }; + let (endpoint_pools, _) = EndpointServerPools::from_volumes(opt.address.clone().as_str(), opt.volumes.clone())?; + // Setup S3 service // 本项目使用s3s库来实现s3服务 let service = { - let mut b = S3ServiceBuilder::new(storage::ecfs::FS::new(opt.address.clone(), opt.volumes.clone()).await?); + let mut b = S3ServiceBuilder::new(storage::ecfs::FS::new(opt.address.clone(), endpoint_pools).await?); //设置AK和SK //其中部份内容从config配置文件中读取 let mut access_key = String::from_str(config::DEFAULT_ACCESS_KEY).unwrap(); diff --git a/rustfs/src/storage/ecfs.rs b/rustfs/src/storage/ecfs.rs index 0117cd831..9de4d419a 100644 --- a/rustfs/src/storage/ecfs.rs +++ b/rustfs/src/storage/ecfs.rs @@ -24,6 +24,7 @@ use std::str::FromStr; use transform_stream::AsyncTryStream; use uuid::Uuid; +use ecstore::endpoints::EndpointServerPools; use ecstore::error::Result; use ecstore::store::ECStore; use tracing::debug; @@ -45,8 +46,8 @@ pub struct FS { } impl FS { - pub async fn new(address: String, endpoints: Vec) -> Result { - let store: ECStore = ECStore::new(address, endpoints).await?; + pub async fn new(address: String, endpoint_pools: EndpointServerPools) -> Result { + let store: ECStore = ECStore::new(address, endpoint_pools).await?; Ok(Self { store }) } }