Skip to content
Draft
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
8 changes: 8 additions & 0 deletions rust/lance-core/src/cache/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ pub trait CacheBackend: Send + Sync + std::fmt::Debug {
codec: Option<CacheCodec>,
) -> Result<(CacheEntry, bool)>;

/// Largest entry size the backend admits to RAM, in bytes. Defaults to
/// the total capacity; sharded backends may report a smaller limit.
/// `None` means the backend does not expose an admission limit.
/// Admission never guarantees that an entry will remain cached.
fn max_entry_bytes(&self) -> Option<u64> {
self.capacity_bytes().map(|bytes| bytes as u64)
}

/// Remove all entries.
async fn clear(&self);

Expand Down
12 changes: 12 additions & 0 deletions rust/lance-core/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,18 @@ impl LanceCache {
self.state.backend.capacity_bytes()
}

/// Largest admissible RAM entry, if reported by the backend. An admitted
/// entry remains subject to ordinary cache eviction.
///
/// ```
/// use lance_core::cache::LanceCache;
/// let cache = LanceCache::with_capacity(1024);
/// assert_eq!(cache.max_entry_bytes(), Some(1024));
/// ```
pub fn max_entry_bytes(&self) -> Option<u64> {
self.state.backend.max_entry_bytes()
}

// -- Stats / clear --------------------------------------------------------

pub async fn stats(&self) -> CacheStats {
Expand Down
11 changes: 11 additions & 0 deletions rust/lance-core/src/cache/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ impl CacheBackend for QuickCacheBackend {
Some(self.capacity)
}

fn max_entry_bytes(&self) -> Option<u64> {
Some((self.capacity / self.cache.num_shards()) as u64)
}

fn approx_num_entries(&self) -> usize {
self.cache.len()
+ self
Expand Down Expand Up @@ -598,6 +602,13 @@ mod tests {
QuickCacheBackend::with_capacity(1 << 20).capacity_bytes(),
Some(1 << 20)
);
for capacity in [0, 1 << 20, 16 << 30] {
let backend = QuickCacheBackend::with_capacity(capacity);
assert_eq!(
backend.max_entry_bytes(),
Some((capacity / backend.cache.num_shards()) as u64)
);
}
}

fn keys_in_shard(
Expand Down
1 change: 1 addition & 0 deletions rust/lance-index/src/vector/bq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod lazy_tests;
pub(crate) mod pairwise;
mod plane_cache;
pub mod prune;
pub mod resident;
pub mod rotation;
pub mod storage;
pub mod transform;
Expand Down
Loading
Loading