Spit chain and peer lmdb envs (#1680)

separate files on disk
separate transactions (batches)
This commit is contained in:
Antioch Peverell 2018-10-07 18:25:12 +01:00 committed by Ignotus Peverell
parent 1a6101f870
commit 3eb64af1ef
2 changed files with 14 additions and 5 deletions

View file

@ -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(),

View file

@ -54,10 +54,18 @@ pub fn option_to_not_found<T>(res: Result<Option<T>, 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();