Move is_write_write_conflict() definition

This commit is contained in:
Pekka Enberg
2023-04-13 10:19:21 +03:00
parent 87ef3e1cd8
commit e2fc841479

View File

@@ -218,29 +218,6 @@ impl<Clock: LogicalClock> Database<Clock> {
}
}
/// A write-write conflict happens when transaction T_m attempts to update a
/// row version that is currently being updated by an active transaction T_n.
fn is_write_write_conflict(
txs: &HashMap<TxID, Transaction>,
tx: &Transaction,
rv: &RowVersion,
) -> bool {
match rv.end {
Some(TxTimestampOrID::TxID(rv_end)) => {
let te = txs.get(&rv_end).unwrap();
match te.state {
TransactionState::Active => tx.tx_id != te.tx_id,
TransactionState::Preparing => todo!(),
TransactionState::Committed => todo!(),
TransactionState::Aborted => todo!(),
TransactionState::Terminated => todo!(),
}
}
Some(TxTimestampOrID::Timestamp(_)) => false,
None => false,
}
}
#[derive(Debug)]
pub struct DatabaseInner<Clock: LogicalClock> {
rows: RefCell<HashMap<u64, Vec<RowVersion>>>,
@@ -379,6 +356,29 @@ impl<Clock: LogicalClock> DatabaseInner<Clock> {
}
}
/// A write-write conflict happens when transaction T_m attempts to update a
/// row version that is currently being updated by an active transaction T_n.
fn is_write_write_conflict(
txs: &HashMap<TxID, Transaction>,
tx: &Transaction,
rv: &RowVersion,
) -> bool {
match rv.end {
Some(TxTimestampOrID::TxID(rv_end)) => {
let te = txs.get(&rv_end).unwrap();
match te.state {
TransactionState::Active => tx.tx_id != te.tx_id,
TransactionState::Preparing => todo!(),
TransactionState::Committed => todo!(),
TransactionState::Aborted => todo!(),
TransactionState::Terminated => todo!(),
}
}
Some(TxTimestampOrID::Timestamp(_)) => false,
None => false,
}
}
fn is_version_visible(txs: &HashMap<TxID, Transaction>, tx: &Transaction, rv: &RowVersion) -> bool {
is_begin_visible(txs, tx, rv) && is_end_visible(txs, tx, rv)
}