From 63aed224eedf47636f3843fbd5a9426978f7078c Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Fri, 21 Jun 2024 16:50:44 +0200 Subject: [PATCH 1/5] Upgrade rocksdb version to 0.22 Move config from SDK to here --- Cargo.toml | 2 +- src/config.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/config.rs diff --git a/Cargo.toml b/Cargo.toml index d6225ad..0bf838e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..9c57e4e --- /dev/null +++ b/src/config.rs @@ -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 +/// 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 +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index cbe93da..92b96b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,6 +22,7 @@ mod schema_batch; #[cfg(feature = "test-utils")] pub mod test; +mod config; use std::path::Path; use std::sync::{Arc, LockResult, RwLock, RwLockReadGuard}; From 42afeb29bbe01198afb74bcc082d77f6ed3b87aa Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Fri, 21 Jun 2024 17:00:08 +0200 Subject: [PATCH 2/5] pub use --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 92b96b2..c7acf13 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,6 +24,8 @@ mod schema_batch; pub mod test; mod config; +pub use config::RocksdbConfig; + use std::path::Path; use std::sync::{Arc, LockResult, RwLock, RwLockReadGuard}; From c6f85d31f698498ea5cc6516306ad95e1b63f773 Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Fri, 21 Jun 2024 17:01:04 +0200 Subject: [PATCH 3/5] Fix lint --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index c7acf13..ae78fd4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,9 +20,9 @@ mod metrics; pub mod schema; mod schema_batch; +mod config; #[cfg(feature = "test-utils")] pub mod test; -mod config; pub use config::RocksdbConfig; From 39fbe00d60fd7f6b457ed1f1cf119ff0f4704649 Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Fri, 21 Jun 2024 17:05:18 +0200 Subject: [PATCH 4/5] Re-export gen function --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index ae78fd4..80e64ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ mod config; #[cfg(feature = "test-utils")] pub mod test; -pub use config::RocksdbConfig; +pub use config::{gen_rocksdb_options, RocksdbConfig}; use std::path::Path; use std::sync::{Arc, LockResult, RwLock, RwLockReadGuard}; From 1fefde04cc78a7608c48087510de30e571a75eef Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Fri, 21 Jun 2024 17:29:41 +0200 Subject: [PATCH 5/5] Another lint fix --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 9c57e4e..0dd1024 100644 --- a/src/config.rs +++ b/src/config.rs @@ -43,4 +43,4 @@ pub fn gen_rocksdb_options(config: &RocksdbConfig, readonly: bool) -> Options { } db_opts -} \ No newline at end of file +}