From 0f61414900a39e8dbb7aaa3d093c2ef7619b9f41 Mon Sep 17 00:00:00 2001 From: MrCroxx Date: Mon, 1 Jul 2024 14:44:19 +0800 Subject: [PATCH 1/5] fix(storage): fix abnormal file cache miss on fetch Signed-off-by: MrCroxx --- Cargo.lock | 16 ++++++---------- Cargo.toml | 2 ++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 80cfce6eb09dc..4151b8c0c4700 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5372,8 +5372,7 @@ dependencies = [ [[package]] name = "foyer" version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0720e9cc504174e952382345ea25fe887fbd4c1761dccdd4c5276c6d1a93dbc5" +source = "git+https://github.com/mrcroxx/foyer?rev=1c20d09a52a38f09988f1d33f119087bab13f384#1c20d09a52a38f09988f1d33f119087bab13f384" dependencies = [ "ahash 0.8.11", "anyhow", @@ -5381,14 +5380,14 @@ dependencies = [ "foyer-memory", "foyer-storage", "madsim-tokio", + "pin-project", "tracing", ] [[package]] name = "foyer-common" version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a823da3228992cc6392ddac757e0ed44fa4923588b03fcbbba4bad1ebfea7b2" +source = "git+https://github.com/mrcroxx/foyer?rev=1c20d09a52a38f09988f1d33f119087bab13f384#1c20d09a52a38f09988f1d33f119087bab13f384" dependencies = [ "bytes", "cfg-if", @@ -5406,8 +5405,7 @@ dependencies = [ [[package]] name = "foyer-intrusive" version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5168b34c3e6369a4c6055f08c6b37e416910652bfdd9a84de55a602f2aa3dcea" +source = "git+https://github.com/mrcroxx/foyer?rev=1c20d09a52a38f09988f1d33f119087bab13f384#1c20d09a52a38f09988f1d33f119087bab13f384" dependencies = [ "foyer-common", "itertools 0.13.0", @@ -5416,8 +5414,7 @@ dependencies = [ [[package]] name = "foyer-memory" version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56055774fa6ed25d0affe30c04e6a3f18fc00713a42ef6a3dbd96e72fe31a3eb" +source = "git+https://github.com/mrcroxx/foyer?rev=1c20d09a52a38f09988f1d33f119087bab13f384#1c20d09a52a38f09988f1d33f119087bab13f384" dependencies = [ "ahash 0.8.11", "bitflags 2.5.0", @@ -5437,8 +5434,7 @@ dependencies = [ [[package]] name = "foyer-storage" version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74811aec3df193b9c304d031e9f4879c4aab86cb78ff6e4cadf1188d014e7069" +source = "git+https://github.com/mrcroxx/foyer?rev=1c20d09a52a38f09988f1d33f119087bab13f384#1c20d09a52a38f09988f1d33f119087bab13f384" dependencies = [ "ahash 0.8.11", "allocator-api2", diff --git a/Cargo.toml b/Cargo.toml index 3fe6abc8787ba..3ee608f6cb24a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -346,6 +346,8 @@ deno_web = { git = "https://github.com/bakjos/deno", rev = "787a232" } deno_websocket = { git = "https://github.com/bakjos/deno", rev = "787a232" } # patch to remove preserve_order from serde_json bson = { git = "https://github.com/risingwavelabs/bson-rust", rev = "e5175ec" } +# patch foyer unitl new version release +foyer = { git = "https://github.com/mrcroxx/foyer", rev = "1c20d09a52a38f09988f1d33f119087bab13f384" } [workspace.metadata.dylint] libraries = [{ path = "./lints" }] From 01e506bf3d5cab2c93d9792dd01afb8264fd9589 Mon Sep 17 00:00:00 2001 From: MrCroxx Date: Tue, 2 Jul 2024 17:12:44 +0800 Subject: [PATCH 2/5] refactor: upgrade foyer Signed-off-by: MrCroxx --- Cargo.lock | 109 ++++++++++++++++++++--- Cargo.toml | 4 +- src/storage/src/hummock/sstable_store.rs | 19 ++-- 3 files changed, 106 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3722b05b286af..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,41 +5387,49 @@ dependencies = [ [[package]] name = "foyer" -version = "0.9.4" -source = "git+https://github.com/mrcroxx/foyer?rev=1c20d09a52a38f09988f1d33f119087bab13f384#1c20d09a52a38f09988f1d33f119087bab13f384" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +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" -source = "git+https://github.com/mrcroxx/foyer?rev=1c20d09a52a38f09988f1d33f119087bab13f384#1c20d09a52a38f09988f1d33f119087bab13f384" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +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" -source = "git+https://github.com/mrcroxx/foyer?rev=1c20d09a52a38f09988f1d33f119087bab13f384#1c20d09a52a38f09988f1d33f119087bab13f384" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f7883ac7a8a69115f5bd84072a0b98d4ba72feacddf9040c217a5012bb352ff" dependencies = [ "foyer-common", "itertools 0.13.0", @@ -5413,8 +5437,9 @@ dependencies = [ [[package]] name = "foyer-memory" -version = "0.5.2" -source = "git+https://github.com/mrcroxx/foyer?rev=1c20d09a52a38f09988f1d33f119087bab13f384#1c20d09a52a38f09988f1d33f119087bab13f384" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fd7b0ce80867803c6b197db20cc1a49fcecc9d5070d2fb829660ec19acf9e72" dependencies = [ "ahash 0.8.11", "bitflags 2.5.0", @@ -5426,15 +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" -source = "git+https://github.com/mrcroxx/foyer?rev=1c20d09a52a38f09988f1d33f119087bab13f384#1c20d09a52a38f09988f1d33f119087bab13f384" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4205359a7ea9d05ff7525f0e55a5257a593c89b4e22ebfa07e06a84c2e163202" dependencies = [ "ahash 0.8.11", "allocator-api2", @@ -5453,6 +5481,7 @@ dependencies = [ "libc", "lz4", "madsim-tokio", + "minitrace", "parking_lot 0.12.1", "pin-project", "rand", @@ -7735,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" @@ -7744,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" @@ -9925,7 +9991,7 @@ dependencies = [ "indoc", "libc", "memoffset", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -12413,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" @@ -15557,7 +15632,7 @@ dependencies = [ "tracing-core", "tracing-log 0.2.0", "tracing-subscriber", - "web-time", + "web-time 0.2.3", ] [[package]] @@ -16679,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 3ee608f6cb24a..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", @@ -346,8 +346,6 @@ deno_web = { git = "https://github.com/bakjos/deno", rev = "787a232" } deno_websocket = { git = "https://github.com/bakjos/deno", rev = "787a232" } # patch to remove preserve_order from serde_json bson = { git = "https://github.com/risingwavelabs/bson-rust", rev = "e5175ec" } -# patch foyer unitl new version release -foyer = { git = "https://github.com/mrcroxx/foyer", rev = "1c20d09a52a38f09988f1d33f119087bab13f384" } [workspace.metadata.dylint] libraries = [{ path = "./lints" }] 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)) } }); From 0060e872fa8af6cb57f3e2ff47faa7c6308f84c0 Mon Sep 17 00:00:00 2001 From: MrCroxx Date: Tue, 2 Jul 2024 17:59:34 +0800 Subject: [PATCH 3/5] fix: fix bench Signed-off-by: MrCroxx --- src/storage/benches/bench_block_cache.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/storage/benches/bench_block_cache.rs b/src/storage/benches/bench_block_cache.rs index f00e6a7b0e2be..ecb96d6a54cd0 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(|block| Arc::new(block)) } }) .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(|block| Arc::new(block)) .map_err(anyhow::Error::from) } }) From 53e1061e07d29857817fa0d7fa9c3b95a780d64d Mon Sep 17 00:00:00 2001 From: MrCroxx Date: Tue, 2 Jul 2024 20:38:52 +0800 Subject: [PATCH 4/5] chore: make clippy happy Signed-off-by: MrCroxx --- src/storage/benches/bench_block_cache.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/storage/benches/bench_block_cache.rs b/src/storage/benches/bench_block_cache.rs index ecb96d6a54cd0..fff5f18ca524f 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)) + .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)) + .map(block) .map_err(anyhow::Error::from) } }) From 8c54f733bb9731807ff879b96c5e92c468071f5c Mon Sep 17 00:00:00 2001 From: MrCroxx Date: Tue, 2 Jul 2024 20:46:45 +0800 Subject: [PATCH 5/5] chore: fix again, hate my local env, QwQ Signed-off-by: MrCroxx --- src/storage/benches/bench_block_cache.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage/benches/bench_block_cache.rs b/src/storage/benches/bench_block_cache.rs index fff5f18ca524f..92b9268a7c7f9 100644 --- a/src/storage/benches/bench_block_cache.rs +++ b/src/storage/benches/bench_block_cache.rs @@ -229,7 +229,7 @@ impl CacheBase for FoyerHybridCache { async move { get_fake_block(sst_object_id, block_idx, latency) .await - .map(block) + .map(Arc::new) .map_err(anyhow::Error::from) } })