diff --git a/chorus-lib/src/store/lmdb/mod.rs b/chorus-lib/src/store/lmdb/mod.rs index 8aa7c94..3a89e8f 100644 --- a/chorus-lib/src/store/lmdb/mod.rs +++ b/chorus-lib/src/store/lmdb/mod.rs @@ -10,6 +10,9 @@ use std::ops::Bound; mod retired; +const FALSE: &[u8] = &[0]; +const TRUE: &[u8] = &[1]; + #[derive(Debug)] pub struct Lmdb { env: Env, @@ -225,6 +228,30 @@ impl Lmdb { Ok(()) } + pub fn get_if_events_are_aligned(&self) -> Result { + let txn = self.read_txn()?; + match self.general.get(&txn, b"events_are_aligned")? { + None => Ok(false), + Some(bytes) => match bytes[0] { + 0 => Ok(false), + _ => Ok(true), + }, + } + } + + pub fn set_if_events_are_aligned( + &self, + txn: &mut RwTxn<'_>, + events_are_aligned: bool, + ) -> Result<(), Error> { + let slice = match events_are_aligned { + false => FALSE, + true => TRUE, + }; + self.general.put(txn, b"events_are_aligned", slice)?; + Ok(()) + } + // Index the event pub fn index(&self, txn: &mut RwTxn<'_>, event: &Event, offset: usize) -> Result<(), Error> { // Index by id diff --git a/chorus-lib/src/store/mod.rs b/chorus-lib/src/store/mod.rs index 72d2628..7ff7179 100644 --- a/chorus-lib/src/store/mod.rs +++ b/chorus-lib/src/store/mod.rs @@ -24,9 +24,11 @@ impl Store { pub fn new(config: &Config) -> Result { let lmdb = Lmdb::new(config)?; + let events_are_aligned = lmdb.get_if_events_are_aligned()?; + let events = { let event_map_file = format!("{}/event.map", &config.data_directory); - EventStore::new(event_map_file, false)? + EventStore::new(event_map_file, events_are_aligned)? }; let store = Store { lmdb, events };