diff --git a/src/environment.rs b/src/environment.rs index c924fa5..8446c48 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -3,7 +3,8 @@ use crate::database::wrapped::WrappedTable; use crate::wrapper::{ByteWrapper, ZeroCopyByteWrapper}; use anyhow::{ensure, Context}; use libmdbx::{ - DatabaseFlags, Environment, EnvironmentFlags, Transaction, TransactionKind, WriteMap, RO, RW, + DatabaseFlags, Environment, EnvironmentFlags, Geometry, Transaction, TransactionKind, WriteMap, + RO, RW, }; use std::marker::PhantomData; use std::path::Path; @@ -18,8 +19,21 @@ impl Env { let mut flags = EnvironmentFlags::default(); flags.no_sub_dir = true; + // TODO make the geometry more configurable. + let mut geom = Geometry::default(); + // Don't stop the database growing until it hits 64 GiB. + // (The default is 1 MiB which is just not enough!) + geom.size = Some(1024 * 1024..64 * 1024 * 1024 * 1024); + + // Grow 4 MiB at a time. + geom.growth_step = Some(4 * 1024 * 1024); + // Shrink 16 MiB at a time. + geom.shrink_threshold = Some(16 * 1024 * 1024); + // (Yes these numbers represent a large database). + let environment = Environment::new() .set_max_dbs(256) + .set_geometry(geom) .set_flags(flags) .open(path)?;