init metacache io

This commit is contained in:
weisd
2024-12-05 17:40:55 +08:00
parent b38c181992
commit ed0966cca3
10 changed files with 330 additions and 33 deletions
+10 -2
View File
@@ -1291,10 +1291,18 @@ impl DiskAPI for LocalDisk {
Ok(entries)
}
// TODO: io.writer
async fn walk_dir(&self, opts: WalkDirOptions) -> Result<Vec<MetaCacheEntry>> {
// FIXME: TODO: io.writer
async fn walk_dir(&self, opts: WalkDirOptions, wr: crate::io::Writer) -> Result<Vec<MetaCacheEntry>> {
// warn!("walk_dir opts {:?}", &opts);
let volume_dir = self.get_bucket_path(&opts.bucket)?;
if !skip_access_checks(&opts.bucket) {
if let Err(e) = access(&volume_dir).await {
return Err(convert_access_error(e, DiskError::VolumeAccessDenied));
}
}
let mut metas = Vec::new();
if opts.base_dir.ends_with(SLASH_SEPARATOR) {
+9 -7
View File
@@ -22,6 +22,7 @@ use crate::{
data_usage_cache::{DataUsageCache, DataUsageEntry},
heal_commands::{HealScanMode, HealingTracker},
},
io,
store_api::{FileInfo, RawFileInfo},
};
use endpoint::Endpoint;
@@ -208,10 +209,10 @@ impl DiskAPI for Disk {
}
}
async fn walk_dir(&self, opts: WalkDirOptions) -> Result<Vec<MetaCacheEntry>> {
async fn walk_dir(&self, opts: WalkDirOptions, wr: crate::io::Writer) -> Result<Vec<MetaCacheEntry>> {
match self {
Disk::Local(local_disk) => local_disk.walk_dir(opts).await,
Disk::Remote(remote_disk) => remote_disk.walk_dir(opts).await,
Disk::Local(local_disk) => local_disk.walk_dir(opts, wr).await,
Disk::Remote(remote_disk) => remote_disk.walk_dir(opts, wr).await,
}
}
@@ -403,7 +404,7 @@ pub trait DiskAPI: Debug + Send + Sync + 'static {
async fn delete_volume(&self, volume: &str) -> Result<()>;
// 并发边读边写 TODO: wr io.Writer
async fn walk_dir(&self, opts: WalkDirOptions) -> Result<Vec<MetaCacheEntry>>;
async fn walk_dir(&self, opts: WalkDirOptions, wr: crate::io::Writer) -> Result<Vec<MetaCacheEntry>>;
// Metadata operations
async fn delete_version(
@@ -599,10 +600,10 @@ pub struct MetaCacheEntry {
pub metadata: Vec<u8>,
// cached contains the metadata if decoded.
cached: Option<FileMeta>,
pub cached: Option<FileMeta>,
// Indicates the entry can be reused and only one reference to metadata is expected.
_reusable: bool,
pub reusable: bool,
}
impl MetaCacheEntry {
@@ -616,6 +617,7 @@ impl MetaCacheEntry {
Ok(wr)
}
pub fn is_dir(&self) -> bool {
self.metadata.is_empty() && self.name.ends_with('/')
}
@@ -838,7 +840,7 @@ impl MetaCacheEntries {
meta_ver: selected.as_ref().unwrap().cached.as_ref().unwrap().meta_ver,
..Default::default()
}),
_reusable: true,
reusable: true,
..Default::default()
});
+1 -1
View File
@@ -346,7 +346,7 @@ impl DiskAPI for RemoteDisk {
Ok(response.volumes)
}
async fn walk_dir(&self, opts: WalkDirOptions) -> Result<Vec<MetaCacheEntry>> {
async fn walk_dir(&self, opts: WalkDirOptions, wr: crate::io::Writer) -> Result<Vec<MetaCacheEntry>> {
info!("walk_dir");
let walk_dir_options = serde_json::to_string(&opts)?;
let mut client = node_service_time_out_client(&self.addr)