Skip to content

Commit

Permalink
refactor: rename gc snapshot to trimmed snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Oct 1, 2024
1 parent c8a6097 commit 5ce0b8b
Show file tree
Hide file tree
Showing 18 changed files with 208 additions and 194 deletions.
7 changes: 5 additions & 2 deletions crates/examples/examples/time_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ pub fn main() {
let snapshot = doc.export(loro::ExportMode::Snapshot);
println!("Snapshot Size {}", ByteSize(snapshot.len()));
println!("mem: {}", get_mem_usage());
let gc_snapshot = doc.export(loro::ExportMode::gc_snapshot(&doc.oplog_frontiers()));
println!("GC Shallow Snapshot Size {}", ByteSize(gc_snapshot.len()));
let trimmed_snapshot = doc.export(loro::ExportMode::trimmed_snapshot(&doc.oplog_frontiers()));
println!(
"GC Shallow Snapshot Size {}",
ByteSize(trimmed_snapshot.len())
);
println!("mem: {}", get_mem_usage());

examples::utils::bench_fast_snapshot(&doc);
Expand Down
2 changes: 1 addition & 1 deletion crates/examples/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn bench_fast_snapshot(doc: &LoroDoc) {
{
println!("======== New snapshot mode with GC =========");
let start = Instant::now();
let snapshot = doc.export(loro::ExportMode::gc_snapshot(&doc.oplog_frontiers()));
let snapshot = doc.export(loro::ExportMode::trimmed_snapshot(&doc.oplog_frontiers()));
let elapsed = start.elapsed();
println!("Fast Snapshot size: {}", ByteSize(snapshot.len()));
println!("Export fast snapshot time: {:?}", elapsed);
Expand Down
14 changes: 7 additions & 7 deletions crates/fuzz/src/crdt_fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ pub fn test_multi_sites_with_gc(
ensure_cov::notify_cov("fuzz_gc");
let mut fuzzer = CRDTFuzzer::new(site_num, fuzz_targets);
let mut applied = Vec::new();
let target_gc_index = actions.len() / 2;
let target_trimmed_index = actions.len() / 2;
for (i, action) in actions.iter_mut().enumerate() {
fuzzer.pre_process(action);
info_span!("ApplyAction", ?action).in_scope(|| {
Expand All @@ -374,15 +374,15 @@ pub fn test_multi_sites_with_gc(
fuzzer.apply_action(action);
});

if i == target_gc_index {
if i == target_trimmed_index {
info_span!("GC 1 => 0").in_scope(|| {
fuzzer.actors[1].loro.attach();
let f = fuzzer.actors[1].loro.oplog_frontiers();
if !f.is_empty() {
ensure_cov::notify_cov("export_gc_snapshot");
ensure_cov::notify_cov("export_trimmed_snapshot");
let bytes = fuzzer.actors[1]
.loro
.export(loro::ExportMode::gc_snapshot(&f));
.export(loro::ExportMode::trimmed_snapshot(&f));
fuzzer.actors[0].loro.import(&bytes).unwrap();
}
})
Expand Down Expand Up @@ -510,9 +510,9 @@ pub fn test_multi_sites_with_gc(
if COUNT.fetch_add(1, std::sync::atomic::Ordering::Relaxed) % 1_000 == 0 {
let must_meet = [
"fuzz_gc",
"export_gc_snapshot",
"gc_snapshot::need_calc",
"gc_snapshot::dont_need_calc",
"export_trimmed_snapshot",
"trimmed_snapshot::need_calc",
"trimmed_snapshot::dont_need_calc",
"loro_internal::history_cache::find_text_chunks_in",
"loro_internal::history_cache::find_list_chunks_in",
"loro_internal::import",
Expand Down
56 changes: 28 additions & 28 deletions crates/fuzz/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9410,7 +9410,7 @@ fn fast_snapshot_5() {
}

#[test]
fn gc_fuzz() {
fn trimmed_fuzz() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand All @@ -9431,7 +9431,7 @@ fn gc_fuzz() {
}

#[test]
fn gc_fuzz_1() {
fn trimmed_fuzz_1() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand All @@ -9455,7 +9455,7 @@ fn gc_fuzz_1() {
}

#[test]
fn gc_fuzz_2() {
fn trimmed_fuzz_2() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand All @@ -9479,7 +9479,7 @@ fn gc_fuzz_2() {
}

#[test]
fn gc_fuzz_3() {
fn trimmed_fuzz_3() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand All @@ -9492,7 +9492,7 @@ fn gc_fuzz_3() {
}

#[test]
fn gc_fuzz_4() {
fn trimmed_fuzz_4() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -9531,7 +9531,7 @@ fn gc_fuzz_4() {
}

#[test]
fn gc_fuzz_5() {
fn trimmed_fuzz_5() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand All @@ -9556,7 +9556,7 @@ fn gc_fuzz_5() {
}

#[test]
fn gc_fuzz_6() {
fn trimmed_fuzz_6() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -9606,7 +9606,7 @@ fn gc_fuzz_6() {
}

#[test]
fn gc_fuzz_8() {
fn trimmed_fuzz_8() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -9656,7 +9656,7 @@ fn gc_fuzz_8() {
}

#[test]
fn gc_fuzz_7() {
fn trimmed_fuzz_7() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand All @@ -9680,7 +9680,7 @@ fn gc_fuzz_7() {
}

#[test]
fn gc_fuzz_9() {
fn trimmed_fuzz_9() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -9738,7 +9738,7 @@ fn gc_fuzz_9() {
}

#[test]
fn gc_fuzz_10() {
fn trimmed_fuzz_10() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -9792,7 +9792,7 @@ fn gc_fuzz_10() {
}

#[test]
fn gc_arb_test() {
fn trimmed_arb_test() {
fn prop(u: &mut Unstructured<'_>, site_num: u8) -> arbitrary::Result<()> {
let xs = u.arbitrary::<Vec<Action>>()?;
if let Err(e) = std::panic::catch_unwind(|| {
Expand All @@ -9810,7 +9810,7 @@ fn gc_arb_test() {
}

#[test]
fn gc_fuzz_11() {
fn trimmed_fuzz_11() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -9878,7 +9878,7 @@ fn gc_fuzz_11() {
}

#[test]
fn gc_fuzz_12() {
fn trimmed_fuzz_12() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -9945,7 +9945,7 @@ fn gc_fuzz_12() {
}

#[test]
fn gc_fuzz_13() {
fn trimmed_fuzz_13() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -10004,7 +10004,7 @@ fn gc_fuzz_13() {
}

#[test]
fn gc_fuzz_14() {
fn trimmed_fuzz_14() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -10053,7 +10053,7 @@ fn gc_fuzz_14() {
}

#[test]
fn gc_fuzz_15() {
fn trimmed_fuzz_15() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -10130,7 +10130,7 @@ fn gc_fuzz_15() {
}

#[test]
fn gc_fuzz_16() {
fn trimmed_fuzz_16() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -10193,7 +10193,7 @@ fn gc_fuzz_16() {
}

#[test]
fn gc_fuzz_17() {
fn trimmed_fuzz_17() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -10273,7 +10273,7 @@ fn gc_fuzz_17() {
}

#[test]
fn gc_fuzz_18() {
fn trimmed_fuzz_18() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -10367,7 +10367,7 @@ fn gc_fuzz_18() {
}

#[test]
fn gc_fuzz_19() {
fn trimmed_fuzz_19() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -10568,7 +10568,7 @@ fn gc_fuzz_19() {
}

#[test]
fn gc_fuzz_20() {
fn trimmed_fuzz_20() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -10791,7 +10791,7 @@ fn gc_fuzz_20() {
}

#[test]
fn gc_fuzz_21() {
fn trimmed_fuzz_21() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -10955,7 +10955,7 @@ fn gc_fuzz_21() {
}

#[test]
fn gc_fuzz_22() {
fn trimmed_fuzz_22() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -11049,7 +11049,7 @@ fn gc_fuzz_22() {
}

#[test]
fn gc_fuzz_24() {
fn trimmed_fuzz_24() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -11255,7 +11255,7 @@ fn detached_editing_failed_case_0() {
}

#[test]
fn gc_fuzz_23() {
fn trimmed_fuzz_23() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -11373,7 +11373,7 @@ fn gc_fuzz_23() {
}

#[test]
fn gc_fuzz_25() {
fn trimmed_fuzz_25() {
test_multi_sites_with_gc(
5,
vec![FuzzTarget::All],
Expand Down Expand Up @@ -11409,7 +11409,7 @@ fn gc_fuzz_25() {
}

#[test]
fn gc_fuzz_unknown() {
fn trimmed_fuzz_unknown() {
test_multi_sites(
5,
vec![FuzzTarget::All],
Expand Down
12 changes: 7 additions & 5 deletions crates/loro-ffi/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,11 @@ impl LoroDoc {
})
}

pub fn export_gc_snapshot(&self, frontiers: &Frontiers) -> Vec<u8> {
pub fn export_trimmed_snapshot(&self, frontiers: &Frontiers) -> Vec<u8> {
self.doc
.export(loro::ExportMode::GcSnapshot(Cow::Owned(frontiers.into())))
.export(loro::ExportMode::TrimmedSnapshot(Cow::Owned(
frontiers.into(),
)))
}

pub fn export_state_only(&self, frontiers: Option<Arc<Frontiers>>) -> Vec<u8> {
Expand Down Expand Up @@ -703,7 +705,7 @@ pub enum ExportMode {
Snapshot,
Updates { from: VersionVector },
UpdatesInRange { spans: Vec<IdSpan> },
GcSnapshot { frontiers: Frontiers },
TrimmedSnapshot { frontiers: Frontiers },
StateOnly { frontiers: Option<Frontiers> },
}

Expand All @@ -717,8 +719,8 @@ impl From<ExportMode> for loro::ExportMode<'_> {
ExportMode::UpdatesInRange { spans } => loro::ExportMode::UpdatesInRange {
spans: Cow::Owned(spans),
},
ExportMode::GcSnapshot { frontiers } => {
loro::ExportMode::GcSnapshot(Cow::Owned(frontiers.into()))
ExportMode::TrimmedSnapshot { frontiers } => {
loro::ExportMode::TrimmedSnapshot(Cow::Owned(frontiers.into()))
}
ExportMode::StateOnly { frontiers } => {
loro::ExportMode::StateOnly(frontiers.map(|x| Cow::Owned(x.into())))
Expand Down
Loading

0 comments on commit 5ce0b8b

Please sign in to comment.