improve debug output in storage layer

This commit is contained in:
bunnie 2023-01-26 23:34:08 +08:00 committed by Sean Cross
parent d244466090
commit be351b0562

View file

@ -339,6 +339,7 @@ impl<S: Storage> Store<S> {
for key in keys { for key in keys {
if let Ok(key_as_usize) = usize::from_str_radix(&key, 10) { if let Ok(key_as_usize) = usize::from_str_radix(&key, 10) {
if key_as_usize >= min_key { if key_as_usize >= min_key {
log::debug!("clear deleting: {}", key);
self.pddb.delete_key(crate::store::OPENSK2_DICT, self.pddb.delete_key(crate::store::OPENSK2_DICT,
&key, &key,
None None
@ -394,7 +395,7 @@ impl<S: Storage> Store<S> {
/// Returns a handle to an entry given its key. /// Returns a handle to an entry given its key.
pub fn find_handle(&self, key: usize) -> StoreResult<Option<StoreHandle>> { pub fn find_handle(&self, key: usize) -> StoreResult<Option<StoreHandle>> {
log::debug!("listing keys"); log::debug!("listing all keys to find_handle {}", key);
let keys = match self.pddb.list_keys( let keys = match self.pddb.list_keys(
crate::store::OPENSK2_DICT, crate::store::OPENSK2_DICT,
None None
@ -402,16 +403,18 @@ impl<S: Storage> Store<S> {
Ok(k) => k, Ok(k) => k,
Err(e) => match e.kind() { Err(e) => match e.kind() {
std::io::ErrorKind::NotFound => { std::io::ErrorKind::NotFound => {
log::debug!("didn't find any keys, returning empty list"); log::debug!("Dictionary does not exist, returning empty list");
Vec::new() Vec::new()
}, },
_ => return Err(StoreError::StorageError) _ => return Err(StoreError::StorageError)
} }
}; };
log::debug!("keylist: {:?}", keys);
if keys.contains(&key.to_string()) { if keys.contains(&key.to_string()) {
log::debug!("find_handle found: {}", key);
Ok(Some(StoreHandle {key})) Ok(Some(StoreHandle {key}))
} else { } else {
log::debug!("find_handle did not find: {}", key);
Ok(None) Ok(None)
} }
} }