Pass directory into Lmdb::new()

This commit is contained in:
Mike Dilger 2024-04-09 13:29:37 +12:00
parent ff4f921e7d
commit 51217ae480
2 changed files with 6 additions and 7 deletions

View File

@ -1,4 +1,3 @@
use crate::config::Config;
use crate::error::Error;
use crate::ip::{HashedIp, IpData};
use crate::types::{Event, Id, Kind, Pubkey, Time};
@ -33,7 +32,7 @@ pub struct Lmdb {
}
impl Lmdb {
pub fn new(config: &Config) -> Result<Lmdb, Error> {
pub fn new(directory: &str) -> Result<Lmdb, Error> {
let mut builder = EnvOpenOptions::new();
unsafe {
builder.flags(EnvFlags::NO_TLS);
@ -41,13 +40,12 @@ impl Lmdb {
builder.max_dbs(32);
builder.map_size(1048576 * 1024 * 24); // 24 GB
let dir = format!("{}/lmdb", &config.data_directory);
fs::create_dir_all(&dir)?;
fs::create_dir_all(directory)?;
let env = match builder.open(&dir) {
let env = match builder.open(directory) {
Ok(env) => env,
Err(e) => {
log::error!("Unable to open LMDB at {}", dir);
log::error!("Unable to open LMDB at {}", directory);
return Err(e.into());
}
};

View File

@ -22,7 +22,8 @@ pub struct Store {
impl Store {
/// Setup persistent storage
pub fn new(config: &Config) -> Result<Store, Error> {
let lmdb = Lmdb::new(config)?;
let dir = format!("{}/lmdb", &config.data_directory);
let lmdb = Lmdb::new(&dir)?;
let events_are_aligned = lmdb.get_if_events_are_aligned()?;