diff --git a/simulator/generation/plan.rs b/simulator/generation/plan.rs index a8b4676d8..4185edad7 100644 --- a/simulator/generation/plan.rs +++ b/simulator/generation/plan.rs @@ -394,30 +394,6 @@ pub enum InteractionsType { Fault(Fault), } -impl Shadow for Interactions { - type Result = (); - - fn shadow(&self, tables: &mut ShadowTablesMut) { - match &self.interactions { - InteractionsType::Property(property) => { - let initial_tables = tables.clone(); - for interaction in property.interactions(self.connection_index) { - let res = interaction.shadow(tables); - if res.is_err() { - // If any interaction fails, we reset the tables to the initial state - **tables = initial_tables.clone(); - break; - } - } - } - InteractionsType::Query(query) => { - let _ = query.shadow(tables); - } - InteractionsType::Fault(_) => {} - } - } -} - impl Interactions { pub(crate) fn name(&self) -> Option<&str> { match &self.interactions { @@ -674,15 +650,17 @@ impl Shadow for InteractionType { type Result = anyhow::Result>>; fn shadow(&self, env: &mut ShadowTablesMut) -> Self::Result { match self { - Self::Query(query) => query.shadow(env), - Self::FsyncQuery(query) => { - let mut first = query.shadow(env)?; - first.extend(query.shadow(env)?); - Ok(first) - } - Self::Assumption(_) | Self::Assertion(_) | Self::Fault(_) | Self::FaultyQuery(_) => { - Ok(vec![]) + Self::Query(query) => { + if !query.is_transaction() { + env.add_query(query); + } + query.shadow(env) } + Self::Assumption(_) + | Self::Assertion(_) + | Self::Fault(_) + | Self::FaultyQuery(_) + | Self::FsyncQuery(_) => Ok(vec![]), } } } diff --git a/simulator/model/mod.rs b/simulator/model/mod.rs index 9a3c81e9f..092d59a13 100644 --- a/simulator/model/mod.rs +++ b/simulator/model/mod.rs @@ -61,6 +61,14 @@ impl Query { Query::Begin(..) | Query::Commit(..) | Query::Rollback(..) => vec![], } } + + #[inline] + pub fn is_transaction(&self) -> bool { + matches!( + self, + Self::Begin(..) | Self::Commit(..) | Self::Rollback(..) + ) + } } impl Display for Query { diff --git a/simulator/runner/env.rs b/simulator/runner/env.rs index 7610a1982..9a23663b0 100644 --- a/simulator/runner/env.rs +++ b/simulator/runner/env.rs @@ -38,15 +38,15 @@ pub(crate) enum SimulationPhase { #[derive(Debug, Clone)] pub struct TransactionTables { - snapshot_tables: Vec, current_tables: Vec
, + pending_changes: Vec, } impl TransactionTables { pub fn new(tables: Vec
) -> Self { Self { - snapshot_tables: tables.clone(), current_tables: tables, + pending_changes: Vec::new(), } } } @@ -104,13 +104,29 @@ where // TODO: as we do not have concurrent tranasactions yet in the simulator // there is no conflict we are ignoring conflict problems right now if let Some(transation_tables) = self.transaction_tables.take() { - *self.commited_tables = transation_tables.current_tables + let mut shadow_table = ShadowTablesMut { + commited_tables: self.commited_tables, + transaction_tables: &mut None, + }; + + for query in transation_tables.pending_changes { + // TODO: maybe panic on shadow error here + let _ = query.shadow(&mut shadow_table); + } } } pub fn delete_snapshot(&mut self) { *self.transaction_tables = None; } + + /// Append non transaction queries to the shadow tables + pub fn add_query(&mut self, query: &Query) { + assert!(!query.is_transaction()); + if let Some(transaction_tables) = self.transaction_tables { + transaction_tables.pending_changes.push(query.clone()); + } + } } impl<'a> Deref for ShadowTablesMut<'a> {