From 3eb64af1ef2fc85622f42e82d9b56fd7a123a413 Mon Sep 17 00:00:00 2001 From: Antioch Peverell Date: Sun, 7 Oct 2018 18:25:12 +0100 Subject: [PATCH] Spit chain and peer lmdb envs (#1680) separate files on disk separate transactions (batches) --- servers/src/grin/server.rs | 5 +++-- store/src/lmdb.rs | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/servers/src/grin/server.rs b/servers/src/grin/server.rs index 0935340e8..a5ef398a6 100644 --- a/servers/src/grin/server.rs +++ b/servers/src/grin/server.rs @@ -160,7 +160,7 @@ impl Server { let db_env = Arc::new(store::new_env(config.db_root.clone())); let shared_chain = Arc::new(chain::Chain::init( config.db_root.clone(), - db_env.clone(), + db_env, chain_adapter.clone(), genesis.clone(), pow::verify_size, @@ -186,8 +186,9 @@ impl Server { Err(_) => None, }; + let peer_db_env = Arc::new(store::new_named_env(config.db_root.clone(), "peer".into())); let p2p_server = Arc::new(p2p::Server::new( - db_env, + peer_db_env, config.p2p_config.capabilities, config.p2p_config.clone(), net_adapter.clone(), diff --git a/store/src/lmdb.rs b/store/src/lmdb.rs index e7315005f..8c26ae304 100644 --- a/store/src/lmdb.rs +++ b/store/src/lmdb.rs @@ -54,10 +54,18 @@ pub fn option_to_not_found(res: Result, Error>, field_name: &str) - } } -/// Create a new LMDB env under the provided directory to spawn various -/// databases from. +/// Create a new LMDB env under the provided directory. +/// By default creates an environment named "lmdb". +/// Be aware of transactional semantics in lmdb +/// (transactions are per environment, not per database). pub fn new_env(path: String) -> lmdb::Environment { - let full_path = path + "/lmdb"; + new_named_env(path, "lmdb".into()) +} + +/// TODO - We probably need more flexibility here, 500GB probably too big for peers... +/// Create a new LMDB env under the provided directory with the provided name. +pub fn new_named_env(path: String, name: String) -> lmdb::Environment { + let full_path = [path, name].join("/"); fs::create_dir_all(&full_path).unwrap(); unsafe { let mut env_builder = lmdb::EnvBuilder::new().unwrap();