Introduce an option to specify the maximum database size

This commit is contained in:
Clément Renault 2020-08-10 13:53:53 +02:00
parent 394844062f
commit ae77fe5a69
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
2 changed files with 12 additions and 4 deletions

View File

@ -52,6 +52,11 @@ struct Opt {
#[structopt(long = "db", parse(from_os_str))] #[structopt(long = "db", parse(from_os_str))]
database: PathBuf, database: PathBuf,
/// The maximum size the database can take on disk. It is recommended to specify
/// the whole disk space (value must be a multiple of a page size).
#[structopt(long = "db-size", default_value = "107374182400")] // 100 GB
database_size: usize,
/// Number of parallel jobs, defaults to # of CPUs. /// Number of parallel jobs, defaults to # of CPUs.
#[structopt(short, long)] #[structopt(short, long)]
jobs: Option<usize>, jobs: Option<usize>,
@ -419,8 +424,7 @@ fn main() -> anyhow::Result<()> {
std::fs::create_dir_all(&opt.database)?; std::fs::create_dir_all(&opt.database)?;
let env = EnvOpenOptions::new() let env = EnvOpenOptions::new()
.map_size(100 * 1024 * 1024 * 1024) // 100 GB .map_size(opt.database_size)
.max_readers(10)
.max_dbs(10) .max_dbs(10)
.open(&opt.database)?; .open(&opt.database)?;

View File

@ -20,6 +20,11 @@ struct Opt {
#[structopt(long = "db", parse(from_os_str))] #[structopt(long = "db", parse(from_os_str))]
database: PathBuf, database: PathBuf,
/// The maximum size the database can take on disk. It is recommended to specify
/// the whole disk space (value must be a multiple of a page size).
#[structopt(long = "db-size", default_value = "107374182400")] // 100 GB
database_size: usize,
/// Verbose mode (-v, -vv, -vvv, etc.) /// Verbose mode (-v, -vv, -vvv, etc.)
#[structopt(short, long, parse(from_occurrences))] #[structopt(short, long, parse(from_occurrences))]
verbose: usize, verbose: usize,
@ -39,8 +44,7 @@ fn main() -> anyhow::Result<()> {
std::fs::create_dir_all(&opt.database)?; std::fs::create_dir_all(&opt.database)?;
let env = EnvOpenOptions::new() let env = EnvOpenOptions::new()
.map_size(100 * 1024 * 1024 * 1024) // 100 GB .map_size(opt.database_size)
.max_readers(10)
.max_dbs(10) .max_dbs(10)
.open(&opt.database)?; .open(&opt.database)?;