Skip to content

Commit

Permalink
Update default function to helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienFT committed Oct 24, 2024
1 parent 82eaa5f commit c1bec23
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 7 additions & 1 deletion bin/fuel-core/src/cli/rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct Command {
#[clap(
long = "rocksdb-max-fds",
env,
default_value = getrlimit(Resource::NOFILE).map(|(_, hard)| i32::try_from(hard.saturating_div(2)).unwrap_or(i32::MAX)).expect("Our supported platforms should return max FD.").to_string()
default_value = get_default_max_fds().to_string()
)]
pub rocksdb_max_fds: i32,

Expand All @@ -39,6 +39,12 @@ pub struct Command {
pub target_block_height: u32,
}

fn get_default_max_fds() -> i32 {
getrlimit(Resource::NOFILE)
.map(|(_, hard)| i32::try_from(hard.saturating_div(2)).unwrap_or(i32::MAX))
.expect("Our supported platforms should return max FD.")
}

pub async fn exec(command: Command) -> anyhow::Result<()> {
use crate::cli::ShutdownListener;

Expand Down
10 changes: 8 additions & 2 deletions bin/fuel-core/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,14 @@ pub struct Command {
pub database_type: DbType,

#[cfg(feature = "rocksdb")]

/// Defines a specific number of file descriptors that RocksDB can use.
///
/// If defined as -1 no limit will be applied and will use the OS limits.
/// If not defined the system default divided by two is used.
#[clap(
long = "rocksdb-max-fds",
env,
default_value = getrlimit(Resource::NOFILE).map(|(_, hard)| i32::try_from(hard.saturating_div(2)).unwrap_or(i32::MAX)).expect("Our supported platforms should return max FD.").to_string()
default_value = get_default_max_fds().to_string()
)]
pub rocksdb_max_fds: i32,

Expand Down Expand Up @@ -612,6 +611,13 @@ impl Command {
}
}

#[cfg(feature = "rocksdb")]
fn get_default_max_fds() -> i32 {
getrlimit(Resource::NOFILE)
.map(|(_, hard)| i32::try_from(hard.saturating_div(2)).unwrap_or(i32::MAX))
.expect("Our supported platforms should return max FD.")
}

pub async fn get_service_with_shutdown_listeners(
command: Command,
) -> anyhow::Result<(FuelService, ShutdownListener)> {
Expand Down
8 changes: 7 additions & 1 deletion bin/fuel-core/src/cli/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct Command {
#[clap(
long = "rocksdb-max-fds",
env,
default_value = getrlimit(Resource::NOFILE).map(|(_, hard)| i32::try_from(hard.saturating_div(2)).unwrap_or(i32::MAX)).expect("Our supported platforms should return max FD.").to_string()
default_value = get_default_max_fds().to_string()
)]
pub rocksdb_max_fds: i32,

Expand Down Expand Up @@ -127,6 +127,12 @@ pub enum SubCommands {
},
}

fn get_default_max_fds() -> i32 {
getrlimit(Resource::NOFILE)
.map(|(_, hard)| i32::try_from(hard.saturating_div(2)).unwrap_or(i32::MAX))
.expect("Our supported platforms should return max FD.")
}

#[cfg(feature = "rocksdb")]
pub async fn exec(command: Command) -> anyhow::Result<()> {
use fuel_core::service::genesis::Exporter;
Expand Down

0 comments on commit c1bec23

Please sign in to comment.