Skip to content

Commit

Permalink
Tests passing again
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgreen42 committed Dec 12, 2024
1 parent 1f1fc55 commit f7ac2a2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pgvectorscale/src/access_method/sbq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl SbqMeans {
quantizer
}
_ => {
pgrx::error!("Invalid page type for SbqMeans");
pgrx::error!("Invalid page type {} for SbqMeans", page_type as u8);
}
}
}
Expand Down
40 changes: 40 additions & 0 deletions pgvectorscale/src/util/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,43 @@ impl<'a, S: StatsNodeRead> Iterator for ChainedItemIterator<'a, S> {
}
}
}

#[cfg(any(test, feature = "pg_test"))]
#[pgrx::pg_schema]
mod tests {
use pgrx::{pg_sys, pg_test, Spi};

use crate::access_method::stats::InsertStats;

use super::*;

fn make_test_relation() -> PgRelation {
Spi::run(
"CREATE TABLE test(encoding vector(3));
CREATE INDEX idxtest
ON test
USING diskann(encoding)
WITH (num_neighbors=30);",
)
.unwrap();

let index_oid = Spi::get_one::<pg_sys::Oid>("SELECT 'idxtest'::regclass::oid")
.unwrap()
.expect("oid was null");
unsafe { PgRelation::from_pg(pg_sys::RelationIdGetRelation(index_oid)) }
}

#[pg_test]
fn test_chain_tape() {
let mut stats = InsertStats::default();
let index = make_test_relation();
let mut tape = ChainTapeWriter::new(&index, PageType::SbqMeans, &mut stats);
let data = b"hello world";
let ip = tape.write(data).unwrap();
let mut reader = ChainTapeReader::new(&index, PageType::SbqMeans, &mut stats);
let mut iter = reader.read(ip);
let item = iter.next().unwrap();
assert_eq!(item.get_data_slice(), data);
assert!(iter.next().is_none());
}
}
19 changes: 6 additions & 13 deletions pgvectorscale/src/util/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ pub enum PageType {
PqQuantizerVector = 3,
SbqMeansV1 = 4,
SbqNode = 5,
MetaV2 = 6,
Meta = 7,
SbqMeans = 8,
Meta = 6,
SbqMeans = 7,
}

impl PageType {
Expand All @@ -44,15 +43,15 @@ impl PageType {
1 => PageType::Node,
2 => PageType::PqQuantizerDef,
3 => PageType::PqQuantizerVector,
4 => PageType::SbqMeans,
4 => PageType::SbqMeansV1,
5 => PageType::SbqNode,
6 => PageType::MetaV2,
7 => PageType::Meta,
6 => PageType::Meta,
7 => PageType::SbqMeans,
_ => panic!("Unknown PageType number {}", value),
}
}

/// `Tape` supports chaining of pages that might contain large data.
/// `ChainTape` supports chaining of pages that might contain large data.
pub fn is_chained(self) -> bool {
matches!(self, PageType::SbqMeans)
}
Expand Down Expand Up @@ -144,12 +143,6 @@ impl<'a> WritablePage<'a> {
unsafe { self.add_item_unchecked(data) }
}

pub unsafe fn replace_item(&mut self, offset: OffsetNumber, data: &[u8]) {
let result =
pg_sys::PageIndexTupleOverwrite(self.page, offset, data.as_ptr() as _, data.len());
assert!(result);
}

pub unsafe fn add_item_unchecked(&mut self, data: &[u8]) -> OffsetNumber {
let size = data.len();
assert!(size < BLCKSZ as usize);
Expand Down
13 changes: 0 additions & 13 deletions pgvectorscale/src/util/tape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,6 @@ mod tests {
node_page
};

{
let mut tape = Tape::resume(&indexrel, PageType::SbqMeans);
let ip = tape.write(&[99]);
assert_eq!(
ip.block_number, tape.current,
"Tape block number should match IP"
);
assert_ne!(
tape.current, node_page,
"Data can only be written to page of its type"
);
}

{
let mut tape = Tape::resume(&indexrel, PageType::PqQuantizerVector);
let ip = tape.write(&[99]);
Expand Down

0 comments on commit f7ac2a2

Please sign in to comment.