mvcc: require exclusive transaction for schema changes

This commit is contained in:
Jussi Saurio
2025-09-24 14:39:06 +03:00
parent b37ddc208f
commit 864fa379dd
2 changed files with 18 additions and 1 deletions

View File

@@ -1340,7 +1340,7 @@ impl<Clock: LogicalClock> MvStore<Clock> {
} }
/// Returns true if the given transaction is the exclusive transaction. /// Returns true if the given transaction is the exclusive transaction.
fn is_exclusive_tx(&self, tx_id: &TxID) -> bool { pub fn is_exclusive_tx(&self, tx_id: &TxID) -> bool {
self.exclusive_tx.read().as_ref() == Some(tx_id) self.exclusive_tx.read().as_ref() == Some(tx_id)
} }

View File

@@ -6560,6 +6560,23 @@ pub fn op_open_write(
} }
}, },
}; };
const SQLITE_SCHEMA_ROOT_PAGE: u64 = 1;
if root_page == SQLITE_SCHEMA_ROOT_PAGE {
if let Some(mv_store) = mv_store {
let Some((tx_id, _)) = program.connection.mv_tx.get() else {
return Err(LimboError::InternalError(
"Schema changes in MVCC mode require an exclusive MVCC transaction".to_string(),
));
};
if !mv_store.is_exclusive_tx(&tx_id) {
// Schema changes in MVCC mode require an exclusive transaction
return Err(LimboError::TableLocked);
}
}
}
let (_, cursor_type) = program.cursor_ref.get(*cursor_id).unwrap(); let (_, cursor_type) = program.cursor_ref.get(*cursor_id).unwrap();
let cursors = &mut state.cursors; let cursors = &mut state.cursors;
let maybe_index = match cursor_type { let maybe_index = match cursor_type {