Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade rocksdb version to 0.22 #11

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading