Files
turso/core/mvcc/persistent_storage/mod.rs
Jussi Saurio a52dbb7842 Handle table ID / rootpages properly for both checkpointed and non-checkpointed tables
Table ID is an opaque identifier that is only meaningful to the MV store.
Each checkpointed MVCC table corresponds to a single B-tree on the pager,
which naturally has a root page.

We cannot use root page as the MVCC table ID directly because:
- We assign table IDs during MVCC commit, but
- we commit pages to the pager only during checkpoint
which means the root page is not easily knowable ahead of time.

Hence, we:

- store the mapping between table id and btree rootpage
- sqlite_schema rows will have a negative rootpage column if the
  table has not been checkpointed yet.
2025-09-30 16:53:12 +03:00

49 lines
1.1 KiB
Rust

use std::fmt::Debug;
use std::sync::{Arc, RwLock};
pub mod logical_log;
use crate::mvcc::database::LogRecord;
use crate::mvcc::persistent_storage::logical_log::LogicalLog;
use crate::types::IOResult;
use crate::{File, Result};
pub struct Storage {
pub logical_log: RwLock<LogicalLog>,
}
impl Storage {
pub fn new(file: Arc<dyn File>) -> Self {
Self {
logical_log: RwLock::new(LogicalLog::new(file)),
}
}
}
impl Storage {
pub fn log_tx(&self, m: &LogRecord) -> Result<IOResult<()>> {
self.logical_log.write().unwrap().log_tx(m)
}
pub fn read_tx_log(&self) -> Result<Vec<LogRecord>> {
todo!()
}
pub fn sync(&self) -> Result<IOResult<()>> {
self.logical_log.write().unwrap().sync()
}
pub fn truncate(&self) -> Result<IOResult<()>> {
self.logical_log.write().unwrap().truncate()
}
pub fn get_logical_log_file(&self) -> Arc<dyn File> {
self.logical_log.write().unwrap().file.clone()
}
}
impl Debug for Storage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "LogicalLog {{ logical_log }}")
}
}