Skip to content

Commit

Permalink
[1.1.0] LMDB Naming consistency fix (#2656)
Browse files Browse the repository at this point in the history
* allow separate db name in store creation

* rustfmt

* fixes to db paths to ensure consistency with 1.0.x
  • Loading branch information
yeastplume authored Mar 6, 2019
1 parent 6fa137a commit fd077a4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct ChainStore {
impl ChainStore {
/// Create new chain store
pub fn new(db_root: &str) -> Result<ChainStore, Error> {
let db = store::Store::new(db_root, Some(STORE_SUBPATH.clone()), None)?;
let db = store::Store::new(db_root, None, Some(STORE_SUBPATH.clone()), None)?;
Ok(ChainStore { db })
}
}
Expand Down
3 changes: 2 additions & 1 deletion p2p/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::core::ser::{self, Readable, Reader, Writeable, Writer};
use crate::types::{Capabilities, PeerAddr, ReasonForBan};
use grin_store::{self, option_to_not_found, to_key, Error};

const DB_NAME: &'static str = "peer";
const STORE_SUBPATH: &'static str = "peers";

const PEER_PREFIX: u8 = 'P' as u8;
Expand Down Expand Up @@ -115,7 +116,7 @@ pub struct PeerStore {
impl PeerStore {
/// Instantiates a new peer store under the provided root path.
pub fn new(db_root: &str) -> Result<PeerStore, Error> {
let db = grin_store::Store::new(db_root, Some(STORE_SUBPATH), None)?;
let db = grin_store::Store::new(db_root, Some(DB_NAME), Some(STORE_SUBPATH), None)?;
Ok(PeerStore { db: db })
}

Expand Down
2 changes: 1 addition & 1 deletion pool/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl ChainAdapter {
pub fn update_db_for_block(&self, block: &Block) {
let header = &block.header;
let tip = Tip::from_header(header);
let mut s = self.store.write();
let s = self.store.write();
let batch = s.batch().unwrap();

batch.save_block_header(header).unwrap();
Expand Down
17 changes: 13 additions & 4 deletions store/src/lmdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,21 @@ impl Store {
/// By default creates an environment named "lmdb".
/// Be aware of transactional semantics in lmdb
/// (transactions are per environment, not per database).
pub fn new(path: &str, name: Option<&str>, max_readers: Option<u32>) -> Result<Store, Error> {
let name = match name {
pub fn new(
root_path: &str,
env_name: Option<&str>,
db_name: Option<&str>,
max_readers: Option<u32>,
) -> Result<Store, Error> {
let name = match env_name {
Some(n) => n.to_owned(),
None => "lmdb".to_owned(),
};
let full_path = [path.to_owned(), name.clone()].join("/");
let db_name = match db_name {
Some(n) => n.to_owned(),
None => "lmdb".to_owned(),
};
let full_path = [root_path.to_owned(), name.clone()].join("/");
fs::create_dir_all(&full_path)
.expect("Unable to create directory 'db_root' to store chain_data");

Expand All @@ -101,7 +110,7 @@ impl Store {
let res = Store {
env: Arc::new(env),
db: RwLock::new(None),
name: name,
name: db_name,
};

{
Expand Down
4 changes: 2 additions & 2 deletions store/tests/lmdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn lmdb_allocate() -> Result<(), store::Error> {
// Allocate more than the initial chunk, ensuring
// the DB resizes underneath
{
let store = store::Store::new(test_dir, Some("test1"), None)?;
let store = store::Store::new(test_dir, Some("test1"), None, None)?;

for i in 0..WRITE_CHUNK_SIZE * 2 {
println!("Allocating chunk: {}", i);
Expand All @@ -87,7 +87,7 @@ fn lmdb_allocate() -> Result<(), store::Error> {
println!("***********************************");
// Open env again and keep adding
{
let store = store::Store::new(test_dir, Some("test1"), None)?;
let store = store::Store::new(test_dir, Some("test1"), None, None)?;
for i in 0..WRITE_CHUNK_SIZE * 2 {
println!("Allocating chunk: {}", i);
let chunk = PhatChunkStruct::new();
Expand Down

0 comments on commit fd077a4

Please sign in to comment.