Skip to content
Draft
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
12 changes: 9 additions & 3 deletions crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@ impl LedgerDB {
/// The returned instance will be at the path `{path}/ledger`.
#[instrument(level = "trace", skip_all, err)]
pub fn with_config(cfg: &RocksdbConfig) -> Result<Self, anyhow::Error> {
let path = cfg.path.join(LedgerDB::DB_PATH_SUFFIX);
let raw_options = cfg.as_raw_options(false);
let tables = cfg
let mut ledger_db_config = cfg.clone();

// RocksDB config assign available open files but since we spawn 3 different rocksdb instances, we need to share between them
// Allocate 10% for LedgerDB
ledger_db_config.max_open_files = ledger_db_config.max_open_files * 10 / 100;

let path = ledger_db_config.path.join(LedgerDB::DB_PATH_SUFFIX);
let raw_options = ledger_db_config.as_raw_options(false);
let tables = ledger_db_config
.column_families
.clone()
.unwrap_or_else(|| LEDGER_TABLES.iter().map(|e| e.to_string()).collect());
Expand Down
10 changes: 8 additions & 2 deletions crates/sovereign-sdk/full-node/db/sov-db/src/native_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ impl NativeDB {

/// Initialize [`sov_schema_db::DB`] that matches tables and columns for NativeDB
pub fn setup_schema_db(cfg: &RocksdbConfig) -> anyhow::Result<sov_schema_db::DB> {
let raw_options = cfg.as_raw_options(false);
let path = cfg.path.join(Self::DB_PATH_SUFFIX);
let mut schema_db_config = cfg.clone();

// RocksDB config assign available open files but since we spawn 3 different rocksdb instances, we need to share between them
// Allocate 20% for NativeDB
schema_db_config.max_open_files = schema_db_config.max_open_files * 20 / 100;

let raw_options = schema_db_config.as_raw_options(false);
let path = schema_db_config.path.join(Self::DB_PATH_SUFFIX);
sov_schema_db::DB::open(
path,
Self::DB_NAME,
Expand Down
29 changes: 14 additions & 15 deletions crates/sovereign-sdk/full-node/db/sov-db/src/rocks_db_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'a> RocksdbConfig<'a> {
max_open_files: Option<i32>,
column_families: Option<Vec<String>>,
) -> Self {
let max_open_files = max_open_files.unwrap_or_else(get_fd_limit);
let max_open_files = max_open_files.unwrap_or_else(get_rocksdb_fd_limit);
Self {
path,
// Allow db to close old sst files, saving memory.
Expand Down Expand Up @@ -104,19 +104,18 @@ impl<'a> RocksdbConfig<'a> {
}
}

fn get_fd_limit() -> i32 {
let (soft_limit, _) = getrlimit(Resource::NOFILE).unwrap_or_else(|err| {
warn!(
"Failed to retrieve max open file limit from the os, defaulting to 256. err={}",
err
);
// Default is 256 due to it being the lowest default limit among operating systems, namely OSX.
(256, 0)
});
fn get_rocksdb_fd_limit() -> i32 {
// Default is 256 due to it being the lowest default limit among operating systems, namely OSX.
const DEFAULT_FD_LIMIT: i32 = 256;

if soft_limit > (i32::MAX as u64) {
i32::MAX
} else {
soft_limit as i32
}
let limit = getrlimit(Resource::NOFILE)
.inspect_err(|e| {
warn!("Failed to retrieve max open file limit from the os, defaulting to 256. err={e}")
})
.map_or(DEFAULT_FD_LIMIT, |(soft_limit, _)| {
soft_limit.min(i32::MAX as u64) as i32
});

// Allocates half of that for rocksdb
limit / 2
}
9 changes: 7 additions & 2 deletions crates/sovereign-sdk/full-node/db/sov-db/src/state_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ impl StateDB {

/// Initialize [`DB`] that should be globally used
pub fn setup_schema_db(cfg: &RocksdbConfig) -> anyhow::Result<sov_schema_db::DB> {
let raw_options = cfg.as_raw_options(false);
let state_db_path = cfg.path.join(Self::DB_PATH_SUFFIX);
let mut state_db_config = cfg.clone();

// RocksDB config assign available open files but since we spawn 3 different rocksdb instances, we need to share between them
// Allocate 70% for StateDB
state_db_config.max_open_files = state_db_config.max_open_files * 70 / 100;
let raw_options = state_db_config.as_raw_options(false);
let state_db_path = state_db_config.path.join(Self::DB_PATH_SUFFIX);
sov_schema_db::DB::open(
state_db_path,
Self::DB_NAME,
Expand Down
Loading