Skip to content

Commit

Permalink
fix(storage): fix abnormal file cache miss on fetch (#17513)
Browse files Browse the repository at this point in the history
Signed-off-by: MrCroxx <[email protected]>
  • Loading branch information
MrCroxx authored Jul 2, 2024
1 parent 65331e6 commit cd4660e
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 26 deletions.
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

0 comments on commit cd4660e

Please sign in to comment.