Skip to content

Commit

Permalink
impl internalize
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Jul 24, 2024
1 parent 5a84039 commit dc2dc3c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/core/src/index/revindex/disk_revindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl RevIndex {
};

let storage = if spec == "rocksdb://" {
todo!("init storage from db")
InnerStorage::new(RocksDBStorage::from_db(db.clone()))
} else {
InnerStorage::from_spec(spec)?
};
Expand All @@ -184,7 +184,7 @@ impl RevIndex {
}
self.db.put_cf(&cf_metadata, MANIFEST, &wtr[..])?;

// write storage spec
// write storage specdisk_re
let spec = self.collection.storage().spec();

// TODO: check if spec if memstorage, would probably have to
Expand Down Expand Up @@ -489,6 +489,11 @@ impl RevIndexOps for RevIndex {
.map(|v| v.set_storage_unchecked(InnerStorage::new(new_storage)));
}

// write storage spec
let cf_metadata = self.db.cf_handle(METADATA).unwrap();
let spec = "rocksdb://";
self.db.put_cf(&cf_metadata, STORAGE_SPEC, spec)?;

Ok(())
}

Expand Down
33 changes: 25 additions & 8 deletions src/core/src/index/revindex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,23 +912,40 @@ mod test {
Some(selection.clone()),
)?;

let mut index = index;
index
.internalize_storage()
.expect("Error internalizing storage");
{
let mut index = index;
index
.internalize_storage()
.expect("Error internalizing storage");

let (counter, query_colors, hash_to_color) = index.prepare_gather_counters(&query);

let matches_internal = index.gather(
counter,
query_colors,
hash_to_color,
0,
&query,
Some(selection.clone()),
)?;
assert_eq!(matches_external, matches_internal);
}
let new_path = outdir.path().join("new_index_path");
std::fs::rename(output.as_path(), new_path.as_path());

Check warning on line 934 in src/core/src/index/revindex/mod.rs

View workflow job for this annotation

GitHub Actions / minimum_rust_version

unused `std::result::Result` that must be used

let index = RevIndex::open(new_path, false, None)?;

let (counter, query_colors, hash_to_color) = index.prepare_gather_counters(&query);

let matches_internal = index.gather(
let matches_moved = index.gather(
counter,
query_colors,
hash_to_color,
0,
&query,
Some(selection),
Some(selection.clone()),
)?;

assert_eq!(matches_external, matches_internal);
assert_eq!(matches_external, matches_moved);

Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/src/storage/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ impl RocksDBStorage {

let db = Arc::new(DB::open_cf_descriptors(&opts, path, cfs).unwrap());

// TODO: save storage_args

Self { db }
}

Expand Down

0 comments on commit dc2dc3c

Please sign in to comment.