diff --git a/simulator/runner/env.rs b/simulator/runner/env.rs
index c000acf9d..7610a1982 100644
--- a/simulator/runner/env.rs
+++ b/simulator/runner/env.rs
@@ -36,21 +36,37 @@ pub(crate) enum SimulationPhase {
Shrink,
}
+#[derive(Debug, Clone)]
+pub struct TransactionTables {
+ snapshot_tables: Vec
,
+ current_tables: Vec,
+}
+
+impl TransactionTables {
+ pub fn new(tables: Vec) -> Self {
+ Self {
+ snapshot_tables: tables.clone(),
+ current_tables: tables,
+ }
+ }
+}
+
#[derive(Debug)]
pub struct ShadowTables<'a> {
commited_tables: &'a Vec,
- transaction_tables: Option<&'a Vec>,
+ transaction_tables: Option<&'a TransactionTables>,
}
#[derive(Debug)]
pub struct ShadowTablesMut<'a> {
commited_tables: &'a mut Vec,
- transaction_tables: &'a mut Option>,
+ transaction_tables: &'a mut Option,
}
impl<'a> ShadowTables<'a> {
fn tables(&self) -> &'a Vec {
- self.transaction_tables.map_or(self.commited_tables, |v| v)
+ self.transaction_tables
+ .map_or(self.commited_tables, |v| &v.current_tables)
}
}
@@ -69,24 +85,26 @@ where
fn tables(&'a self) -> &'a Vec {
self.transaction_tables
.as_ref()
+ .map(|t| &t.current_tables)
.unwrap_or(self.commited_tables)
}
fn tables_mut(&'b mut self) -> &'b mut Vec {
self.transaction_tables
.as_mut()
+ .map(|t| &mut t.current_tables)
.unwrap_or(self.commited_tables)
}
pub fn create_snapshot(&mut self) {
- *self.transaction_tables = Some(self.commited_tables.clone());
+ *self.transaction_tables = Some(TransactionTables::new(self.commited_tables.clone()));
}
pub fn apply_snapshot(&mut self) {
// 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
+ *self.commited_tables = transation_tables.current_tables
}
}
@@ -109,36 +127,6 @@ impl<'a> DerefMut for ShadowTablesMut<'a> {
}
}
-#[derive(Debug, Clone)]
-pub(crate) struct SimulatorTables {
- pub(crate) tables: Vec,
- pub(crate) snapshot: Option>,
-}
-impl SimulatorTables {
- pub(crate) fn new() -> Self {
- Self {
- tables: Vec::new(),
- snapshot: None,
- }
- }
-
- pub(crate) fn clear(&mut self) {
- self.tables.clear();
- self.snapshot = None;
- }
-
- pub(crate) fn push(&mut self, table: Table) {
- self.tables.push(table);
- }
-}
-impl Deref for SimulatorTables {
- type Target = Vec;
-
- fn deref(&self) -> &Self::Target {
- &self.tables
- }
-}
-
pub(crate) struct SimulatorEnv {
pub(crate) opts: SimulatorOpts,
pub profile: Profile,
@@ -154,7 +142,7 @@ pub(crate) struct SimulatorEnv {
pub memory_io: bool,
/// If connection state is None, means we are not in a transaction
- pub connection_tables: Vec