Skip to content

Commit 703bfdc

Browse files
committed
Add a failing test triggering the bug when we don't update all the splitnodes
1 parent 44b732d commit 703bfdc

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

src/tests/assets/v0_6/large.mdb

176 KB
Binary file not shown.
File renamed without changes.

src/tests/upgrade.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use crate::upgrade::from_0_6_to_current;
99
use crate::{Database, Reader};
1010

1111
#[test]
12-
fn upgrade_v0_6_to_v0_7() {
12+
fn simple_upgrade_v0_6_to_v0_7() {
1313
let dir = tempfile::tempdir().unwrap();
14-
std::fs::copy("src/tests/assets/v0_6/data.mdb", dir.path().join("data.mdb")).unwrap();
14+
std::fs::copy("src/tests/assets/v0_6/smol.mdb", dir.path().join("data.mdb")).unwrap();
1515
let env =
1616
unsafe { EnvOpenOptions::new().map_size(200 * 1024 * 1024).open(dir.path()) }.unwrap();
1717
let rtxn = env.read_txn().unwrap();
@@ -92,3 +92,47 @@ fn upgrade_v0_6_to_v0_7() {
9292
Item 5: Leaf(Leaf { header: NodeHeaderEuclidean { bias: 0.0 }, vector: [5.0000, 0.0000] })
9393
"#);
9494
}
95+
96+
97+
// Same test as above but with a larger database. See its original snapshot here: https://github.com/meilisearch/arroy/blob/f52bf0560f5ceef27946bf0522730649be46ccdd/src/tests/snapshots/arroy__tests__writer__write_and_update_lot_of_random_points-2.snap
98+
#[test]
99+
fn large_upgrade_v0_6_to_v0_7() {
100+
let dir = tempfile::tempdir().unwrap();
101+
std::fs::copy("src/tests/assets/v0_6/large.mdb", dir.path().join("data.mdb")).unwrap();
102+
let env =
103+
unsafe { EnvOpenOptions::new().map_size(200 * 1024 * 1024).open(dir.path()) }.unwrap();
104+
let rtxn = env.read_txn().unwrap();
105+
let database: Database<Euclidean> = env.open_database(&rtxn, None).unwrap().unwrap();
106+
107+
// First step is to know if we can still read into the database before the upgrade
108+
let reader = Reader::open(&rtxn, 0, database).unwrap();
109+
// The version is wrong but that's ok because the nodes format didn't change between v0.4 and v0.6 included.
110+
// This bug has been fixed in v0.7.
111+
insta::assert_snapshot!(reader.version(), @"v0.4.0");
112+
insta::assert_snapshot!(reader.n_items(), @"100");
113+
insta::assert_snapshot!(reader.n_trees(), @"10");
114+
insta::assert_snapshot!(reader.dimensions(), @"30");
115+
insta::assert_snapshot!(format!("{:?}", reader.item_ids()), @"RoaringBitmap<100 values between 0 and 99>");
116+
insta::assert_snapshot!(format!("{:?}", reader.stats(&rtxn).unwrap()), @"Stats { leaf: 100, tree_stats: [TreeStats { depth: 4, dummy_normals: 0, split_nodes: 4, descendants: 5 }, TreeStats { depth: 5, dummy_normals: 0, split_nodes: 5, descendants: 6 }, TreeStats { depth: 4, dummy_normals: 0, split_nodes: 4, descendants: 5 }, TreeStats { depth: 7, dummy_normals: 0, split_nodes: 6, descendants: 7 }, TreeStats { depth: 5, dummy_normals: 0, split_nodes: 5, descendants: 6 }, TreeStats { depth: 5, dummy_normals: 0, split_nodes: 6, descendants: 7 }, TreeStats { depth: 4, dummy_normals: 0, split_nodes: 4, descendants: 5 }, TreeStats { depth: 6, dummy_normals: 0, split_nodes: 6, descendants: 7 }, TreeStats { depth: 5, dummy_normals: 0, split_nodes: 4, descendants: 5 }, TreeStats { depth: 6, dummy_normals: 0, split_nodes: 5, descendants: 6 }] }");
117+
insta::assert_snapshot!(format!("{:?}", reader.item_vector(&rtxn, 0).unwrap()), @"Some([0.59189945, 0.9953131, 0.7271174, 0.7734485, 0.5760655, 0.8882299, 0.84973, 0.08173108, 0.39887708, 0.33842397, 0.16736221, 0.13506532, 0.7610012, 0.50516164, 0.51428705, 0.7101963, 0.44652337, 0.7144127, 0.31324244, 0.43315363, 0.98117304, 0.21394211, 0.8465342, 0.27935255, 0.70608264, 0.44866508, 0.9707988, 0.6317311, 0.94693947, 0.17849642])");
118+
insta::assert_snapshot!(format!("{:?}", reader.item_vector(&rtxn, 25).unwrap()), @"Some([0.011625171, 0.53228873, 0.39399207, 0.13821805, 0.19865465, 0.7286784, 0.40262043, 0.14423728, 0.59565574, 0.03397578, 0.54211503, 0.80171144, 0.88514394, 0.5250775, 0.2614928, 0.4367664, 0.94518125, 0.05161941, 0.7546513, 0.5079431, 0.72314125, 0.47682863, 0.36076427, 0.3593862, 0.99203247, 0.5132183, 0.9997714, 0.8521869, 0.58587575, 0.5980581])");
119+
120+
let nns = reader
121+
.nns(3)
122+
.search_k(NonZeroUsize::new(100).unwrap())
123+
.by_vector(&rtxn, &[0.0; 30])
124+
.unwrap();
125+
insta::assert_snapshot!(NnsRes(Some(nns)), @r"
126+
id(92): distance(2.4881108)
127+
id(24): distance(2.5068686)
128+
id(78): distance(2.5809734)
129+
");
130+
131+
let mut wtxn = env.write_txn().unwrap();
132+
from_0_6_to_current(&rtxn, database, &mut wtxn, database).unwrap();
133+
wtxn.commit().unwrap();
134+
drop(rtxn);
135+
136+
let handle = DatabaseHandle { env: env.clone(), database, tempdir: dir };
137+
insta::assert_snapshot!(handle);
138+
}

0 commit comments

Comments
 (0)