core/mvcc: begin pager read txn on mvcc begin_txn

This commit is contained in:
Pere Diaz Bou
2025-07-30 13:00:15 +02:00
parent b4ac38cd25
commit b399ddea1b
2 changed files with 6 additions and 2 deletions

View File

@@ -495,12 +495,16 @@ impl<Clock: LogicalClock> MvStore<Clock> {
/// This function starts a new transaction in the database and returns a `TxID` value
/// that you can use to perform operations within the transaction. All changes made within the
/// transaction are isolated from other transactions until you commit the transaction.
pub fn begin_tx(&self) -> TxID {
pub fn begin_tx(&self, pager: Rc<Pager>) -> TxID {
let tx_id = self.get_tx_id();
let begin_ts = self.get_timestamp();
let tx = Transaction::new(tx_id, begin_ts);
tracing::trace!("begin_tx(tx_id={})", tx_id);
self.txs.insert(tx_id, RwLock::new(tx));
// TODO: we need to tie a pager's read transaction to a transaction ID, so that future refactors to read
// pages from WAL/DB read from a consistent state to maintiain snapshot isolation.
pager.begin_read_tx().unwrap();
tx_id
}

View File

@@ -1984,7 +1984,7 @@ pub fn op_transaction(
if state.mv_tx_id.is_none() {
// We allocate the first page lazily in the first transaction.
return_if_io!(pager.maybe_allocate_page1());
let tx_id = mv_store.begin_tx();
let tx_id = mv_store.begin_tx(pager.clone());
conn.mv_transactions.borrow_mut().push(tx_id);
state.mv_tx_id = Some(tx_id);
}