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 committed Jul 3, 2024
1 parent 18bc831 commit 422d8fd
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 25 deletions.
103 changes: 92 additions & 11 deletions Cargo.lock

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

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ 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",
"bzip",
"xz",
] }
auto_enums = { version = "0.8", features = ["futures03", "tokio1"] }
await-tree = "0.2.1"
aws-config = { version = "1", default-features = false, features = [
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 @@ -416,7 +416,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 @@ -440,7 +440,7 @@ impl SstableStore {
Block::decode(block_data, uncompressed_capacity)
.map_err(anyhow::Error::from)?,
);
Ok((block, context))
Ok(block)
}
};

Expand All @@ -450,12 +450,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 @@ -476,16 +477,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 @@ -575,7 +572,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 422d8fd

Please sign in to comment.