更新全局disk

This commit is contained in:
weisd
2024-09-11 14:25:53 +08:00
parent c494bd56ed
commit 7e108f167d
10 changed files with 301 additions and 103 deletions
+15 -4
View File
@@ -1,6 +1,7 @@
use std::{path::PathBuf, sync::RwLock, time::Duration};
use bytes::Bytes;
use futures::lock::Mutex;
use protos::{
node_service_time_out_client,
proto_gen::node_service::{
@@ -32,6 +33,7 @@ use super::{
#[derive(Debug)]
pub struct RemoteDisk {
id: Mutex<Option<Uuid>>,
channel: RwLock<Option<Channel>>,
url: url::Url,
pub root: PathBuf,
@@ -45,6 +47,7 @@ impl RemoteDisk {
channel: RwLock::new(None),
url: ep.url.clone(),
root,
id: Mutex::new(None),
})
}
@@ -83,15 +86,23 @@ impl DiskAPI for RemoteDisk {
fn is_local(&self) -> bool {
false
}
fn id(&self) -> Uuid {
Uuid::nil()
async fn close(&self) -> Result<()> {
Ok(())
}
fn path(&self) -> PathBuf {
self.root.clone()
}
async fn get_disk_id(&self) -> Option<Uuid> {
self.id.lock().await.clone()
}
async fn set_disk_id(&self, id: Option<Uuid>) -> Result<()> {
let mut lock = self.id.lock().await;
*lock = id;
Ok(())
}
async fn read_all(&self, volume: &str, path: &str) -> Result<Bytes> {
let mut client = self.get_client();
let request = Request::new(ReadAllRequest {