LMDB does not guarantee alignment.

This commit is contained in:
Nadja Reitzenstein 2022-03-15 21:24:21 +01:00
parent 648026574f
commit a145efc948
3 changed files with 18 additions and 4 deletions

View File

@ -144,6 +144,7 @@ impl<A: Adapter> DB<A>
-> Result<Option<&'txn Archived<A::Value>>, A::Error>
{
if let Some(buf) = self.db.get(txn, key).map_err(A::from_db_err)? {
tracing::trace!(?buf, ptr=?buf.as_ptr(), "db read");
Ok(Some(unsafe { archived_root::<A::Value>(buf.as_ref()) }))
} else {
Ok(None)
@ -171,10 +172,19 @@ impl<'a, A> DB<A>
let pos = serializer.serialize_value(val)
.map_err(A::from_ser_err)?;
let buf = serializer.into_slice();
self.db.put(txn, key, &buf, flags)
let buf = buf.as_ref();
println!("{:?}", buf);
tracing::trace!(len=buf.len(), pos, "writing value into db");
let mut stor = self.db.reserve(txn, key, buf.len(), flags)
.map_err(A::from_db_err)?;
tracing::trace!(store=?stor.as_ptr(), "store");
stor.copy_from_slice(&buf[..]);
Ok(pos)
}
}

View File

@ -36,7 +36,11 @@ impl Inner {
state
} else {
tracing::info!(%id, "No previous state, defaulting to `free`");
MachineState::free(None)
let state = MachineState::used(UserRef::new("test".to_string()), Some(UserRef::new
("prev".to_string())));
let update = state.to_state();
db.update(id.as_bytes(), &update, &update).unwrap();
state
};
let signal = Mutable::new(state.to_state());

View File

@ -43,8 +43,8 @@ pub struct StateDB {
impl StateDB {
pub fn open_env<P: AsRef<Path>>(path: P) -> lmdb::Result<Arc<Environment>> {
Environment::new()
.set_flags( EnvironmentFlags::WRITE_MAP
| EnvironmentFlags::NO_SUB_DIR
.set_flags( EnvironmentFlags::WRITE_MAP
| EnvironmentFlags::NO_SUB_DIR
| EnvironmentFlags::NO_TLS
| EnvironmentFlags::NO_READAHEAD)
.set_max_dbs(4)