Skip to content

[ENH]: bump foyer to v0.17.3 #4473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Cargo.lock

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

27 changes: 27 additions & 0 deletions rust/blockstore/src/arrow/block/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,3 +855,30 @@ where

Ok(())
}

#[cfg(test)]
mod tests {

use std::sync::Arc;

use arrow::{
array::Int32Array,
datatypes::{DataType, Field, Schema},
};

use super::*;

#[test]
fn test_block_serde() {
let batch = RecordBatch::try_new(
Arc::new(Schema::new(vec![Field::new("id", DataType::Int32, false)])),
vec![Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5]))],
)
.unwrap();
let b1 = Block::from_record_batch(Uuid::new_v4(), batch.clone());
let bytes = bincode::serialize(&b1).unwrap();
let b2 = bincode::deserialize::<Block>(&bytes).unwrap();
assert_eq!(b1.id, b2.id);
assert_eq!(b1.data.0, b2.data.0);
}
}
4 changes: 2 additions & 2 deletions rust/cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ path = "src/lib.rs"

[dependencies]
clap = { workspace = true }
foyer = { version = "0.15.3", features = ["tracing"] }
mixtrics = { version = "0.0.4", features = ["opentelemetry_0_27"] }
foyer = { version = "0.17.3", features = ["tracing", "serde"] }
mixtrics = { version = "0.1.0", features = ["opentelemetry_0_27"] }
anyhow = "1.0"
opentelemetry = { version = "0.27.0", default-features = false, features = ["trace", "metrics"] }

Expand Down
30 changes: 15 additions & 15 deletions rust/cache/src/foyer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use chroma_tracing::util::Stopwatch;
use clap::Parser;
use foyer::{
CacheBuilder, DirectFsDeviceOptions, Engine, FifoConfig, FifoPicker, HybridCacheBuilder,
InvalidRatioPicker, LargeEngineOptions, LfuConfig, LruConfig, RateLimitPicker, S3FifoConfig,
StorageKey, StorageValue, TracingOptions,
InvalidRatioPicker, LargeEngineOptions, LfuConfig, LruConfig, S3FifoConfig, StorageKey,
StorageValue, Throttle, TracingOptions,
};
use opentelemetry::global;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -303,7 +303,7 @@ where
K: Clone + Send + Sync + StorageKey + Eq + PartialEq + Hash + 'static,
V: Clone + Send + Sync + StorageValue + Weighted + 'static,
{
cache: foyer::HybridCache<K, V>,
cache: foyer::HybridCache<K, V, RandomState>,
cache_hit: opentelemetry::metrics::Counter<u64>,
cache_miss: opentelemetry::metrics::Counter<u64>,
get_latency: opentelemetry::metrics::Histogram<u64>,
Expand Down Expand Up @@ -376,7 +376,7 @@ where
);
builder.with_hash_builder(rs)
}
false => builder,
false => builder.with_hash_builder(RandomState::new()),
};

let Some(dir) = config.dir.as_ref() else {
Expand All @@ -385,14 +385,19 @@ where
)));
};

let mut builder = builder
let mut device_options = DirectFsDeviceOptions::new(dir)
.with_capacity(config.disk * MIB)
.with_file_size(config.file_size * MIB);
if config.admission_rate_limit > 0 {
device_options = device_options.with_throttle(
Throttle::new().with_write_throughput(config.admission_rate_limit * MIB),
);
}

let builder = builder
.with_weighter(|_, v| v.weight())
.storage(Engine::Large)
.with_device_options(
DirectFsDeviceOptions::new(dir)
.with_capacity(config.disk * MIB)
.with_file_size(config.file_size * MIB),
)
.with_device_options(device_options)
.with_flush(config.flush)
.with_recover_mode(foyer::RecoverMode::Strict)
.with_large_object_disk_cache_options(
Expand All @@ -408,11 +413,6 @@ where
]),
);

if config.admission_rate_limit > 0 {
builder = builder.with_admission_picker(Arc::new(RateLimitPicker::new(
config.admission_rate_limit * MIB,
)));
}
let cache = builder.build().await.map_err(|e| {
CacheError::InvalidCacheConfig(format!("builder failed: {:?}", e)).boxed()
})?;
Expand Down