Skip to content

Commit

Permalink
save version in DB
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Oct 9, 2023
1 parent 3a13ab2 commit 2a0a619
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/core/src/index/revindex/disk_revindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::collection::{Collection, CollectionSet};
use crate::encodings::{Color, Idx};
use crate::index::revindex::{
self as module, prepare_query, stats_for_cf, Datasets, DbStats, HashToColor, QueryColors,
RevIndexOps, DB, HASHES, MANIFEST, METADATA, STORAGE_SPEC,
RevIndexOps, DB, HASHES, MANIFEST, METADATA, STORAGE_SPEC, VERSION,
};
use crate::index::{GatherResult, SigCounter};
use crate::manifest::Manifest;
Expand All @@ -23,6 +23,8 @@ use crate::sketch::Sketch;
use crate::storage::{InnerStorage, Storage};
use crate::Result;

const DB_VERSION: u8 = 1;

fn compute_color(idxs: &Datasets) -> Color {
let s = BuildHasherDefault::<twox_hash::Xxh3Hash128>::default();
let mut hasher = s.build_hasher();
Expand Down Expand Up @@ -126,6 +128,9 @@ impl RevIndex {
fn load_collection_from_rocksdb(db: Arc<DB>) -> Result<CollectionSet> {
let cf_metadata = db.cf_handle(METADATA).unwrap();

let rdr = db.get_cf(&cf_metadata, VERSION)?.unwrap();
assert_eq!(rdr[0], DB_VERSION);

let rdr = db.get_cf(&cf_metadata, MANIFEST)?.unwrap();
let manifest = Manifest::from_reader(&rdr[..])?;

Expand All @@ -144,6 +149,11 @@ impl RevIndex {
fn save_collection(&self) -> Result<()> {
let cf_metadata = self.db.cf_handle(METADATA).unwrap();

// save DB version
// TODO: probably should go together with a more general
// saving procedure used in create/update
self.db.put_cf(&cf_metadata, VERSION, &[DB_VERSION])?;

// write manifest
let mut wtr = vec![];
{
Expand Down
9 changes: 7 additions & 2 deletions src/core/src/index/revindex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ type HashToColorT = HashMap<HashIntoType, Color, BuildNoHashHasher<HashIntoType>
#[derive(Serialize, Deserialize)]
pub struct HashToColor(HashToColorT);

// Column families
const HASHES: &str = "hashes";
const COLORS: &str = "colors";
const METADATA: &str = "metadata";

// DB metadata saved in the METADATA column family
const MANIFEST: &str = "manifest";
const STORAGE_SPEC: &str = "storage_spec";
const VERSION: &str = "version";

#[enum_dispatch(RevIndexOps)]
pub enum RevIndex {
Expand Down Expand Up @@ -205,11 +209,12 @@ impl RevIndex {
block_opts.set_block_size(16 * 1024);
block_opts.set_cache_index_and_filter_blocks(true);
block_opts.set_pin_l0_filter_and_index_blocks_in_cache(true);
block_opts.set_format_version(5);
block_opts.set_format_version(6);
opts.set_block_based_table_factory(&block_opts);
// End of updated defaults

opts.increase_parallelism(8);
opts.increase_parallelism(rayon::current_num_threads() as i32);
//opts.max_background_jobs = 6;
// opts.optimize_level_style_compaction();
// opts.optimize_universal_style_compaction();

Expand Down

0 comments on commit 2a0a619

Please sign in to comment.