Skip to content

Commit

Permalink
Upgrade rocksdb version to 0.22 (#11)
Browse files Browse the repository at this point in the history
* Upgrade rocksdb version to 0.22

Move config from SDK to here
  • Loading branch information
citizen-stig authored Jun 24, 2024
1 parent 6e8be84 commit e9aa4ae
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ once_cell = "1"
prometheus = { version = "0.13" }
proptest = { version = "1", optional = true }
proptest-derive = { version = "0.4", optional = true }
rocksdb = { version = "0.21" }
rocksdb = { version = "0.22", features = ["lz4"], default-features = false }
thiserror = "1"
tracing = "0.1"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
Expand Down
46 changes: 46 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use rocksdb::Options;

/// Port selected RocksDB options for tuning underlying rocksdb instance of our state db.
/// The current default values are taken from Aptos. TODO: tune rocksdb for our workload.
/// see <https://github.com/facebook/rocksdb/blob/master/include/rocksdb/options.h>
/// for detailed explanations.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct RocksdbConfig {
/// The maximum number of files that can be open concurrently. Defaults to 5000
pub max_open_files: i32,
/// Once write-ahead logs exceed this size, RocksDB will start forcing the flush of column
/// families whose memtables are backed by the oldest live WAL file. Defaults to 1GB
pub max_total_wal_size: u64,
/// The maximum number of background threads, including threads for flushing and compaction. Defaults to 16.
pub max_background_jobs: i32,
}

impl Default for RocksdbConfig {
fn default() -> Self {
Self {
// Allow db to close old sst files, saving memory.
max_open_files: 5000,
// For now we set the max total WAL size to be 1G. This config can be useful when column
// families are updated at non-uniform frequencies.
max_total_wal_size: 1u64 << 30,
// This includes threads for flushing and compaction. Rocksdb will decide the # of
// threads to use internally.
max_background_jobs: 16,
}
}
}

/// Generate [`rocksdb::Options`] corresponding to the given [`RocksdbConfig`].
pub fn gen_rocksdb_options(config: &RocksdbConfig, readonly: bool) -> Options {
let mut db_opts = Options::default();
db_opts.set_max_open_files(config.max_open_files);
db_opts.set_max_total_wal_size(config.max_total_wal_size);
db_opts.set_max_background_jobs(config.max_background_jobs);
if !readonly {
db_opts.create_if_missing(true);
db_opts.create_missing_column_families(true);
db_opts.set_atomic_flush(true);
}

db_opts
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ mod metrics;
pub mod schema;
mod schema_batch;

mod config;
#[cfg(feature = "test-utils")]
pub mod test;

pub use config::{gen_rocksdb_options, RocksdbConfig};

use std::path::Path;
use std::sync::{Arc, LockResult, RwLock, RwLockReadGuard};

Expand Down

0 comments on commit e9aa4ae

Please sign in to comment.