Skip to content

Commit 7154868

Browse files
committed
Revert production code to use local LRU caches
The shared memory LRU implementation requires proper hook registration (shmem_request_hook and shmem_startup_hook) which is not yet implemented. This reverts the production code (neighbor_store.rs and cache.rs) back to using the process-local util::lru::LruCacheWithStats implementation until the shared memory infrastructure is properly set up. The shared memory LRU code remains in src/lru/ for future use.
1 parent 7870720 commit 7154868

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

pgvectorscale/src/access_method/graph/neighbor_store.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use pgrx::debug1;
55
use rkyv::{Archive, Deserialize, Serialize};
66

77
use crate::access_method::build::maintenance_work_mem_bytes;
8-
// Use the PostgreSQL-native version
9-
use crate::lru::pg_lru_cache_with_stats::PgLruCacheWithStats;
8+
// TODO: Switch back to PostgreSQL-native version once shared memory hooks are implemented
9+
// use crate::lru::pg_lru_cache_with_stats::PgLruCacheWithStats;
10+
use crate::util::lru::LruCacheWithStats;
1011
use crate::util::{IndexPointer, ItemPointer};
1112

1213
use crate::access_method::graph::neighbor_with_distance::*;
@@ -50,7 +51,7 @@ impl NeighborCacheEntry {
5051

5152
pub struct BuilderNeighborCache {
5253
/// Map of node pointer to neighbor cache entry
53-
neighbor_map: RefCell<PgLruCacheWithStats<ItemPointer, NeighborCacheEntry>>,
54+
neighbor_map: RefCell<LruCacheWithStats<ItemPointer, NeighborCacheEntry>>,
5455
num_neighbors: usize,
5556
max_alpha: f64,
5657
}
@@ -63,7 +64,7 @@ impl BuilderNeighborCache {
6364
/ NeighborCacheEntry::size(meta_page.get_num_neighbors() as _, meta_page.has_labels());
6465

6566
Self {
66-
neighbor_map: RefCell::new(PgLruCacheWithStats::new(
67+
neighbor_map: RefCell::new(LruCacheWithStats::new(
6768
NonZero::new(capacity).unwrap(),
6869
"Builder neighbor",
6970
)),

pgvectorscale/src/access_method/sbq/cache.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use std::num::NonZero;
33
use pgrx::debug1;
44

55
use crate::access_method::storage::Storage;
6-
// Use the PostgreSQL-native version
7-
use crate::lru::pg_lru_cache_with_stats::PgLruCacheWithStats;
6+
// TODO: Switch back to PostgreSQL-native version once shared memory hooks are implemented
7+
// use crate::lru::pg_lru_cache_with_stats::PgLruCacheWithStats;
8+
use crate::util::lru::LruCacheWithStats;
89

910
use crate::{
1011
access_method::{
@@ -17,7 +18,7 @@ use crate::{
1718
use super::{node::SbqNode, SbqSpeedupStorage, SbqVectorElement};
1819

1920
pub struct QuantizedVectorCache {
20-
cache: PgLruCacheWithStats<ItemPointer, Vec<SbqVectorElement>>,
21+
cache: LruCacheWithStats<ItemPointer, Vec<SbqVectorElement>>,
2122
// Cache the last accessed value to return references
2223
last_value: Option<Vec<SbqVectorElement>>,
2324
}
@@ -29,7 +30,7 @@ impl QuantizedVectorCache {
2930
let capacity = std::cmp::max(memory_budget / Self::entry_size(sbq_vec_len), min_capacity);
3031

3132
Self {
32-
cache: PgLruCacheWithStats::new(NonZero::new(capacity).unwrap(), "Quantized vector"),
33+
cache: LruCacheWithStats::new(NonZero::new(capacity).unwrap(), "Quantized vector"),
3334
last_value: None,
3435
}
3536
}
@@ -51,7 +52,7 @@ impl QuantizedVectorCache {
5152
#[cfg(not(test))]
5253
{
5354
if let Some(value) = self.cache.get(&index_pointer) {
54-
self.last_value = Some(value);
55+
self.last_value = Some(value.clone());
5556
} else {
5657
// Not in cache, need to read from storage
5758
let node = unsafe {

0 commit comments

Comments
 (0)