Add pgno field to CacheError::Locked for debugging

This commit is contained in:
Jussi Saurio
2025-08-19 15:24:51 +03:00
parent 366281eeab
commit 687e593361

View File

@@ -47,7 +47,7 @@ struct HashMapNode {
#[derive(Debug, PartialEq)]
pub enum CacheError {
InternalError(String),
Locked,
Locked { pgno: usize },
Dirty { pgno: usize },
Pinned { pgno: usize },
ActiveRefs,
@@ -189,7 +189,9 @@ impl DumbLruPageCache {
) -> Result<(), CacheError> {
let entry_mut = unsafe { entry.as_mut() };
if entry_mut.page.is_locked() {
return Err(CacheError::Locked);
return Err(CacheError::Locked {
pgno: entry_mut.page.get().id,
});
}
if entry_mut.page.is_dirty() {
return Err(CacheError::Dirty {
@@ -911,7 +913,10 @@ mod tests {
let mut cache = DumbLruPageCache::default();
let (_, mut entry) = insert_and_get_entry(&mut cache, 1);
unsafe { entry.as_mut().page.set_locked() };
assert_eq!(cache.detach(entry, false), Err(CacheError::Locked));
assert_eq!(
cache.detach(entry, false),
Err(CacheError::Locked { pgno: 1 })
);
cache.verify_list_integrity();
}