Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactoring LruCacheLayer with list_with_metakey and concurrent_stat_in_list #4596

Merged
merged 10 commits into from
Aug 23, 2024
24 changes: 13 additions & 11 deletions src/object-store/src/layers/lru_cache/read_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use common_telemetry::debug;
use futures::FutureExt;
use moka::future::Cache;
use moka::notification::ListenerFuture;
use opendal::raw::oio::{List, Read, Reader, Write};
use opendal::raw::{Access, OpDelete, OpList, OpRead, OpStat, OpWrite, RpRead};
use opendal::{Error as OpendalError, ErrorKind, Result};
use opendal::raw::oio::{Read, Reader, Write};
use opendal::raw::{Access, OpDelete, OpRead, OpStat, OpWrite, RpRead};
use opendal::{Error as OpendalError, ErrorKind, Metakey, OperatorBuilder, Result};

use crate::metrics::{
OBJECT_STORE_LRU_CACHE_BYTES, OBJECT_STORE_LRU_CACHE_ENTRIES, OBJECT_STORE_LRU_CACHE_HIT,
Expand Down Expand Up @@ -142,18 +142,20 @@ impl<C: Access> ReadCache<C> {
/// Recover existing cache items from `file_cache` to `mem_cache`.
/// Return entry count and total approximate entry size in bytes.
pub(crate) async fn recover_cache(&self) -> Result<(u64, u64)> {
let (_, mut pager) = self.file_cache.list("/", OpList::default()).await?;

while let Some(entry) = pager.next().await? {
let op = OperatorBuilder::new(self.file_cache.clone()).finish();
let mut entries = op
.list_with("/")
.metakey(Metakey::ContentLength | Metakey::ContentType)
.concurrent(1)
ozewr marked this conversation as resolved.
Show resolved Hide resolved
.await?;

while let Some(entry) = entries.pop() {
let read_key = entry.path();

// We can't retrieve the metadata from `[opendal::raw::oio::Entry]` directly,
// because it's private field.
let size = {
let stat = self.file_cache.stat(read_key, OpStat::default()).await?;

stat.into_metadata().content_length()
};
// let size = entry.
let size = entry.metadata().content_length();

OBJECT_STORE_LRU_CACHE_ENTRIES.inc();
OBJECT_STORE_LRU_CACHE_BYTES.add(size as i64);
Expand Down