mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
refactor: is_version_visible() -> RowVersion::is_visible_to()
This commit is contained in:
parent
a0460ae2d5
commit
c23d97f33c
2 changed files with 17 additions and 13 deletions
|
@ -320,7 +320,7 @@ impl<Clock: LogicalClock, T: Sync + Send + Clone + Debug + 'static> MvStore<Cloc
|
|||
assert_eq!(tx.state, TransactionState::Active);
|
||||
// A transaction cannot delete a version that it cannot see,
|
||||
// nor can it conflict with it.
|
||||
if !is_version_visible(&self.txs, &tx, rv) {
|
||||
if !rv.is_visible_to(&tx, &self.txs) {
|
||||
continue;
|
||||
}
|
||||
if is_write_write_conflict(&self.txs, &tx, rv) {
|
||||
|
@ -367,11 +367,13 @@ impl<Clock: LogicalClock, T: Sync + Send + Clone + Debug + 'static> MvStore<Cloc
|
|||
assert_eq!(tx.state, TransactionState::Active);
|
||||
if let Some(row_versions) = self.rows.get(&id) {
|
||||
let row_versions = row_versions.value().read().unwrap();
|
||||
for rv in row_versions.iter().rev() {
|
||||
if is_version_visible(&self.txs, &tx, rv) {
|
||||
tx.insert_to_read_set(id);
|
||||
return Ok(Some(rv.row.clone()));
|
||||
}
|
||||
for rv in row_versions
|
||||
.iter()
|
||||
.rev()
|
||||
.filter(|rv| rv.is_visible_to(&tx, &self.txs))
|
||||
{
|
||||
tx.insert_to_read_set(id);
|
||||
return Ok(Some(rv.row.clone()));
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
|
@ -764,12 +766,14 @@ pub(crate) fn is_write_write_conflict<T>(
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_version_visible<T>(
|
||||
txs: &SkipMap<TxID, RwLock<Transaction>>,
|
||||
tx: &Transaction,
|
||||
rv: &RowVersion<T>,
|
||||
) -> bool {
|
||||
is_begin_visible(txs, tx, rv) && is_end_visible(txs, tx, rv)
|
||||
impl<T> RowVersion<T> {
|
||||
pub fn is_visible_to(
|
||||
&self,
|
||||
tx: &Transaction,
|
||||
txs: &SkipMap<TxID, RwLock<Transaction>>,
|
||||
) -> bool {
|
||||
is_begin_visible(txs, tx, self) && is_end_visible(txs, tx, self)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_begin_visible<T>(
|
||||
|
|
|
@ -699,7 +699,7 @@ fn test_snapshot_isolation_tx_visible1() {
|
|||
},
|
||||
};
|
||||
tracing::debug!("Testing visibility of {row_version:?}");
|
||||
is_version_visible(&txs, ¤t_tx, &row_version)
|
||||
row_version.is_visible_to(¤t_tx, &txs)
|
||||
};
|
||||
|
||||
// begin visible: transaction committed with ts < current_tx.begin_ts
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue