cleanup + comments

This commit is contained in:
pedrocarlo
2025-08-26 10:18:35 -03:00
parent 53cfae1db4
commit bc707fd9be
2 changed files with 7 additions and 7 deletions

View File

@@ -165,6 +165,10 @@ impl DumbLruPageCache {
pub fn get(&mut self, key: &PageCacheKey) -> Result<Option<PageRef>, CacheError> {
if let Some(page) = self.peek(key, true) {
// Because we can abort a read_page completion, this means a page can be in the cache but be unloaded and unlocked.
// However, if we do not evict that page from the page cache, we will return an unloaded page later which will trigger
// assertions later on. This is worsened by the fact that page cache is not per `Statement`, so you can abort a completion
// in one Statement, and trigger some error in the next one if we don't evict the page here.
if !page.is_loaded() && !page.is_locked() {
self.delete(*key)?;
Ok(None)

View File

@@ -1124,12 +1124,8 @@ impl Pager {
let mut page_cache = self.page_cache.write();
let page_key = PageCacheKey::new(page_idx);
if let Some(page) = page_cache.get(&page_key)? {
if page.is_loaded() {
tracing::trace!("read_page(page_idx = {}) = cached", page_idx);
return Ok((page.clone(), None));
} else if !page.is_locked() {
page_cache.delete(page_key)?;
}
tracing::trace!("read_page(page_idx = {}) = cached", page_idx);
return Ok((page.clone(), None));
}
let (page, c) = self.read_page_no_cache(page_idx, None, false)?;
self.cache_insert(page_idx, page.clone(), &mut page_cache)?;
@@ -2414,7 +2410,7 @@ mod tests {
let mut cache = cache.write();
let page_key = PageCacheKey::new(1);
let page = Page::new(1);
// Set loaded so that we avoid eviction due to the pagi
// Set loaded so that we avoid eviction, as we evict the page from cache if it is not locked and not loaded
page.set_loaded();
cache.insert(page_key, Arc::new(page)).unwrap();
})