mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-06 05:17:42 +00:00
更新全局disk
This commit is contained in:
+19
-19
@@ -1,11 +1,10 @@
|
||||
use ecstore::{
|
||||
disk::{DeleteOptions, DiskStore, ReadMultipleReq, ReadOptions, WalkDirOptions},
|
||||
endpoints::EndpointServerPools,
|
||||
erasure::{ReadAt, Write},
|
||||
peer::{LocalPeerS3Client, PeerS3Client},
|
||||
store::{all_local_disk_path, find_local_disk},
|
||||
store_api::{BucketOptions, FileInfo, MakeBucketOptions},
|
||||
};
|
||||
use tokio::fs;
|
||||
use tonic::{Request, Response, Status};
|
||||
use tracing::{debug, error, info};
|
||||
|
||||
@@ -29,28 +28,29 @@ struct NodeService {
|
||||
pub local_peer: LocalPeerS3Client,
|
||||
}
|
||||
|
||||
pub fn make_server(endpoint_pools: EndpointServerPools) -> NodeServer<impl Node> {
|
||||
// TODO: 参考rustfs创建 https://github.com/rustfs/s3-rustfs/issues/30#issuecomment-2339664516
|
||||
let local_disks = Vec::new();
|
||||
let local_peer = LocalPeerS3Client::new(local_disks, None, None);
|
||||
pub fn make_server() -> NodeServer<impl Node> {
|
||||
// let local_disks = all_local_disk().await;
|
||||
let local_peer = LocalPeerS3Client::new(None, None);
|
||||
NodeServer::new(NodeService { local_peer })
|
||||
}
|
||||
|
||||
impl NodeService {
|
||||
async fn find_disk(&self, disk_path: &String) -> Option<DiskStore> {
|
||||
let disk_path = match fs::canonicalize(disk_path).await {
|
||||
Ok(disk_path) => disk_path,
|
||||
Err(_) => return None,
|
||||
};
|
||||
self.local_peer.local_disks.iter().find(|&x| x.path() == disk_path).cloned()
|
||||
find_local_disk(disk_path).await
|
||||
// let disk_path = match fs::canonicalize(disk_path).await {
|
||||
// Ok(disk_path) => disk_path,
|
||||
// Err(_) => return None,
|
||||
// };
|
||||
// self.local_peer.local_disks.iter().find(|&x| x.path() == disk_path).cloned()
|
||||
}
|
||||
|
||||
fn all_disk(&self) -> Vec<String> {
|
||||
self.local_peer
|
||||
.local_disks
|
||||
.iter()
|
||||
.map(|disk| disk.path().to_string_lossy().to_string())
|
||||
.collect()
|
||||
async fn all_disk(&self) -> Vec<String> {
|
||||
all_local_disk_path().await
|
||||
// self.local_peer
|
||||
// .local_disks
|
||||
// .iter()
|
||||
// .map(|disk| disk.path().to_string_lossy().to_string())
|
||||
// .collect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,7 +501,7 @@ impl Node for NodeService {
|
||||
} else {
|
||||
Ok(tonic::Response::new(MakeVolumesResponse {
|
||||
success: false,
|
||||
error_info: Some(format!("can not find disk, all disks: {:?}", self.all_disk())),
|
||||
error_info: Some(format!("can not find disk, all disks: {:?}", self.all_disk().await)),
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -522,7 +522,7 @@ impl Node for NodeService {
|
||||
} else {
|
||||
Ok(tonic::Response::new(MakeVolumeResponse {
|
||||
success: false,
|
||||
error_info: Some(format!("can not find disk, all disks: {:?}", self.all_disk())),
|
||||
error_info: Some(format!("can not find disk, all disks: {:?}", self.all_disk().await)),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
+14
-3
@@ -4,7 +4,11 @@ mod service;
|
||||
mod storage;
|
||||
|
||||
use clap::Parser;
|
||||
use ecstore::{endpoints::EndpointServerPools, error::Result, store::ECStore};
|
||||
use ecstore::{
|
||||
endpoints::EndpointServerPools,
|
||||
error::Result,
|
||||
store::{init_local_disks, update_erasure_type, ECStore},
|
||||
};
|
||||
use grpc::make_server;
|
||||
use hyper_util::{
|
||||
rt::{TokioExecutor, TokioIo},
|
||||
@@ -72,7 +76,13 @@ async fn run(opt: config::Opt) -> Result<()> {
|
||||
// };
|
||||
|
||||
// 用于rpc
|
||||
let (endpoint_pools, _) = EndpointServerPools::from_volumes(opt.address.clone().as_str(), opt.volumes.clone())?;
|
||||
let (endpoint_pools, setup_type) = EndpointServerPools::from_volumes(opt.address.clone().as_str(), opt.volumes.clone())?;
|
||||
|
||||
update_erasure_type(setup_type).await;
|
||||
|
||||
// 初始化本地磁盘
|
||||
init_local_disks(endpoint_pools.clone()).await?;
|
||||
|
||||
// Setup S3 service
|
||||
// 本项目使用s3s库来实现s3服务
|
||||
let service = {
|
||||
@@ -108,7 +118,8 @@ async fn run(opt: config::Opt) -> Result<()> {
|
||||
|
||||
b.build()
|
||||
};
|
||||
let rpc_service = make_server(endpoint_pools.clone());
|
||||
|
||||
let rpc_service = make_server();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let hyper_service = service.into_shared();
|
||||
|
||||
+15
-15
@@ -61,7 +61,7 @@ impl S3 for FS {
|
||||
let input = req.input;
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -94,7 +94,7 @@ impl S3 for FS {
|
||||
let input = req.input;
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -125,7 +125,7 @@ impl S3 for FS {
|
||||
let objects: Vec<ObjectToDelete> = vec![dobj];
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -192,7 +192,7 @@ impl S3 for FS {
|
||||
.collect();
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -233,7 +233,7 @@ impl S3 for FS {
|
||||
let input = req.input;
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -276,7 +276,7 @@ impl S3 for FS {
|
||||
let opts = &ObjectOptions::default();
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -306,7 +306,7 @@ impl S3 for FS {
|
||||
let input = req.input;
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -330,7 +330,7 @@ impl S3 for FS {
|
||||
let HeadObjectInput { bucket, key, .. } = req.input;
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -357,7 +357,7 @@ impl S3 for FS {
|
||||
// mc ls
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -412,7 +412,7 @@ impl S3 for FS {
|
||||
let delimiter = delimiter.unwrap_or_default();
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -499,7 +499,7 @@ impl S3 for FS {
|
||||
let reader = PutObjReader::new(body, content_length as usize);
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -527,7 +527,7 @@ impl S3 for FS {
|
||||
debug!("create_multipart_upload meta {:?}", &metadata);
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -570,7 +570,7 @@ impl S3 for FS {
|
||||
let opts = ObjectOptions::default();
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -632,7 +632,7 @@ impl S3 for FS {
|
||||
}
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
@@ -662,7 +662,7 @@ impl S3 for FS {
|
||||
} = req.input;
|
||||
|
||||
let layer = new_object_layer_fn();
|
||||
let lock = layer.lock().await;
|
||||
let lock = layer.read().await;
|
||||
let store = match lock.as_ref() {
|
||||
Some(s) => s,
|
||||
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, format!("Not init",))),
|
||||
|
||||
Reference in New Issue
Block a user