use rocksdb::{BlockBasedOptions, Options, SliceTransform};
use crate::{store::rocks::store::RocksOptions, types::kv_codec::EDGE_PREFIX_LENGTH};
const BLOOM_FILTER_BITS_PER_KEY: f64 = 10.0;
const BLOCK_FORMAT_VERSION: i32 = 6;
pub(super) fn vertex_block_opts(rocksdb_opts: &RocksOptions) -> BlockBasedOptions {
let mut opts = BlockBasedOptions::default();
opts.set_bloom_filter(BLOOM_FILTER_BITS_PER_KEY, false);
opts.set_format_version(BLOCK_FORMAT_VERSION);
opts.set_block_size(rocksdb_opts.vertex_block_size);
opts.set_cache_index_and_filter_blocks(rocksdb_opts.cache_index_and_filter_blocks);
if rocksdb_opts.cache_index_and_filter_blocks {
opts.set_pin_l0_filter_and_index_blocks_in_cache(true);
}
opts
}
pub(super) fn vertex_cf_opts(rocksdb_opts: &RocksOptions, block_opts: &BlockBasedOptions) -> Options {
let mut opts = Options::default();
opts.set_block_based_table_factory(block_opts);
opts.set_write_buffer_size(rocksdb_opts.write_buffer_size);
opts.set_max_write_buffer_number(rocksdb_opts.max_write_buffer_number);
opts
}
pub(super) fn edge_block_opts(rocksdb_opts: &RocksOptions) -> BlockBasedOptions {
let mut opts = BlockBasedOptions::default();
opts.set_bloom_filter(BLOOM_FILTER_BITS_PER_KEY, false);
opts.set_format_version(BLOCK_FORMAT_VERSION);
opts.set_block_size(rocksdb_opts.edge_block_size);
opts.set_cache_index_and_filter_blocks(rocksdb_opts.cache_index_and_filter_blocks);
if rocksdb_opts.cache_index_and_filter_blocks {
opts.set_pin_l0_filter_and_index_blocks_in_cache(true);
}
opts
}
pub(super) fn edge_cf_opts(rocksdb_opts: &RocksOptions, block_opts: &BlockBasedOptions) -> Options {
let mut opts = Options::default();
opts.set_prefix_extractor(SliceTransform::create_fixed_prefix(EDGE_PREFIX_LENGTH));
opts.set_block_based_table_factory(block_opts);
opts.set_write_buffer_size(rocksdb_opts.write_buffer_size);
opts.set_max_write_buffer_number(rocksdb_opts.max_write_buffer_number);
opts.set_memtable_prefix_bloom_ratio(0.1);
opts
}