fix GLOBAL_LOCAL_DISK_MAP key

Signed-off-by: junxiang Mu <1948535941@qq.com>
This commit is contained in:
junxiang Mu
2024-12-09 14:55:38 +08:00
parent d66c22c4a6
commit 8f8a645568
2 changed files with 47 additions and 36 deletions
+19 -8
View File
@@ -1048,7 +1048,7 @@ type NodeClient = NodeServiceClient<
#[derive(Debug)] #[derive(Debug)]
pub struct RemoteFileWriter { pub struct RemoteFileWriter {
pub root: PathBuf, pub endpoint: Endpoint,
pub volume: String, pub volume: String,
pub path: String, pub path: String,
pub is_append: bool, pub is_append: bool,
@@ -1057,7 +1057,13 @@ pub struct RemoteFileWriter {
} }
impl RemoteFileWriter { impl RemoteFileWriter {
pub async fn new(root: PathBuf, volume: String, path: String, is_append: bool, mut client: NodeClient) -> Result<Self> { pub async fn new(
endpoint: Endpoint,
volume: String,
path: String,
is_append: bool,
mut client: NodeClient,
) -> Result<Self> {
let (tx, rx) = mpsc::channel(128); let (tx, rx) = mpsc::channel(128);
let in_stream = ReceiverStream::new(rx); let in_stream = ReceiverStream::new(rx);
@@ -1066,7 +1072,7 @@ impl RemoteFileWriter {
let resp_stream = response.into_inner(); let resp_stream = response.into_inner();
Ok(Self { Ok(Self {
root, endpoint,
volume, volume,
path, path,
is_append, is_append,
@@ -1084,7 +1090,7 @@ impl Writer for RemoteFileWriter {
async fn write(&mut self, buf: &[u8]) -> Result<()> { async fn write(&mut self, buf: &[u8]) -> Result<()> {
let request = WriteRequest { let request = WriteRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: self.volume.to_string(), volume: self.volume.to_string(),
path: self.path.to_string(), path: self.path.to_string(),
is_append: self.is_append, is_append: self.is_append,
@@ -1239,7 +1245,7 @@ impl Reader for LocalFileReader {
#[derive(Debug)] #[derive(Debug)]
pub struct RemoteFileReader { pub struct RemoteFileReader {
pub root: PathBuf, pub endpoint: Endpoint,
pub volume: String, pub volume: String,
pub path: String, pub path: String,
tx: Sender<ReadAtRequest>, tx: Sender<ReadAtRequest>,
@@ -1247,7 +1253,12 @@ pub struct RemoteFileReader {
} }
impl RemoteFileReader { impl RemoteFileReader {
pub async fn new(root: PathBuf, volume: String, path: String, mut client: NodeClient) -> Result<Self> { pub async fn new(
endpoint: Endpoint,
volume: String,
path: String,
mut client: NodeClient,
) -> Result<Self> {
let (tx, rx) = mpsc::channel(128); let (tx, rx) = mpsc::channel(128);
let in_stream = ReceiverStream::new(rx); let in_stream = ReceiverStream::new(rx);
@@ -1256,7 +1267,7 @@ impl RemoteFileReader {
let resp_stream = response.into_inner(); let resp_stream = response.into_inner();
Ok(Self { Ok(Self {
root, endpoint,
volume, volume,
path, path,
tx, tx,
@@ -1269,7 +1280,7 @@ impl RemoteFileReader {
impl Reader for RemoteFileReader { impl Reader for RemoteFileReader {
async fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Result<usize> { async fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Result<usize> {
let request = ReadAtRequest { let request = ReadAtRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: self.volume.to_string(), volume: self.volume.to_string(),
path: self.path.to_string(), path: self.path.to_string(),
offset: offset.try_into().unwrap(), offset: offset.try_into().unwrap(),
+28 -28
View File
@@ -130,7 +130,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(ReadAllRequest { let request = Request::new(ReadAllRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
path: path.to_string(), path: path.to_string(),
}); });
@@ -152,7 +152,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(WriteAllRequest { let request = Request::new(WriteAllRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
path: path.to_string(), path: path.to_string(),
data, data,
@@ -174,7 +174,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(DeleteRequest { let request = Request::new(DeleteRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
path: path.to_string(), path: path.to_string(),
options, options,
@@ -196,7 +196,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(VerifyFileRequest { let request = Request::new(VerifyFileRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
path: path.to_string(), path: path.to_string(),
file_info, file_info,
@@ -220,7 +220,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(CheckPartsRequest { let request = Request::new(CheckPartsRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
path: path.to_string(), path: path.to_string(),
file_info, file_info,
@@ -243,7 +243,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(RenamePartRequst { let request = Request::new(RenamePartRequst {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
src_volume: src_volume.to_string(), src_volume: src_volume.to_string(),
src_path: src_path.to_string(), src_path: src_path.to_string(),
dst_volume: dst_volume.to_string(), dst_volume: dst_volume.to_string(),
@@ -265,7 +265,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(RenameFileRequst { let request = Request::new(RenameFileRequst {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
src_volume: src_volume.to_string(), src_volume: src_volume.to_string(),
src_path: src_path.to_string(), src_path: src_path.to_string(),
dst_volume: dst_volume.to_string(), dst_volume: dst_volume.to_string(),
@@ -285,7 +285,7 @@ impl DiskAPI for RemoteDisk {
info!("create_file"); info!("create_file");
Ok(FileWriter::Remote( Ok(FileWriter::Remote(
RemoteFileWriter::new( RemoteFileWriter::new(
self.root.clone(), self.endpoint.clone(),
volume.to_string(), volume.to_string(),
path.to_string(), path.to_string(),
false, false,
@@ -301,7 +301,7 @@ impl DiskAPI for RemoteDisk {
info!("append_file"); info!("append_file");
Ok(FileWriter::Remote( Ok(FileWriter::Remote(
RemoteFileWriter::new( RemoteFileWriter::new(
self.root.clone(), self.endpoint.clone(),
volume.to_string(), volume.to_string(),
path.to_string(), path.to_string(),
true, true,
@@ -317,7 +317,7 @@ impl DiskAPI for RemoteDisk {
info!("read_file"); info!("read_file");
Ok(FileReader::Remote( Ok(FileReader::Remote(
RemoteFileReader::new( RemoteFileReader::new(
self.root.clone(), self.endpoint.clone(),
volume.to_string(), volume.to_string(),
path.to_string(), path.to_string(),
node_service_time_out_client(&self.addr) node_service_time_out_client(&self.addr)
@@ -334,7 +334,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(ListDirRequest { let request = Request::new(ListDirRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
}); });
@@ -354,7 +354,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(WalkDirRequest { let request = Request::new(WalkDirRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
walk_dir_options, walk_dir_options,
}); });
@@ -387,7 +387,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(RenameDataRequest { let request = Request::new(RenameDataRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
src_volume: src_volume.to_string(), src_volume: src_volume.to_string(),
src_path: src_path.to_string(), src_path: src_path.to_string(),
file_info, file_info,
@@ -412,7 +412,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(MakeVolumesRequest { let request = Request::new(MakeVolumesRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volumes: volumes.iter().map(|s| (*s).to_string()).collect(), volumes: volumes.iter().map(|s| (*s).to_string()).collect(),
}); });
@@ -431,7 +431,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(MakeVolumeRequest { let request = Request::new(MakeVolumeRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
}); });
@@ -450,7 +450,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(ListVolumesRequest { let request = Request::new(ListVolumesRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
}); });
let response = client.list_volumes(request).await?.into_inner(); let response = client.list_volumes(request).await?.into_inner();
@@ -474,7 +474,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(StatVolumeRequest { let request = Request::new(StatVolumeRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
}); });
@@ -496,7 +496,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(DeletePathsRequest { let request = Request::new(DeletePathsRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
paths, paths,
}); });
@@ -518,7 +518,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(UpdateMetadataRequest { let request = Request::new(UpdateMetadataRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
path: path.to_string(), path: path.to_string(),
file_info, file_info,
@@ -541,7 +541,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(WriteMetadataRequest { let request = Request::new(WriteMetadataRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
path: path.to_string(), path: path.to_string(),
file_info, file_info,
@@ -570,7 +570,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(ReadVersionRequest { let request = Request::new(ReadVersionRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
path: path.to_string(), path: path.to_string(),
version_id: version_id.to_string(), version_id: version_id.to_string(),
@@ -594,7 +594,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(ReadXlRequest { let request = Request::new(ReadXlRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
path: path.to_string(), path: path.to_string(),
read_data, read_data,
@@ -626,7 +626,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(DeleteVersionRequest { let request = Request::new(DeleteVersionRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
path: path.to_string(), path: path.to_string(),
file_info, file_info,
@@ -660,7 +660,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(DeleteVersionsRequest { let request = Request::new(DeleteVersionsRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
versions: versions_str, versions: versions_str,
opts, opts,
@@ -695,7 +695,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(ReadMultipleRequest { let request = Request::new(ReadMultipleRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
read_multiple_req, read_multiple_req,
}); });
@@ -720,7 +720,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(DeleteVolumeRequest { let request = Request::new(DeleteVolumeRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
volume: volume.to_string(), volume: volume.to_string(),
}); });
@@ -740,7 +740,7 @@ impl DiskAPI for RemoteDisk {
.await .await
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(DiskInfoRequest { let request = Request::new(DiskInfoRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
opts, opts,
}); });
@@ -772,7 +772,7 @@ impl DiskAPI for RemoteDisk {
let in_stream = ReceiverStream::new(rx); let in_stream = ReceiverStream::new(rx);
let mut response = client.ns_scanner(in_stream).await?.into_inner(); let mut response = client.ns_scanner(in_stream).await?.into_inner();
let request = NsScannerRequest { let request = NsScannerRequest {
disk: self.root.to_string_lossy().to_string(), disk: self.endpoint.to_string(),
cache, cache,
scan_mode: scan_mode as u64, scan_mode: scan_mode as u64,
}; };