Skip to content
Merged
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
31 changes: 25 additions & 6 deletions src/storage/storage_runtime.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::{cell::RefCell, path::PathBuf};

use crate::core::{PAGE_SIZE, PageId, error::StorageResult};
use crate::core::{
PAGE_SIZE, PageId,
error::{InternalError, InvariantViolation, StorageError, StorageResult},
};
#[cfg(test)]
use crate::storage::transaction_manager::FaultInjectingTransactionManager;
use crate::storage::{
Expand Down Expand Up @@ -63,7 +66,10 @@ impl StorageRuntime {
}

pub(crate) fn record_page_alloc(&self, page_id: PageId) -> StorageResult<Option<Lsn>> {
self.transactions.borrow_mut().record_page_alloc(page_id)
let Some(txn_id) = self.active_transaction_id() else {
return Ok(None);
};
self.transactions.borrow_mut().record_page_alloc(txn_id, page_id)
}

pub(crate) fn read_page(
Expand Down Expand Up @@ -93,7 +99,9 @@ impl StorageRuntime {

pub(crate) fn flush_wal_through(&self, lsn: Lsn) -> StorageResult<()> {
let mut log = self.log.borrow_mut();
self.transactions.borrow_mut().append_pending_through(&mut log, lsn)?;
if let Some(txn_id) = self.active_transaction_id() {
self.transactions.borrow_mut().append_pending_through(txn_id, &mut log, lsn)?;
}
log.flush_through(lsn)?;
Ok(())
}
Expand All @@ -116,6 +124,11 @@ impl StorageRuntime {
}

pub(crate) fn begin_transaction(&self) -> StorageResult<TxnId> {
if let Some(txn_id) = self.active_transaction_id() {
return Err(StorageError::Internal(InternalError::InvariantViolation(
InvariantViolation::ActiveTransaction { txn_id },
)));
}
self.transactions.borrow_mut().begin(&mut self.log.borrow_mut())
}

Expand All @@ -125,15 +138,21 @@ impl StorageRuntime {
before: &[u8; PAGE_SIZE],
after: &[u8; PAGE_SIZE],
) -> StorageResult<Option<LoggedPageUpdate>> {
let result = self.transactions.borrow_mut().record_page_update(page_id, before, after);
let Some(txn_id) = self.active_transaction_id() else {
return Ok(None);
};
let result =
self.transactions.borrow_mut().record_page_update(txn_id, page_id, before, after);
if result.is_err() {
self.transactions.borrow_mut().record_failure();
self.transactions.borrow_mut().record_failure(txn_id);
}
result
}

pub(crate) fn record_transaction_failure(&self) {
self.transactions.borrow_mut().record_failure();
if let Some(txn_id) = self.active_transaction_id() {
self.transactions.borrow_mut().record_failure(txn_id);
}
}

pub(crate) fn active_transaction_id(&self) -> Option<TxnId> {
Expand Down
Loading
Loading