Skip to content

Commit

Permalink
Expose format version (rust-rocksdb#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian authored and Oleksandr Anyshchenko committed Nov 28, 2019
1 parent 4a7cf46 commit 64bd098
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* Updated lz4 to v1.9.2 (ordian)
* BlockBasedOptions: expose `format_version`, `[index_]block_restart_interval` (ordian)

## 0.13.0 (2019-11-12)

Expand Down
34 changes: 34 additions & 0 deletions src/db_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,40 @@ impl BlockBasedOptions {
);
}
}

/// Format version, reserved for backward compatibility.
/// See https://github.com/facebook/rocksdb/blob/f059c7d9b96300091e07429a60f4ad55dac84859/include/rocksdb/table.h#L249-L274.
///
/// Default: 2.
pub fn set_format_version(&mut self, version: i32) {
unsafe {
ffi::rocksdb_block_based_options_set_format_version(self.inner, version);
}
}

/// Number of keys between restart points for delta encoding of keys.
/// This parameter can be changed dynamically. Most clients should
/// leave this parameter alone. The minimum value allowed is 1. Any smaller
/// value will be silently overwritten with 1.
///
/// Default: 16.
pub fn set_block_restart_interval(&mut self, interval: i32) {
unsafe {
ffi::rocksdb_block_based_options_set_block_restart_interval(self.inner, interval);
}
}

/// Same as block_restart_interval but used for the index block.
/// If you don't plan to run RocksDB before version 5.16 and you are
/// using `index_block_restart_interval` > 1, you should
/// probably set the `format_version` to >= 4 as it would reduce the index size.
///
/// Default: 1.
pub fn set_index_block_restart_interval(&mut self, interval: i32) {
unsafe {
ffi::rocksdb_block_based_options_set_index_block_restart_interval(self.inner, interval);
}
}
}

impl Default for BlockBasedOptions {
Expand Down
22 changes: 20 additions & 2 deletions tests/test_rocksdb_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extern crate rocksdb;
mod util;

use rocksdb::{BlockBasedOptions, Options, ReadOptions, DB};
use std::{fs, io::Read as _};
use util::DBPath;

#[test]
Expand Down Expand Up @@ -52,16 +53,33 @@ fn test_set_level_compaction_dynamic_level_bytes() {
}

#[test]
fn test_set_pin_l0_filter_and_index_blocks_in_cache() {
let n = DBPath::new("_rust_rocksdb_test_set_pin_l0_filter_and_index_blocks_in_cache");
fn test_block_based_options() {
let path = "_rust_rocksdb_test_block_based_options";
let n = DBPath::new(path);
{
let mut opts = Options::default();
opts.create_if_missing(true);

let mut block_opts = BlockBasedOptions::default();
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(4);
block_opts.set_index_block_restart_interval(16);

opts.set_block_based_table_factory(&block_opts);
let _db = DB::open(&opts, &n).unwrap();

// read the setting from the LOG file
let mut rocksdb_log = fs::File::open(format!("{}/LOG", n.as_ref().to_str().unwrap()))
.expect("rocksdb creates a LOG file");
let mut settings = String::new();
rocksdb_log.read_to_string(&mut settings).unwrap();

// check the settings are set in the LOG file
assert!(settings.contains("cache_index_and_filter_blocks: 1"));
assert!(settings.contains("pin_l0_filter_and_index_blocks_in_cache: 1"));
assert!(settings.contains("format_version: 4"));
assert!(settings.contains("index_block_restart_interval: 16"));
}
}

Expand Down

0 comments on commit 64bd098

Please sign in to comment.