Skip to content
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

fix: remove dup cache consts and respect index size param #2948

Merged
merged 2 commits into from
Sep 29, 2024
Merged
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
3 changes: 0 additions & 3 deletions rust/lance-core/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ use object_store::path::Path;
use crate::utils::path::LancePathExt;
use crate::Result;

pub const DEFAULT_INDEX_CACHE_SIZE: usize = 128;
pub const DEFAULT_METADATA_CACHE_SIZE: usize = 128;

type ArcAny = Arc<dyn Any + Send + Sync>;

#[derive(Clone)]
Expand Down
9 changes: 9 additions & 0 deletions rust/lance/src/index/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use moka::sync::{Cache, ConcurrentCacheExt};

use std::sync::atomic::{AtomicU64, Ordering};

use crate::dataset::DEFAULT_INDEX_CACHE_SIZE;

#[derive(Debug, Default, DeepSizeOf)]
struct CacheStats {
hits: AtomicU64,
Expand Down Expand Up @@ -71,6 +73,13 @@ impl IndexCache {
}
}

pub(crate) fn capacity(&self) -> u64 {
self.vector_cache
.policy()
.max_capacity()
.unwrap_or(DEFAULT_INDEX_CACHE_SIZE as u64)
}

#[allow(dead_code)]
pub(crate) fn len_vector(&self) -> usize {
self.vector_cache.sync();
Expand Down
5 changes: 3 additions & 2 deletions rust/lance/src/index/vector/ivf/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use futures::prelude::stream::{self, StreamExt, TryStreamExt};
use lance_arrow::RecordBatchExt;
use lance_core::cache::FileMetadataCache;
use lance_core::utils::tokio::get_num_compute_intensive_cpus;
use lance_core::{cache::DEFAULT_INDEX_CACHE_SIZE, Error, Result};
use lance_core::{Error, Result};
use lance_encoding::decoder::{DecoderMiddlewareChain, FilterExpression};
use lance_file::v2::reader::FileReader;
use lance_index::vector::flat::index::{FlatIndex, FlatQuantizer};
Expand Down Expand Up @@ -122,6 +122,7 @@ impl<S: IvfSubIndex + 'static, Q: Quantization> IVFIndex<S, Q> {
.upgrade()
.map(|sess| sess.file_metadata_cache.clone())
.unwrap_or_else(FileMetadataCache::no_cache);
let index_cache_capacity = session.upgrade().unwrap().index_cache.capacity();
let index_reader = FileReader::try_open(
scheduler
.open_file(&index_dir.child(uuid.as_str()).child(INDEX_FILE_NAME))
Expand Down Expand Up @@ -191,7 +192,7 @@ impl<S: IvfSubIndex + 'static, Q: Quantization> IVFIndex<S, Q> {
ivf,
reader: index_reader,
storage,
partition_cache: Cache::new(DEFAULT_INDEX_CACHE_SIZE as u64),
partition_cache: Cache::new(index_cache_capacity),
partition_locks: PartitionLoadLock::new(num_partitions),
sub_index_metadata,
distance_type,
Expand Down
Loading