store 'events_are_aligned' in lmdb

This commit is contained in:
Mike Dilger 2024-04-09 18:22:31 +12:00
parent ea3d66f746
commit ff4f921e7d
2 changed files with 30 additions and 1 deletions

View File

@ -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<bool, Error> {
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

View File

@ -24,9 +24,11 @@ impl Store {
pub fn new(config: &Config) -> Result<Store, Error> {
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 };