Skip to content

Commit

Permalink
added mutex to match env definitions from lmdb
Browse files Browse the repository at this point in the history
  • Loading branch information
eserilev committed Jun 25, 2023
1 parent fa44260 commit 160f99e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion slasher/src/database/redb_impl.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#![cfg(feature = "redb")]

use redb::TableDefinition;

use crate::config::Config;
use crate::database::{interface::OpenDatabases, *};
use crate::Error;
use std::marker::PhantomData;
use std::path::PathBuf;

pub struct Builder {
builder: redb::Builder,
Expand Down Expand Up @@ -33,15 +36,21 @@ impl Builder {

pub struct Environment {
builder: redb::Builder,
dbi_open_mutex: Mutex<i32>,
}

impl Environment {
pub fn new(config: &Config) -> Result<Environment, Error> {
let builder = redb::Builder::new();
Ok(Environment { builder })
let mutex = Mutex::new(0);
Ok(Environment {
builder,
dbi_open_mutex: mutex,
})
}

pub fn create_databases(&self) -> Result<OpenDatabases, Error> {
let mutex = self.dbi_open_mutex.lock();
let indexed_attestation_db = self.builder.create(INDEXED_ATTESTATION_DB).unwrap();
let indexed_attestation_id_db = self.builder.create(INDEXED_ATTESTATION_ID_DB).unwrap();
let attesters_db = self.builder.create(ATTESTERS_DB).unwrap();
Expand All @@ -59,6 +68,8 @@ impl Environment {
})
};

drop(mutex);

Ok(OpenDatabases {
indexed_attestation_db: wrap(indexed_attestation_db),
indexed_attestation_id_db: wrap(indexed_attestation_id_db),
Expand All @@ -71,4 +82,15 @@ impl Environment {
metadata_db: wrap(metadata_db),
})
}

pub fn begin_rw_txn(&self) -> Result<RwTransaction, Error> {
todo!()
}

pub fn filenames(&self, config: &Config) -> Vec<PathBuf> {
vec![
config.database_path.join("data.mdb"),
config.database_path.join("lock.mdb"),
]
}
}

0 comments on commit 160f99e

Please sign in to comment.