From 9c3cd5a246236c670fc457880b983f847d55218d Mon Sep 17 00:00:00 2001 From: MrCroxx Date: Thu, 17 Apr 2025 22:52:44 +0800 Subject: [PATCH 1/3] feat: add feature hybrid Signed-off-by: MrCroxx --- Cargo.toml | 2 +- foyer/Cargo.toml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 25ab3184..73fce5dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ edition = "2021" rust-version = "1.81.0" repository = "https://github.com/foyer-rs/foyer" homepage = "https://foyer.rs" -keywords = ["cache", "hybrid"] +keywords = ["cache", "hybrid", "tiered"] authors = ["MrCroxx "] license = "Apache-2.0" readme = "README.md" diff --git a/foyer/Cargo.toml b/foyer/Cargo.toml index 10f4222b..3d71c8d8 100644 --- a/foyer/Cargo.toml +++ b/foyer/Cargo.toml @@ -56,7 +56,8 @@ tokio = { package = "tokio", version = "1", features = [ ] } [features] -default = [] +default = ["hybrid"] +hybrid = [] serde = ["foyer-common/serde", "foyer-storage/serde"] tracing = [ "fastrace/enable", From 92fec2d51c22c68f4f5778c55596912c06d8ac9b Mon Sep 17 00:00:00 2001 From: MrCroxx Date: Thu, 17 Apr 2025 23:55:10 +0800 Subject: [PATCH 2/3] feat: support disable `hybrid` feature to memory cache only Signed-off-by: MrCroxx --- .github/workflows/ci.yml | 23 +++++++++++++++++++++++ Makefile | 1 + foyer-memory/src/raw.rs | 4 +--- foyer/Cargo.toml | 4 ++-- foyer/src/lib.rs | 2 ++ foyer/src/prelude.rs | 12 ++++++++---- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37af8b60..5b100444 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,6 +89,28 @@ jobs: toolchain: stable - name: Run cargo machete uses: bnjbvr/cargo-machete@main + rust-cargo-tree: + name: show rust dependencies + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest, ubuntu-24.04-arm] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Install rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + - name: Print in-memory only foyer dependencies + run: | + cargo tree -p foyer --no-default-features -e normal + - name: Print hybrid foyer dependencies + run: | + cargo tree -p foyer -e normal + rust-udeps: name: rust udeps test strategy: @@ -205,6 +227,7 @@ jobs: - name: Run rust clippy check (stable) if: matrix.rust_toolchain == 'stable' run: | + cargo clippy -p foyer --no-default-features cargo clippy --all-targets ${{ matrix.serde }} --features tokio-console -- -D warnings cargo clippy --all-targets ${{ matrix.serde }} --features deadlock -- -D warnings cargo clippy --all-targets ${{ matrix.serde }} --features tracing -- -D warnings diff --git a/Makefile b/Makefile index e7a7a154..2d5b1c07 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ check-all: cargo sort -w taplo fmt cargo fmt --all + cargo clippy -p foyer --no-default-features cargo clippy --all-targets --features deadlock cargo clippy --all-targets --features tokio-console cargo clippy --all-targets --features tracing diff --git a/foyer-memory/src/raw.rs b/foyer-memory/src/raw.rs index 122dd6b8..2af7a4ad 100644 --- a/foyer-memory/src/raw.rs +++ b/foyer-memory/src/raw.rs @@ -344,9 +344,7 @@ where let (tx, rx) = oneshot::channel(); o.get_mut().push(tx); self.metrics.memory_queue.increase(1); - RawShardFetch::Wait(rx.in_span(Span::enter_with_local_parent( - "foyer::memory::raw::fetch_with_runtime::wait", - ))) + RawShardFetch::Wait(rx.in_span(Span::enter_with_local_parent("foyer::memory::raw::fetch_queue::wait"))) } HashMapEntry::Vacant(v) => { v.insert(vec![]); diff --git a/foyer/Cargo.toml b/foyer/Cargo.toml index 3d71c8d8..6281619d 100644 --- a/foyer/Cargo.toml +++ b/foyer/Cargo.toml @@ -22,7 +22,7 @@ equivalent = { workspace = true } fastrace = { workspace = true } foyer-common = { workspace = true } foyer-memory = { workspace = true } -foyer-storage = { workspace = true } +foyer-storage = { workspace = true, optional = true } mixtrics = { workspace = true } pin-project = { workspace = true } serde = { workspace = true } @@ -57,7 +57,7 @@ tokio = { package = "tokio", version = "1", features = [ [features] default = ["hybrid"] -hybrid = [] +hybrid = ["dep:foyer-storage"] serde = ["foyer-common/serde", "foyer-storage/serde"] tracing = [ "fastrace/enable", diff --git a/foyer/src/lib.rs b/foyer/src/lib.rs index 0cdc7d00..e9475c9f 100644 --- a/foyer/src/lib.rs +++ b/foyer/src/lib.rs @@ -28,8 +28,10 @@ use foyer_common as common; use foyer_memory as memory; +#[cfg(feature = "hybrid")] use foyer_storage as storage; +#[cfg(feature = "hybrid")] mod hybrid; mod prelude; diff --git a/foyer/src/prelude.rs b/foyer/src/prelude.rs index 573f1f42..f9640f06 100644 --- a/foyer/src/prelude.rs +++ b/foyer/src/prelude.rs @@ -21,15 +21,19 @@ pub use crate::{ range::RangeBoundsExt, tracing::TracingOptions, }, + memory::{ + Cache, CacheBuilder, CacheEntry, CacheHint, EvictionConfig, FetchState, FifoConfig, LfuConfig, LruConfig, + S3FifoConfig, Weighter, + }, +}; + +#[cfg(feature = "hybrid")] +pub use crate::{ hybrid::{ builder::{HybridCacheBuilder, HybridCacheBuilderPhaseMemory, HybridCacheBuilderPhaseStorage}, cache::{HybridCache, HybridCacheEntry, HybridCachePolicy, HybridFetch}, writer::{HybridCacheStorageWriter, HybridCacheWriter}, }, - memory::{ - Cache, CacheBuilder, CacheEntry, CacheHint, EvictionConfig, FetchState, FifoConfig, LfuConfig, LruConfig, - S3FifoConfig, Weighter, - }, storage::{ AdmissionPicker, AdmitAllPicker, ChainedAdmissionPicker, ChainedAdmissionPickerBuilder, Compression, Dev, DevConfig, DevExt, DirectFileDevice, DirectFileDeviceOptions, DirectFsDevice, DirectFsDeviceOptions, Engine, From 47e83e4a5c1b2bdd41d4a56291c30a35b53d4588 Mon Sep 17 00:00:00 2001 From: MrCroxx Date: Thu, 17 Apr 2025 23:58:24 +0800 Subject: [PATCH 3/3] chore: make ffmt happy Signed-off-by: MrCroxx --- foyer/src/prelude.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/foyer/src/prelude.rs b/foyer/src/prelude.rs index f9640f06..ea967c6b 100644 --- a/foyer/src/prelude.rs +++ b/foyer/src/prelude.rs @@ -26,7 +26,6 @@ pub use crate::{ S3FifoConfig, Weighter, }, }; - #[cfg(feature = "hybrid")] pub use crate::{ hybrid::{