Skip to content

Commit 4dd9814

Browse files
committed
Review comments
1 parent 4e64d44 commit 4dd9814

File tree

8 files changed

+447
-340
lines changed

8 files changed

+447
-340
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/blockstore/src/arrow/flusher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl ArrowBlockfileFlusher {
7676
self.count
7777
}
7878

79-
pub(crate) fn num_blocks(&self) -> usize {
80-
self.blocks.len()
79+
pub(crate) fn num_entries(&self) -> usize {
80+
self.blocks.iter().fold(0, |acc, block| acc + block.len())
8181
}
8282
}

rust/blockstore/src/types/flusher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ impl BlockfileFlusher {
3939
}
4040
}
4141

42-
pub fn num_blocks(&self) -> usize {
42+
pub fn num_entries(&self) -> usize {
4343
match self {
4444
BlockfileFlusher::MemoryBlockfileFlusher(_) => unimplemented!(),
45-
BlockfileFlusher::ArrowBlockfileFlusher(flusher) => flusher.num_blocks(),
45+
BlockfileFlusher::ArrowBlockfileFlusher(flusher) => flusher.num_entries(),
4646
}
4747
}
4848
}

rust/cache/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ uuid = { workspace = true }
2727

2828
chroma-config = { workspace = true }
2929
chroma-error = { workspace = true }
30+
chroma-tracing = { workspace = true }
3031
chroma-types = { workspace = true }
3132

3233
[dev-dependencies]

rust/cache/src/foyer.rs

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::{CacheError, Weighted};
22
use ahash::RandomState;
33
use chroma_error::ChromaError;
4+
use chroma_tracing::util::Stopwatch;
45
use clap::Parser;
56
use foyer::{
67
CacheBuilder, DirectFsDeviceOptions, Engine, FifoConfig, FifoPicker, HybridCacheBuilder,
@@ -286,24 +287,6 @@ impl Default for FoyerCacheConfig {
286287
}
287288
}
288289

289-
struct Stopwatch<'a>(
290-
&'a opentelemetry::metrics::Histogram<u64>,
291-
std::time::Instant,
292-
);
293-
294-
impl<'a> Stopwatch<'a> {
295-
fn new(histogram: &'a opentelemetry::metrics::Histogram<u64>) -> Self {
296-
Self(histogram, std::time::Instant::now())
297-
}
298-
}
299-
300-
impl Drop for Stopwatch<'_> {
301-
fn drop(&mut self) {
302-
let elapsed = self.1.elapsed().as_micros() as u64;
303-
self.0.record(elapsed, &[]);
304-
}
305-
}
306-
307290
#[derive(Clone)]
308291
pub struct FoyerHybridCache<K, V>
309292
where
@@ -457,7 +440,7 @@ where
457440
V: Clone + Send + Sync + StorageValue + Weighted + 'static,
458441
{
459442
async fn get(&self, key: &K) -> Result<Option<V>, CacheError> {
460-
let _stopwatch = Stopwatch::new(&self.get_latency);
443+
let _stopwatch = Stopwatch::new(&self.get_latency, &[]);
461444
let res = self.cache.get(key).await?.map(|v| v.value().clone());
462445
if res.is_some() {
463446
self.cache_hit.add(1, &[]);
@@ -468,22 +451,22 @@ where
468451
}
469452

470453
async fn insert(&self, key: K, value: V) {
471-
let _stopwatch = Stopwatch::new(&self.insert_latency);
454+
let _stopwatch = Stopwatch::new(&self.insert_latency, &[]);
472455
self.cache.insert(key, value);
473456
}
474457

475458
async fn remove(&self, key: &K) {
476-
let _stopwatch = Stopwatch::new(&self.remove_latency);
459+
let _stopwatch = Stopwatch::new(&self.remove_latency, &[]);
477460
self.cache.remove(key);
478461
}
479462

480463
async fn clear(&self) -> Result<(), CacheError> {
481-
let _stopwatch = Stopwatch::new(&self.clear_latency);
464+
let _stopwatch = Stopwatch::new(&self.clear_latency, &[]);
482465
Ok(self.cache.clear().await?)
483466
}
484467

485468
async fn obtain(&self, key: K) -> Result<Option<V>, CacheError> {
486-
let _stopwatch = Stopwatch::new(&self.obtain_latency);
469+
let _stopwatch = Stopwatch::new(&self.obtain_latency, &[]);
487470
let res = self.cache.obtain(key).await?.map(|v| v.value().clone());
488471
if res.is_some() {
489472
self.cache_hit.add(1, &[]);
@@ -622,7 +605,7 @@ where
622605
V: Clone + Send + Sync + Weighted + 'static,
623606
{
624607
async fn get(&self, key: &K) -> Result<Option<V>, CacheError> {
625-
let _stopwatch = Stopwatch::new(&self.get_latency);
608+
let _stopwatch = Stopwatch::new(&self.get_latency, &[]);
626609
let res = self.cache.get(key).map(|v| v.value().clone());
627610
if res.is_some() {
628611
self.cache_hit.add(1, &[]);
@@ -633,23 +616,23 @@ where
633616
}
634617

635618
async fn insert(&self, key: K, value: V) {
636-
let _stopwatch = Stopwatch::new(&self.insert_latency);
619+
let _stopwatch = Stopwatch::new(&self.insert_latency, &[]);
637620
self.cache.insert(key, value);
638621
}
639622

640623
async fn remove(&self, key: &K) {
641-
let _stopwatch = Stopwatch::new(&self.remove_latency);
624+
let _stopwatch = Stopwatch::new(&self.remove_latency, &[]);
642625
self.cache.remove(key);
643626
}
644627

645628
async fn clear(&self) -> Result<(), CacheError> {
646-
let _stopwatch = Stopwatch::new(&self.clear_latency);
629+
let _stopwatch = Stopwatch::new(&self.clear_latency, &[]);
647630
self.cache.clear();
648631
Ok(())
649632
}
650633

651634
async fn obtain(&self, key: K) -> Result<Option<V>, CacheError> {
652-
let _stopwatch = Stopwatch::new(&self.obtain_latency);
635+
let _stopwatch = Stopwatch::new(&self.obtain_latency, &[]);
653636
let res = self.cache.get(&key).map(|v| v.value().clone());
654637
if res.is_some() {
655638
self.cache_hit.add(1, &[]);

rust/index/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ chroma-blockstore = { workspace = true }
2727
chroma-cache = { workspace = true }
2828
chroma-config = { workspace = true }
2929
chroma-storage = { workspace = true }
30+
chroma-tracing = { workspace = true }
3031
chroma-distance = { workspace = true }
3132
itertools = { workspace = true }
3233
hnswlib = { workspace = true }

0 commit comments

Comments
 (0)