mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 01:58:16 +00:00
Page cache by page_number and frame_number
Since page cache is now shared by default, we need to cache pages by page number and something else. I chose to go with max_frame of connection, because this connection will have a max_frame set until from the start of a transaction until the end of it. With key pairs of (pgno, max_frame) we make sure each connection is caching based on the snapshot it is at as two different connections might have the same pageno being using but a different frame. If both have same max_frame then they will share same page.
This commit is contained in:
parent
138b3a00e8
commit
39a75147d4
7 changed files with 375 additions and 253 deletions
13
core/lib.rs
13
core/lib.rs
|
@ -27,7 +27,8 @@ use std::{cell::RefCell, rc::Rc};
|
|||
use storage::btree::btree_init_page;
|
||||
#[cfg(feature = "fs")]
|
||||
use storage::database::FileStorage;
|
||||
use storage::pager::{allocate_page, DumbLruPageCache};
|
||||
use storage::page_cache::DumbLruPageCache;
|
||||
use storage::pager::allocate_page;
|
||||
use storage::sqlite3_ondisk::{DatabaseHeader, DATABASE_HEADER_SIZE};
|
||||
pub use storage::wal::WalFile;
|
||||
pub use storage::wal::WalFileShared;
|
||||
|
@ -82,14 +83,16 @@ impl Database {
|
|||
let wal_path = format!("{}-wal", path);
|
||||
let db_header = Pager::begin_open(page_io.clone())?;
|
||||
io.run_once()?;
|
||||
let wal_shared =
|
||||
WalFileShared::open_shared(&io, wal_path.as_str(), db_header.borrow().page_size)?;
|
||||
let page_size = db_header.borrow().page_size;
|
||||
let wal_shared = WalFileShared::open_shared(&io, wal_path.as_str(), page_size)?;
|
||||
let buffer_pool = Rc::new(BufferPool::new(page_size as usize));
|
||||
let wal = Rc::new(RefCell::new(WalFile::new(
|
||||
io.clone(),
|
||||
db_header.borrow().page_size as usize,
|
||||
wal_shared.clone(),
|
||||
buffer_pool.clone(),
|
||||
)));
|
||||
Self::open(io, page_io, wal, wal_shared)
|
||||
Self::open(io, page_io, wal, wal_shared, buffer_pool)
|
||||
}
|
||||
|
||||
pub fn open(
|
||||
|
@ -97,6 +100,7 @@ impl Database {
|
|||
page_io: Rc<dyn DatabaseStorage>,
|
||||
wal: Rc<RefCell<dyn Wal>>,
|
||||
shared_wal: Arc<RwLock<WalFileShared>>,
|
||||
buffer_pool: Rc<BufferPool>,
|
||||
) -> Result<Arc<Database>> {
|
||||
let db_header = Pager::begin_open(page_io.clone())?;
|
||||
io.run_once()?;
|
||||
|
@ -111,6 +115,7 @@ impl Database {
|
|||
wal,
|
||||
io.clone(),
|
||||
shared_page_cache.clone(),
|
||||
buffer_pool,
|
||||
)?);
|
||||
let bootstrap_schema = Rc::new(RefCell::new(Schema::new()));
|
||||
let conn = Rc::new(Connection {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue