mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-22 12:57:20 +00:00
fix: tree diff calc retreat cache current vv
This commit is contained in:
parent
0635f0a036
commit
75e14dea6b
3 changed files with 23 additions and 24 deletions
|
@ -421,8 +421,8 @@ impl ApplyDiff for TreeTracker {
|
|||
}
|
||||
|
||||
fn apply_diff(&mut self, diff: Diff) {
|
||||
trace!("current tree: {:#?}", &self.tree);
|
||||
trace!("applying diff: {:#?}", &diff);
|
||||
// trace!("current tree: {:#?}", &self.tree);
|
||||
// trace!("applying diff: {:#?}", &diff);
|
||||
let diff = diff.as_tree().unwrap();
|
||||
for diff in &diff.diff {
|
||||
let target = diff.target;
|
||||
|
|
|
@ -189,22 +189,15 @@ impl TreeDiffCalculator {
|
|||
}
|
||||
tracing::info!(msg="retreat ops", retreat_ops=?retreat_ops);
|
||||
for op in retreat_ops {
|
||||
tree_cache
|
||||
.tree
|
||||
.get_mut(&op.op.target())
|
||||
.unwrap()
|
||||
.remove(&op);
|
||||
tree_cache.current_vv.shrink_to_exclude(IdSpan::new(
|
||||
op.id.peer,
|
||||
op.id.counter,
|
||||
op.id.counter + 1,
|
||||
));
|
||||
tree_cache.retreat_op(&op);
|
||||
}
|
||||
|
||||
// forward and apply
|
||||
let current_frontiers = tree_cache.current_vv.to_frontiers(&oplog.dag);
|
||||
let forward_min_lamport = self
|
||||
.get_min_lamport_by_frontiers(¤t_frontiers, oplog)
|
||||
.min(min_lamport);
|
||||
|
||||
let max_lamport = self.get_max_lamport_by_frontiers(&to_frontiers, oplog);
|
||||
let mut forward_ops = vec![];
|
||||
let group = h
|
||||
|
@ -292,16 +285,7 @@ impl TreeDiffCalculator {
|
|||
|
||||
// tracing::info!("retreat ops {:?}", retreat_ops);
|
||||
for op in retreat_ops.into_iter().sorted().rev() {
|
||||
tree_cache
|
||||
.tree
|
||||
.get_mut(&op.op.target())
|
||||
.unwrap()
|
||||
.remove(&op);
|
||||
tree_cache.current_vv.shrink_to_exclude(IdSpan::new(
|
||||
op.id.peer,
|
||||
op.id.counter,
|
||||
op.id.counter + 1,
|
||||
));
|
||||
tree_cache.retreat_op(&op);
|
||||
let (old_parent, position, last_effective_move_op_id) =
|
||||
tree_cache.get_parent_with_id(op.op.target());
|
||||
if op.effected {
|
||||
|
@ -485,6 +469,23 @@ impl std::fmt::Debug for TreeCacheForDiff {
|
|||
}
|
||||
|
||||
impl TreeCacheForDiff {
|
||||
fn retreat_op(&mut self, op: &MoveLamportAndID) {
|
||||
self.tree.get_mut(&op.op.target()).unwrap().remove(&op);
|
||||
self.current_vv.shrink_to_exclude(IdSpan::new(
|
||||
op.id.peer,
|
||||
op.id.counter,
|
||||
op.id.counter + 1,
|
||||
));
|
||||
// Only shrink cannot get the correct empty vv,
|
||||
if self.is_empty() {
|
||||
self.current_vv = VersionVector::default();
|
||||
}
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
self.tree.iter().all(|(_, v)| v.is_empty())
|
||||
}
|
||||
|
||||
fn is_ancestor_of(&self, maybe_ancestor: &TreeID, node_id: &TreeParentId) -> bool {
|
||||
if !self.tree.contains_key(maybe_ancestor) {
|
||||
return false;
|
||||
|
|
|
@ -1083,8 +1083,6 @@ impl ContainerState for TreeState {
|
|||
TreeInternalDiff::UnCreate => {
|
||||
// maybe the node created and moved to the parent deleted
|
||||
if !self.is_node_deleted(&target).unwrap() {
|
||||
trace!("tree {:#?}", &self.trees);
|
||||
trace!("DEL from b {:?}", target);
|
||||
ans.push(TreeDiffItem {
|
||||
target,
|
||||
action: TreeExternalDiff::Delete {
|
||||
|
|
Loading…
Reference in a new issue