rocksolid 3.0.0

An ergonomic, high-level RocksDB wrapper for Rust. Features CF-aware optimistic & pessimistic transactions, advanced routing for merge operators and compaction filters, performance tuning profiles, batching, TTL values, and DAO macros.
Documentation
mod common;

use common::setup_logging;

use rocksdb::Options as RocksDbOptions;
use rocksolid::tuner::Tunable;

#[test]
fn test_tunable_locking_behavior() {
  setup_logging();

  // `set_` applies the option and locks its key.
  let mut opts = Tunable::new(RocksDbOptions::default());
  opts.set_max_open_files(100);
  assert!(opts.is_locked("db_max_open_files"));
  // Other keys are unaffected.
  assert!(!opts.is_locked("db_max_background_jobs"));

  // `tune_` on a locked key is a no-op and leaves the lock in place.
  opts.tune_set_max_open_files(200);
  assert!(opts.is_locked("db_max_open_files"));

  // `tune_` on an unlocked key applies the option but does not lock it,
  // so a later `set_` still applies (and locks).
  let mut opts2 = Tunable::new(RocksDbOptions::default());
  opts2.tune_set_max_open_files(50);
  assert!(!opts2.is_locked("db_max_open_files"));
  opts2.set_max_open_files(75);
  assert!(opts2.is_locked("db_max_open_files"));
}

// `use_fsync` is the one option with both a Tunable setter and a getter on
// `rocksdb::Options`, so it lets us verify the actual values, not just the
// lock bookkeeping.
#[test]
fn test_tunable_locked_value_is_not_overwritten() {
  setup_logging();

  // A `tune_` after a `set_` must not overwrite the value.
  let mut opts = Tunable::new(RocksDbOptions::default());
  opts.set_use_fsync(true); // locks "db_use_fsync"
  opts.tune_set_use_fsync(false); // must be a no-op
  assert!(opts.inner.get_use_fsync(), "tune_ overwrote a locked option value");

  // A `tune_` on an unlocked key must actually apply the value.
  let mut opts2 = Tunable::new(RocksDbOptions::default());
  assert!(!opts2.inner.get_use_fsync()); // default is false
  opts2.tune_set_use_fsync(true);
  assert!(
    opts2.inner.get_use_fsync(),
    "tune_ failed to apply an unlocked option value"
  );
  assert!(!opts2.is_locked("db_use_fsync")); // tune_ does not lock

  // `into_inner` hands back the customized raw options.
  let raw = opts.into_inner();
  assert!(raw.get_use_fsync());
}