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

fix(storage): fix abnormal file cache miss on fetch #17513

Merged
merged 7 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 93 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ license = "Apache-2.0"
repository = "https://github.com/risingwavelabs/risingwave"

[workspace.dependencies]
foyer = { version = "0.9.4", features = ["nightly"] }
foyer = { version = "0.10.0", features = ["nightly"] }
apache-avro = { git = "https://github.com/risingwavelabs/avro", rev = "25113ba88234a9ae23296e981d8302c290fdaa4b", features = [
"snappy",
"zstandard",
Expand Down
4 changes: 2 additions & 2 deletions src/storage/benches/bench_block_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl CacheBase for FoyerCache {
async move {
get_fake_block(sst_object_id, block_idx, latency)
.await
.map(|block| (Arc::new(block), foyer::CacheContext::Default))
.map(Arc::new)
}
})
.await?;
Expand Down Expand Up @@ -229,7 +229,7 @@ impl CacheBase for FoyerHybridCache {
async move {
get_fake_block(sst_object_id, block_idx, latency)
.await
.map(|block| (Arc::new(block), foyer::CacheContext::Default))
.map(Arc::new)
.map_err(anyhow::Error::from)
}
})
Expand Down
19 changes: 8 additions & 11 deletions src/storage/src/hummock/sstable_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl SstableStore {
};

// future: fetch block if hybrid cache miss
let fetch_block = move |context: CacheContext| {
let fetch_block = move || {
let range = range.clone();

async move {
Expand All @@ -453,7 +453,7 @@ impl SstableStore {
Block::decode(block_data, uncompressed_capacity)
.map_err(anyhow::Error::from)?,
);
Ok((block, context))
Ok(block)
}
};

Expand All @@ -463,12 +463,13 @@ impl SstableStore {

match policy {
CachePolicy::Fill(context) => {
let entry = self.block_cache.fetch(
let entry = self.block_cache.fetch_with_context(
SstableBlockIndex {
sst_id: object_id,
block_idx: block_index as _,
},
move || fetch_block(context),
context,
fetch_block,
);
if matches!(entry.state(), FetchState::Miss) {
stats.cache_data_block_miss += 1;
Expand All @@ -489,16 +490,12 @@ impl SstableStore {
entry,
)))
} else {
let (block, _) = fetch_block(CacheContext::default())
.await
.map_err(HummockError::foyer_error)?;
let block = fetch_block().await.map_err(HummockError::foyer_error)?;
Ok(BlockResponse::Block(BlockHolder::from_owned_block(block)))
}
}
CachePolicy::Disable => {
let (block, _) = fetch_block(CacheContext::default())
.await
.map_err(HummockError::foyer_error)?;
let block = fetch_block().await.map_err(HummockError::foyer_error)?;
Ok(BlockResponse::Block(BlockHolder::from_owned_block(block)))
}
}
Expand Down Expand Up @@ -590,7 +587,7 @@ impl SstableStore {
let sst = Sstable::new(object_id, meta);
let add = (now.elapsed().as_secs_f64() * 1000.0).ceil();
stats_ptr.fetch_add(add as u64, Ordering::Relaxed);
Ok((Box::new(sst), CacheContext::Default))
Ok(Box::new(sst))
}
});

Expand Down
Loading