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> -> Result<Option<&'txn Archived<A::Value>>, A::Error>
{ {
if let Some(buf) = self.db.get(txn, key).map_err(A::from_db_err)? { 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()) })) Ok(Some(unsafe { archived_root::<A::Value>(buf.as_ref()) }))
} else { } else {
Ok(None) Ok(None)
@ -171,10 +172,19 @@ impl<'a, A> DB<A>
let pos = serializer.serialize_value(val) let pos = serializer.serialize_value(val)
.map_err(A::from_ser_err)?; .map_err(A::from_ser_err)?;
let buf = serializer.into_slice(); 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)?; .map_err(A::from_db_err)?;
tracing::trace!(store=?stor.as_ptr(), "store");
stor.copy_from_slice(&buf[..]);
Ok(pos) Ok(pos)
} }
} }

View File

@ -36,7 +36,11 @@ impl Inner {
state state
} else { } else {
tracing::info!(%id, "No previous state, defaulting to `free`"); 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()); let signal = Mutable::new(state.to_state());