fix: frontiers_to_vv err

This commit is contained in:
Zixuan Chen 2024-08-18 21:45:11 +08:00
parent 6fd6aeb13d
commit b06f617d3b
No known key found for this signature in database
8 changed files with 85 additions and 19 deletions

View file

@ -51,7 +51,7 @@ impl Actor {
))));
let cb_tracker = tracker.clone();
loro.subscribe_root(Arc::new(move |e| {
info_span!("ApplyDiff", id = id).in_scope(|| {
info_span!("[Fuzz] tracker.apply_diff", id = id).in_scope(|| {
let mut tracker = cb_tracker.lock().unwrap();
tracker.apply_diff(e)
});
@ -140,7 +140,7 @@ impl Actor {
}
let after_undo = self.loro.get_deep_value();
assert_value_eq(&before_undo, &after_undo);
assert_value_eq(&before_undo, &after_undo, None);
}
pub fn check_tracker(&self) {
@ -149,7 +149,7 @@ impl Actor {
let tracker = self.tracker.lock().unwrap();
let loro_value = loro.get_deep_value();
let tracker_value = tracker.to_value();
assert_value_eq(&loro_value, &tracker_value);
assert_value_eq(&loro_value, &tracker_value, None);
self.targets.values().for_each(|t| t.check_tracker());
});
}
@ -173,11 +173,23 @@ impl Actor {
let f = Frontiers::from(f);
let from = &self.loro.state_frontiers();
let to = &f;
tracing::info_span!("Checkout", ?from, ?to).in_scope(|| {
let peer = self.peer;
tracing::info_span!("Checkout", ?from, ?to, ?peer).in_scope(|| {
self.loro.checkout(&f).unwrap();
// self.loro.check_state_correctness_slow();
let actual = self.loro.get_deep_value();
assert_value_eq(v, &actual);
assert_value_eq(
v,
&actual,
Some(&mut || {
format!(
"loro.vv = {:#?}, loro updates = {:#?}",
self.loro.oplog_vv(),
self.loro
.export_json_updates(&Default::default(), &self.loro.oplog_vv())
)
}),
);
});
}
let f = self.rand_frontiers();
@ -348,7 +360,7 @@ pub trait ActorTrait {
fn add_new_container(&mut self, container: Container);
}
pub fn assert_value_eq(a: &LoroValue, b: &LoroValue) {
pub fn assert_value_eq(a: &LoroValue, b: &LoroValue, mut log: Option<&mut dyn FnMut() -> String>) {
#[must_use]
fn eq(a: &LoroValue, b: &LoroValue) -> bool {
match (a, b) {
@ -400,9 +412,10 @@ pub fn assert_value_eq(a: &LoroValue, b: &LoroValue) {
}
assert!(
eq(a, b),
"Expect left == right, but\nleft = {:#?}\nright = {:#?}",
"Expect left == right, but\nleft = {:#?}\nright = {:#?}\n{}",
a,
b
b,
log.as_mut().map_or(String::new(), |f| f())
);
}

View file

@ -70,7 +70,7 @@ impl ActorTrait for CounterActor {
unknown_loro.import(&loro.export_snapshot()).unwrap();
let new_loro = LoroDoc::new();
new_loro.import(&unknown_loro.export_snapshot()).unwrap();
assert_value_eq(&new_loro.get_deep_value(), &loro.get_deep_value());
assert_value_eq(&new_loro.get_deep_value(), &loro.get_deep_value(), None);
// updates to updates
let unknown_loro = LoroDocWithoutCounter::new();
@ -81,7 +81,7 @@ impl ActorTrait for CounterActor {
new_loro
.import(&unknown_loro.export_from(&Default::default()))
.unwrap();
assert_value_eq(&new_loro.get_deep_value(), &loro.get_deep_value());
assert_value_eq(&new_loro.get_deep_value(), &loro.get_deep_value(), None);
// snapshot to updates
let unknown_loro = LoroDocWithoutCounter::new();
@ -90,7 +90,7 @@ impl ActorTrait for CounterActor {
new_loro
.import(&unknown_loro.export_from(&Default::default()))
.unwrap();
assert_value_eq(&new_loro.get_deep_value(), &loro.get_deep_value());
assert_value_eq(&new_loro.get_deep_value(), &loro.get_deep_value(), None);
// updates to snapshot
let unknown_loro = LoroDocWithoutCounter::new();
@ -99,7 +99,7 @@ impl ActorTrait for CounterActor {
.unwrap();
let new_loro = LoroDoc::new();
new_loro.import(&unknown_loro.export_snapshot()).unwrap();
assert_value_eq(&new_loro.get_deep_value(), &loro.get_deep_value());
assert_value_eq(&new_loro.get_deep_value(), &loro.get_deep_value(), None);
}
fn add_new_container(&mut self, container: Container) {

View file

@ -8478,6 +8478,44 @@ fn diff_calc_fuzz_err_3() {
)
}
#[test]
fn fast_snapshot_0() {
test_multi_sites(
5,
vec![FuzzTarget::All],
&mut [
Handle {
site: 254,
target: 255,
container: 255,
action: Generic(GenericAction {
value: Container(Map),
bool: true,
key: 48059,
pos: 13527611514411810816,
length: 11,
prop: 13527612320720337851,
}),
},
Sync { from: 187, to: 187 },
Sync { from: 187, to: 69 },
Handle {
site: 187,
target: 187,
container: 187,
action: Generic(GenericAction {
value: I32(0),
bool: false,
key: 0,
pos: 0,
length: 0,
prop: 0,
}),
},
],
)
}
#[test]
fn minify() {
minify_error(

View file

@ -6,7 +6,7 @@ use generic_btree::{
};
use loro_common::{Counter, HasId, HasIdSpan, IdFull, IdSpan, Lamport, PeerID, ID};
use rle::HasLength as _;
use tracing::instrument;
use tracing::{instrument, trace};
use crate::{cursor::AbsolutePosition, VersionVector};
@ -82,6 +82,12 @@ impl Tracker {
}
pub(crate) fn insert(&mut self, mut op_id: IdFull, mut pos: usize, mut content: RichtextChunk) {
trace!(
"TrackerInsert op_id = {:#?}, pos = {:#?}, content = {:#?}",
op_id,
&pos,
&content
);
// tracing::span!(tracing::Level::INFO, "TrackerInsert");
if let ControlFlow::Break(_) =
self.skip_applied(op_id.id(), content.len(), |applied_counter_end| {
@ -589,6 +595,7 @@ impl Tracker {
None
}
// #[tracing::instrument(skip(self), level = "info")]
pub(crate) fn diff(
&mut self,
from: &VersionVector,

View file

@ -15,7 +15,7 @@ use loro_common::{
};
use loro_delta::DeltaRope;
use smallvec::SmallVec;
use tracing::instrument;
use tracing::{instrument, trace};
use crate::{
change::Lamport,
@ -146,7 +146,7 @@ impl DiffCalculator {
after_frontiers: Option<&Frontiers>,
container_filter: Option<&dyn Fn(ContainerIdx) -> bool>,
) -> Vec<InternalContainerDiff> {
let s = tracing::span!(tracing::Level::INFO, "DiffCalc");
let s = tracing::span!(tracing::Level::INFO, "DiffCalc", ?before, ?after,);
let _e = s.enter();
let mut use_persisted_shortcut = false;
@ -238,6 +238,7 @@ impl DiffCalculator {
op.atom_len().min((end_counter - op.counter) as usize),
));
op = stack_sliced_op.as_ref().unwrap();
trace!("Trim op");
}
let vv = &mut vv.borrow_mut();
@ -260,6 +261,7 @@ impl DiffCalculator {
// don't checkout if we have already checked out this container in this round
calculator.apply_change(oplog, RichOp::new_by_change(&change, op), None);
} else {
trace!("ApplyChange op = {:#?}", &op);
calculator.apply_change(
oplog,
RichOp::new_by_change(&change, op),

View file

@ -1098,9 +1098,10 @@ impl LoroDoc {
#[instrument(level = "info", skip(self))]
fn checkout_without_emitting(&self, frontiers: &Frontiers) -> Result<(), LoroError> {
info!(
"checkout from={:?} to={:?}",
"checkout from={:?} to={:?} cur_vv={:?}",
self.state_frontiers(),
frontiers
frontiers,
self.oplog_vv()
);
self.commit_then_stop();
let oplog = self.oplog.lock().unwrap();

View file

@ -10,6 +10,7 @@ use std::cmp::Ordering;
use std::collections::{BTreeMap, BTreeSet};
use std::fmt::Display;
use std::sync::Mutex;
use tracing::trace;
use super::change_store::BatchDecodeInfo;
use super::ChangeStore;
@ -532,7 +533,7 @@ impl AppDag {
ans_vv.extend_to_include_vv(dep_vv.iter());
}
ans_vv.insert(node.peer, node.ctr_last());
ans_vv.insert(node.peer, node.ctr_end());
}
node.vv.set(ans_vv.clone()).unwrap();
@ -581,6 +582,11 @@ impl AppDag {
for id in frontiers.iter() {
let x = self.get(*id)?;
let target_vv = self.ensure_vv_for(&x);
trace!(
"FrontiersToVV id = {:#?} target_vv = {:#?}",
&id,
&target_vv
);
vv.extend_to_include_vv(target_vv.iter());
vv.extend_to_include_last_id(*id);
}

View file

@ -283,7 +283,6 @@ impl ContainerState for RichtextState {
unreachable!()
};
trace!("diff = {:#?}, mode = {:?}", richtext, _ctx.mode);
// tracing::info!("Self state = {:#?}", &self);
// PERF: compose delta
let mut ans: TextDiff = TextDiff::new();