diff --git a/bffhd/db/typed.rs b/bffhd/db/typed.rs index a10fa78..dcec053 100644 --- a/bffhd/db/typed.rs +++ b/bffhd/db/typed.rs @@ -144,6 +144,7 @@ impl DB -> Result>, 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::(buf.as_ref()) })) } else { Ok(None) @@ -171,10 +172,19 @@ impl<'a, A> DB 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) } } diff --git a/bffhd/resources/mod.rs b/bffhd/resources/mod.rs index 91ae695..cb8bd7e 100644 --- a/bffhd/resources/mod.rs +++ b/bffhd/resources/mod.rs @@ -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()); diff --git a/bffhd/resources/state/db.rs b/bffhd/resources/state/db.rs index 4e3117c..1b5ca94 100644 --- a/bffhd/resources/state/db.rs +++ b/bffhd/resources/state/db.rs @@ -43,8 +43,8 @@ pub struct StateDB { impl StateDB { pub fn open_env>(path: P) -> lmdb::Result> { 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)