diff --git a/Cargo.lock b/Cargo.lock index 3bd81fd37f7b4..2c85ea791906e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2421,6 +2421,12 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "cache-padded" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "981520c98f422fcc584dc1a95c334e6953900b9106bc47a9839b81790009eb21" + [[package]] name = "cache_control" version = "0.2.0" @@ -3414,6 +3420,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "ctor" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" +dependencies = [ + "quote", + "syn 1.0.109", +] + [[package]] name = "ctr" version = "0.9.2" @@ -5371,43 +5387,49 @@ dependencies = [ [[package]] name = "foyer" -version = "0.9.4" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0720e9cc504174e952382345ea25fe887fbd4c1761dccdd4c5276c6d1a93dbc5" +checksum = "cbfceb28a004d50b6110fd012db1d52d318d15f721dbb5b65eda261b821c1baa" dependencies = [ "ahash 0.8.11", "anyhow", "foyer-common", "foyer-memory", "foyer-storage", + "futures", "madsim-tokio", + "minitrace", + "pin-project", "tracing", ] [[package]] name = "foyer-common" -version = "0.7.3" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a823da3228992cc6392ddac757e0ed44fa4923588b03fcbbba4bad1ebfea7b2" +checksum = "6ce1b903e1e142eafe8cd3183087fcd7ed6452e5dc8dfb5356a607ec2aa1c869" dependencies = [ "bytes", "cfg-if", "crossbeam", + "futures", "hashbrown 0.14.3", "itertools 0.13.0", "madsim-tokio", "metrics", + "minitrace", "nix 0.29.0", "parking_lot 0.12.1", + "pin-project", "rustversion", "serde", ] [[package]] name = "foyer-intrusive" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5168b34c3e6369a4c6055f08c6b37e416910652bfdd9a84de55a602f2aa3dcea" +checksum = "2f7883ac7a8a69115f5bd84072a0b98d4ba72feacddf9040c217a5012bb352ff" dependencies = [ "foyer-common", "itertools 0.13.0", @@ -5415,9 +5437,9 @@ dependencies = [ [[package]] name = "foyer-memory" -version = "0.5.2" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56055774fa6ed25d0affe30c04e6a3f18fc00713a42ef6a3dbd96e72fe31a3eb" +checksum = "9fd7b0ce80867803c6b197db20cc1a49fcecc9d5070d2fb829660ec19acf9e72" dependencies = [ "ahash 0.8.11", "bitflags 2.5.0", @@ -5429,16 +5451,18 @@ dependencies = [ "itertools 0.13.0", "libc", "madsim-tokio", + "minitrace", "parking_lot 0.12.1", + "pin-project", "serde", "tracing", ] [[package]] name = "foyer-storage" -version = "0.8.5" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74811aec3df193b9c304d031e9f4879c4aab86cb78ff6e4cadf1188d014e7069" +checksum = "4205359a7ea9d05ff7525f0e55a5257a593c89b4e22ebfa07e06a84c2e163202" dependencies = [ "ahash 0.8.11", "allocator-api2", @@ -5457,6 +5481,7 @@ dependencies = [ "libc", "lz4", "madsim-tokio", + "minitrace", "parking_lot 0.12.1", "pin-project", "rand", @@ -7739,6 +7764,33 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "minitrace" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "197d538cd69839d49a593c8c72df44291b0ea3296ecc0c85529002c53c8fbc6f" +dependencies = [ + "minitrace-macro", + "minstant", + "once_cell", + "parking_lot 0.12.1", + "pin-project", + "rand", + "rtrb", +] + +[[package]] +name = "minitrace-macro" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14efd4b574325fcb981bce1ac700b9ccf071ec2eb94f7a6a6b583a84f228ba47" +dependencies = [ + "proc-macro-error 1.0.4", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "miniz_oxide" version = "0.7.2" @@ -7748,6 +7800,16 @@ dependencies = [ "adler", ] +[[package]] +name = "minstant" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fb9b5c752f145ac5046bccc3c4f62892e3c950c1d1eab80c5949cd68a2078db" +dependencies = [ + "ctor", + "web-time 1.1.0", +] + [[package]] name = "mio" version = "0.8.11" @@ -9929,7 +9991,7 @@ dependencies = [ "indoc", "libc", "memoffset", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -12417,6 +12479,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rtrb" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99e704dd104faf2326a320140f70f0b736d607c1caa1b1748a6c568a79819109" +dependencies = [ + "cache-padded", +] + [[package]] name = "rumqttc" version = "0.24.0" @@ -15561,7 +15632,7 @@ dependencies = [ "tracing-core", "tracing-log 0.2.0", "tracing-subscriber", - "web-time", + "web-time 0.2.3", ] [[package]] @@ -16683,6 +16754,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webpki" version = "0.22.4" diff --git a/Cargo.toml b/Cargo.toml index 3fe6abc8787ba..f6c0d5bc229ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", diff --git a/src/storage/benches/bench_block_cache.rs b/src/storage/benches/bench_block_cache.rs index f00e6a7b0e2be..92b9268a7c7f9 100644 --- a/src/storage/benches/bench_block_cache.rs +++ b/src/storage/benches/bench_block_cache.rs @@ -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?; @@ -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) } }) diff --git a/src/storage/src/hummock/sstable_store.rs b/src/storage/src/hummock/sstable_store.rs index 3240a4243a586..c654e12bb7d69 100644 --- a/src/storage/src/hummock/sstable_store.rs +++ b/src/storage/src/hummock/sstable_store.rs @@ -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 { @@ -453,7 +453,7 @@ impl SstableStore { Block::decode(block_data, uncompressed_capacity) .map_err(anyhow::Error::from)?, ); - Ok((block, context)) + Ok(block) } }; @@ -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; @@ -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))) } } @@ -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)) } });