From b399ddea1bb7aebcbbd368ca6e94c39a253e9cec Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Wed, 30 Jul 2025 13:00:15 +0200 Subject: [PATCH] core/mvcc: begin pager read txn on mvcc begin_txn --- core/mvcc/database/mod.rs | 6 +++++- core/vdbe/execute.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/mvcc/database/mod.rs b/core/mvcc/database/mod.rs index 47faae986..83265163b 100644 --- a/core/mvcc/database/mod.rs +++ b/core/mvcc/database/mod.rs @@ -495,12 +495,16 @@ impl MvStore { /// 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) -> 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 } diff --git a/core/vdbe/execute.rs b/core/vdbe/execute.rs index 583a24e1b..f60c12ff8 100644 --- a/core/vdbe/execute.rs +++ b/core/vdbe/execute.rs @@ -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); }