diff --git a/services/pddb/src/backend/hw.rs b/services/pddb/src/backend/hw.rs index 67bd64d3d..ee1f8241c 100644 --- a/services/pddb/src/backend/hw.rs +++ b/services/pddb/src/backend/hw.rs @@ -822,7 +822,8 @@ impl PddbOs { self.fspace_cache.replace(pp); } else if pp.journal() == prev_pp.journal() { log::error!("got two identical journal revisions -- this shouldn't happen, prev: {:?}, candidate: {:?}", prev_pp, pp); - panic!("Inconsistent FSCB state"); + log::error!("replacing the previous version with the candidate, but this might not be the right decision!"); + self.fspace_cache.replace(pp); } } else { log::warn!("Strange...we have a journal entry for a free space page that isn't already in our cache. Guru meditation: {:?}", pp); diff --git a/services/pddb/src/lib.rs b/services/pddb/src/lib.rs index 77a03c78e..55b7941fd 100644 --- a/services/pddb/src/lib.rs +++ b/services/pddb/src/lib.rs @@ -437,7 +437,7 @@ impl Pddb { }; let mut buf = Buffer::into_buf(request) .or(Err(Error::new(ErrorKind::Other, "Xous internal error")))?; - buf.lend_mut(self.conn, Opcode::DeleteKey.to_u32().unwrap()) + buf.lend_mut(self.conn, Opcode::DeleteDict.to_u32().unwrap()) .or(Err(Error::new(ErrorKind::Other, "Xous internal error")))?; let response = buf.to_original::().unwrap(); @@ -448,6 +448,23 @@ impl Pddb { } } + pub fn sync(&mut self) -> Result<()> { + let response = send_message( + self.conn, + Message::new_blocking_scalar(Opcode::WriteKeyFlush.to_usize().unwrap(), 0, 0, 0, 0) + ).or(Err(Error::new(ErrorKind::Other, "Xous internal error")))?; + if let xous::Result::Scalar1(rcode) = response { + match FromPrimitive::from_u8(rcode as u8) { + Some(PddbRetcode::Ok) => Ok(()), + Some(PddbRetcode::BasisLost) => Err(Error::new(ErrorKind::BrokenPipe, "Basis lost")), + Some(PddbRetcode::DiskFull) => Err(Error::new(ErrorKind::OutOfMemory, "Out of disk space, some data lost on sync")), + _ => Err(Error::new(ErrorKind::Interrupted, "Flush failed for unspecified reasons")), + } + } else { + Err(Error::new(ErrorKind::Other, "Xous internal error")) + } + } + pub fn list_keys(&mut self, dict_name: &str, basis_name: Option<&str>) -> Result> { if dict_name.len() > (DICT_NAME_LEN - 1) { return Err(Error::new(ErrorKind::InvalidInput, "dictionary name too long")); diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index c6154c25c..58f651b56 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -830,6 +830,7 @@ fn xmain() -> ! { None }; let dict = req.dict.as_str().expect("dict utf-8 decode error"); + log::debug!("attempting to remove dict {} basis {:?}", dict, bname); match basis_cache.dict_remove(&mut pddb_os, dict, bname, false) { Ok(_) => { let mut evict_list = Vec::::new();