insert UndoPoint appropriately into the replica operations

This commit is contained in:
Dustin J. Mitchell
2021-12-19 21:37:37 +00:00
parent 103bbcdf8f
commit 1647ba9144
4 changed files with 141 additions and 15 deletions

View File

@@ -1,10 +1,7 @@
use crate::server::{Server, SyncOp};
use crate::storage::{Storage, TaskMap};
use crate::storage::{ReplicaOp, Storage, TaskMap};
use uuid::Uuid;
#[cfg(test)]
use crate::storage::ReplicaOp;
mod apply;
mod snapshot;
mod sync;
@@ -43,6 +40,13 @@ impl TaskDb {
apply::apply(txn.as_mut(), op)
}
/// Add an UndoPoint operation to the list of replica operations.
pub fn add_undo_point(&mut self) -> anyhow::Result<()> {
let mut txn = self.storage.txn()?;
txn.add_operation(ReplicaOp::UndoPoint)?;
txn.commit()
}
/// Get all tasks.
pub fn all_tasks(&mut self) -> anyhow::Result<Vec<(Uuid, TaskMap)>> {
let mut txn = self.storage.txn()?;
@@ -171,6 +175,13 @@ mod tests {
assert_eq!(db.operations(), vec![ReplicaOp::Create { uuid }]);
}
#[test]
fn test_add_undo_point() {
let mut db = TaskDb::new_inmemory();
db.add_undo_point().unwrap();
assert_eq!(db.operations(), vec![ReplicaOp::UndoPoint]);
}
fn newdb() -> TaskDb {
TaskDb::new(Box::new(InMemoryStorage::new()))
}

View File

@@ -75,7 +75,7 @@ pub(super) fn sync(
let mut local_ops: Vec<SyncOp> = txn
.operations()?
.drain(..)
.map(|op| op.into_sync())
.filter_map(|op| op.into_sync())
.collect();
// first pull changes and "rebase" on top of them