Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@ impl Connection {
if content.buffer.is_empty() {
return Ok(false);
}
page.copy_from_slice(content.as_ptr());
page.copy_from_slice(content.as_slice());
Ok(true)
}

Expand Down
579 changes: 324 additions & 255 deletions core/storage/btree.rs

Large diffs are not rendered by default.

40 changes: 17 additions & 23 deletions core/storage/page_cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use intrusive_collections::{intrusive_adapter, LinkedList, LinkedListLink};
use rustc_hash::FxHashMap;
use std::sync::{atomic::Ordering, Arc};
use std::sync::Arc;
use tracing::trace;

use crate::turso_assert;
Expand Down Expand Up @@ -233,24 +233,18 @@ impl PageCache {
let page = &entry.page;

if page.is_locked() {
return Err(CacheError::Locked {
pgno: page.get().id,
});
return Err(CacheError::Locked { pgno: page.id() });
}
if page.is_dirty() {
return Err(CacheError::Dirty {
pgno: page.get().id,
});
return Err(CacheError::Dirty { pgno: page.id() });
}
if page.is_pinned() {
return Err(CacheError::Pinned {
pgno: page.get().id,
});
return Err(CacheError::Pinned { pgno: page.id() });
}

if clean_page {
page.clear_loaded();
let _ = page.get().contents.take();
page.clear_contents();
}

// Remove from map first
Expand Down Expand Up @@ -399,7 +393,7 @@ impl PageCache {

// Clean the page
page.clear_loaded();
let _ = page.get().contents.take();
page.clear_contents();

// Remove from queue
unsafe {
Expand Down Expand Up @@ -429,7 +423,7 @@ impl PageCache {
let entry = unsafe { &*entry_ptr };
if entry.page.is_dirty() && !clear_dirty {
return Err(CacheError::Dirty {
pgno: entry.page.get().id,
pgno: entry.page.id(),
});
}
}
Expand All @@ -438,7 +432,7 @@ impl PageCache {
for &entry_ptr in self.map.values() {
let entry = unsafe { &*entry_ptr };
entry.page.clear_loaded();
let _ = entry.page.get().contents.take();
entry.page.clear_contents();
}

self.map.clear();
Expand Down Expand Up @@ -472,8 +466,8 @@ impl PageCache {
"slot={}, page={:?}, flags={}, pin_count={}, ref_bit={:?}",
i,
entry.key,
page.get().flags.load(Ordering::SeqCst),
page.get().pin_count.load(Ordering::SeqCst),
page.flags(),
page.pin_count(),
entry.ref_bit,
);
cursor.move_next();
Expand Down Expand Up @@ -569,7 +563,7 @@ mod tests {
buffer: Arc::new(buffer),
overflow_cells: Vec::new(),
};
page.get().contents = Some(page_content);
page.replace_contents(page_content);
page.set_loaded();
}
page
Expand Down Expand Up @@ -678,14 +672,14 @@ mod tests {
let key2 = insert_page(&mut cache, 2);

// With capacity=1, inserting key2 should evict key1
assert_eq!(cache.get(&key2).unwrap().unwrap().get().id, 2);
assert_eq!(cache.get(&key2).unwrap().unwrap().id(), 2);
assert!(
cache.get(&key1).unwrap().is_none(),
"key1 should be evicted"
);

// key2 should still be accessible
assert_eq!(cache.get(&key2).unwrap().unwrap().get().id, 2);
assert_eq!(cache.get(&key2).unwrap().unwrap().id(), 2);
assert!(
cache.get(&key1).unwrap().is_none(),
"capacity=1 should have evicted the older page"
Expand Down Expand Up @@ -808,8 +802,8 @@ mod tests {
let key1 = insert_page(&mut cache, 1);
let key2 = insert_page(&mut cache, 2);

assert_eq!(cache.get(&key1).unwrap().unwrap().get().id, 1);
assert_eq!(cache.get(&key2).unwrap().unwrap().get().id, 2);
assert_eq!(cache.get(&key1).unwrap().unwrap().id(), 1);
assert_eq!(cache.get(&key2).unwrap().unwrap().id(), 2);
cache.verify_cache_integrity();
}

Expand Down Expand Up @@ -1063,8 +1057,8 @@ mod tests {
// Verify all pages in reference_map are in cache
for (key, page) in &reference_map {
let cached_page = cache.peek(key, false).expect("Page should be in cache");
assert_eq!(cached_page.get().id, key.0);
assert_eq!(page.get().id, key.0);
assert_eq!(cached_page.id(), key.0);
assert_eq!(page.id(), key.0);
}
}
}
Expand Down
Loading
Loading