support undo operations

This commit is contained in:
Dustin J. Mitchell
2021-12-21 00:43:26 +00:00
parent 1647ba9144
commit 9d93928996
6 changed files with 280 additions and 56 deletions

View File

@@ -5,6 +5,7 @@ use uuid::Uuid;
mod apply;
mod snapshot;
mod sync;
mod undo;
mod working_set;
/// A TaskDb is the backend for a replica. It manages the storage, operations, synchronization,
@@ -37,7 +38,7 @@ impl TaskDb {
/// (but leave the TaskDb in a consistent state).
pub fn apply(&mut self, op: SyncOp) -> anyhow::Result<TaskMap> {
let mut txn = self.storage.txn()?;
apply::apply(txn.as_mut(), op)
apply::apply_and_record(txn.as_mut(), op)
}
/// Add an UndoPoint operation to the list of replica operations.
@@ -120,6 +121,13 @@ impl TaskDb {
sync::sync(server, txn.as_mut(), avoid_snapshots)
}
/// Undo local operations until the most recent UndoPoint, returning false if there are no
/// local operations to undo.
pub fn undo(&mut self) -> anyhow::Result<bool> {
let mut txn = self.storage.txn()?;
undo::undo(txn.as_mut())
}
// functions for supporting tests
#[cfg(test)]